public HSummaryGraph(DataGridView p) { int row; const int colHmin = 6; const int colHavg = 8; const int colHmax = 9; const string sHmin = "Hmin"; const string sHavg = "Havg"; const string sHmax = "Hmax"; dgvWeatherAnalysis = p; InitializeComponent(); HSummary.Series[sHmin].XValueType = ChartValueType.Date; HSummary.Series[sHavg].XValueType = ChartValueType.Date; HSummary.Series[sHmax].XValueType = ChartValueType.Date; row = 1; foreach (DataGridViewRow dgvr in dgvWeatherAnalysis.Rows) { if (dgvr.Cells[0].Value != null) { DateTime x = DateParser.DateStringToDateTime((string)dgvr.Cells[0].Value); HSummary.Series[sHmin].Points.AddXY(x.ToOADate(), dgvr.Cells[colHmin].Value); HSummary.Series[sHavg].Points.AddXY(x.ToOADate(), dgvr.Cells[colHavg].Value); HSummary.Series[sHmax].Points.AddXY(x.ToOADate(), dgvr.Cells[colHmax].Value); row++; } } }
public PSummary(DataGridView p) { const string sPmin = "Pmin"; const string sPavg = "Pavg"; const string sPmax = "Pmax"; const int colPmin = 15; const int colPavg = 17; const int colPmax = 18; int row; dgvWeatherAnalysis = p; InitializeComponent(); this.pressureChart.Series[sPmin].XValueType = ChartValueType.Date; this.pressureChart.Series[sPavg].XValueType = ChartValueType.Date; this.pressureChart.Series[sPmax].XValueType = ChartValueType.Date; this.pressureChart.ChartAreas[0].AxisY.Minimum = 99000; this.pressureChart.ChartAreas[0].AxisY.Maximum = 104000; row = 1; foreach (DataGridViewRow dgvr in dgvWeatherAnalysis.Rows) { if (dgvr.Cells[0].Value != null) { DateTime x = DateParser.DateStringToDateTime((string)dgvr.Cells[0].Value); this.pressureChart.Series[sPmin].Points.AddXY(x.ToOADate(), dgvr.Cells[colPmin].Value); this.pressureChart.Series[sPavg].Points.AddXY(x.ToOADate(), dgvr.Cells[colPavg].Value); this.pressureChart.Series[sPmax].Points.AddXY(x.ToOADate(), dgvr.Cells[colPmax].Value); row++; } } }
public BSummaryGraph(DataGridView p) { int row; const int colBmin = 11; const int colBmax = 13; const string sBmin = "Bmin"; const string sBmax = "Bmax"; const string sChartArea = "ChartArea1"; dgvWeatherAnalysis = p; InitializeComponent(); BattChart.Series[sBmin].XValueType = ChartValueType.Date; BattChart.Series[sBmax].XValueType = ChartValueType.Date; BattChart.ChartAreas[sChartArea].AxisY.Minimum = 3.4; BattChart.ChartAreas[sChartArea].AxisY.Maximum = 4.5; row = 1; foreach (DataGridViewRow dgvr in dgvWeatherAnalysis.Rows) { if (dgvr.Cells[0].Value != null) { DateTime x = DateParser.DateStringToDateTime((string)dgvr.Cells[0].Value); BattChart.Series[sBmin].Points.AddXY(x.ToOADate(), dgvr.Cells[colBmin].Value); BattChart.Series[sBmax].Points.AddXY(x.ToOADate(), dgvr.Cells[colBmax].Value); row++; } } InitializeComponent(); }
public InDayAllCharts(DataTable dtWeather, string date) { int row; bool found = false; const int colTemp1 = 5; const int colTemp2 = 6; const int colTemp3 = 7; const int colHumidity = 8; const int colPressure = 9; const int colBattery = 2; InitializeComponent(); Text += " " + date; // Add the date we are showing to form window caption // Set X Axis as Time axis and Y scale for each graph this.temperatures.Series[0].XValueType = ChartValueType.Time; this.humidity.Series[0].XValueType = ChartValueType.Time; this.humidity.ChartAreas[0].AxisY.Minimum = 0; this.humidity.ChartAreas[0].AxisY.Maximum = 100; this.pressure.Series[0].XValueType = ChartValueType.Time; this.pressure.ChartAreas[0].AxisY.Minimum = 99000; this.pressure.ChartAreas[0].AxisY.Maximum = 104000; this.battery.Series[0].XValueType = ChartValueType.Time; this.battery.ChartAreas[0].AxisY.Minimum = 3.4; this.battery.ChartAreas[0].AxisY.Maximum = 4.5; row = 1; foreach (DataRow dr in dtWeather.Rows) { if (date.Equals((string)dr[0])) { float humidity = (float)dr[colHumidity]; if (humidity != 0) // Sometimes the DHT22 fails and we are getting 0's. There is no 0% humidity realistically, so drop these points { DateTime x = DateParser.DateAndTimeStringToDateTime((string)dr[0], (string)dr[1]); found = true; double temp = ((float)dr[colTemp1] + (float)dr[colTemp2] + (float)dr[colTemp3]) / 3; this.temperatures.Series[0].Points.AddXY(x.ToShortTimeString(), temp); this.humidity.Series[0].Points.AddXY(x.ToShortTimeString(), dr[colHumidity]); this.pressure.Series[0].Points.AddXY(x.ToShortTimeString(), dr[colPressure]); this.battery.Series[0].Points.AddXY(x.ToShortTimeString(), dr[colBattery]); /* * SummaryChart.Series[sTmin].Points.AddXY(x.ToOADate(), dgvr.Cells[colTmin].Value); * SummaryChart.Series[sTavg].Points.AddXY(x.ToOADate(), dgvr.Cells[colTavg].Value); * SummaryChart.Series[sTmax].Points.AddXY(x.ToOADate(), dgvr.Cells[colTmax].Value); */ } } else if (found == true) // If not equal anymore and we did find the date, break the foreach loop { break; } row++; } }
private void AnalyzeData(DataTable weatherData, bool filterSet, DateTime dtStart, DateTime dtEnd) { // Do some data analysis here DataRow oldDr = null; DataMeasure temperature = new DataMeasure(-273); // Not likely to get this temperature ever DataMeasure humidity = new DataMeasure(0); // Sometimes the DHT22 gives 0 reading. Simply ignore those DataMeasure voltage = new DataMeasure(6); // We won't get 6V reading for sure DataMeasure pressure = new DataMeasure(0); bool row_avail = false; float humidityValue; foreach (DataRow dr in weatherData.Rows) { //DateTime dt = new DateTime((int)dr[4], (int)dr[5], (int)dr[6], (int)dr[7], (int)dr[8], (int)dr[9]); // The data and time of this reading as parsed from computer time DateTime dt = DateParser.DateAndTimeStringToDateTime((string)dr[0], (string)dr[1]); // check if filtering by dates and if so, if the record is in the range of the filter if ((filterSet == false) || ((filterSet == true) && (dt >= dtStart) && (dt <= dtEnd))) { // loop through all the rows, and if this is not the first one if (oldDr != null) { string s1 = (string)dr[0]; string s2 = (string)oldDr[0]; if (s1.Equals(s2) == false) // Did we change dates? { AddTodayRow((string)oldDr[0], temperature, humidity, voltage, pressure); // And now reset the accumulators for next day reading temperature.reset(); humidity.reset(); voltage.reset(); pressure.reset(); row_avail = false; } } humidityValue = (float)dr[8]; if (humidityValue != 0) // Drop DHT22 reading if the humidity is 0. { temperature.add(((float)dr[5] + (float)dr[6] + (float)dr[7]) / 3, dt); // Average temperature from 3 temperatures sensor humidity.add((float)dr[8], dt); } else { temperature.add(((float)dr[5] + (float)dr[7]) / 2, dt); // Average temperature from 2 temperatures sensor other than DHT22 } voltage.add((float)dr[2], dt); long l = (long)dr[9]; pressure.add(l, dt); dtRange.add(dt); row_avail = true; oldDr = dr; } } // Check if last line needs to be added if (row_avail) { AddTodayRow((string)oldDr[0], temperature, humidity, voltage, pressure); } // Now update the controls of date filter with min and max dates bool firstTime = dtRange.firstTime(); DateTime dtMin = dtRange.getMin(); DateTime dtMax = dtRange.getMax(); this.dateTimePickerFrom.MinDate = dtMin; this.dateTimePickerFrom.MaxDate = dtMax; if (firstTime == false) { this.dateTimePickerFrom.Value = dtMin; } this.dateTimePickerTo.MinDate = dtMin; this.dateTimePickerTo.MaxDate = dtMax; if (firstTime == false) { this.dateTimePickerTo.Value = dtMax; } }