public string ApproximatedTimeData() { try { string estBuildDone = "Process.TimeApproximation.BuildDoneTime"; string buildDone = "Alarms.BuildDone"; //string estimatedTotalTime = "Process.TimeApproximation.EstimatedBuildDoneTime"; string heatStartPlateDone = "Process.ProcessManager.HeatStartPlateDone"; //var allBuildDone = new FullnameEnumerator(currents, m_Database).ToArray(); //var allFeedback = new FullnameEnumerator(feedback, m_Database).ToArray(); LogRowData buildDoneItem = m_Database.GetLastItem(buildDone, p => p.Value == "Set"); string output = string.Empty; if (buildDoneItem != null) { DateTime buildDoneTime = buildDoneItem.TimeStamp; LogRowData buildStartMeltTime = m_Database.GetLastItem(heatStartPlateDone); IEnumerable <LogRowData> allEstBuildDoneItems = m_Database.GetAll(estBuildDone).Where(p => p.TimeStamp >= buildStartMeltTime.TimeStamp && p.TimeStamp < buildDoneTime - TimeSpan.FromMinutes(15)); output = $"Build done: \t\t{buildDoneTime}\r\n\r\n"; foreach (LogRowData estBuildDoneItem in allEstBuildDoneItems) { DateTime estDoneTime = DateTime.Parse(estBuildDoneItem.Value); TimeSpan totalTimeDiff = estDoneTime - buildDoneTime; TimeSpan timeForEstimation = buildDoneTime - estBuildDoneItem.TimeStamp; double diff = Math.Abs(totalTimeDiff.TotalSeconds / timeForEstimation.TotalSeconds); output += $"{estBuildDoneItem.TimeStamp}:\t{estDoneTime} \t{totalTimeDiff:d\\.hh\\:mm} \t{100 * diff:0.0}%\r\n"; } } return(output); } catch (Exception) { } return(string.Empty); }
private void CompareLogFile(object o, EventArgs args) { var textWindow = new Form { Text = "Compare themes", Width = 600, Height = 600 }; var txt = new RichTextBox { ShortcutsEnabled = true, Text = "Loading second file...", Width = 580, Height = 570, Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left, ScrollBars = RichTextBoxScrollBars.Vertical, ReadOnly = true, Multiline = true }; textWindow.Controls.Add(txt); textWindow.Show(); LogDatabase referenceDb = null; try { var openReferenceLogFileDialog = new OpenFileDialog { Filter = "Log files |*.zip; *.plg|All files (*.*)|*.*", FilterIndex = 1, Multiselect = false, Title = "Select reference file" }; DialogResult userClickedOK = openReferenceLogFileDialog.ShowDialog(); if (userClickedOK != DialogResult.OK) { return; } referenceDb = new LogDatabase(openReferenceLogFileDialog.FileName, true, null); referenceDb.Start(); //wait while indexing reference log file database while (referenceDb.State != ProgressStateEnum.Done && referenceDb.State != ProgressStateEnum.Monitoring) { Thread.Sleep(500); } //Add ids in themes and machine, except process themes Func <string[], Dictionary <string, string> > getIds = ids => ids.Where(p => p.StartsWith("Machine.")).Concat(ids.Where(p => p.StartsWith("Themes.") && !p.StartsWith( "Themes.ProcessStep["))) .ToDictionary(p => p); Dictionary <string, string> loadedIds = getIds(m_Database.GetItemsIDs().ToArray()); Dictionary <string, string> referenceIds = getIds(referenceDb.GetItemsIDs().ToArray()); KeyValuePair <string, string>[] changesInLoadedIds = loadedIds.Where(p => m_Database.GetAll(p.Key).Count() > 1).ToArray(); KeyValuePair <string, string>[] changesInReferenceIds = referenceIds.Where(p => referenceDb.GetAll(p.Key).Count() > 1).ToArray(); string output = $"Comparing {m_Database.Filename} with reference {referenceDb.Filename}" + Environment.NewLine + Environment.NewLine; if (changesInLoadedIds.Length > 0) { output += "These items have multiple entries in the log file. Using the last entry as comparison:" + Environment.NewLine; } output = changesInLoadedIds.Aggregate(output, (current, changesInLoadedId) => current + changesInLoadedId.Key + Environment.NewLine); if (changesInReferenceIds.Length > 0) { output += Environment.NewLine + "These items have multiple entries in the reference file. Using the last entry as comparison:" + Environment.NewLine; } output = changesInReferenceIds.Aggregate(output, (current, changesInRefId) => current + changesInRefId.Key + Environment.NewLine); output += Environment.NewLine; output += "Changes compared to reference file:" + Environment.NewLine; foreach (KeyValuePair <string, string> id in referenceIds) { bool compareExist = m_Database.Exists(id.Key); string refValue = referenceDb.GetLastItem(id.Key, t => t.CycleIndex >= 0).Value; if (compareExist) { string compareValue = m_Database.GetLastItem(id.Key, t => t.CycleIndex >= 0).Value; if (compareValue != refValue) { output += $"Change \t{id.Value} \t{refValue} \t->\t {compareValue}" + Environment.NewLine; } } else { output += $"Removed \t{id.Value} \t{refValue}" + Environment.NewLine; } } foreach (KeyValuePair <string, string> loadedId in loadedIds.Where(p => !referenceDb.Exists(p.Key))) { string compareValue = m_Database.GetLastItem(loadedId.Key, t => t.CycleIndex >= 0).Value; output += $"New \t{loadedId.Value} \t{compareValue}" + Environment.NewLine; } txt.Text = output; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { referenceDb?.Dispose(); } }