Suppose, you want to create a rest api method for different car brands (BMW, AUDI, MERCEDES).
You also want to create a new car, including the car brand as property.
How can I validate if the car brand exist, before creating a new car in the table?
From the front-end, you want a dropdown list (select / option).
From the backend you want to validate the input.
What is the best practice for this?
The get car brands method will read the dynamodb table too often, creating hot partitions.
The API call to the DynamoDB table when attempting to create a new car brand would be to use a Conditional Put. That way you would say "only insert this new car brand if it does not exist already".
For the read of list of car brands, if this is something in your UI that is presented thousands of times per second, then i'd have an out of band lambda function that updates the list only when a new car brand is input (use DynamoDB Streams). I would put that list X number of items all with the same data, but different PKs. For example: pk = "CarBrandList_0" all the way through pk = "CarBrandList_5". In your code to get the car brand list, you give it the PK and a random number between 0 and 5. You have now avoided creating hot keys
Related
I am new to blue prism. I have a scenario where I am giving input (passengers details for traveling) to a travel portal and based on the input its generating a booking reference number, total cost etc. Now I want to read all the outputs into a collection but the problem is data is not tabular (cant use Get Table in read component). Its just the details of travel which are populating into textboxes. Please find attached the screen shot to have more clarity on this.
How to achieve this? Any leads will be appreciated.
Based on the screenshot you've provided, this is part of the Blue Prism Advanced Consolidation Exercise ("BPTravel").
"Get Table" won't work on this data because it is not a table. As you've mentioned, the data is presented in a series of textboxes.
The way to tabularize this data would be to create a Collection in your Process and manually define each of the Field Names in the collection, then read each text field in individually to the correct column in the collection.
Read each text box data into data item. Create a named collection (i.e Collection with pre-defined column name). Loop through the collection.column_name(You will be getting column name as collection by using Utility - Collection Manipulation action and get the column names) and first add a row to collection and assign values to collection fields
I have a list of unique customers who have made transactions over a year (Jan – Dec). They have bought products using 3 different methods (card, cash, check). My goal is to build a multi-classification model to predict the method pf payment.
To do this I am engineering some Recency and Frequency features into my training data, but am having trouble with the following frequency count because the only way I know how to do it is in Excel using the Countifs and SUMIFs functions, which are inhibitingly slow. If someone can help and/or suggest another solution, it would be very much appreciated:
So I have a data set with 3 columns (Customer ID, Purchase Date, and Payment Type) that is sorted by Purchase Date then Customer ID. How do I then get a prior frequency count of payment type by date that does not include the count of the current row transaction or any future transactions that are > the Purchase Date. So basically I want to do a running count of each payment option, based on a unique Customer ID, and a date range that is < purchase date of that training row. In my head I see it as “crawling” backwards through the transactions and counting. Simplified screenshot of data frame is below with the 3 prior count columns I am looking to generate programmatically.
Screenshot
This gives you the answer as a list of CustomerID, PurchaseDate, PaymentMethod and prior counts
SELECT CustomerID, PurchaseDate, PaymentMethod,
(
select count(CustomerID) from History T
where
T.CustomerID=History.CustomerID
and T.PaymentMethod=History.PaymentMethod
and T.PurchaseDate<History.PurchaseDate
)
AS PriorCount
FROM History;
You can save this query and use it as the source for a crosstab query to get the columnar format you want
Some notes:
I assumed "History" as the source table name - you can change the query above to use the correct source
To use this as a query, open a new query in design view. Close the window that asks what tables the query is to be built on. Open the SQL view of the query design - like design view, but it shows the SQL instead of the normal design interface. Copy the above into the SQL view.
You should now be able to switch to datasheet view and see the results
When the query is working to your satisfaction, save it with any appropriate name
Open a new query in design view
When you get the list of tables to include, switch to the list of queries and include the query you just saved
Change the query type to crosstab and update the query as needed to select rows, columns and values - look up "access crosstab queries" if you need more help.
Another tip to see what is happening here:
You can take the subquery - the parts inside the () above - and make
just that statement into it's own query, excluding the opening and closing (). Then you can look at it's design view to see what it does
Save it with an appropriate name and put it into the query above in place of the statement in () - then you can look at the design view.
Sometimes it's easier to visualize and learn from 2 queries strung together this way than to work with sub queries.
Hi all,
I have 3 tables in an access 2010 database:
Crew: CrewID; Name; Adres;...
Voyage: VoyageId; Voyage name; Departure harbour; Arrival harbour
Crewlist: CrewlistId, VoaygeId, CrewId, Rank
The VoaygeId and CrewId from the Crewlist table are linked (relation) to the autonumber ID's from tables 2 and 1.
My first and main question is: Upon boarding everyone has to ‘sign in’ selecting the voyage and there name, and assign them a roll (of to be donde by the responsible officer). How can I make a form that lets the users browse through the voyagenames and crewnames in stead of the ID’s uses in the ‘mother’ table (table 3: Crewlist)
2nd question: how can I make sure that someone isn’t enrolled twice for the same voyage (adding same voyagenumber and same crewId number in crewlist). This would preferably be blocked upon trying to add the same person a second time on a voyage.
To prevent duplicates in Crewlist, add a unique index to the table on both CrewId and VoyageId
It would be a good idea to add relationships and enforce referential integrity
You are now in a position to use the wizards to create a form based on Voyage and a subform based on CrewList with a combobox based on Crew
There are a number of refinements you could add.
Make sure you do not use reserved words like Name and do not put spaces in field names. You will thank yourself later.
See also create form to add records in multiple tables
I have just started learning CakePHP and Need help in this situation.
I have one table(Student) and corresponding model (Student) which has one property called 'Educational Qualification' which can have multiple values (MBA, MCA, BCA, BA, PHD) so i have created a master table which contains list of all the degrees.
Now When a Student is going to register himself/herself he has to choose multiple options in qualifications.
I want to get DegreeMst data from database in my View as multiple options.
My question is that in this manytomany relationship Do i have to create a new model DegreeMst and then create ManytoMany relationship with Student model .
Or Can i do this without creating new Model DegreeMst
First and foremost, if you find yourself needing to fetch data from a table without creating a model in an MVC framework, there's a good chance you're doing something wrong.
If you've really only got 5 possible values (MBA, MCA, BCA, BA, PHD), I'd probably just make them 5 separate tinyint(1) fields in your table, like has_mba, has_mca, etc. Then just show each in your view as a separate checkbox. That's probably the simplest way.
If you don't want to do that, and you definitely want a separate DegreeMst table, then what you'll want is a hasAndBelongsToMany relationship.
You'll need a separate join table, something like students_degreemsts, with a student_id and a degreemst_id columns. You don't need to create a Model for the joins table.
Once it's set up, the code in your view to output the checkboxes will be something like:
echo $this->Form->input('Student.DegreeMst',array('label'=>'Select your degrees','multiple'=>'true'));
UPDATE
You'll need 3 database tables, and 2 models. You know about Many-to-Many (ie, what Cake calls hasAndBelongsToMany) relationships and joins tables?
In your database, you'll need 3 tables, named according to CakePHP convetions:
students (id, name, address, other_field)
degrees (id, name, another_field)
students_degrees (id, student_id, degree_id)
That last table is your joining table, and it should contain those 2 foreign keys to the students and degrees table. In CakePHP, you don't need a Model or Controller for the joining table.
You obviously do need a model for your Students table, which is where you'll define your hasAndBelongsToMany relationship:
public $hasAndBelongsToMany = array(
'Degree' => array(
'className' => 'Degree',
'joinTable' => 'students_degrees',
'foreignKey' => 'student_id',
'associationForeignKey' => 'degree_id',
),
);
You also need a Model for your degrees table, but you don't neccessarily have to define a hasAndBelongsToMany relationship again in that model, unless you need it.
We have a db driven asp.net /sql server website and would like to investigate how we can allow users to create a new database category and fields - is this crazy?. Is there any examples of such organic websites out there - the fact that I havent seen any maybe suggest i am?
Interested in the best approach which would allow some level of control by Admin.
I've implemented things along these lines with a dictionary table, rather than a more traditional table.
The dictionary table might look something like this:
create table tblDictionary
(id uniqueidentifier, --Surrogate Key (PK)
itemid uniqueidentifier, --Think PK in a traditional database
colmn uniqueidentifier, --Think "column name" in a traditional database
value nvarchar, --Can hold either string or number
sortby integer) --Sorting columns may or may not be needed.
So, then, what would have been one row in a traditional table would become multiple rows:
Traditional Way (of course I'm not making up GUIDs):
ID Type Make Model Year Color
1 Car Ford Festiva 2010 Lime
...would become multiple rows in the dictionary:
ID ITEMID COLUMN VALUE
0 1 Type Car
1 1 CarMake Ford
2 1 CarModel Festiva
3 1 CarYear 2010
4 1 CarColor Lime
Your GUI can search for all records where itemid=1 and get all of the columns it needs.
Or it can search for all records where itemid in (select itemid from tblDictionary where column='Type' and value='Car' to get all columns for all cars.
In theory, you can put the user-defined types into the same table (Type='Type') as well as the user-defined columns that that Type has (Type='Column', Column='ColumnName'). This is where the sortby column comes into it - to help build the the GUI in the correct order, if you don't want to rely on something else.
A number of times, though, I have felt that storing the user-defined dictionary elements in the dictionary was a bit too much drinking-the-kool-aid. Those can be separate tables because you already know what structure they need at design time. :)
This method will never have the speed or quality of reporting that a traditional table would have. Those generally require the developer to have pre-knowledge of the structures. But if the requirement is flexibility, this can do the job.
Often enough, what starts out as a user-defined area of my sites has had a later project to normalize the data for reporting, etc. But this allows users to get started in a limited way and work out their requirements before engaging the developers.
After all that, I just want to mention a few more options which may or may not work for you:
If you have SharePoint, users already have the ability to create
their own lists in this way.
Excel documents in a shared folder that are saved in such a way
to allow multiple simultaneous edits would also serve the purpose.
Excel documents, stored on the webserver and accessed via ODBC
would also serve as single-table databases like this.