public void addNotify(TemperatureEntry ent) { history.entries.AddLast(ent); // Remove old entries long time = DateTime.UtcNow.Ticks; long ltime = (long)time; long lhour = ltime / 36000000000; double mintime = time - 36000000000; while (history.entries.First.Value.time < mintime) history.entries.RemoveFirst(); // Create average values int nExtruder = 0, nBed = 0, nOut = 0; float sumExtruder = 0, sumBed = 0, sumOutput = 0; mintime = DateTime.UtcNow.Ticks - avgPeriod * 10000000; foreach (TemperatureEntry e in history.entries) { if (e.time < mintime) continue; if (e.extruder > -1000) { nExtruder++; sumExtruder += e.extruder; } if (e.bed > -1000) { nBed++; sumBed += e.bed; } if (e.output > -1000) { nOut++; sumOutput += e.output; } } if (nExtruder > 0) ent.avgExtruder = sumExtruder / (float)nExtruder; if (nBed > 0) ent.avgBed = sumBed / (float)nBed; if (nOut > 0) ent.avgOutput = sumOutput / (float)nOut; history.maxTime = time; history.minTime = time - 36000000000; if (lhour != currentHour) { currentHour = lhour; DateTime now = DateTime.Now; string stime = now.ToString("MMMM dd, HH"); ToolStripMenuItem item = new ToolStripMenuItem(stime,null, Main.main.selectTimePeriod); item.Tag = lists.Count; hourHistory = new TemperatureList(); hourHistory.minTime = lhour * 36000000000; hourHistory.maxTime = hourHistory.minTime + 36000000000; lists.AddLast(hourHistory); Main.main.timeperiodMenuItem.DropDownItems.Add(item); } hourHistory.entries.AddLast(ent); if (Main.main.tabControlView.SelectedIndex == 1) Main.main.tabPageTemp.Refresh(); }
public void addNotify(TemperatureEntry ent) { history.entries.AddLast(ent); // Remove old entries long time = DateTime.UtcNow.Ticks; long ltime = (long)time; long lhour = ltime / 36000000000; double mintime = time - 36000000000; while (history.entries.First.Value.time < mintime) { history.entries.RemoveFirst(); } // Create average values int nExtruder = 0, nBed = 0, nOut = 0; float sumExtruder = 0, sumBed = 0, sumOutput = 0; mintime = DateTime.UtcNow.Ticks - avgPeriod * 10000000; foreach (TemperatureEntry e in history.entries) { if (e.time < mintime) { continue; } if (e.extruder > -1000) { nExtruder++; sumExtruder += e.extruder; } if (e.bed > -1000) { nBed++; sumBed += e.bed; } if (e.output > -1000) { nOut++; sumOutput += e.output; } } if (nExtruder > 0) { ent.avgExtruder = sumExtruder / (float)nExtruder; } if (nBed > 0) { ent.avgBed = sumBed / (float)nBed; } if (nOut > 0) { ent.avgOutput = sumOutput / (float)nOut; } history.maxTime = time; history.minTime = time - 36000000000; if (lhour != currentHour) { currentHour = lhour; DateTime now = DateTime.Now; string stime = now.ToString("MMMM dd, HH"); ToolStripMenuItem item = new ToolStripMenuItem(stime, null, Main.main.selectTimePeriod); item.Tag = lists.Count; hourHistory = new TemperatureList(); hourHistory.minTime = lhour * 36000000000; hourHistory.maxTime = hourHistory.minTime + 36000000000; lists.AddLast(hourHistory); Main.main.timeperiodMenuItem.DropDownItems.Add(item); } hourHistory.entries.AddLast(ent); if (Main.main.tabControlView.SelectedIndex == 1) { Main.main.tabPageTemp.Refresh(); } }