2 Replies Latest reply on Nov 25, 2015 10:47 AM by qn RSS
    brianf Newbie

    Data Interrogation in Widgets

    I am having some trouble getting my mashup to display what I want in regards to batch information. I have a ProductionData stream that, among other things, captures the product ID, energy consumption and water consumption. I have stream entries being created randomly, but the product ID is always one of 4 numbers. I was hoping to show pie charts for total energy and water consumption by product and I can't seem to figure out how to do that. I can get it to show each individual record's values and product ID, but I can't ever get it to show 4 slices. 


    Similarly I was hoping should show mix, max and average values by product. I figure if I have to, I can create these values on a Thing and then just display from there, but I didn't know if there was an easier / better way. I also don't think that would necessarily work for the pie charts.


    Thanks for your help!



      • Data Interrogation in Widgets
        andyb Explorer

        Remember that the widgets themselves are really intended to be visual aids rather than data processors...and with that you likely will need to structure your data feed to them to facilitate what you want. The best way to accomplish this would be to create a service on a Thing in the IDE that feeds your desired data structure to the mashup by using infotable functions from the script resources. For example, on the Acme Manufacturing demo we are similarly capturing production data in a stream and in order to 'feed' the sustainability bar chart we used the script below in a service that returns the data in the needed format. Note the use of InfoTableFunctions to derive and aggregate fields to create the x-axis "newDate" field for the grouping in the aggregate functions...

         

        //get all stream entries - not super efficient, may want to use query here to pre-filter?

        result = Things['ProductionDataStream'].GetStreamEntriesWithData({"maxItems":999999});


        var plantSearch = "";


        //get the lines in the region/plant based on the filter parameter passed into the service

        var containedThings = Networks['AcmeNetwork'].GetSubNetworkConnections({"start":filter});


        for each (var line in containedThings.rows) {

        plantSearch = plantSearch + line.from + ";";

        }


        logger.warn("PLANT SEARCH: " + plantSearch);


        plantSearch = plantSearch.substr(0,plantSearch.length - 1);

        result = Resources['InfoTableFunctions'].SetFilter({"t":result, "fieldName":"source", "matchValues":plantSearch});


        result = Resources['InfoTableFunctions'].DeriveFields({"t":result, "columns":"newDate", "types":"NUMBER", "expressions":"Number(timestamp.toString().split(' ')[2])-4"});

        result = Resources['InfoTableFunctions'].Aggregate({"t":result, "columns":"waterUsage,quantity,energyUsage", "aggregates":"SUM,SUM,SUM", "groupByColumns":"newDate"});

        result = Resources['InfoTableFunctions'].DeriveFields({"t":result, "columns":"WaterSus,EnergySus", "types":"NUMBER,NUMBER", "expressions":"SUM_waterUsage/SUM_quantity,1+SUM_energyUsage/SUM_quantity"});




        • Re: Data Interrogation in Widgets
          qn Communicator

          Hi, you'll need new service which feeds the data to the chart.

           

          First chart:

          I have a ProductionData stream that, among other things, captures the product ID, energy consumption and water consumption. I have stream entries being created randomly, but the product ID is always one of 4 numbers. I was hoping to show pie charts for total energy and water consumption by product and I can't seem to figure out how to do that.

          - DataShape: ProductID, value (total enerdy and water consumption)

          - Service returning an InfoTable based on the new DataShape above. This service would use some query to calculate the sum

               - QueryPropertiesHistory / GetStreamEntriesWithData

               - "Aggregate" : to sum, or add the values manually

               - New InfoTable from the new DataShape. Add 4 rows for 4 product ID with the values calculated.

          - Bind the result to the PieChart

           

          Second chart:

          Similarly I was hoping should show mix, max and average values by product. I figure if I have to, I can create these values on a Thing and then just display from there, but I didn't know if there was an easier / better way. I also don't think that would necessarily work for the pie charts.

           

          I had this situation too. So there are two ways like you said:

          1) New Thing's properties

          - Calculate the max, average values...

          - Update the properties' values

          - Bind directly the properties' value to the chart

          - If it's a PieChart for 4 products, a new service which fetch all the properties' values and which return an InfoTable based on the DataShape of the chart above would be needed.

           

          2) A new service which calulate on the fly the max, average values and return the InfoTable of values