//private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) //{ // Console.WriteLine(e.RowIndex + " cell entered"); // if (e.RowIndex == -1) // { // return; // Table is not populated yet // } //} //private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e) //{ // Console.WriteLine(e.RowIndex + " cell left"); //} #endregion private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { string resI, resU; if (e.ColumnIndex == 0) { labelValues.Text = ""; return; } int offset = e.RowIndex * 96 + e.ColumnIndex - 1; // Check if there are any values if (dataPtr.data[offset].flags.missingFlag) { return; } if (dataPtr.data[offset].Values.successfullyParsed == false) // Check if null values { resI = "Ia=NULL Ib=NULL ic=NULL" + " "; resU = "Vab=NULL Vbc=NULL Vca=NULL"; } else { // Data is valid FloatValues f = dataPtr.data[offset].Values; resI = "Ia=" + f.ia.ToString("0.000") + " " + "Ib=" + f.ib.ToString("0.000") + " " + "Ic=" + f.ic.ToString("0.000") + " "; resU = "Vab=" + f.vab.ToString("0.000") + " " + "Vbc=" + f.vbc.ToString("0.000") + " " + "Vca=" + f.vca.ToString("0.000"); } labelValues.Text = resI + resU; }
/// <summary> /// Decode data from database and fill AllData[currentRow] with results /// </summary> /// <param name="dataString"></param> /// <param name="dateStart"></param> /// <param name="dateEnd"></param> /// <param name="id"></param> /// <param name="delim"></param> public void FillDataRow(string dataString, int id, char delim) { string validFlag; string timestamp; DateTime currentDate, readDate; TimeSpan ts; int current15MinValue = 0; string[] rows = dataString.Split(delim); // split monolithic data to single rows currentDate = startDate; // Fill everything with data missing ts = endDate.Subtract(currentDate); while (ts.TotalMinutes != 0) { data[current15MinValue] = new Data15MinClass(currentDate); // Fill with "missing" data currentDate = currentDate.AddMinutes(15); // Update current date current15MinValue++; ts = endDate.Subtract(currentDate); } // Sometimes there wont be any data if (rows.Length == 1 && dataString.Equals("")) {// This is when no results came from db deviceID = id; return; } else { // Everything is ok (we have some data), loop thru every row and parse it for (int i = 0; i < rows.Length; i++) { #warning I experimented with null values // Read values string[] temp = rows[i].Split(';'); // Split row from db to separated searched values // t[0]=valid, t[1]=ia, t[2]=ib, t[3]=ic, t[4]=vab, t[5]=vbc, t[6]=vca, t[7]=read_time validFlag = temp[0]; timestamp = temp[7]; readDate = HelperClass.ConvertOracleTimeToDateTime(timestamp); FloatValues fv = new FloatValues(temp[1], temp[2], temp[3], temp[4], temp[5], temp[6], temp[8]); if (!fv.successfullyParsed) { // This is null value, replace with default values for null fv.ReplaceWithNullValue(); } // Get number of minutes since start ts = readDate.Subtract(startDate); // Calculate 15min sector and update it current15MinValue = (int)ts.TotalMinutes / 15; data[current15MinValue].UpdateData15min(Convert.ToInt32(validFlag), fv); } } deviceID = id; }
/// <summary> /// Analyze all 15min data points and rise internal flags based on values /// </summary> public void ProcessData() { lastFw = new FloatValues(); // Initialize with devil data foreach (var d in data) { if (d.valid == 1) { // Data is valid if (d.numberOfPoints != 0) { // First check if there is some data (null values) if (d.Values == null) { d.flags.nullFlag = true; continue; } // Check is it zero d.flags.zeroFlag = FloatHelper.CheckIfZero(d.Values); if (!d.flags.zeroFlag) { // Check if data is repeating, ignoring zero values d.flags.dataRepeatFlag = FloatHelper.CompareDuplicateValues(lastFw, d.Values); // This duplicate is based on last storred value lastFw = d.Values; // make sure next 15min point compares with this value } // Check if null if (!d.Values.successfullyParsed) // Probably redundant { d.flags.nullFlag = true; } if (d.numberOfPoints > 1) // Is it duplicate (more data points arrived for this timestamp) { d.flags.duplicateFlag = true; } } else { // numberOfPoints = 0 // Data is missing d.flags.missingFlag = true; } } else { // Data is not valid d.flags.invalidFlag = true; } } // foreach }
/// <summary> /// This method is called when we found data point /// </summary> /// <param name="data"></param> public void UpdateData15min(int val, FloatValues data) // This should be called when readTime < currentTime, probably duplicate { //double.TryParse(uniqueID, out this.uniqueID); if (val != 1) // if this data read from database is corrupted abort { return; } // Database readings are valid, continue numberOfPoints++; Values = data; // Add newer data (this is special setter method not just assignment) //if (data.successfullyParsed) //{ // Values = data; // Add newer data if data is consistent (this is special setter method not just assignment) //} }
private string GenerateDatabaseRemoveCommand(FloatValues point) { return("DELETE FROM DATA_HISTORY WHERE ID = " + point.uniqueID.ToString()); }
public void RemoveValue(FloatValues f) { internalValues.Remove(f); numberOfPoints--; }