cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Automated Distribution and Logistics Part 1

No ratings

 

Learn how to create systems to handle logistics and production distribution

 

GUIDE CONCEPT

 

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.

 

 

YOU'LL LEARN HOW TO

 

    • Create automated logistical processes
    • Use Services, Alerts, and Subscriptions to handle processes without human interaction
    • Integrating complex logic with straight forward step by step systems

 

NOTE: This guide's content aligns with ThingWorx 9.3. The estimated time to complete All parts of this guide is 60 minutes. 

 

 

Step 1: Examples and Strategy

 

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.

 

Setting Up Orders

 

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.

 

  1. In the ThingWorx Composer, click the + New in the top left of the screen.

     

    select_new.png

     

  2. Select Data Shape in the dropdown.

     

    create_new_datashape.png

     

  3. 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.

     

    new_order_datashape.png

     

  4. Click Save then Edit to store all changes now.

  5. Add the list of properties below:

NameBase TypeAspectsDescription
IDInteger0 minimum, primary key, default 0Row identifier
CustomerIdIntegerN/AString used as unique identifer across multiple platforms
TypeStringN/AType of customer (individual or another company)
FactorsTagData TagThis will hold the different type of data points or tags that will help to analyze a customer's order
ProductsInfotableData Shape: Fizos.DataShapes.ProductsList of orders
TotalPriceNumberMinimum 0Price of the order
StatusStringN/AThe current order status (ie, processed, shipped, completed, etc)
CompletedBooleanN/AWhether the order has been completed

 

The Properties for the Fizos.Orders.DataShape Data Shape are as follows:

 
order_datashape_fields.png

6. In the ThingWorx Composer, click the + New in the top left of the screen.

select_new.png

 

7. Select Data Table in the dropdown and select Data Table in the prompt.


create_new_datatable.png

 

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).

 

new_order_datatable.png

 

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.

 

 

Step 2: Expanding Customer Models 

 

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.

 

Creating Customer Data Tags

 

These data tags will help us decide priority, relationships, and much more.

 

  1. In the ThingWorx Composer, click the + New in the top left of the screen.

     

    select_new.png

     

  2. Select Data Tag in the dropdown.

     

    create_new_datatag.png

     

  3. In the name field, enter Fizos.CustomerTags and select a Project (ie, PTCDefaultProject).

  4. Check the Dynamic checkbox. This allows for new vocabulary terms to be created during runtime.


    new_customer_tag.png

     

  5. Click on the Vocabulary Terms tab, and add the following terms and then add as many more as you see fit:

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.

Version history
Last update:
‎Nov 11, 2022 10:23 AM
Updated by:
Labels (1)
Attachments
Contributors