Ejemplo: KPI Índice de retrabajo
En este ejemplo se crea un nuevo KPI llamado Índice de retrabajo (ISO_22400). El índice de retrabajo es la relación entre la cantidad de retrabajo (RQ) y la cantidad producida (PQ) para una unidad de trabajo, un producto, una orden de producción o un tipo de defecto:
RQ/PQ
El elemento KPI de cantidad de retrabajo (RQ) se crea como parte de este ejemplo.
1. Cree una nueva definición de cosa denominada ACME_CORP.KPI.ReworkRatioThingShape con las propiedades siguientes:
ReworkRatio_currentValue, con Tipo base=Number
ReworkRatio_lastCalculatedTime, con Tipo base=DateTime
ReworkRatio_unitOfMeasure, con Tipo base=String
Asegúrese de que la casilla Persistente esté seleccionada para cada una de estas propiedades.
2. Implemente los siguientes servicios en la definición de cosa ACME_CORP.KPI.ReworkRatioThingShape:
Get_ReworkRatio_CurrentValue
Get_ReworkRatio_ThresholdValues
Get_ReworkRatio_Trend
ReworkRatio_Calculate
Set_ReworkRatio_CurrentValue
3. En la plantilla de cosa de cada tipo de equipo para el que se debe calcular este KPI, sustituya el servicio GetKPINames. Añada la definición de cosa ACME_CORP.KPI.ReworkRatioThingShape, como en el siguiente código de ejemplo:
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. Declare los umbrales para el KPI Índice de retrabajo. En la página Configuración de la cosa PTC.SCA.SCO.DefaultKPIManager, añada una nueva tabla de configuración.
a. En la cosa PTC.SCA.SCO.DefaultKPIManager, añada una tabla de configuración con los valores siguientes:
Nombre de la tabla:ReworkRatioThresholdValues
Definición de datos:PTC.SCA.SCO.KPIThresholdValues
Permitir varias filas: asegúrese de que esta casilla esté marcada.
b. Añada filas a la tabla de configuración ReworkRatioThresholdValues para los rangos de valores deseados, de forma similar a lo que se muestra en la imagen siguiente:
5. Defina el elemento KPI de cantidad de retrabajo (RQ).
a. Cree una propiedad en la definición de cosa ACME_CORP.KPI.ReworkRatioThingShape llamada reworkQuantity_RQ, con un valor de Tipo base de Number, y la casilla Persistente seleccionada.
b. Cree un nuevo servicio en la definición de cosa ACME_CORP.KPI.ReworkRatioThingShape llamado reworkQuantity_RQ_Calculate con el código siguiente:
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. En la plantilla de cosa de cada tipo de equipo para el que se debe calcular este KPI, sustituya el servicio GetKPIElementNames. Añada la nueva propiedad a la lista. Por ejemplo:
result = "actualProductionTime_APT,goodQuantity_GQ,plannedBusyTime_PBT,plannedRunTimePerItem_PRI,producedQuantity_PQ,reworkQuantity_RQ";
d. Actualice el servicio ReworkRatio_Calculate creado en el paso 2 para incluir el nuevo elemento de KPI de cantidad de retrabajo (RQ). Por ejemplo:
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;