Esempio: KPI rapporto di rilavorazione
In questo esempio viene creato un nuovo indicatore KPI denominato rapporto di rilavorazione (ISO_22400). Il rapporto di rilavorazione è la relazione tra la quantità di rilavorazione (RQ) e la quantità prodotta (PQ) per un'unità di lavorazione, un prodotto, un ordine di produzione o un tipo di difetto:
RQ/PQ
L'elemento KPI quantità di rilavorazione (RQ) viene creato in questo esempio.
1. Creare una nuova thing shape ACME_CORP.KPI.ReworkRatioThingShape con le proprietà seguenti:
ReworkRatio_currentValue, con Tipo di base=Number
ReworkRatio_lastCalculatedTime, con Tipo di base=DateTime
ReworkRatio_unitOfMeasure, con Tipo di base=String
Assicurarsi che la casella di controllo Persistente sia selezionata per ciascuna di queste proprietà.
2. Implementare i seguenti servizi nella thing shape ACME_CORP.KPI.ReworkRatioThingShape:
Get_ReworkRatio_CurrentValue
Get_ReworkRatio_ThresholdValues
Get_ReworkRatio_Trend
ReworkRatio_Calculate
Set_ReworkRatio_CurrentValue
3. Nel modello di oggetto di ciascun tipo di impianto per cui deve essere calcolato questo indicatore KPI, sostituire il servizio GetKPINames. Aggiungere la thing shape ACME_CORP.KPI.ReworkRatioThingShape come indicato nel seguente codice di esempio:
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. Dichiarare le soglie per l'indicatore KPI rapporto di rilavorazione. Nella pagina Configurazione dell'oggetto PTC.SCA.SCO.DefaultKPIManager, aggiungere una nuova tabella di configurazione.
a. Nell'oggetto PTC.SCA.SCO.DefaultKPIManager, aggiungere una tabella di configurazione con i valori seguenti:
Nome tabella - ReworkRatioThresholdValues
Data shape - PTC.SCA.SCO.KPIThresholdValues
Consenti più righe - Assicurarsi che questa casella di controllo sia selezionata.
b. Aggiungere righe alla tabella di configurazione ReworkRatioThresholdValues per gli intervalli di valori desiderati, in modo analogo all'immagine seguente:
5. Definire l'elemento KPI di quantità di rilavorazione (RQ).
a. Creare una proprietà reworkQuantity_RQ nella thing shape ACME_CORP.KPI.ReworkRatioThingShape, con Number come Tipo di base e con la casella di controllo Persistente selezionata.
b. Creare un nuovo servizio reworkQuantity_RQ_Calculate nella thing shape ACME_CORP.KPI.ReworkRatioThingShape con il codice seguente:
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. Nel modello di oggetto di ciascun tipo di impianto per cui deve essere calcolato questo indicatore KPI, sostituire il servizio GetKPIElementNames. Aggiungere la nuova proprietà all'elenco. Ad esempio:
result = "actualProductionTime_APT,goodQuantity_GQ,plannedBusyTime_PBT,plannedRunTimePerItem_PRI,producedQuantity_PQ,reworkQuantity_RQ";
d. Aggiornare il servizio ReworkRatio_Calculate creato al passo 2 per includere il nuovo elemento KPI quantità di rilavorazione (RQ). Ad esempio:
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;