/// <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> /// Create and return commands for deleting duplicate items from database /// </summary> /// <returns></returns> private List <string> CreateDBRemoveCommands() { List <string> commands = new List <string>(); // List of database commands foreach (Data15MinClass d15 in dataPtr.data) { if (d15.numberOfPoints < 2) { continue; // If point have less than 2 values ignore } var uniqueValues = new List <FloatValues>(); // Create new list which will hold unique values var all15minValues = d15.GetAllValues(); // Some 15min point can have multiple values, duplicates // First value is always unique uniqueValues.Add(all15minValues[0]); // Generate remove command for each duplicated value, leave values that are different in float values for (int i = 1; i < d15.GetAllValues().Count; i++) // Skip first { bool equalFlag = false; // This will be set to true if any of data point is true duplicate foreach (var item2 in uniqueValues) { if (FloatHelper.CompareDuplicateValues(item2, all15minValues[i])) // Check if they are equal { equalFlag = true; // Generate command for row removal from database and add it to list of commands commands.Add(GenerateDatabaseRemoveCommand(all15minValues[i])); } } if (!equalFlag) { // This garantiues unique value uniqueValues.Add(all15minValues[i]); } equalFlag = false; } } return(commands); }