private static int comp_func(Record x, Record y) { if (x.date > y.date) return 1; if (x.date == y.date) return 0; if (x.date < y.date) return -1; return -1; }
private static void part1() { list_rec2 = new List<Record>(); int size = array_rec.Length; for (int i = 0; i < size; i++) { list_rec2.Add(array_rec[i]); DateTime next_date; // not last record if (i != size - 1) { int j = 1; next_date = array_rec[i].date.AddDays(j); while (next_date != array_rec[i + 1].date) { // insert extrapolate element Record new_rec = new Record(); new_rec.date = next_date; new_rec.high_temp = (array_rec[i].high_temp + array_rec[i + 1].high_temp) / 2.0; new_rec.low_temp = (array_rec[i].low_temp + array_rec[i + 1].low_temp) / 2.0; new_rec.ave_temp = (new_rec.low_temp + new_rec.high_temp) / 2.0; new_rec.is_missing = true; Console.WriteLine(next_date.ToString("dd-MMM-yyyy")); list_rec2.Add(new_rec); j++; next_date = array_rec[i].date.AddDays(j); } } } array_rec2 = list_rec2.ToArray(); }
private static void read_data() { list_rec = new List<Record>(); try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. using (StreamReader sr = new StreamReader("NYCTemps.csv")) { String line; // bypass first line sr.ReadLine(); // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { string[] line_array = line.Split(','); //create Record Object for each entry Record rec = new Record(); rec.date = Convert.ToDateTime(line_array[0]); rec.high_temp = Convert.ToDouble(line_array[1]); rec.low_temp = Convert.ToDouble(line_array[2]); rec.ave_temp = (rec.high_temp + rec.low_temp) / 2.0; rec.is_missing = false; /* Console.WriteLine(line); Console.WriteLine(rec.date); Console.WriteLine(rec.high_temp); Console.WriteLine(rec.low_temp); Console.WriteLine(rec.ave_temp); //*/ list_rec.Add(rec); } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }