{
  "productInfo" : {
    "company" : "HighByte",
    "product" : "IntelligenceHub",
    "version" : "4.3.3",
    "build" : "2026.1.5.1",
    "stage" : "Release"
  },
  "project" : {
    "version" : 12,
    "connections" : [ {
      "name" : "MQTT_KB",
      "uri" : "mqtt://localhost:1885",
      "tags" : [ "ProductionTransactionExample" ],
      "writes" : {
        "flattenModeledValues" : false
      },
      "subscriptions" : { },
      "storeForward" : {
        "enabled" : false,
        "maxEntries" : 100,
        "waitOnFailureInterval" : {
          "duration" : 1,
          "units" : "Seconds"
        }
      },
      "settings" : {
        "connectionTimeoutSeconds" : 10,
        "keepAliveSeconds" : 60,
        "requestTimeoutMS" : 5000,
        "cleanSession" : true
      }
    }, {
      "name" : "SQLite_KB",
      "uri" : "jdbc.sqlite://SQLite_KB",
      "tags" : [ "ProductionTransactionExample" ],
      "writes" : {
        "flattenModeledValues" : false
      },
      "subscriptions" : { },
      "storeForward" : {
        "enabled" : false,
        "maxEntries" : 100,
        "waitOnFailureInterval" : {
          "duration" : 1,
          "units" : "Seconds"
        }
      },
      "settings" : {
        "strategy" : {
          "type" : "default"
        },
        "database" : "../appData/KB.db"
      }
    } ],
    "inputs" : [ {
      "name" : "DeleteProductionTransactionExample",
      "connection" : "SQLite_KB",
      "type" : "jdbc.sqlite",
      "qualifier" : {
        "query" : "Delete from ProductionTransactionExample"
      },
      "cacheLifetime" : {
        "enabled" : false
      },
      "template" : {
        "type" : "Off"
      },
      "parameters" : {
        "type" : "EmptyParameters"
      }
    }, {
      "name" : "ProductionTransactionExample",
      "connection" : "SQLite_KB",
      "type" : "jdbc.sqlite",
      "qualifier" : {
        "query" : "Select * from ProductionTransactionExample"
      },
      "cacheLifetime" : {
        "enabled" : false
      },
      "template" : {
        "type" : "Off"
      },
      "parameters" : {
        "type" : "EmptyParameters"
      }
    }, {
      "name" : "ProductionTransactionExample_ByStationByShiftByStateFilterDate",
      "connection" : "SQLite_KB",
      "type" : "jdbc.sqlite",
      "qualifier" : {
        "query" : "SELECT     Sum(Quantity) AS Quantity,\n    Sum(EndDate - StartDate) / 60000.0 as DurationMinutes,\n    Station,\n    Shift, \n    State \nFROM ProductionTransactionExample\nWHERE StartDate >= {{this.StartTimestamp}}\n  AND EndDate <  {{this.EndTimestamp}}\nGROUP BY   Station,\n    Shift, \n    State "
      },
      "cacheLifetime" : {
        "enabled" : false
      },
      "template" : {
        "type" : "Off"
      },
      "parameters" : {
        "type" : "inline",
        "model" : {
          "name" : "params",
          "tags" : [ ],
          "attributes" : [ {
            "attributeType" : "Internal",
            "name" : "StartTimestamp",
            "nullable" : false,
            "required" : false,
            "array" : false,
            "defaultValue" : 1769922000000,
            "internalType" : "String"
          }, {
            "attributeType" : "Internal",
            "name" : "EndTimestamp",
            "nullable" : false,
            "required" : false,
            "array" : false,
            "defaultValue" : 1769969756240,
            "internalType" : "String"
          } ]
        }
      }
    } ],
    "outputs" : [ {
      "name" : "ProductionTransactionExample",
      "connection" : "SQLite_KB",
      "type" : "jdbc.sqlite",
      "qualifier" : {
        "writeType" : "insert",
        "createOption" : "create_and_update",
        "breakupArrays" : false,
        "tableCacheInterval" : {
          "duration" : 1,
          "units" : "Hours"
        },
        "table" : "ProductionTransactionExample"
      }
    } ],
    "modeling" : {
      "models" : [ {
        "name" : "ProductionTransactionExample",
        "tags" : [ "ProductionTransactionExample" ],
        "attributes" : [ {
          "attributeType" : "Internal",
          "name" : "ProductionID",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        }, {
          "attributeType" : "Internal",
          "name" : "OrderNumber",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        }, {
          "attributeType" : "Internal",
          "name" : "MaterialNumber",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        }, {
          "attributeType" : "Internal",
          "name" : "SerialNumber",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        }, {
          "attributeType" : "Internal",
          "name" : "Station",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        }, {
          "attributeType" : "Internal",
          "name" : "State",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        }, {
          "attributeType" : "Internal",
          "name" : "Quantity",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Int32"
        }, {
          "attributeType" : "Internal",
          "name" : "StartDate",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "DateTime"
        }, {
          "attributeType" : "Internal",
          "name" : "EndDate",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "DateTime"
        }, {
          "attributeType" : "Internal",
          "name" : "Shift",
          "nullable" : false,
          "required" : false,
          "array" : false,
          "internalType" : "Any"
        } ]
      } ],
      "instances" : [ ]
    },
    "conditions" : [ ],
    "functions" : [ ],
    "tags" : [ {
      "name" : "ProductionTransactionExample"
    } ],
    "pipelines" : [ {
      "name" : "ProductionTransactionExample_Insert",
      "tags" : [ "ProductionTransactionExample" ],
      "inputStages" : [ "SetCurrentDate" ],
      "stages" : [ {
        "name" : "SetCurrentDate",
        "display" : {
          "position" : {
            "x" : 240,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".JavaScriptTransformConfig",
          "transformExpression" : "const currentDate = new Date();\r\nstage.setMetadata(\"CurrentDate\", currentDate);\r\nstage.setValue(event.value);"
        },
        "outputs" : [ "GetPrevStationMessage" ]
      }, {
        "name" : "PrevStationTransaction",
        "display" : {
          "position" : {
            "x" : 1140,
            "y" : 67
          }
        },
        "config" : {
          "type" : ".SwitchConfig",
          "switchCases" : [ {
            "expression" : "return Boolean(event.metadata.hasOwnProperty('PrevStationTransaction'))",
            "outputs" : [ "PrevStationTransactionModel" ],
            "description" : "Running"
          }, {
            "expression" : "return true",
            "outputs" : [ ],
            "description" : "Pause"
          } ],
          "evaluationType" : "onFirst"
        },
        "outputs" : [ ]
      }, {
        "name" : "PrevStationTransactionModel",
        "display" : {
          "position" : {
            "x" : 1590,
            "y" : 67
          }
        },
        "config" : {
          "type" : ".ModelConfig",
          "model" : "ProductionTransactionExample",
          "objectName" : "PrevStationTransactionModel",
          "initExpression" : "",
          "attributes" : [ {
            "name" : "ProductionID",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.ProductionID;"
            }
          }, {
            "name" : "OrderNumber",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.OrderNumber;"
            }
          }, {
            "name" : "MaterialNumber",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.MaterialNumber;"
            }
          }, {
            "name" : "SerialNumber",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.Quantity;\r\n"
            }
          }, {
            "name" : "Station",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.Station;"
            }
          }, {
            "name" : "State",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.State;"
            }
          }, {
            "name" : "Quantity",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.Quantity;"
            }
          }, {
            "name" : "StartDate",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.StartDate"
            }
          }, {
            "name" : "EndDate",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.CurrentDate;"
            }
          }, {
            "name" : "Shift",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.PrevStationTransaction.Shift;"
            }
          } ]
        },
        "outputs" : [ "StoreInSQLite" ]
      }, {
        "name" : "SetCalcShift",
        "display" : {
          "position" : {
            "x" : 1140,
            "y" : -67
          }
        },
        "config" : {
          "type" : ".JavaScriptTransformConfig",
          "transformExpression" : "// get current hour from CurrentDate\r\nconst hour = event.metadata.CurrentDate.getHours(); \r\n// if hour less than 8, Shift1\r\nif (hour < 8)\r\n{\r\n    stage.setMetadata(\"Shift\", \"Shift1\");\r\n}\r\n// if hour less than 16 (and greater than or equal 8), Shift2\r\nelse if (hour < 16)\r\n{\r\n    stage.setMetadata(\"Shift\", \"Shift2\");\r\n}\r\n// shift 3 (greater than or equal 16)\r\nelse\r\n{\r\n    stage.setMetadata(\"Shift\", \"Shift3\");\r\n}\r\n\r\nstage.setValue(event.value);"
        },
        "outputs" : [ "CurrentStationTransactionModel" ]
      }, {
        "name" : "CurrentStationTransactionModel",
        "display" : {
          "position" : {
            "x" : 1590,
            "y" : -67
          }
        },
        "config" : {
          "type" : ".ModelConfig",
          "model" : "ProductionTransactionExample",
          "objectName" : "CurrentStationTransactionModel",
          "initExpression" : "",
          "attributes" : [ {
            "name" : "ProductionID",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.ProductionID;"
            }
          }, {
            "name" : "OrderNumber",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.OrderNumber;"
            }
          }, {
            "name" : "MaterialNumber",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.MaterialNumber;"
            }
          }, {
            "name" : "SerialNumber",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.Quantity;\r\n"
            }
          }, {
            "name" : "Station",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.Station;"
            }
          }, {
            "name" : "State",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.State;"
            }
          }, {
            "name" : "Quantity",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.value.Quantity;"
            }
          }, {
            "name" : "StartDate",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.CurrentDate;"
            }
          }, {
            "name" : "EndDate",
            "expression" : {
              "type" : "JavaScript",
              "expression" : ""
            }
          }, {
            "name" : "Shift",
            "expression" : {
              "type" : "JavaScript",
              "expression" : "return event.metadata.Shift;"
            }
          } ]
        },
        "outputs" : [ "StoreInState" ]
      }, {
        "name" : "StoreInState",
        "display" : {
          "position" : {
            "x" : 2040,
            "y" : -67
          }
        },
        "config" : {
          "type" : ".JavaScriptTransformConfig",
          "transformExpression" : "state.pipeline.set(event.value.Station, event.value);\r\nstage.setValue(event.value);"
        },
        "outputs" : [ ]
      }, {
        "name" : "GetPrevStationMessage",
        "display" : {
          "position" : {
            "x" : 690,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".JavaScriptTransformConfig",
          "transformExpression" : "const prevStationTransaction = state.pipeline.get(event.value.Station);\r\nif (prevStationTransaction !== undefined)\r\n{\r\n    stage.setMetadata(\"PrevStationTransaction\", prevStationTransaction);\r\n}\r\n\r\nstage.setValue(event.value);"
        },
        "outputs" : [ "SetCalcShift", "PrevStationTransaction" ]
      }, {
        "name" : "StoreInSQLite",
        "display" : {
          "position" : {
            "x" : 2040,
            "y" : 67
          }
        },
        "config" : {
          "type" : ".WriteConfig",
          "failureOutputs" : [ ],
          "references" : [ "{{Connection.SQLite_KB.ProductionTransactionExample}}" ],
          "writeReturn" : "completion"
        },
        "outputs" : [ ]
      } ],
      "trackActivity" : true,
      "triggers" : [ ],
      "errorHandler" : {
        "type" : "default"
      }
    }, {
      "name" : "ProductionTransactionExample_UpdateMQTT",
      "tags" : [ "ProductionTransactionExample" ],
      "inputStages" : [ "SetTimestamps" ],
      "stages" : [ {
        "name" : "Object",
        "display" : {
          "position" : {
            "x" : 2040,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".BreakupConfig",
          "breakupType" : "object",
          "depth" : 1
        },
        "outputs" : [ "MQTT_KB" ]
      }, {
        "name" : "SetTimestamps",
        "display" : {
          "position" : {
            "x" : 240,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".JavaScriptTransformConfig",
          "transformExpression" : "const startOfToday = new Date();\r\nstartOfToday.setHours(0, 0, 0, 0);   // local midnight today\r\nlet currentTime = new Date();\r\n\r\nstage.setMetadata(\"StartTimestamp\", startOfToday.getTime());\r\nstage.setMetadata(\"EndTimestamp\", currentTime.getTime());\r\n\r\nstage.setValue(event.value);"
        },
        "outputs" : [ "SQLite" ]
      }, {
        "name" : "StationShiftState",
        "display" : {
          "position" : {
            "x" : 1590,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".AttributeFilterConfig",
          "filterOption" : "exclude",
          "filterList" : [ {
            "filterType" : "exactPathFilter",
            "filterText" : "Station"
          }, {
            "filterType" : "exactPathFilter",
            "filterText" : "Shift"
          }, {
            "filterType" : "exactPathFilter",
            "filterText" : "State"
          } ],
          "retainAsMetadata" : true,
          "metadataKey" : "filtered"
        },
        "outputs" : [ "Object" ]
      }, {
        "name" : "SQLite",
        "display" : {
          "position" : {
            "x" : 690,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".ReadConfig",
          "failureOutputs" : [ ],
          "reference" : {
            "type" : "Input",
            "name" : "ProductionTransactionExample_ByStationByShiftByStateFilterDate",
            "path" : "",
            "params" : {
              "StartTimestamp" : "{{event.metadata.StartTimestamp}}",
              "EndTimestamp" : "{{event.metadata.EndTimestamp}}"
            },
            "connectionName" : "SQLite_KB"
          }
        },
        "outputs" : [ "Array" ]
      }, {
        "name" : "Array",
        "display" : {
          "position" : {
            "x" : 1140,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".BreakupConfig",
          "breakupType" : "array",
          "depth" : 1
        },
        "outputs" : [ "StationShiftState" ]
      }, {
        "name" : "MQTT_KB",
        "display" : {
          "position" : {
            "x" : 2490,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".DynamicWriteConfig",
          "failureOutputs" : [ ],
          "connectionReference" : "{{Connection.MQTT_KB}}",
          "qualifier" : {
            "topic" : "ProductionTransactionExample/{{event.metadata.filtered.Station}}/{{event.metadata.filtered.Shift}}/{{event.metadata.filtered.State}}/{{event.metadata.breakupName}}",
            "qos" : 0,
            "namedRoot" : false,
            "retained" : true,
            "breakupArrays" : false,
            "filterList" : [ "_timestamp" ],
            "type" : "Tag"
          },
          "qualifierExpression" : "",
          "writeReturn" : "completion"
        },
        "outputs" : [ ]
      } ],
      "trackActivity" : false,
      "triggers" : [ {
        "name" : "EveryMinute",
        "display" : {
          "position" : {
            "x" : -450,
            "y" : 0
          }
        },
        "config" : {
          "type" : ".TriggerCron",
          "enabled" : true,
          "logging" : "off",
          "schedule" : "*/1 * * * *",
          "timezone" : "utc"
        }
      } ],
      "errorHandler" : {
        "type" : "default"
      }
    } ],
    "namespace" : [ ]
  },
  "network" : {
    "groups" : [ ],
    "hubs" : [ ]
  }
}