Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Learn how to create systems to handle logistics and production distribution
This project will introduce complex aspects of the ThingWorx Composer and solution building.
Following the steps in this guide, you will develop your own IoT application or get a jump start in how to utilize ThingWorx for your needs.
We will teach you how to create a focused rules engine or service level logic to be used with the ThingWorx Platform.
NOTE: This guide's content aligns with ThingWorx 9.3. The estimated time to complete All parts of this guide is 60 minutes.
This guide builds on the knowledge gained in Factory Line Automation.
Download FoodIndustry.zip attached to this guide and extract/import the contents.
For the completed example, download the automated_food_industry.zip, also attached here. This download provides three Users and a Security Group. Please watch your count for Users or the import could fail.
In this tutorial we continue with our real-world scenario for the Fizos food company. We already have our factory data, and automated cooking processed for our sausage product lines. Now, let's see how we can use the data model we built before into making a smarter system of deliveries. We will take into consideration the locations of our factories, the vehicles we have available, our customers (stores and individuals), and see how much we can automate.
One important part of being in business is having a product that people or companies want to buy. You'll need a way to track these sales and we're going to start with doing just that. Let's create our order shapes and tables.
In the ThingWorx Composer, click the + New in the top left of the screen.
Select Data Shape in the dropdown.
In the name field, enter Fizos.Orders.DataShape and select a Project (ie, PTCDefaultProject). All of our orders will be based off this Data Shape.
Name | Base Type | Aspects | Description |
ID | Integer | 0 minimum, primary key, default 0 | Row identifier |
CustomerId | Integer | N/A | String used as unique identifer across multiple platforms |
Type | String | N/A | Type of customer (individual or another company) |
Factors | Tag | Data Tag | This will hold the different type of data points or tags that will help to analyze a customer's order |
Products | Infotable | Data Shape: Fizos.DataShapes.Products | List of orders |
TotalPrice | Number | Minimum 0 | Price of the order |
Status | String | N/A | The current order status (ie, processed, shipped, completed, etc) |
Completed | Boolean | N/A | Whether the order has been completed |
The Properties for the Fizos.Orders.DataShape Data Shape are as follows:
6. In the ThingWorx Composer, click the + New in the top left of the screen.
7. Select Data Table in the dropdown and select Data Table in the prompt.
8. In the name field, enter Fizos.Orders.DataTable. Our differing types of customers will fall under this template.
9. For the Data Shape field, select Fizos.Orders.DataShape and select a Project (ie, PTCDefaultProject).
10. Click Save then Edit to store all changes now.
11. This Entity will be used to house our data and provide assistance with our analytics.
We now have our model of orders ready to be stored. Of course, our orders are simplified. We can add much more to get them rolling, but the most important aspect right now is our Factors field. While we know a ton of information about customers, we can also analyze what kind of products they're buying and their ordering habits.
Let's start with our customers. We created the data shape for customers before when we decided to put them in data tables. This time, we'll add some customers, but also expand on our modeling of what a customer entails. In this step, as with all the steps in this learning path, you can go as granular as you like. If you'd like to make 100 data tags, then it helps with understanding your customer, but it might be too much based on your goals. Remember, more data means more processing of that data.
These data tags will help us decide priority, relationships, and much more.
In the ThingWorx Composer, click the + New in the top left of the screen.
Select Data Tag in the dropdown.
In the name field, enter Fizos.CustomerTags and select a Project (ie, PTCDefaultProject).
Name |
Store |
Individual |
Office |
Company |
FirstTime |
Repeat |
Partner |
LongTerm |
ShortTerm |
Old |
MiddleAged |
Young |
Loyal |
We just added a number of data tags based on customer type, age, times the customer has bought from us, etc. This will help us with characterizing and modeling our customers. We'll also cheat a bit and use these data tags to help with deliveries. If you're a partment brand, we might work faster to send goods. For example, the code below returns the list of orders that were made by partners. We can add this as a service to our Fizos.Logistics template.
var index; var customerId; var partnerObj = {}; var query = { "filters": { "type": "EQ", "fieldName": "Completed", "value": false } }; var orders = Things["Fizos.Orders.DataTable"].QueryDataTableEntries({ query: query }); var customers = Things["Fizos.Customers.DataTable"].GetDataTableEntries(); var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({ infoTableName : "InfoTable", dataShapeName : "Fizos.Orders.DataShape" }); var partners = Resources["InfoTableFunctions"].TagFilter({ inclusive: true, fieldName: "Factors", t: customers, tags: "Fizos.CustomerTags:Partner" }); for(index = 0; index < partners.rows.length; index++) { customerId = partners.rows[index].ID; partnerObj[customerId] = true; } for(index = 0; index < orders.rows.length; index++) { customerId = orders.rows[index].CustomerId; if(partnerObj[customerId] === true) { var newEntry = new Object(); newEntry.ID = orders.rows[index].ID; newEntry.CustomerId = orders.rows[index].CustomerId; newEntry.Type = orders.rows[index].Type; newEntry.Products = orders.rows[index].Products; newEntry.Factors = orders.rows[index].Factors; newEntry.TotalPrice = orders.rows[index].TotalPrice; result.AddRow(newEntry); } }
This code will retrieve all orders that are not in a completed state. It will then figure out which orders are for partners and return those orders. You can see in this simple example how Data Tags can be used.
Click here to view Part 2 of this guide.