using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Linq; using System.Text; using Xylem.Common.Logic.ServiceCore; namespace CommonConsole { public class ProgramLogFileHelper { public class resultRep { public double GreenLEDTime = 0.0; public string Date { get; internal set; } public DateTime DataDate { get; internal set; } public string CustomerName { get; internal set; } public string PcbId { get; internal set; } public string Core { get; internal set; } public string FW { get; internal set; } public string POWERMON_BatteryVoltage { get; internal set; } public string POWERMON_BatteryQuantity { get; internal set; } public string GENESISFLOW_ScaledBilling { get; internal set; } public string GENESISFLOW_SampleRate { get; internal set; } public string IRDA_AdapterID { get; internal set; } public string IRDA_PulseReportRate { get; internal set; } public string METROLOGYASST_PulseResolution { get; internal set; } public string METROLOGYASST_PulseEvenDistribution { get; internal set; } public string POWERMON_TotalUsedCharge { get; internal set; } public string POWERMON_TotalUsedSeconds { get; internal set; } public string GENESISFLOW_LedMode { get; internal set; } public string METROLOGYASST_PulseWeight { get; internal set; } public string METROLOGYASST_PulseMode { get; internal set; } public string METROLOGYASST_PulseLength { get; internal set; } public String Source { get; internal set; } public Boolean PwFileUpdate { get; internal set; } = false; public void Calc() { string[] formats = { "dd/MM/yyyy", "dd/M/yyyy", "d/M/yyyy", "d/MM/yyyy", "dd/MM/yy", "dd/M/yy", "d/M/yy", "d/MM/yy"}; if (string.IsNullOrEmpty(Date) && DataDate == new DateTime()) { return; } if (DataDate == new DateTime()) { if (Date.Contains(":")) { if (DateTime.TryParseExact(Date.Trim().Substring(0, "yyyy-MM-dd".Length), "yyyy-MM-dd", null, DateTimeStyles.None, out var tmp)) { DataDate = tmp; } else { } //2019-10-30 15:46:18.767 } else if (Date.Contains("/")) { if (DateTime.TryParseExact(Date.Trim(), "mm/dd/yyyy", new CultureInfo("us-US"), DateTimeStyles.None, out var tmp)) { DataDate = tmp; } else { var strDate = Date.Trim().Split('/'); if (strDate[0].Length == 1) { strDate[0] = "0" + strDate[0]; } if (strDate[1].Length == 1) { strDate[1] = "0" + strDate[1]; } if (DateTime.TryParseExact(strDate[1] + "." + strDate[0] + "." + strDate[2], "dd.MM.yyyy", null, DateTimeStyles.None, out var tmphelp)) { DataDate = tmphelp; } else { } } } else if (Date.Contains("-")) { if (DateTime.TryParseExact(Date.Trim(), "dd.MM.yyyy", null, DateTimeStyles.None, out var tmp)) { DataDate = tmp; } else { } } else { if (DateTime.TryParseExact(Date.Trim(), "dd.MM.yyyy", null, DateTimeStyles.None, out var tmp)) { DataDate = tmp; } else { var strDate = Date.Replace(" ", "").Split('.'); if (strDate[0].Length == 1) { strDate[0] = "0" + strDate[0]; } if (strDate[1].Length == 1) { strDate[1] = "0" + strDate[1]; } if (DateTime.TryParseExact(strDate[1] + "." + strDate[0] + "." + strDate[2], "dd.MM.yyyy", null, DateTimeStyles.None, out var tmphelp)) { DataDate = tmphelp; } } } } if (!string.IsNullOrEmpty(POWERMON_BatteryQuantity)) { if (POWERMON_BatteryQuantity.Contains("1")) { BatteryQuantity = 1; } else { BatteryQuantity = 2; } } DrainedBatteryLoad_uAs = 0; ExceededLifeTime_s = 0; if (!string.IsNullOrEmpty(POWERMON_TotalUsedCharge) && POWERMON_TotalUsedCharge != "NULL") { if (POWERMON_TotalUsedCharge.Contains(" - ")) { var trim = POWERMON_TotalUsedCharge.LastIndexOf(" - ") + 3; POWERMON_TotalUsedCharge = POWERMON_TotalUsedCharge.Substring(trim, POWERMON_TotalUsedCharge.Length - trim); UInt64.TryParse(POWERMON_TotalUsedCharge, out DrainedBatteryLoad_uAs); } else { if (POWERMON_TotalUsedCharge.Length > "E2-AF-58-A3-00-00-00-00".Length) { POWERMON_TotalUsedCharge = POWERMON_TotalUsedCharge.Substring(0, "E2-AF-58-A3-00-00-00-00".Length); } String[] arr = POWERMON_TotalUsedCharge.Split('-'); Byte[] raw = new Byte[arr.Length]; for (Int32 i = arr.Length - 1; i >= 0; i--) { raw[i] = Convert.ToByte(arr[i], 16); } if (POWERMON_TotalUsedCharge.Length == "C5-1F-04-BD".Length) { Calculated = false; return; } DrainedBatteryLoad_uAs = BitConverter.ToUInt64(raw, 0); } } if (!string.IsNullOrEmpty(POWERMON_TotalUsedSeconds) && POWERMON_TotalUsedSeconds != "NULL") { if (POWERMON_TotalUsedSeconds.Contains(" - ")) { var trim = POWERMON_TotalUsedSeconds.LastIndexOf(" - ") + 3; POWERMON_TotalUsedSeconds = POWERMON_TotalUsedSeconds.Substring(trim, POWERMON_TotalUsedSeconds.Length - trim); UInt32.TryParse(POWERMON_TotalUsedSeconds, out ExceededLifeTime_s); } else { String[] arr = POWERMON_TotalUsedSeconds.Split('-'); Byte[] raw = new Byte[arr.Length]; for (Int32 i = arr.Length - 1; i >= 0; i--) { raw[i] = Convert.ToByte(arr[i], 16); } ExceededLifeTime_s = BitConverter.ToUInt32(raw, 0); } } if (DrainedBatteryLoad_uAs == 0 || ExceededLifeTime_s == 0) { return; } InitialBatteryLoad_mAh = 19000; // Calculate the initial overall battery load of all batteries in uAs as the drained load uses this unit. var initialBatteryLoad_uAs = 1000 * 3600 * InitialBatteryLoad_mAh * (UInt64)BatteryQuantity; // Relation of drained to initial load, set the battery to fully unloaded for failed check to force a recalculation var drainedBatteryLoad_rel = 1.0; if (initialBatteryLoad_uAs != 0) { drainedBatteryLoad_rel = (Double)DrainedBatteryLoad_uAs / initialBatteryLoad_uAs; } DrainedBatteryLoadPercent = drainedBatteryLoad_rel * 100; // The estimated life time uses the drained load over the actual exceeded life time and assumes, that further on // an identical load will be consumed over the remaining life cycle. The initial load will be multiplied with the // drained load relation. Set the estimated time to the exceeded time to force a recalculation on failed input. var estimatedLifeTime_s = (Double)ExceededLifeTime_s; if (drainedBatteryLoad_rel != 0.0) { estimatedLifeTime_s = ExceededLifeTime_s / drainedBatteryLoad_rel; } var remainingLifetime_s = estimatedLifeTime_s - ExceededLifeTime_s; // convert the seconds to years RemainingLifeTimeYears = remainingLifetime_s / 3600 / 24 / 365.25; UNTLimit = 1368000000 + (ExceededLifeTime_s * 77.7); // + (POWERMON_TotalUsedSeconds * 77.7) This allows 1 % battery capacity usage during manufacture on top of an average consumption of 77.7uA Calculated = true; } public UInt32 ExceededLifeTime_s; public UInt64 DrainedBatteryLoad_uAs; public Int32 BatteryQuantity; public UInt64 InitialBatteryLoad_mAh; public Double DrainedBatteryLoadPercent; public Double RemainingLifeTimeYears; public Double UNTLimit { get; private set; } public bool Calculated = false; } private class GreenHistoryItem { public int SR = 2; public DateTime Time { get; set; } public bool Idel { get; set; } = false; public bool LedMode { get; set; } = false; public string Remark { get; set; } public bool HighConsumption { get; set; } public double SecondsInHighConsumption { get; set; } public void Cal() { if (Idel) { HighConsumption = false; return; } if (!LedMode) { HighConsumption = false; return; } if (SR == 2) { HighConsumption = false; return; } HighConsumption = true; } } public static void MainHelper(string[] args) { #region stuff //var listRes = new Dictionary>(); //foreach (var repFile in Directory.GetFiles("E:\\bat\\report\\")) //{ // var newlines = new List(); // var alllinesfromfile = File.ReadAllLines(repFile); // var R = new resultRep(); // R.Source = "CUST"; // foreach (var lc in alllinesfromfile) // { // if (lc.StartsWith("Datum:")) // { R.Date = lc.Replace("Datum:", ""); } // if (lc.StartsWith("Date:")) // { R.Date = lc.Replace("Date:", ""); } // if (lc.StartsWith("Kundenname:")) // { R.CustomerName = lc.Replace("Kundenname:", ""); } // if (lc.StartsWith("Customer Name:")) // { R.CustomerName = lc.Replace("Customer Name:", ""); } // if (lc.StartsWith("PCB ID:")) // { R.PcbId = lc.Replace("PCB ID:", "").Trim(); ; } // if (lc.StartsWith("Systemkern-Version:")) // { R.Core = lc.Replace("Systemkern-Version:", ""); } // if (lc.StartsWith("System Core Revision:")) // { R.Core = lc.Replace("System Core Revision:", ""); } // if (lc.StartsWith("Nummer: 0x18 - V:")) // { R.FW = lc.Replace("Nummer: 0x18 - V:", "").Replace(" - Name: FLEXNETVERSION", ""); } // if (lc.StartsWith("AppId: 0x18 - V:")) // { R.FW = lc.Replace("AppId: 0x18 - V:", "").Replace(" - AppName: FLEXNETVERSION", ""); } // if (lc.StartsWith("Lese Register: POWERMON_BatteryVoltage")) // { R.POWERMON_BatteryVoltage = lc.Replace("Lese Register: POWERMON_BatteryVoltage", ""); } // if (lc.StartsWith("Lese Register: POWERMON_BatteryQuantity")) // { R.POWERMON_BatteryQuantity = lc.Replace("Lese Register: POWERMON_BatteryQuantity", ""); } // if (lc.StartsWith("Lese Register: POWERMON_TotalUsedCharge")) // { R.POWERMON_TotalUsedCharge = lc.Replace("Lese Register: POWERMON_TotalUsedCharge", ""); } // if (lc.StartsWith("Lese Register: POWERMON_TotalUsedSeconds")) // { R.POWERMON_TotalUsedSeconds = lc.Replace("Lese Register: POWERMON_TotalUsedSeconds", ""); } // if (lc.StartsWith("Lese Register: GENESISFLOW_LedMode")) // { R.GENESISFLOW_LedMode = lc.Replace("Lese Register: GENESISFLOW_LedMode", ""); } // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseWeight")) // { R.METROLOGYASST_PulseWeight = lc.Replace("Lese Register: METROLOGYASST_PulseWeight", ""); } // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseMode")) // { R.METROLOGYASST_PulseMode = lc.Replace("Lese Register: METROLOGYASST_PulseMode", ""); } // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseLength")) // { R.METROLOGYASST_PulseLength = lc.Replace("Lese Register: METROLOGYASST_PulseLength", ""); } // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseEvenDistribution")) // { R.METROLOGYASST_PulseEvenDistribution = lc.Replace("Lese Register: METROLOGYASST_PulseEvenDistribution", ""); } // if (lc.StartsWith("Lese Register: METROLOGYASST_PulseResolution")) // { R.METROLOGYASST_PulseResolution = lc.Replace("Lese Register: METROLOGYASST_PulseResolution", ""); } // if (lc.StartsWith("Lese Register: IRDA_PulseReportRate")) // { R.IRDA_PulseReportRate = lc.Replace("Lese Register: IRDA_PulseReportRate", ""); } // if (lc.StartsWith("Lese Register: IRDA_AdapterID ")) // { R.IRDA_AdapterID = lc.Replace("Lese Register: IRDA_AdapterID ", ""); } // if (lc.StartsWith("Lese Register: GENESISFLOW_SampleRate ")) // { R.GENESISFLOW_SampleRate = lc.Replace("Lese Register: GENESISFLOW_SampleRate ", ""); } // if (lc.StartsWith("Lese Register: GENESISFLOW_ScaledBilling ")) // { R.GENESISFLOW_ScaledBilling = lc.Replace("Lese Register: GENESISFLOW_ScaledBilling ", ""); } // if (lc.StartsWith("Read register: POWERMON_BatteryVoltage")) // { R.POWERMON_BatteryVoltage = lc.Replace("Read register: POWERMON_BatteryVoltage", ""); } // if (lc.StartsWith("Read register: POWERMON_BatteryQuantity")) // { R.POWERMON_BatteryQuantity = lc.Replace("Read register: POWERMON_BatteryQuantity", ""); } // if (lc.StartsWith("Read register: POWERMON_TotalUsedCharge")) // { R.POWERMON_TotalUsedCharge = lc.Replace("Read register: POWERMON_TotalUsedCharge", ""); } // if (lc.StartsWith("Read register: POWERMON_TotalUsedSeconds")) // { R.POWERMON_TotalUsedSeconds = lc.Replace("Read register: POWERMON_TotalUsedSeconds", ""); } // if (lc.StartsWith("Read register: GENESISFLOW_LedMode")) // { R.GENESISFLOW_LedMode = lc.Replace("Read register: GENESISFLOW_LedMode", ""); } // if (lc.StartsWith("Read register: METROLOGYASST_PulseWeight")) // { R.METROLOGYASST_PulseWeight = lc.Replace("Read register: METROLOGYASST_PulseWeight", ""); } // if (lc.StartsWith("Read register: METROLOGYASST_PulseMode")) // { R.METROLOGYASST_PulseMode = lc.Replace("Read register: METROLOGYASST_PulseMode", ""); } // if (lc.StartsWith("Read register: METROLOGYASST_PulseLength")) // { R.METROLOGYASST_PulseLength = lc.Replace("Read register: METROLOGYASST_PulseLength", ""); } // if (lc.StartsWith("Read register: METROLOGYASST_PulseEvenDistribution")) // { R.METROLOGYASST_PulseEvenDistribution = lc.Replace("Read register: METROLOGYASST_PulseEvenDistribution", ""); } // if (lc.StartsWith("Read register: METROLOGYASST_PulseResolution")) // { R.METROLOGYASST_PulseResolution = lc.Replace("Read register: METROLOGYASST_PulseResolution", ""); } // if (lc.StartsWith("Read register: IRDA_PulseReportRate")) // { R.IRDA_PulseReportRate = lc.Replace("Read register: IRDA_PulseReportRate", ""); } // if (lc.StartsWith("Read register: IRDA_AdapterID ")) // { R.IRDA_AdapterID = lc.Replace("Read register: IRDA_AdapterID ", ""); } // if (lc.StartsWith("Read register: GENESISFLOW_SampleRate ")) // { R.GENESISFLOW_SampleRate = lc.Replace("Read register: GENESISFLOW_SampleRate ", ""); } // if (lc.StartsWith("Read register: GENESISFLOW_ScaledBilling ")) // { R.GENESISFLOW_ScaledBilling = lc.Replace("Read register: GENESISFLOW_ScaledBilling ", ""); } // if (lc.StartsWith("Password file restore succeeded")) // { // R.PwFileUpdate = true; // } // if (lc.StartsWith("Paßwortdatei erfolgreich wiederhergestellt")) // { // R.PwFileUpdate = true; // } // // // } // if (!string.IsNullOrEmpty(R.PcbId)) // { // if (listRes.ContainsKey(R.PcbId)) // { // listRes[R.PcbId].Add(R); // } // else // { // listRes.Add(R.PcbId, new List() { R }); // } // } //} //var listEOL = new Dictionary>(); //foreach (var item in listRes) //{ // Console.WriteLine($"'{item.Key}', "); //} //Console.ReadLine(); //foreach (var line in File.ReadAllLines("E:\\bat\\History.csv")) //{ // var csvelm = line.Split(';'); // var cPcbId = csvelm[1]; // if (cPcbId.Length > 5) // { // var cAddress = csvelm[2]; // var cValue = csvelm[3]; // var cDate = csvelm[4]; // } //} var listEOL = new Dictionary>(); var pcbCheck = new List() { 222830007, 222830022 , 222830068 , 222830076 , 222830077 , 222830097 , 222830099 , 222830101 , 222830109 , 222830112 , 222830118 , 222830121 , 222830153 , 222830172 , 222830174 , 222830213 , 222830249 , 222830296 , 230930011 , 230930019 , 230930032 , 230930049 , 230930051 , 230930059 , 230930122 , 230930127 , 230930128 , 230930129 , 230930136 , 230930137 , 230930143 , 230930149 , 230930227 , 230930228 , 230930237 , 230930277 , 230930279 , 230930280 , 230930281 , 230930299 , 230930308 , 230930325 , 230930329 , 230930382 , 230930387 , 230930391 , 230930396 , 230930403 , 230930408 , 230930411 }; #endregion if (true) { foreach (var item in pcbCheck) { //Console.WriteLine($"'{item.Key}', "); //foreach (var re in item.Value) //{ // re.Calc(); //} var sbq = new StringBuilder(); sbq.AppendLine(" declare @PcbID as nvarchar(50) "); sbq.AppendLine(" declare @Adress as nvarchar(50) "); sbq.AppendLine($" set @PcbID = '{item}' "); sbq.AppendLine(" SELECT [ID] "); sbq.AppendLine(" ,[PcbId] "); sbq.AppendLine(" ,[Address] "); sbq.AppendLine(" ,[Value] "); sbq.AppendLine(" ,[date] "); sbq.AppendLine(" FROM [Auftrag].[dbo].[GenesisMeterRegisterHistory] "); sbq.AppendLine(" where PcbId = @PcbID "); sbq.AppendLine(" and (@Adress is null or [Address] = @Adress ) "); sbq.AppendLine(" order by [date] desc "); using (var dataacces = new SqlDataAccess("Data Source=SLASQL01.emea.sensus.net;;Initial Catalog=Auftrag;Persist Security Info=False;User ID=GenesisPasswordService;Password=PcbID;Connection Timeout=120")) { var dt = dataacces.ExecuteQuery(sbq.ToString()); foreach (DataRow row in dt.Rows) { resultRep currentRespons; if (!listEOL.ContainsKey(item)) { listEOL.Add(item, new List()); currentRespons = new resultRep() { DataDate = (DateTime)row["date"], PcbId = item.ToString(), Source = "PROD" }; listEOL[item].Add(currentRespons); } else { if (listEOL[item].Any(r => r.DataDate.Date == ((DateTime)row["date"]).Date)) { currentRespons = listEOL[item].First(r => r.DataDate.Date == ((DateTime)row["date"]).Date); } else { currentRespons = new resultRep() { DataDate = (DateTime)row["date"], PcbId = item.ToString(), Source = "PROD" }; listEOL[item].Add(currentRespons); } } switch (row["Address"].ToString()) { case "12-12": currentRespons.METROLOGYASST_PulseResolution = row["Value"].ToString(); break; case "12-11": currentRespons.METROLOGYASST_PulseEvenDistribution = row["Value"].ToString(); break; case "12-02": currentRespons.METROLOGYASST_PulseWeight = row["Value"].ToString(); break; case "12-03": currentRespons.METROLOGYASST_PulseMode = row["Value"].ToString(); break; case "12-04": currentRespons.METROLOGYASST_PulseLength = row["Value"].ToString(); break; case "0F-13": currentRespons.GENESISFLOW_ScaledBilling = row["Value"].ToString(); break; case "0F-00": currentRespons.GENESISFLOW_SampleRate = row["Value"].ToString(); break; case "0F-16": currentRespons.GENESISFLOW_LedMode = row["Value"].ToString(); break; case "01-09": var strTmp = row["Value"].ToString(); if (strTmp.Length > "D5-7A-AC-24-00-00-00-00".Length) { strTmp.Substring(0, "D5-7A-AC-24-00-00-00-00".Length); } if (String.IsNullOrEmpty(currentRespons.POWERMON_TotalUsedCharge)) { currentRespons.POWERMON_TotalUsedCharge = strTmp; } else { if (strTmp.Length == "D5-7A-AC-24-00-00-00-00".Length) { currentRespons.POWERMON_TotalUsedCharge = strTmp; } else { } } break; case "01-0A": if (row["Value"].ToString() != "00-00-00-00") { currentRespons.POWERMON_TotalUsedSeconds = row["Value"].ToString(); } break; case "01-00": if (row["Value"].ToString() != "00-00-00-00") { currentRespons.POWERMON_BatteryVoltage = row["Value"].ToString(); } break; case "01-04": currentRespons.POWERMON_BatteryQuantity = row["Value"].ToString(); break; case "14-09": if (row["Value"].ToString() != "00-00-00-00") { currentRespons.IRDA_AdapterID = row["Value"].ToString(); } break; case "14-00": if (row["Value"].ToString() != "00-00-00-00") { currentRespons.IRDA_PulseReportRate = row["Value"].ToString(); } break; default: break; } } } } } var pcbDate = new Dictionary(); var sbLEDQery = new StringBuilder(); sbLEDQery.AppendLine("select * from GenesisMeterRegisterHistory where PcbId in ( "); sbLEDQery.AppendLine(" "); sbLEDQery.AppendLine("'230930011', "); sbLEDQery.AppendLine("'230930127', "); sbLEDQery.AppendLine("'230930281', "); sbLEDQery.AppendLine("'230930129', "); sbLEDQery.AppendLine("'230930137', "); sbLEDQery.AppendLine("'230930280', "); sbLEDQery.AppendLine("'230930411', "); sbLEDQery.AppendLine("'230930049', "); sbLEDQery.AppendLine("'230930279', "); sbLEDQery.AppendLine("'222830068', "); sbLEDQery.AppendLine("'222830076', "); sbLEDQery.AppendLine("'222830174', "); sbLEDQery.AppendLine("'222830121', "); sbLEDQery.AppendLine("'222830112', "); sbLEDQery.AppendLine("'230930059', "); sbLEDQery.AppendLine("'222830022', "); sbLEDQery.AppendLine("'222830099', "); sbLEDQery.AppendLine("'230930122', "); sbLEDQery.AppendLine("'230930051', "); sbLEDQery.AppendLine("'230930227', "); sbLEDQery.AppendLine("'230930382', "); sbLEDQery.AppendLine("'230930391', "); sbLEDQery.AppendLine("'230930408', "); sbLEDQery.AppendLine("'230930308', "); sbLEDQery.AppendLine("'222830109', "); sbLEDQery.AppendLine("'230930128', "); sbLEDQery.AppendLine("'222830077', "); sbLEDQery.AppendLine("'222830101', "); sbLEDQery.AppendLine("'222830007', "); sbLEDQery.AppendLine("'222830249', "); sbLEDQery.AppendLine("'230930019', "); sbLEDQery.AppendLine("'230930299', "); sbLEDQery.AppendLine("'230930396', "); sbLEDQery.AppendLine("'230930387', "); sbLEDQery.AppendLine("'222830118', "); sbLEDQery.AppendLine("'230930403', "); sbLEDQery.AppendLine("'230930228', "); sbLEDQery.AppendLine("'222830097', "); sbLEDQery.AppendLine("'230930237', "); sbLEDQery.AppendLine("'230930032', "); sbLEDQery.AppendLine("'230930149', "); sbLEDQery.AppendLine("'222830213', "); sbLEDQery.AppendLine("'230930143', "); sbLEDQery.AppendLine("'230930136', "); sbLEDQery.AppendLine("'230930329', "); sbLEDQery.AppendLine("'230930277', "); sbLEDQery.AppendLine("'230930325', "); sbLEDQery.AppendLine("'222830296', "); sbLEDQery.AppendLine("'222830153', "); sbLEDQery.AppendLine("'222830172' "); sbLEDQery.AppendLine(") "); sbLEDQery.AppendLine("and Address in ('0F-16', '0F-00', '0F-22') order by PcbId, date"); var dic = new Dictionary>(); var dateTimeold = new DateTime(); var oldValue = false; var oldPCbID = ""; using (var dataacces = new SqlDataAccess("Data Source=SLASQL01.emea.sensus.net;;Initial Catalog=Auftrag;Persist Security Info=False;User ID=GenesisPasswordService;Password=PcbID;Connection Timeout=120")) { var dt = dataacces.ExecuteQuery(sbLEDQery.ToString()); foreach (DataRow row in dt.Rows) { var time = (DateTime)row["date"]; var pcb = (string)row["PcbId"]; var reg = (string)row["Address"]; var strVal = (string)row["Value"]; bool State = false; var re = ""; GreenHistoryItem last; if (!dic.ContainsKey(pcb)) { dic.Add(pcb, new List()); dic[pcb].Add(new GreenHistoryItem()); } last = dic[pcb].Last(); var newItem = new GreenHistoryItem() { Time = time, Idel = last.Idel, SR = last.SR, LedMode = last.LedMode, Remark = "int" }; switch (reg) { case "0F-16": if (strVal == "00-00-00-00") { newItem.LedMode = false; re = "LED Mode off"; } else { re = "LED Mode On"; newItem.LedMode = true; ; } break; case "0F-22": if (strVal == "00-00-00-00") { re = "Trigger active"; newItem.Idel = false; } else { re = "Trigger idel"; newItem.Idel = true; } break; case "0F-21": re = "Trigger active"; newItem.Idel = false; break; case "0F-00": if (strVal == "00-00-00-02") { newItem.SR = 2; re = "Sampel rate 2"; } else { newItem.SR = 10; re = "Sampel rate < 2"; } break; default: break; } newItem.Cal(); dic[pcb].Add(newItem); oldPCbID = pcb; } } Console.WriteLine("key;time;highconsumption;idel;ledmodeSR;totalConsomtion;add seconds;"); var dicS = new Dictionary(); foreach (var item in dic) { var s = 0.0; int c = -1; foreach (var gItem in item.Value) { if (c >= 0) { if (!item.Value[c].HighConsumption) { //war aus } else if (item.Value[c].HighConsumption) { gItem.SecondsInHighConsumption = (gItem.Time - item.Value[c].Time).TotalSeconds; s = s + gItem.SecondsInHighConsumption; } } if (item.Key == "230930325" || item.Key == "222830153" || item.Key == "230930329") { Console.WriteLine($"{item.Key};{gItem.Time};{gItem.HighConsumption};{gItem.Idel};{gItem.LedMode};{gItem.SR};{gItem.SecondsInHighConsumption}; {s}"); } c = c + 1; } dicS.Add(item.Key.ToString(), s); } Console.WriteLine("PcbId;Date;RemainingLifeTimeYears;DrainedBatteryLoadPercent;ExceededLifeTime_s;DrainedBatteryLoad_uAs;UNTLimit;unt Pass;Green LED days"); foreach (var item in listEOL) { if (item.Value != null && item.Value.Any()) { item.Value.ForEach(c => c.Calc()); foreach (var rItem in item.Value.OrderByDescending(o => o.DataDate)) { if (rItem.Calculated) { var s = 0.0; if (dicS.ContainsKey(rItem.PcbId)) { s = dicS[rItem.PcbId]; } Console.WriteLine($"{rItem.PcbId};{rItem.DataDate};{rItem.RemainingLifeTimeYears};{rItem.DrainedBatteryLoadPercent};{rItem.ExceededLifeTime_s};{rItem.DrainedBatteryLoad_uAs};{rItem.UNTLimit};{rItem.DrainedBatteryLoad_uAs>= rItem.UNTLimit };{s/60/60/24}"); break; } } } } foreach (var item in dic) { Console.WriteLine($"{item.Key};{item.Value}"); } Console.ReadLine(); //foreach (var item in listRes) //{ // if (item.Value.Any(a => a.PwFileUpdate)) // { // foreach (var v in item.Value) // { // v.Calc(); // Console.WriteLine($"{item.Key}; {v.DataDate}"); // } // } //} ////foreach (var item in listRes) ////{ //// if (item.Value.Any(a => !a.PwFileUpdate)) //// { //// Console.WriteLine($"{item.Key}; Prob Good"); //// } ////} //foreach (var item in listEOL.Where(c => c.Value.Any(r => r.Calculated))) //{ //} //var sb = new StringBuilder(); //foreach (var item in listRes) //{ // var Reps = item.Value.OrderBy(o => o.DataDate); // var SbDate = new StringBuilder(); // var SbSource = new StringBuilder(); // var sbCore = new StringBuilder(); // var sbCustomerName = new StringBuilder(); // var sbDrainedBatteryLoadPercent = new StringBuilder(); // var sbDrainedBatteryLoad_uAs = new StringBuilder(); // var sbExceededLifeTime_s = new StringBuilder(); // var sbPOWERMON_BatteryQuantity = new StringBuilder(); // var sbRemainingLifeTimeYears = new StringBuilder(); // var sbFW = new StringBuilder(); // var sbGENESISFLOW_LedMode = new StringBuilder(); // var sbGENESISFLOW_SampleRate = new StringBuilder(); // var sbGENESISFLOW_ScaledBilling = new StringBuilder(); // var sbIRDA_AdapterID = new StringBuilder(); // var sbIRDA_PulseReportRate = new StringBuilder(); // var sbMETROLOGYASST_PulseEvenDistribution = new StringBuilder(); // var sbMETROLOGYASST_PulseLength = new StringBuilder(); // var sbMETROLOGYASST_PulseMode = new StringBuilder(); // var sbMETROLOGYASST_PulseResolution = new StringBuilder(); // var sbMETROLOGYASST_PulseWeight = new StringBuilder(); // foreach (var rep in Reps.Where(c => c.Calculated)) // { // SbDate.Append(rep.DataDate).Append(';'); // SbSource.Append(rep.Source).Append(';'); // sbCore.Append(rep.Core).Append(';'); // sbCustomerName.Append(rep.CustomerName).Append(';'); // sbDrainedBatteryLoadPercent.Append(rep.DrainedBatteryLoadPercent).Append(';'); // sbDrainedBatteryLoad_uAs.Append(rep.DrainedBatteryLoad_uAs).Append(';'); // sbExceededLifeTime_s.Append(rep.ExceededLifeTime_s).Append(';'); // sbPOWERMON_BatteryQuantity.Append(rep.POWERMON_BatteryQuantity).Append(';'); // sbRemainingLifeTimeYears.Append(rep.RemainingLifeTimeYears).Append(';'); // sbFW.Append(rep.FW).Append(';'); // sbGENESISFLOW_LedMode.Append(rep.GENESISFLOW_LedMode).Append(';'); // sbGENESISFLOW_SampleRate.Append(rep.GENESISFLOW_SampleRate).Append(';'); // sbGENESISFLOW_ScaledBilling.Append(rep.GENESISFLOW_ScaledBilling).Append(';'); // sbIRDA_AdapterID.Append(rep.IRDA_AdapterID).Append(';'); // sbIRDA_PulseReportRate.Append(rep.IRDA_PulseReportRate).Append(';'); // sbMETROLOGYASST_PulseEvenDistribution.Append(rep.METROLOGYASST_PulseEvenDistribution).Append(';'); // sbMETROLOGYASST_PulseLength.Append(rep.METROLOGYASST_PulseLength).Append(';'); // sbMETROLOGYASST_PulseMode.Append(rep.METROLOGYASST_PulseMode).Append(';'); // sbMETROLOGYASST_PulseResolution.Append(rep.METROLOGYASST_PulseResolution).Append(';'); // sbMETROLOGYASST_PulseWeight.Append(rep.METROLOGYASST_PulseWeight).Append(';'); // } // if (Reps.Any(c => c.Calculated && c.Source == "PROD") && Reps.Any(c => c.Calculated && c.Source == "CUST")) // { // sb.AppendLine($"PCBId;{item.Key};"); // sb.AppendLine($"Date;{SbDate}"); // sb.AppendLine($"Source;{SbSource}"); // sb.AppendLine($"Core;{sbCore}"); // sb.AppendLine($"CustomerName;{sbCustomerName}"); // sb.AppendLine($"DrainedBatteryLoadPercent;{sbDrainedBatteryLoadPercent}"); // sb.AppendLine($"DrainedBatteryLoad_uAs;{sbDrainedBatteryLoad_uAs}"); // sb.AppendLine($"ExceededLifeTime_s;{sbExceededLifeTime_s}"); // sb.AppendLine($"POWERMON_BatteryQuantity;{sbPOWERMON_BatteryQuantity}"); // sb.AppendLine($"RemainingLifeTimeYears;{sbRemainingLifeTimeYears}"); // sb.AppendLine($"FW;{sbFW}"); // sb.AppendLine($"GENESISFLOW_LedMode;{sbGENESISFLOW_LedMode}"); // sb.AppendLine($"GENESISFLOW_SampleRate;{sbGENESISFLOW_SampleRate}"); // sb.AppendLine($"GENESISFLOW_ScaledBilling;{sbGENESISFLOW_ScaledBilling}"); // sb.AppendLine($"IRDA_AdapterID;{sbIRDA_AdapterID}"); // sb.AppendLine($"IRDA_PulseReportRate;{sbIRDA_PulseReportRate}"); // sb.AppendLine($"METROLOGYASST_PulseEvenDistribution;{sbMETROLOGYASST_PulseEvenDistribution}"); // sb.AppendLine($"METROLOGYASST_PulseLength;{sbMETROLOGYASST_PulseLength}"); // sb.AppendLine($"METROLOGYASST_PulseMode;{sbMETROLOGYASST_PulseMode}"); // sb.AppendLine($"METROLOGYASST_PulseResolution;{sbMETROLOGYASST_PulseResolution}"); // sb.AppendLine($"METROLOGYASST_PulseWeight;{sbMETROLOGYASST_PulseWeight}"); // } //} //sb.AppendLine(); //sb.AppendLine(); //sb.AppendLine($"PCbID;LastProdDate;LastCUSTDate;TotalDays;LastProd_DrainedBatteryLoadPercent ;LastCUST_DrainedBatteryLoadPercent;LastProd_RemainingLifeTimeYears ;LastCUST_RemainingLifeTimeYears; "); //foreach (var item in listRes) //{ // if (item.Value.Any(c => c.Calculated && c.Source == "PROD") && item.Value.Any(c => c.Calculated && c.Source == "CUST")) // { // var LastProd = item.Value.First(f => f.DataDate == item.Value.Where(c => c.Source == "PROD").Max(m => m.DataDate)); // var LastCUST = item.Value.First(f => f.DataDate == item.Value.Where(c => c.Source == "CUST").Max(m => m.DataDate)); // if (LastProd.DataDate < LastCUST.DataDate) // { // var ts = LastCUST.DataDate - LastProd.DataDate; // sb.AppendLine($"{item.Key};{LastProd.DataDate};{LastCUST.DataDate };{ts.TotalDays};{LastProd.DrainedBatteryLoadPercent} ;{LastCUST.DrainedBatteryLoadPercent};{LastProd.RemainingLifeTimeYears} ;{LastCUST.RemainingLifeTimeYears}; "); // } // } //} //File.WriteAllText("output.csv", sb.ToString()); Console.ReadLine(); } } }