Tuesday, March 29, 2011

Kevin's Week 9 Report

This week I worked on redesigning the webpage and testing some communications with Andrew and Ashley.  In redesigning the webpage, I decided to do away with the drop down button list as I could not find a way to obtain current available year, month, day, and hour data to appear in the dropdown list when the user loaded the page.  I instead decided to make a setup where the user will click a “Browse” tab.  This page starts out in the yearly data selection.  It starts out with a list of all available years that have data.  Next to each year the user can select either to view data for the year or view the months available with data for that year.  If they select to view the data, a graph of yearly data will show up.  If they select to view the months available within that year, a list of all the months that have data appears.  These months have the same options as the year did.  This continues until we get to the hourly data page.  This page has a link to view the data.  When the user clicks data for that hour will be shown.  I have gotten this test webpage up and working over the previous days, however, I must have made a small change that I need to find, as right now it is not showing data for the year at the start, so I cannot move past that page.  I am going to get this up in the next day and post some screenshots of the website.  For the meantime, I posted the new code I have for the browser tab in the site below.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using MySql.Data.MySqlClient;

namespace EnergyViewHPM
{
    public partial class Browse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Browse - EnergyView HPM";

            if (Request.QueryString["Type"] != null)
            {
                string mode = Request.QueryString["Type"].ToString().ToLower();
                switch (mode)
                {
                    case "month":
                        butBack.Text = "Back to Years";
                        if (Request.QueryString["Year"] != null)
                        {
                            monthHandler(Request.QueryString["Year"].ToString());
                        }
                        else
                        {
                            Response.Redirect("/browse.aspx");
                        }
                        break;
                    case "day":
                        butBack.Text = "Back to Months";
                        if ((Request.QueryString["Year"] != null)
                            && (Request.QueryString["Month"] != null))
                        {
                            dayHandler(Request.QueryString["Year"].ToString(),
                                Request.QueryString["Month"].ToString());
                        }
                        else
                        {
                            Response.Redirect("/browse.aspx");
                        }
                        break;
                    case "hour":
                        butBack.Text = "Back to Days";
                        if ((Request.QueryString["Year"] != null)
                            && (Request.QueryString["Month"] != null)
                            && (Request.QueryString["Day"] != null))
                        {
                            hourHandler(Request.QueryString["Year"].ToString(),
                                Request.QueryString["Month"].ToString(),
                                Request.QueryString["Day"].ToString());
                        }
                        else
                        {
                            Response.Redirect("/browse.aspx");
                        }
                        break;
                    default:
                        Response.Redirect("/browse.aspx");
                        break;
                }
            }
            else
            {
                butBack.Visible = false;
                yearHandler();
            }
        }

        protected ArrayList dbQuery(string query)
        {
            ArrayList results = new ArrayList();
            MySqlConnection dbCon = new MySqlConnection(ConfigurationManager.ConnectionStrings["DataDB"].ToString());
            dbCon.Open();

            MySqlCommand dbCmd = new MySqlCommand(query, dbCon);
            MySqlDataReader dbDr = dbCmd.ExecuteReader();

            while (dbDr.Read())
            {
                results.Add(dbDr.GetDateTime(0));
            }

            dbCon.Close();
            return results;
        }

        protected string viewLinkConstruct(string destination, string year, string month,
            string day, string hour)
        {
            string result = "<a href='/" + destination + ".aspx";

            result += (year != null ? ("?Year=" + year) : "");
            result += (month != null ? ("&Month=" + month) : "");
            result += (day != null ? ("&Day=" + day) : "");
            result += (hour != null ? ("&Hour=" + hour) : "");

            result += "'>View " + destination + " Data</a>";

            return result;
        }

        protected string moreLinkConstruct(string type, string year, string month, string day)
        {
            string result = "<a href='/browse.aspx?Type=" + type;

            result += (year != null ? ("&Year=" + year) : "");
            result += (month != null ? ("&Month=" + month) : "");
            result += (day != null ? ("&Day=" + day) : "");

            result += "'>See " + type + "s</a>";
           
            return result;
        }

        protected void yearHandler()
        {
            string query = "SELECT timest FROM day_data GROUP BY YEAR(timest)";
            ArrayList results = dbQuery(query);

            string elements = "";
            foreach (DateTime dt in results)
            {
                elements += "<li>" + dt.Year + "&nbsp;-&nbsp;"
                    + viewLinkConstruct("Year", dt.Year.ToString(), null, null, null)
                    + "&nbsp;-&nbsp;" + moreLinkConstruct("Month", dt.Year.ToString(), null, null)
                    + "</li>";
            }

            lblTitle.Text = "Select Year";
            lblElements.Text = elements;
        }

        protected void monthHandler(string year)
        {
            string query = "SELECT timest FROM day_data WHERE YEAR(timest)='" + year + "' GROUP BY MONTH(timest)";
            ArrayList results = dbQuery(query);

            string elements = "";
            foreach (DateTime dt in results)
            {
                elements += "<li>" + dt.ToString("MMM, yyyy") + "&nbsp;-&nbsp;"
                    + viewLinkConstruct("Month", dt.Year.ToString(), dt.Month.ToString(), null, null)
                    + "&nbsp;-&nbsp;" + moreLinkConstruct("Day", dt.Year.ToString(), dt.Month.ToString(), null)
                    + "</li>";
            }

            lblTitle.Text = "Select Month";
            lblElements.Text = elements;
        }

        protected void dayHandler(string year, string month)
        {
            string query = "SELECT timest FROM day_data WHERE YEAR(timest)='" + year
                + "' AND MONTH(timest)='" + month + "' GROUP BY DAY(timest)";
            ArrayList results = dbQuery(query);

            string elements = "";
            foreach (DateTime dt in results)
            {
                elements += "<li>" + dt.ToString("ddd, MMM dd, yyyy") + "&nbsp;-&nbsp;"
                    + viewLinkConstruct("Day", dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString(), null)
                    + "&nbsp;-&nbsp;" + moreLinkConstruct("Hour", dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString())
                    + "</li>";
            }

            lblTitle.Text = "Select Day";
            lblElements.Text = elements;
        }

        protected void hourHandler(string year, string month, string day)
        {
            string query = "SELECT timest FROM minute_data WHERE YEAR(timest)='" + year
                + "' AND MONTH(timest)='" + month + "' AND DAY(timest)='" + day
                + "' GROUP BY HOUR(timest)";
            ArrayList results = dbQuery(query);

            string elements = "";
            foreach (DateTime dt in results)
            {
                elements += "<li>" + dt.ToString("ddd, MMM dd, yyyy hh tt") + "&nbsp;-&nbsp;"
                    + viewLinkConstruct("Hour", dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString(), dt.Hour.ToString())
                    + "</li>";
            }

            lblTitle.Text = "Select Hour";
            lblElements.Text = elements;
        }

        protected void butBack_Click(object sender, EventArgs e)
        {
            string addon = "";
            switch(Request.QueryString["Type"].ToString().ToLower())
            {
                case "month":
                    break;
                case "day":
                    addon = "?Type=Month&Year=" + Request.QueryString["Year"];
                    break;
                case "hour":
                    addon = "?Type=Day&Year=" + Request.QueryString["Year"] + "&Month="
                        + Request.QueryString["Month"];
                    break;
            }
            Response.Redirect("/Browse.aspx" + addon);
        }
    }
}


Over the weekend and this morning, Andrew, Ashley, and I met up to work on communications for the system.  We were able to calibrate the RMS Voltage on the ADE7763 chip and output the right value of 120V.  Using our test serial connection, we were able to read the correct value from the ATMega328P.  We worked on trying to initialize the W5100 chip using a test program from http://www.ermicro.com/blog/?p=1773 to ping the pc for communication.  However, it was not getting the correct address information.  Over the next week I plan to finish up the website and work on helping to calibrate the W5100 and ADE7763 f

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home