Skip to main content
7-Bedrock
September 9, 2024
Question

Time Breakout Chart

  • September 9, 2024
  • 2 replies
  • 797 views
I am using ThingWorx Platform Release 9.3 and DatecodeSP9

I am using the Bar Chart widget and using it as a column chart. I need help developing the service to get the data into an infotable that will have runtime in minutes for every 20 minutes with planned downtime in certain columns (3-4). I have an example of what the customer wants it to look like.

    2 replies

    16-Pearl
    September 10, 2024

    Hi @wtaylor1 , I think you can try to use the Auto Refresh function to refresh the data source service to have it updated every 20 minutes.

    wtaylor17-BedrockAuthor
    7-Bedrock
    September 12, 2024

    Here is the example of the chart I am trying to populate:

     

    wtaylor1_0-1726146899546.png

     

     

    Here is the Here is the code I am trying to use. 

    // Create a new service in ThingWorx

    // Name: CreateRuntimeInfoTable

    // Inputs: MashDate & Runtime_Min_Total

    // Outputs: INFOTABLE (DataShape: RuntimeDataShape)

     

    var result = Resources['InfoTableFunctions'].CreateInfoTableFromDataShape({

        infoTableName: "InfoTable",

        dataShapeName: "OEETImeBreakChart_DS",

      });

     

      // Define the start time and end time

      var startTime = MashupDate;

      startTime.setHours(6, 0, 0, 0); // 6:00 AM

      var endTime = new Date();

      endTime.setHours(18, 0, 0, 0); // 6:00 PM

     

      // Define the interval in milliseconds (20 minutes)

      var interval = 20 * 60 * 1000;

     

      // Loop through the time range and add rows to the InfoTable

      for (var time = startTime.getTime(); time <= endTime.getTime(); time += interval) {

          // Query the Value Stream for the runtime value at the specific time

          var query = {

              oldestFirst: true,

              maxItems: 1,

              query: {

                  filters: {

                    type: "AND",

                    filters: [

                        {

                        type: "EQ",

                        fieldName: "timestamp",

                        value: dateFormat(new Date(time), "00:00:000"),

                        },

                        {

                        type: "EQ",

                        fieldName: "Runtime_Min_Total",

                        value: Things["KepConn_TruLaserWeldNPP"].Runtime_Min_Total,

                        },

                    ],

                }

            },

          };

         

          var streamEntries = Things["KepConn_TruLaserWeldNPP"].QueryNamedPropertyHistory(query);

          var runtimeValue = 0;

          if (streamEntries.rows.length > 0) {

              runtimeValue = streamEntries.rows[0].Runtime_Min_Total; // Replace 'Runtime' with the actual property name

          }

          var row = {

              timestamp: new Date(time),

              Runtime_Min_Total: runtimeValue

          };

          result.AddRow(row);

      }

      // Return the InfoTable

      var output = result;