//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 Snapshot LoadLastSnapshot(int thermostatId) { Snapshots result = Snapshots.LoadSnapshots("SELECT * FROM snapshots where thermostat_id=@ThermostatId and start_time = (select MAX(start_time) from snapshots where thermostat_id=@ThermostatId)", CommandType.Text, new MySqlParameter[] { new MySqlParameter("@ThermostatId", thermostatId) }); if (result.Count > 0) { return(result[0]); } else { return(null); } }
public static Snapshots LoadAllSnapshots() { return(Snapshots.LoadSnapshots("snapshots_load_all", CommandType.StoredProcedure, null)); }
public static Snapshots LoadSnapshotsByThermostatId(int thermostatId) { return(Snapshots.LoadSnapshots("snapshots_load_by_thermostat_id", CommandType.StoredProcedure, new MySqlParameter[] { new MySqlParameter("@thermostat_id", thermostatId) })); }
public static Snapshots LoadSnapshotsByThermostatId(System.Int32 thermostatId) { return(Snapshots.LoadSnapshots("LoadSnapshotsByThermostatId", CommandType.StoredProcedure, new SqlParameter[] { new SqlParameter("@ThermostatId", thermostatId) })); }