protected void Page_Load(object sender, EventArgs e) { DeleteOldData(); DataTable thermostats = ThermostatMonitorLib.Thermostats.LoadPublicThermostats(); OutputCSV(ThermostatMonitorLib.Utils.DataTableToCSV(thermostats), "/dump/thermostats.csv"); foreach (DataRow row in thermostats.Rows) { int id = Convert.ToInt32(row["Id"]); int locationId = Convert.ToInt32(row["LocationId"]); double acKilowatts = Convert.ToDouble(row["ACKilowatts"]); double fanKilowatts = Convert.ToDouble(row["FanKilowatts"]); double heatBTU = 0; try { heatBTU = Convert.ToDouble(row["HeatBtuPerHour"]); } catch { } ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(id, new DateTime(2000, 1, 1), DateTime.Now); OutputCSV(cycles.GetCSV(acKilowatts, fanKilowatts, heatBTU, 0), "/dump/t" + id.ToString() + "_cycles.csv"); OutputCSV(ThermostatMonitorLib.Temperatures.LoadTemperaturesByThermostatId(id).GetCSV(), "/dump/t" + id.ToString() + "_inside.csv"); OutputCSV(ThermostatMonitorLib.OutsideConditions.LoadOutsideConditionsByLocationId(locationId).GetCSV(), "/dump/l" + locationId.ToString() + "_outside.csv"); } ZipFiles(); Response.Redirect("/dump/export.zip"); }
private void PopulateCycles(int thermostatId) { DataTable dt = new DataTable(); dt.Columns.Add("LogDate", typeof(DateTime)); dt.Columns.Add("AC_On", typeof(int)); int days = Convert.ToInt32(Request["days"]); ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(thermostatId, DateTime.Now.AddDays(-1).AddDays(days), DateTime.Now.AddDays(days)); if (cycles.Count > 0) { DataRow row = dt.NewRow(); row[0] = DateTime.Now.AddDays(-1); row[1] = 0; dt.Rows.Add(row); } foreach (ThermostatMonitorLib.Cycle cycle in cycles) { if (cycle.IsEndDateNull) { cycle.EndDate = DateTime.Now; } DataRow row = dt.NewRow(); row[0] = cycle.StartDate.AddSeconds(-1); row[1] = 0; dt.Rows.Add(row); row = dt.NewRow(); row[0] = cycle.StartDate; row[1] = 1; dt.Rows.Add(row); row = dt.NewRow(); row[0] = cycle.EndDate.AddSeconds(-1); row[1] = 1; dt.Rows.Add(row); row = dt.NewRow(); row[0] = cycle.EndDate; row[1] = 0; dt.Rows.Add(row); } if (cycles.Count > 0) { DataRow row = dt.NewRow(); row[0] = DateTime.Now; row[1] = 0; dt.Rows.Add(row); } OutputCycles(dt); }
protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Request["Id"]); ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(id); ThermostatMonitorLib.Location location = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId); if (location.UserId != AppUser.Current.UserData.Id) { Response.Redirect("/login.aspx"); } TimezoneDifference = AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings); ThermostatName.Text = thermostat.DisplayName + " (" + thermostat.IpAddress + ")"; //ThermostatMonitorLib.Cycle currentCycle=ThermostatMonitorLib.Cycle.LoadOpenCycle(thermostat.Id); ThermostatMonitorLib.OutsideCondition currentCondition = ThermostatMonitorLib.OutsideCondition.LoadCurrentCondition(location.Id); ThermostatMonitorLib.Temperature currentTemperature = ThermostatMonitorLib.Temperature.LoadCurrentTemperature(thermostat.Id); CurrentConditionsLit.Text = "Currently: "; //if (currentCycle == null) CurrentConditionsLit.Text += "Off"; else CurrentConditionsLit.Text += currentCycle.CycleType; if (currentTemperature != null && currentCondition != null) { CurrentConditionsLit.Text += " - Inside: " + currentTemperature.Degrees.ToString() + "°"; CurrentConditionsLit.Text += " - Outside: " + currentCondition.Degrees.ToString() + "°"; } else { CurrentConditionsLit.Text = "No data has been gathered for this thermostat."; } ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(id, DateTime.Now.AddDays(-1).AddHours(AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings)), DateTime.Now.AddHours(AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings))); DataTable dt = ThermostatMonitorLib.Cycles.LoadFullSummary(thermostat.LocationId, thermostat.Id, DateTime.Today.AddDays(-7), DateTime.Today, AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings)); HistorySummary1.Populate(dt, thermostat); }
private void OutputCycles(ThermostatMonitorLib.Thermostat thermostat, ThermostatMonitorLib.Location location) { ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(thermostat.Id, new DateTime(2000, 1, 1), DateTime.Now); OutputCSV(cycles.GetCSV(thermostat.ACKilowatts, thermostat.FanKilowatts, thermostat.HeatBtuPerHour, AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings)), "cycles.csv"); }
public Cycles GetByTime(DateTime startTime,DateTime endTime) { Cycles result = new Cycles(); foreach (ThermostatMonitorLib.Cycle c in this) { if (c.StartDate <= endTime && c.EndDate >= startTime) result.Add(c); } return result; }
private void Populate(int thermostatId) { DataTable dt = new DataTable(); dt.Columns.Add("LogDate", typeof(DateTime)); dt.Columns.Add("AC_On", typeof(int)); ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(thermostatId, startTime, endTime); if (cycles.Count > 0) { DataRow row = dt.NewRow(); row[0] = startTime; row[1] = 0; dt.Rows.Add(row); } foreach (ThermostatMonitorLib.Cycle cycle in cycles) { if (cycle.IsEndDateNull) { cycle.EndDate = endTime; } DataRow row = dt.NewRow(); row[0] = cycle.StartDate.AddSeconds(-1); row[1] = 0; dt.Rows.Add(row); row = dt.NewRow(); row[0] = cycle.StartDate; row[1] = 1; dt.Rows.Add(row); row = dt.NewRow(); row[0] = cycle.EndDate.AddSeconds(-1); row[1] = 1; dt.Rows.Add(row); row = dt.NewRow(); row[0] = cycle.EndDate; row[1] = 0; dt.Rows.Add(row); } foreach (DataRow row in dt.Rows) { DateTime theDate = Convert.ToDateTime(row[0]); if (theDate < startTime) { theDate = startTime; } if (theDate > endTime) { theDate = endTime; } row[0] = theDate; } if (cycles.Count > 0) { DataRow row = dt.NewRow(); row[0] = endTime; row[1] = 0; dt.Rows.Add(row); } Output(dt); }
public static Cycles LoadRange(System.Int32 thermostatId, DateTime startDate, DateTime endDate) { return(Cycles.LoadCycles("SELECT * FROM cycles WHERE thermostat_id=@ThermostatId AND start_date BETWEEN @StartDate and @EndDate", CommandType.Text, new MySqlParameter[] { new MySqlParameter("@ThermostatId", thermostatId), new MySqlParameter("@StartDate", startDate), new MySqlParameter("@EndDate", endDate) })); }