Example #1
0
    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);
    }
    public void Populate(int thermostatId, DateTime startTime, DateTime endTime)
    {
        ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(thermostatId);

        ThermostatMonitorLib.Temperatures      temps      = ThermostatMonitorLib.Temperatures.LoadRange(thermostatId, startTime, endTime);
        ThermostatMonitorLib.OutsideConditions conditions = ThermostatMonitorLib.OutsideConditions.LoadRange(thermostat.LocationId, startTime, endTime);



        DataTable dt = new DataTable();

        dt.Columns.Add("LogDate", typeof(DateTime));
        dt.Columns.Add("InsideTemperature", typeof(double));
        //dt.Columns.Add("AC_On", typeof(double));
        dt.Columns.Add("OutsideTemperature", typeof(double));


        for (int i = 0; i < temps.Count; i++)
        {
            ThermostatMonitorLib.Temperature temp = temps[i];
            if (temp.Degrees == Convert.ToInt32(temp.Degrees))
            {
                if (i > 0)
                {
                    DataRow pRow = dt.NewRow();
                    pRow[0] = temp.LogDate.AddSeconds(-1);
                    pRow[1] = temps[i - 1].Degrees;
                    dt.Rows.Add(pRow);
                }
                DataRow row = dt.NewRow();
                row[0] = temp.LogDate;
                row[1] = temp.Degrees;
                dt.Rows.Add(row);
            }
        }



        foreach (ThermostatMonitorLib.OutsideCondition condition in conditions)
        {
            DataRow row = dt.NewRow();
            row[0] = condition.LogDate;
            row[2] = condition.Degrees;
            dt.Rows.Add(row);
        }
        if (conditions.Count > 0 && temps.Count > 0)
        {
            DataRow row = dt.NewRow();
            row[0] = startTime;
            row[1] = temps[0].Degrees;
            row[2] = conditions[0].Degrees;
            dt.Rows.Add(row);

            row    = dt.NewRow();
            row[0] = endTime;
            row[1] = temps[temps.Count - 1].Degrees;
            row[2] = conditions[conditions.Count - 1].Degrees;
            dt.Rows.Add(row);
        }



        OutputData(dt);
        return;
    }