示例:技术效率 KPI
此示例中会创建一个名为“技术效率”的新 KPI (ISO_22400)。工作单元的技术效率为实际生产时间 (APT) 与实际生产时间 (APT) 和实际单元延迟时间 (ADET) 总和之间的关系,包括延迟和故障引起的中断。
APT/(APT+ADET)
在本例中,实际单元延迟时间 (ADET) 会一同创建。此示例中的代码示例假定已实施“返工率 KPI”。
1. 使用以下属性创建名为 ACME_CORP.KPI.TechnicalEfficiencyThingShape 的新事物形态:
TechnicalEfficiency_currentValue“基本类型”=Number
TechnicalEfficiency_lastCalculatedTime“基本类型”=DateTime
TechnicalEfficiency_unitOfMeasure“基本类型”=String
确保各属性均选中“持续”复选框。
2. ACME_CORP.KPI.TechnicalEfficiencyThingShape 事物形态上实施以下服务:
Get_TechnicalEfficiency_CurrentValue
Get_TechnicalEfficiency_ThresholdValues
Get_TechnicalEfficiency_Trend
TechnicalEfficiency_Calculate
Set_TechnicalEfficiency_CurrentValue
3. 在要计算此 KPI 的每种设备类型的事物模板上,覆盖 GetKPINames 服务以添加 ACME_CORP.KPI.TechnicalEfficiencyThingShape 事物形态。例如:
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'},
{kpiThingShapeName: 'ACME_CORP.KPI.TechnicalEfficiencyThingShape', kpiName: 'TechnicalEfficiency'}
];
var result = Things["PTC.SCA.SCO.DefaultKPIManager"].GetImplementedKPIsOnThing({
thingName: me.name,
kpiInfo: kpiInfoJSON
});
4. 声明“技术效率 KPI”的阈值。在 PTC.SCA.SCO.DefaultKPIManager 事物的“配置”页面,添加新的配置表。
a. PTC.SCA.SCO.DefaultKPIManager 事物上,添加具有以下值的配置表:
“表名称” - TechnicalEfficiencyThresholdValues
“数据形状” - PTC.SCA.SCO.KPIThresholdValues
“允许多行” - 确保选中此复选框。
b. 添加行至 TechnicalEfficiencyThresholdValues 配置表以获取所需的值范围:
5. 定义实际单元延迟时间 (ADET) KPI 元素。
a. 在名为 actualUnitDelayTime_ADETACME_CORP.KPI.TechnicalEfficiencyThingShape 事物形态上创建属性,“基本类型”Number,并选中“持续”复选框。
b. 使用以下代码在名为 actualUnitDelayTime_ADET_CalculateACME_CORP.KPI.TechnicalEfficiencyThingShape 事物形态上创建新的服务:
var adet = me.CalculateTimeElement({
elementName: "ADET", /* STRING */
TimeInfo : TimeInfo
});
me.actualUnitDelayTime_ADET = adet;
var result = adet;
c. 在要计算此 KPI 的每种设备类型的事物模板上,覆盖 GetKPIElementNames 服务。添加新属性至 KPI 元素列表。例如:
result = "actualProductionTime_APT,goodQuantity_GQ,plannedBusyTime_PBT,plannedRunTimePerItem_PRI,producedQuantity_PQ,reworkQuantity_RQ,actualUnitDelayTime_ADET";
d. 更新在步骤 2 中创建的 TechnicalEfficiency_Calculate 服务以包含新的实际单元延迟时间 (ADET) KPI 元素。例如:
customLogger = logger.getLoggerContext().getLogger(logger.getName()+".com.ptc.sca.sco.KPICalculation.TechnicalEfficiency");
var technicalEfficiency = 0;
var aptTime = me.actualProductionTime_APT;
var adetTime = me.actualUnitDelayTime_ADET;
customLogger.debug("TechnicalEfficiency_Calculate aptTime:"+aptTime+" adetTime:"+adetTime);
if ( aptTime !== 0){
technicalEfficiency = aptTime / (aptTime+adetTime);
}else{
technicalEfficiency = 1;
}
customLogger.debug("TechnicalEfficiency_Calculate TechnicalEfficiency:"+technicalEfficiency);
me.Set_TechnicalEfficiency_CurrentValue({
value: technicalEfficiency
});
me.TechnicalEfficiency_lastCalculatedTime = Date.now();
var result = technicalEfficiency;
6. 由于实际单元延迟时间 (ADET) KPI 元素为时间元素,因此请更新相应的状况定义以包含 ADET (作为 timeElement 值)。计算指定的 KPI 元素时,会考虑具有 timeElement 值的状况。在本例中,将 Custom1 状态的 timeElement 值配置为 ADET,PBT,以便在计算 ADET 和 PBT 时考虑 Custom1 状态。
有关详细信息,请参阅 配置设备状况