{
  "custom": {
    "live_analysis_time": {
      "$": [
        "ts",
        192,
        1715385019165
      ],
      "$ts": 1715385019163
    }
  },
  "params": {
    "configuring": false,
    "equipmentPath": "",
    "title": "Site Production Goal"
  },
  "propConfig": {
    "custom.live_analysis_time": {
      "binding": {
        "config": {
          "fallbackDelay": 2.5,
          "mode": "indirect",
          "references": {
            "provider": "{session.custom.defaultTagProvider}"
          },
          "tagPath": "{provider}Time Periods/Current Shift/End"
        },
        "type": "tag"
      },
      "persistent": true
    },
    "params.configuring": {
      "onChange": {
        "enabled": null,
        "script": "\tviewParams\u003dself.params\n\tconfigParams\u003dself.getChild(\"root/configuration\").props.params\n\tif currentValue.value:\n\t\tconfigParams.equipmentPathIn \u003d viewParams.equipmentPath\t\n\t\tconfigParams.titleIn \u003d viewParams.title\n\telif previousValue is not None and previousValue.value:\n\t\tviewParams.equipmentPath \u003d configParams.equipmentPathOut\n\t\tviewParams.title \u003d configParams.titleOut"
      },
      "paramDirection": "input",
      "persistent": true
    },
    "params.equipmentPath": {
      "paramDirection": "inout",
      "persistent": true
    },
    "params.title": {
      "paramDirection": "inout",
      "persistent": true
    }
  },
  "props": {
    "defaultSize": {
      "height": 313,
      "width": 492
    }
  },
  "root": {
    "children": [
      {
        "meta": {
          "name": "configuration"
        },
        "position": {
          "basis": "320px",
          "grow": 1
        },
        "propConfig": {
          "position.display": {
            "binding": {
              "config": {
                "path": "view.params.configuring"
              },
              "type": "property"
            }
          }
        },
        "props": {
          "params": {
            "equipmentPathIn": "",
            "equipmentPathOut": "",
            "timePeriodIn": "",
            "timePeriodOut": "",
            "titleIn": "Next Schedule",
            "titleOut": "Next Schedule"
          },
          "path": "Page/Widgets/Configuration/Site Path, Title"
        },
        "type": "ia.display.view"
      },
      {
        "children": [
          {
            "meta": {
              "name": "EmbeddedView"
            },
            "position": {
              "shrink": 0
            },
            "propConfig": {
              "props.params.text": {
                "binding": {
                  "config": {
                    "path": "view.params.title"
                  },
                  "type": "property"
                },
                "persistent": true
              }
            },
            "props": {
              "params": {
                "text": "Site Production Goal"
              },
              "path": "Page/Embedded/Widget Title",
              "style": {
                "overflow": "hidden"
              }
            },
            "type": "ia.display.view"
          },
          {
            "meta": {
              "name": "Label"
            },
            "position": {
              "basis": "60px"
            },
            "type": "ia.display.label"
          },
          {
            "meta": {
              "name": "PieChart"
            },
            "position": {
              "grow": 1
            },
            "propConfig": {
              "position.display": {
                "binding": {
                  "config": {
                    "path": "view.params.equipmentPath"
                  },
                  "transforms": [
                    {
                      "code": "\treturn value !\u003d \"\"",
                      "type": "script"
                    }
                  ],
                  "type": "property"
                }
              },
              "props.data": {
                "binding": {
                  "config": {
                    "struct": {
                      "eqPath": "{view.params.equipmentPath}",
                      "time": "{view.custom.live_analysis_time}"
                    },
                    "waitOnAll": true
                  },
                  "transforms": [
                    {
                      "code": "\tif value[\"eqPath\"] \u003d\u003d \"\":\n\t\treturn []\n\t\n\tfilter \u003d system.mes.object.filter.createFilter()\n\tfilter.setMESObjectTypeName(\u0027Line\u0027)\n\tfilter.setPrimaryMESObjectPath(self.view.params.equipmentPath)\n\tlines \u003d system.mes.searchMESObjects(filter)\n\t\n\ttotalProduced, totalRejects, totalRemaining, remaining \u003d 0,0,0,0\n\t\n\t\n\t#Iterate through all lines to sum counters\n\tfor mesObjectLink in lines:\n\t\tfault \u003d False\n\t\teqPath \u003d mesObjectLink.getMESObject().getEquipmentPath()\n\t\tparentPath \u003d \u0027[MES]\u0027 + eqPath.replace(\u0027\\\\\u0027,\u0027/\u0027) + \u0027/Live Analysis/Day(production)/\u0027\n\t\tresults \u003d system.tag.readBlocking([parentPath + \u0027OEE Outfeed Count\u0027,parentPath + \u0027OEE Reject Count\u0027,parentPath + \u0027Line Target Count Variance\u0027],1000)\n\t\t\n\t\tfor tag in results:\n\t\t\tif not (tag.getQuality().isGood()):\n\t\t\t\tlogger \u003d system.util.getLogger(\u0027MES Admin\u0027)\n\t\t\t\tlogger.warn(str(parentPath) +\u0027Tag not found for Site Production Goal. Ensure onboarding is complete and check Live Analysis\u0027)\n\t\t\t\tfault \u003d True\n\t\t\t\tbreak\n\t\tif fault:\n\t\t\tlogger.warn(\u0027skipping \u0027 + str(eqPath))\n\t\t\tcontinue\n\t\t\t\n\t\tproduced \u003d int(results[0].value)\n\t\trejects \u003d int(results[1].value)\n\t\tremaining \u003d int(results[2].value)\n\t\t\n\t\tif remaining \u003c 0:\n\t\t\tremaining \u003d abs(remaining)\n\t\telif remaining \u003e 0:\n\t\t\tremaining \u003d 0\n\t\t\n\t\ttotalProduced +\u003d produced\n\t\ttotalRejects +\u003d rejects\n\t\ttotalRemaining +\u003d remaining\n\t\t\n\t\tdata \u003d [{\u0027title\u0027:\u0027Produced\u0027,\u0027count\u0027:totalProduced},{\u0027title\u0027:\u0027Rejects\u0027,\u0027count\u0027:totalRejects},{\u0027title\u0027:\u0027Remaining\u0027,\u0027count\u0027:totalRemaining}]\n\t\treturn data",
                      "type": "script"
                    }
                  ],
                  "type": "expr-struct"
                },
                "persistent": false
              }
            },
            "props": {
              "colors": [
                "#4C9C2E",
                "#EC1C24",
                "#A1CB91",
                "#CCC233",
                "#E69300"
              ],
              "cutoutRadius": 60,
              "labels": {
                "color": "#999393",
                "showName": false,
                "showValue": false,
                "wrap": {
                  "enabled": true,
                  "maxWidth": 115
                }
              },
              "legend": {
                "fontSize": 15
              },
              "legendLabelColor": "#808080",
              "valueFormat": {
                "showValueAsPercent": false
              }
            },
            "type": "ia.chart.pie"
          }
        ],
        "custom": {
          "BeginTime": null,
          "EndTime": null,
          "Scheduled": "",
          "workOrder": ""
        },
        "meta": {
          "name": "runtime"
        },
        "position": {
          "basis": "200px",
          "grow": 1
        },
        "propConfig": {
          "custom.product": {
            "binding": {
              "config": {
                "expression": "toStr(tag(\u0027[MES]\u0027+ {view.params.equipmentPath} + \u0027/Live Analysis/Current Shift/Product Code\u0027)) + \"~\" + toStr({view.params.equipmentPath})"
              },
              "transforms": [
                {
                  "code": "\teqPath \u003d str(value).split(\"~\")[1]\n\tcurrentProductCode \u003d str(value).split(\"~\")[0]\n\tdef clearData():\n\t\tself.getChild(\"EmbeddedViewTimeLine\").position.display \u003d False\n\t\tself.custom.BeginTime \u003d None\n\t\tself.custom.EndTime \u003d None\n\t\tself.custom.workOrder \u003d \"\"\n\t\tself.custom.Scheduled \u003d \"\"\n\t\treturn \"\"\n\t\n\tif eqPath \u003d\u003d \"\":\n\t\treturn clearData()\n\t\n\t#define the start and end dates\n\tbegin \u003d system.date.now()\n\tend \u003d system.date.addDays(system.date.now(), 100)\n\t  \n\t#let category be \u0027Active\u0027\n\tcategory \u003d \u0027Active\u0027\n\t  \n\t#Gets the equipment schedule entries\n\t#https://help.sepasoft.com/docs/display/SEPA/system.mes.getEquipmentScheduleEntries\n\tlist \u003d system.mes.getEquipmentScheduleEntries(eqPath, begin, end, category, False)\n\t\n\tnextSchedule \u003d None\n\t\n\tnow \u003d system.date.now()\n\t\n\tStartDate \u003d 0\n\tEndDate \u003d 0\n\t\n\tfor Schedule in list:\n\t\tStartDate \u003d Schedule.getScheduledStartDate()\n\t\tEndDate \u003d Schedule.getScheduledEndDate()\n\t\tstate \u003d Schedule.getState()\n\t\tif ( state \u003d\u003d 2 or state \u003d\u003d 5):\n\t\t\tcontinue\n\t\t\n\t\tif (system.date.secondsBetween(now, StartDate) \u003e 0 and system.date.secondsBetween(now, EndDate) \u003e 0):\n\t\t\tnextSchedule \u003d Schedule\t\t\n\t\t\tbreak\n\t\t\t\n\t\n\tif (nextSchedule is None):\n\t\treturn clearData()\n\t\t\n\t\n\n\tself.custom.BeginTime \u003d StartDate\n\tself.custom.EndTime \u003d EndDate\n\tself.getChild(\"EmbeddedViewTimeLine\").position.display \u003d True\n\n\tWorkOrderLink \u003d nextSchedule.getWorkOrderLink()\n\t#find label, material/work order\n\t#\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\n\tmaterialName \u003d nextSchedule.getMESOperationsRequestLink().getName().split(\u0027-\u0027)[0]\n\tlabel \u003d materialName\n\tif label \u003d\u003d currentProductCode:\n\t\treturn clearData()\n\t\n\t#get count\n\topSchedule \u003d nextSchedule.getMESOperationsScheduleLink().getMESObject()\n\tscheduleCount \u003d opSchedule.getScheduleProductionCount()\n\t\n\tself.custom.Scheduled \u003d scheduleCount\n\n\treturn label",
                  "type": "script"
                }
              ],
              "type": "expr"
            }
          },
          "position.display": {
            "binding": {
              "config": {
                "expression": "!{view.params.configuring}"
              },
              "type": "expr"
            }
          }
        },
        "props": {
          "direction": "column",
          "style": {
            "overflow": "hidden"
          }
        },
        "type": "ia.container.flex"
      }
    ],
    "meta": {
      "name": "root"
    },
    "props": {
      "direction": "column",
      "style": {
        "fontFamily": "Roboto",
        "fontSize": "12px"
      }
    },
    "type": "ia.container.flex"
  }
}