範例︰重工比率 KPI
此範例會建立名為「重工比率」的新 KPI (ISO_22400)。重工比率是工作單位、產品、生產訂單或瑕疵類型的重工數量 (RQ) 與生產數量 (PQ) 之間的關係︰
RQ/PQ
會將重工數量 (RQ) KPI 元素建立為此範例的一部份。
1. 使用下列屬性建立名為 ACME_CORP.KPI.ReworkRatioThingShape 的新物形式︰
ReworkRatio_currentValue「基礎類型」=Number
ReworkRatio_lastCalculatedTime「基礎類型」=DateTime
ReworkRatio_unitOfMeasure「基礎類型」=String
請確保已針對這些屬性中的每個屬性選取「持續」核取方塊。
2. ACME_CORP.KPI.ReworkRatioThingShape 物形式上實行下列服務︰
Get_ReworkRatio_CurrentValue
Get_ReworkRatio_ThresholdValues
Get_ReworkRatio_Trend
ReworkRatio_Calculate
Set_ReworkRatio_CurrentValue
3. 在要針對其計算此 KPI 的每個設備類型的物範本上,取代 GetKPINames 服務。新增 ACME_CORP.KPI.ReworkRatioThingShape 物形式,如下列範例編碼所示︰
var kpiInfoJSON = new Object();
// JSON of KPI information we want to test if they are implemented on "me"
// For custom KPI, please add into this JSON and following given format
// Warning the order is important
kpiInfoJSON.kpiInfoArray = [
{kpiThingShapeName: 'PTC.SCA.SCO.AvailabilityThingShape', kpiName: 'Availability'},
{kpiThingShapeName: 'PTC.SCA.SCO.QualityRatioThingShape', kpiName: 'QualityRatio'},
{kpiThingShapeName: 'PTC.SCA.SCO.EffectivenessThingShape', kpiName: 'Effectiveness'},
{kpiThingShapeName: 'PTC.SCA.SCO.OEEThingShape', kpiName: 'OEE'},
{kpiThingShapeName: 'ACME_CORP.KPI.ReworkRatioThingShape', kpiName: 'ReworkRatio'}
];
var result = Things["PTC.SCA.SCO.DefaultKPIManager"].GetImplementedKPIsOnThing({
thingName: me.name,
kpiInfo: kpiInfoJSON
});
4. 宣告重工比率 KPI 的臨界值。在 PTC.SCA.SCO.DefaultKPIManager 項目的「組態」頁面上,新增新的組態表。
a. PTC.SCA.SCO.DefaultKPIManager 項目上新增具有下列值的組態表︰
「表格名稱」ReworkRatioThresholdValues
「資料形式」PTC.SCA.SCO.KPIThresholdValues
「允許多列」—確保已選取此核取方塊。
b. 將列新增至所需值範圍的 ReworkRatioThresholdValues 組態表,如下圖所示︰
5. 定義重工數量 (RQ) KPI 元素。
a. 在名為 reworkQuantity_RQ「基礎類型」Number 且選取「持續」核取方塊的 ACME_CORP.KPI.ReworkRatioThingShape 物形式上建立內容。
b. 使用下列編碼在命名為 reworkQuantity_RQ_CalculateACME_CORP.KPI.ReworkRatioThingShape 物形式上建立新服務︰
function isUndefinedOrNull(value){
return (value === null || typeof(value) === "undefined" );
}
result = me.reworkQuantity_RQ;
//Register first value to cache
me.RegisterValueToKPICache({
key: "reworkQuantity_RQ_firstValue" /* STRING */,
value: result, /* NUMBER */
TimeInfo : TimeInfo
});
c. 在要針對其計算此 KPI 的每個設備類型的物範本上,取代 GetKPIElementNames 服務。將新內容新增至清單。例如:
result = "actualProductionTime_APT,goodQuantity_GQ,plannedBusyTime_PBT,plannedRunTimePerItem_PRI,producedQuantity_PQ,reworkQuantity_RQ";
d. 更新在步驟 2 中建立的 ReworkRatio_Calculate 服務,以包括新的重工數量 (RQ) KPI 元素。例如:
var customLogger = logger.getLoggerContext().getLogger(logger.getName()+".com.ptc.sca.sco.KPICalculation.ReworkRatio");
var reworkRatio = me.reworkQuantity_RQ;
var producedQuantity = me.producedQuantity_PQ;
if (TimeInfo.getRowCount() > 0){
var row = TimeInfo.getRow(0);
var startTime = row.StartTimeDate;
var generatedID= row.GeneratedID;
// result from service GetKPIElementStartValue: INFOTABLE dataShape: "PTC.SCA.SCO.KPIElementValue"
var reworkQuantity_RQ_firstValue = me.GetKPICacheValue({
generatedID: generatedID/* STRING */,
name: "reworkQuantity_RQ_firstValue" /* STRING */
});
var producedQuantity_PQ_firstValue = me.GetKPICacheValue({
generatedID: generatedID/* STRING */,
name: "producedQuantity_PQ_firstValue" /* STRING */
});
var producedTotalQuantity = 0;
var producedReworkQuantity = 0;
if ( (typeof producedQuantity_PQ_firstValue !== 'undefined') && (typeof reworkQuantity_RQ_firstValue !== 'undefined') ){
producedTotalQuantity = (producedQuantity - producedQuantity_PQ_firstValue);
producedReworkQuantity = (reworkRatio - reworkQuantity_RQ_firstValue);
if ( producedTotalQuantity === 0 ){
// Until items are produced, rework ratio cannot be measured and will default to 1
// with producedReworkQuantity greater than 0, then the service will return 0.
reworkRatio = producedReworkQuantity > 0 ? 0: 1;
}
else{
reworkRatio = producedReworkQuantity / producedTotalQuantity;
}

customLogger.debug("ReworkRatio_Calculate: produced quantity value when time info started - last produced quantity :"+ producedQuantity_PQ_firstValue+"-"+producedQuantity);
customLogger.debug("ReworkRatio_Calculate: rework quantity value when time info started - last good quantity: "+ reworkQuantity_RQ_firstValue+"-"+reworkRatio);
customLogger.debug("ReworkRatio_Calculate: produced Rework Quantity / produced total quantity = quality ratio: " +producedReworkQuantity+ " / " + producedTotalQuantity + " = " + reworkRatio);
}
else{
customLogger.warn("ReworkRatio_Calculate for "+me.name+" could not retrieve the good quantity or produced quantity at the start of the time info.");
}
}
else{
customLogger.warn("ReworkRatio_Calculate for "+me.name+" could not retrieve the current time info. ReworkRatio = 0.");
}
var result = reworkRatio;
me.Set_ReworkRatio_CurrentValue({
value: result
});
var now = new Date();
me.ReworkRatio_lastCalculatedTime = now;