//Loads a wider range and trims off that seconds from the first and last snapshots to match the date range provided. public static Snapshots LoadRange(int thermostatId, DateTime startDate, DateTime endDate) { Snapshots snapshots = Snapshots.LoadSnapshots("SELECT * FROM Snapshots WHERE thermostat_id=@ThermostatId and start_time BETWEEN @StartDate AND @EndDate ORDER BY start_time", CommandType.Text, new MySqlParameter[] { new MySqlParameter("@ThermostatId", thermostatId), new MySqlParameter("@StartDate", startDate.AddDays(-1)), new MySqlParameter("@EndDate", endDate) }); //filter through them and chop off seconds before and after the cycle; Snapshots result = new Snapshots(); foreach (Snapshot existing in snapshots) { DateTime endTime = existing.StartTime.AddSeconds(existing.Seconds); if (endTime > startDate) { Snapshot snapshot = existing; if (snapshot.StartTime < startDate) { snapshot.Seconds = snapshot.Seconds - (int)new TimeSpan(startDate.Ticks - snapshot.StartTime.Ticks).TotalSeconds; snapshot.StartTime = startDate; } if (endTime > endDate) { snapshot.Seconds = snapshot.Seconds - (int)new TimeSpan(endTime.Ticks - endDate.Ticks).TotalSeconds; } result.Add(snapshot); } } return(result); }
public static Snapshots ConvertFromDT(DataTable dt) { Snapshots result = new Snapshots(); foreach (DataRow row in dt.Rows) { result.Add(Snapshot.GetSnapshot(row)); } return(result); }
public Snapshots Sort(string column, bool desc) { var sortedList = desc ? this.OrderByDescending(x => x.GetPropertyValue(column)) : this.OrderBy(x => x.GetPropertyValue(column)); Snapshots result = new Snapshots(); foreach (var i in sortedList) { result.Add((Snapshot)i); } return(result); }
//Loads a wider range and trims off that seconds from the first and last snapshots to match the date range provided. public static Snapshots LoadRange(int thermostatId, DateTime startDate, DateTime endDate) { Snapshots snapshots = Snapshots.LoadSnapshots("SELECT * FROM Snapshots WHERE thermostat_id=@ThermostatId and start_time BETWEEN @StartDate AND @EndDate ORDER BY start_time", CommandType.Text, new MySqlParameter[] { new MySqlParameter("@ThermostatId", thermostatId), new MySqlParameter("@StartDate", startDate.AddDays(-1)), new MySqlParameter("@EndDate", endDate) }); //filter through them and chop off seconds before and after the cycle; Snapshots result = new Snapshots(); foreach (Snapshot existing in snapshots) { DateTime endTime = existing.StartTime.AddSeconds(existing.Seconds); if (endTime > startDate) { Snapshot snapshot = existing; if (snapshot.StartTime < startDate) { snapshot.Seconds = snapshot.Seconds - (int)new TimeSpan(startDate.Ticks - snapshot.StartTime.Ticks).TotalSeconds; snapshot.StartTime = startDate; } if (endTime > endDate) { snapshot.Seconds = snapshot.Seconds - (int)new TimeSpan(endTime.Ticks - endDate.Ticks).TotalSeconds; } result.Add(snapshot); } } return result; }