private int ProcessSigmaMeasure(double totalPower, Meter meter, IOrderedEnumerable<SigmaMeasure> queryDay, DateTime initialUtcDate, DateTime localDate, string executionResume,Plant plant) { //It saves the minutes offset os a date converted to UTC //When a date with hour on the hour is converted to UTC in some time zones it could //be converted in half-past hour or something similar so we need to save this parameter int minutesOffset = initialUtcDate.Minute; DateTime utcDate = new DateTime(); int lastNumPeriod = -1; //this block generate a new SMeasure or increment value of a created SMeasure if was created with same date and time //ProductionValue parameter include all meters power sum per plant and datetime foreach (var sigmaMeasure in queryDay) { //Fix errors of same numperiod in two or more different sigmaMeasures if (sigmaMeasure.NumPeriod != lastNumPeriod) { while (sigmaMeasure.NumPeriod - lastNumPeriod != 1) { Logger.Warn(string.Format("Missing Period Number {0} in meter with ID '{1}' and local date {2}", lastNumPeriod, sigmaMeasure.Id_Meter, localDate.ToShortDateString())); executionResume = string.Format("{0}\n\tMissing Period Number {1} in meter with ID '{2}' and local date {3}", executionResume, lastNumPeriod, sigmaMeasure.Id_Meter, localDate.ToShortDateString()); lastNumPeriod++; } lastNumPeriod = sigmaMeasure.NumPeriod; utcDate = initialUtcDate.AddHours(sigmaMeasure.NumPeriod); SMeasure sm = SMeasureInListByDate(ListOfSMeasures, plant.Id, utcDate); if (sm == null) { sm = new SMeasure(plant.Id, utcDate.Date, utcDate.Hour, minutesOffset, sigmaMeasure.ProductionValue * meter.LosingRate * meter.PowerPercentage, ((meter.Power * 1000) / totalPower)); ListOfSMeasures.Add(sm); } else { sm.Value += sigmaMeasure.ProductionValue * meter.LosingRate * meter.PowerPercentage; //Preguntar si "meter.PowerPercentage" es necesario para el calculo de porcentaje de medida //Si porcentaje de medida indica la cantidad de medidas que hay NO sería necesario //Si indicara el porcentaje de potencia con respecto al total SI sm.MeasurePercentage += ((meter.Power * 1000) / totalPower); } } else { Logger.Warn(string.Format("Repeated Period Number {0} in meter with ID '{1}' and local date {2}", lastNumPeriod, sigmaMeasure.Id_Meter, localDate.ToShortDateString())); executionResume = string.Format("{0}\n\tRepeated Period Number {1} in meter with ID '{2}' and local date {3}", executionResume, lastNumPeriod, sigmaMeasure.Id_Meter, localDate.ToShortDateString()); } } return lastNumPeriod; }
/// <summary> /// Transforma a 1 o 2 Meters (ver caso OLMFW01) una fila de la tabla de resultados /// </summary> /// <param name="row"></param> /// <returns></returns> private static IEnumerable<Meter> getRowMeterList(IRfcStructure row) { IList<Meter> result = new List<Meter>(); int numberOfCounters = getNumberOfCountersInThisRow(row); if (numberOfCounters == 0) return result; double num = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))); double den=double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)); DateTime startDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_START_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)); DateTime endDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_END_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)); Meter firstMeter = new Meter() { //IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_ID), //IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF), //LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_PERD)), //Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)) / numberOfCounters), //PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)) // / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))) IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_ID), IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF), startDate=DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_START_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)), endDate=DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_END_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)), LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_PERD)), Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))), PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)) / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER))) }; result.Add(firstMeter); if (numberOfCounters == 1) return result; Meter secondMeter = new Meter() { //IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_ID), //IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF), //LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_PERD)), //Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)) / numberOfCounters), //PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER)) // / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER))) IdMeter = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_ID), IdPlant = (string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_UF), startDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_START_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)), endDate = DateTime.ParseExact((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_END_DATE), FORMAT_DATE_SAP, new CultureInfo("es-ES", true)), LosingRate = double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT2_PERD)), Power = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)) / numberOfCounters), PowerPercentage = (double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_CONT1_POWER)) / double.Parse((string)row.GetValue(RFC_FUNCTION_RETURN_TABLE_FIELD_POWER))) }; result.Add(secondMeter); return result; }