示例#1
0
        public List <WindRecord> GetFullList()
        {
            string cmdText = "select * from " + dbToUse + " imei=" + imei + "order by time";

            using (DbConnection conn = GetDbConnection(GetDBConnString()))
            {
                conn.Open();
                List <WindRecord> list = new List <WindRecord>();
                using (DbCommand cmd = GetDBCommand(cmdText, conn))
                {
                    DbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        WindRecord wr = new WindRecord();
                        wr.Time             = Convert.ToDateTime(reader["time"]);
                        wr.AverageDirection = int.Parse(reader["averageDir"].ToString());
                        wr.MaxDirection     = int.Parse(reader["maxDir"].ToString());
                        wr.MinDirection     = int.Parse(reader["minDir"].ToString());
                        wr.AverageSpeed     = float.Parse(reader["averageSpeed"].ToString());
                        wr.MaxSpeed         = float.Parse(reader["maxSpeed"].ToString());
                        wr.MinSpeed         = float.Parse(reader["minSpeed"].ToString());
                        list.Add(wr);
                    }
                }
                return(list);
            }
        }
示例#2
0
        public WindRecord GetCurrentWind()
        {
            WindRecord currWind = new WindRecord();

            using (DbConnection conn = GetDbConnection(GetDBConnString()))
                using (DbCommand cmd = GetDBCommand("select * from " + dbToUse + " WHERE imei=" + imei + " order by time desc limit 0,1", conn))
                {
                    conn.Open();
                    DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
                    if (reader.Read())
                    {
                        currWind.Time             = Convert.ToDateTime(reader["time"]);
                        currWind.AverageDirection = int.Parse(reader["averageDir"].ToString());
                        currWind.MaxDirection     = int.Parse(reader["maxDir"].ToString());
                        currWind.MinDirection     = int.Parse(reader["minDir"].ToString());
                        currWind.AverageSpeed     = float.Parse(reader["averageSpeed"].ToString());
                        currWind.MaxSpeed         = float.Parse(reader["maxSpeed"].ToString());
                        currWind.MinSpeed         = float.Parse(reader["minSpeed"].ToString());
                        // TODO, uncomment next two lines when the database has posts for temperature
                        currWind.AverageAirTemp   = int.Parse(reader["airTemp"].ToString());
                        currWind.AverageWaterTemp = int.Parse(reader["waterTemp"].ToString());
                        currWind.Moisture         = int.Parse(reader["moisture"].ToString());
                    }
                }

            return(currWind);
        }
示例#3
0
        public List <WindRecord> GetListBetweenDate(DateTime startDate, DateTime endDate)
        {
            string cmdText = string.Format("select * from " + dbToUse + " WHERE imei=" + imei + " AND time between {0} order by time desc", (isMySqlDB ? "?start and ?end" : "@start and @end"));

            using (DbConnection conn = GetDbConnection(GetDBConnString()))
            {
                List <WindRecord> list = new List <WindRecord>();
                conn.Open();
                using (DbCommand cmd = GetDBCommand(cmdText, conn))
                {
                    cmd.Parameters.Add(GetDBParam("start", startDate));
                    cmd.Parameters.Add(GetDBParam("end", endDate));
                    DbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        WindRecord wr = new WindRecord();
                        wr.Time             = Convert.ToDateTime(reader["time"]);
                        wr.AverageDirection = int.Parse(reader["averageDir"].ToString());
                        wr.MaxDirection     = int.Parse(reader["maxDir"].ToString());
                        wr.MinDirection     = int.Parse(reader["minDir"].ToString());
                        wr.AverageSpeed     = float.Parse(reader["averageSpeed"].ToString());
                        wr.MaxSpeed         = float.Parse(reader["maxSpeed"].ToString());
                        wr.MinSpeed         = float.Parse(reader["minSpeed"].ToString());
                        list.Add(wr);
                    }
                }
                return(list);
            }
        }
示例#4
0
        public void ProcessRequest(HttpContext context)
        {
            String imei    = context.Request.QueryString["imei"];
            String dbToUse = "";

            dbToUse = "Surfvind_data";


            WindData wd = new WindData(true, dbToUse);

            //bool isMySQL = true;
            wd.SetImei(imei);
            WindRecord wr = wd.GetCurrentWind();

            Bitmap   bitmap = new Bitmap(250, 100);
            Graphics g      = Graphics.FromImage(bitmap);

            String text  = "Speed: " + wr.AverageSpeed.ToString("F2") + " m/s";
            String text2 = "Direction: " + wr.AverageDirection + " degrees";
            String text3 = "Surfvind.se";

            RectangleF rectH = new RectangleF(1, 5, 250, 30);

            RectangleF   rect   = new RectangleF(1, 40, 250, 30);
            RectangleF   rect2  = new RectangleF(1, 70, 250, 30);
            StringFormat format = new StringFormat();

            format.Alignment = StringAlignment.Center;
            Font font  = new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold);
            Font font2 = new Font(FontFamily.GenericSansSerif, 20, FontStyle.Bold);

            g.DrawString(text, font, Brushes.Red, rect, format);
            g.DrawString(text2, font, Brushes.Red, rect2, format);
            g.DrawString(text3, font2, Brushes.Blue, rectH, format);
            Image img = null;

            /*
             * try
             * {
             *   img = Image.FromFile(HttpContext.Current.Server.MapPath("~/Images/" + imei + "_img_compass.png"));
             *
             * }
             * catch { }
             * if (img != null)
             * {
             *   g.DrawImage(img, 10, 10);
             * }*/


            MemoryStream mem = new MemoryStream();

            bitmap.Save(mem, ImageFormat.Png);

            byte[] buffer = mem.ToArray();

            context.Response.ContentType = "image/png";
            context.Response.BinaryWrite(buffer);
            context.Response.Flush();
        }
示例#5
0
        public List <WindRecord> GetListBetweenDate2(DateTime startDate, DateTime endDate)
        {
            TimeSpan interval = endDate.Subtract(startDate);
            TimeSpan t        = new TimeSpan(interval.Ticks / 50);

            endDate = startDate.Add(t);
            List <WindRecord> list = new List <WindRecord>();

            try
            {
                using (DbConnection conn = GetDbConnection(GetDBConnString()))
                {
                    conn.Open();
                    for (int i = 0; i < 50; i++)
                    {
                        string cmdText = string.Format("select avg(averageDir),max(maxDir),min(minDir),avg(averageSpeed),max(maxSpeed),min(minSpeed) from " + dbToUse + " WHERE imei=" + imei + " AND time >\"" + startDate.ToString() + "\" and time <\"" + endDate.ToString() + "\" order by time desc");
                        using (DbCommand cmd = GetDBCommand(cmdText, conn))
                        {
                            DbDataReader reader = cmd.ExecuteReader();
                            while (reader.Read())
                            {
                                WindRecord wr = new WindRecord();
                                //wr.Time = Convert.ToDateTime(reader["time"]);
                                if (reader["avg(averageDir)"] != null)
                                {
                                    string test = reader["avg(averageDir)"].ToString();
                                    if (test.Equals("null") || test.Equals(""))
                                    {
                                        continue;
                                    }
                                    wr.Time             = endDate;//
                                    wr.AverageDirection = (int)float.Parse(reader["avg(averageDir)"].ToString());
                                    wr.MaxDirection     = (int)float.Parse(reader["max(maxDir)"].ToString());
                                    wr.MinDirection     = (int)float.Parse(reader["min(minDir)"].ToString());
                                    wr.AverageSpeed     = float.Parse(reader["avg(averageSpeed)"].ToString());
                                    wr.MaxSpeed         = float.Parse(reader["max(maxSpeed)"].ToString());
                                    wr.MinSpeed         = float.Parse(reader["min(minSpeed)"].ToString());
                                    list.Add(wr);
                                }
                                else
                                {
                                }
                            }
                            reader.Close();
                        }
                        startDate = startDate.Add(t);
                        endDate   = endDate.Add(t);
                    }
                    list.Reverse();
                }
            }
            catch (Exception e)
            {
                int a = 0;
                a++;
            }
            return(list);
        }
示例#6
0
        public void generateSensorImages(String imei, WindData wd)
        {
            Start = DateTime.Now;
            try
            {
                WindRecord currentWind = wd.GetCurrentWind();
                if (currentWind.Time < DateTime.Now.AddHours(-2))
                {
                    currentWind.AverageSpeed     = 0;
                    currentWind.MinSpeed         = 0;
                    currentWind.MaxSpeed         = 0;
                    currentWind.AverageDirection = 0;
                    currentWind.MinDirection     = 0;
                    currentWind.MaxDirection     = 0;
                }

                /* TODO, move this functionality to an own method since we only need to do this once
                 * For no, lets settle with a check if this is the first time for any given location
                 */
                String path = HttpContext.Current.Server.MapPath("~/") + "Images/" + imei;
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                Helper.GetWindSpeedPic(currentWind.AverageSpeed, currentWind.MinSpeed, currentWind.MaxSpeed, Server).Save(Server.MapPath("~/Images/" + imei + "_img_speed.png"));
                LogTime();
                Helper.GetCompassPic(currentWind.AverageDirection, currentWind.MinDirection, currentWind.MaxDirection, Server).Save(Server.MapPath("~/Images/" + imei + "_img_compass.png"));
                LogTime();

                /* Create temperature images */
                float water_temp;
                float air_temp;

                water_temp = currentWind.AverageWaterTemp;
                air_temp   = currentWind.AverageAirTemp;
                String test = Server.MapPath("~/Images/" + imei + "_img_water_temp.png");
                Helper.getTempImage(water_temp).Save(Server.MapPath("~/Images/" + imei + "_img_water_temp.png"));
                Helper.getTempImage(air_temp).Save(Server.MapPath("~/Images/" + imei + "_img_air_temp.png"));
            } catch {
                Debug.WriteLine("Problem1");
            }
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String location = Request.QueryString["location"];

            Start = DateTime.Now;
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            try
            {
                String   dbToUse  = "Surfvind_data";
                bool     isMySQL  = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]);
                WindData windData = new WindData(isMySQL, dbToUse);

                List <Location> allWeatherStations = windData.GetLocations();
                allWeatherStations.Sort();

                /* Populate location scrollbar */
                populateLocationScrollbar(allWeatherStations);
                if (allWeatherStations.Count > 0)
                {
                    imei = allWeatherStations.ToArray()[ddlWhere.SelectedIndex].imei.ToString();
                }
                if (location != null)
                {
                    int index = getIndexForLocation(allWeatherStations, location);
                    if (index >= 0)
                    {
                        ddlWhere.SelectedIndex = index;
                        imei = location;
                    }
                }
                windData.SetImei(imei);
                /* Set google map location */
                addGMap(allWeatherStations[ddlWhere.SelectedIndex]);

                GenGraphs graphGenerator = new GenGraphs();
                graphGenerator.generateSensorImages(imei, windData);


                /* Get pre-stored direction and speed arrows */
                imgSpeed.ImageUrl   = "~/Images/" + imei + "_img_speed.png";
                imgCompass.ImageUrl = "~/Images/" + imei + "_img_compass.png";

                WindRecord wr = windData.GetCurrentWind();

                if (wr.Moisture != 0)
                {
                    // Set temp images
                    air_temp.ImageUrl = "~/Images/" + imei + "_img_air_temp.png";
                    power.Text        = wr.AverageWaterTemp + " V";
                    moisture.Text     = wr.Moisture + " %";

                    air_temp.ToolTip = "Air temperature: " + wr.AverageAirTemp + " °C";

                    moisture_container.Visible    = true;
                    battery_container.Visible     = true;
                    temperature_container.Visible = true;
                }
                else
                {
                    moisture_container.Visible    = false;
                    battery_container.Visible     = false;
                    temperature_container.Visible = false;
                }

                // Graphs are now generated on demand.
                graphGenerator.fetchData(2, windData);
                twentyFourHGraph.ImageUrl = graphGenerator.generateGraphOnServer(2, 1050, 250);
                graphGenerator.fetchData(1, windData);
                fiveHGraph.ImageUrl = graphGenerator.generateGraphOnServer(1, 1050, 250);
                /* Set the applet location */
                setAppletLocation(windData);
            }
            catch (Exception eee)
            {
                debug.Width  = 200;
                debug.Height = 200;
                debug.Text   = eee.Message + "\n";
                debug.Text  += eee.StackTrace;
            }
        }
示例#8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String location = Request.QueryString["location"];

            Start = DateTime.Now;
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            try
            {
                LogTime();
                String dbToUse = "";
                dbToUse = "Surfvind_data";

                LogTime();

                WindData wd      = new WindData(true, dbToUse);
                bool     isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]);

                List <Location> loc = wd.GetLocations();
                loc.Sort();

                locations = loc;
                /* Populate location scrollbar */
                populateLocationScrollbar(loc);
                if (loc.Count > 0)
                {
                    imei = loc.ToArray()[ddlWhere.SelectedIndex].imei.ToString();
                    wd.SetImei(imei);
                    /* Set google map location */
                    addGMap(loc[ddlWhere.SelectedIndex]);
                }

                GenGraphs t = new GenGraphs();
                t.update2(imei);


                if (location != null)
                {
                    OldSelectedIndex = ddlWhere.SelectedIndex;
                    int index = getIndexForLocation(loc, location);
                    if (index >= 0)
                    {
                        ddlWhere.SelectedIndex = index;
                        imei = location;
                        wd.SetImei(imei);
                    }
                }

                /* Get pre-stored direction and speed arrows */
                imgSpeed.ImageUrl   = "~/Images/" + imei + "_img_speed.png";
                imgCompass.ImageUrl = "~/Images/" + imei + "_img_compass.png";

                if (imei == "12345") //Set this to the IMEI nbr that you use for developement of water air and humidity temp
                {
                    // Set temp images
                    water_temp.ImageUrl = "~/Images/" + imei + "_img_water_temp.png";
                    air_temp.ImageUrl   = "~/Images/" + imei + "_img_air_temp.png";

                    int w_temp;
                    int a_temp;

                    WindRecord wr = wd.GetCurrentWind();
                    w_temp = wr.AverageWaterTemp;
                    a_temp = wr.AverageAirTemp;

                    water_temp.ToolTip = "Water temperature: " + w_temp + " °C";
                    air_temp.ToolTip   = "Air temperature: " + a_temp + " °C";
                    Label1.Text        = "Moisture: " + wr.Moisture + "%";
                }
                else
                {
                    air.Visible      = false;
                    moisture.Visible = false;
                    water.Visible    = false;
                }

                /* Set the applet location */
                setAppletLocation();


                twentyFourHGraph.ImageUrl = "~/Applet/" + imei + "/graph_2.png";
                fiveHGraph.ImageUrl       = "~/Applet/" + imei + "/graph_1.png";
            }
            catch (Exception eee)
            {
                debug.Width  = 200;
                debug.Height = 200;
                debug.Text   = eee.Message + "\n";
                debug.Text  += eee.StackTrace;
                //Response.Redirect("~/ErrorPage.aspx");
            }
        }
示例#9
0
        public void generateGraph(int interval, String imei, WindData wd)
        {
            Start = DateTime.Now;
            try
            {
                DateTime endInterval   = DateTime.Now;
                DateTime beginInterval = GetStartInterval(interval, endInterval);
                LogTime();

                WindRecord currentWind = wd.GetCurrentWind();
                if (currentWind.Time < DateTime.Now.AddHours(-1))
                {
                    currentWind.AverageSpeed     = 0;
                    currentWind.MinSpeed         = 0;
                    currentWind.MaxSpeed         = 0;
                    currentWind.AverageDirection = 0;
                    currentWind.MinDirection     = 0;
                    currentWind.MaxDirection     = 0;
                }
                List <float>  dirValues   = new List <float>();
                List <string> timeLabels  = new List <string>();
                List <float>  speedValues = new List <float>();
                List <float>  minValues   = new List <float>();
                List <float>  maxValues   = new List <float>();
                LogTime();
                List <WindRecord> windData = wd.GetListBetweenDate2(beginInterval, endInterval);
                LogTime();

                foreach (WindRecord w in windData)
                {
                    minValues.Add(w.MinSpeed);
                    maxValues.Add(w.MaxSpeed);
                    speedValues.Add(w.AverageSpeed);
                    timeLabels.Add(w.Time.ToShortDateString() + "*" + w.Time.ToShortTimeString());
                    dirValues.Add(w.AverageDirection);
                }
                LogTime();

                this.dirValues      = dirValues.ToArray();
                this.speedValues    = speedValues.ToArray();
                this.timeLabels     = timeLabels.ToArray();
                this.minSpeedValues = minValues.ToArray();
                this.maxSpeedValues = maxValues.ToArray();
                LogTime();

                /* TODO, move this functionality to an own method since we only need to do this once
                 * For no, lets settle with a check if this is the first time for any given location
                 */
                if (interval == 0)
                {
                    String path = HttpContext.Current.Server.MapPath("~/") + "Images/" + imei;
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }

                    Helper.GetWindSpeedPic(currentWind.AverageSpeed, currentWind.MinSpeed, currentWind.MaxSpeed, Server).Save(Server.MapPath("~/Images/" + imei + "_img_speed.png"));
                    LogTime();
                    Helper.GetCompassPic(currentWind.AverageDirection, currentWind.MinDirection, currentWind.MaxDirection, Server).Save(Server.MapPath("~/Images/" + imei + "_img_compass.png"));
                    LogTime();

                    /* Create temperature images */
                    int water_temp;
                    int air_temp;

                    water_temp = currentWind.AverageWaterTemp;
                    air_temp   = currentWind.AverageAirTemp;
                    String test = Server.MapPath("~/Images/" + imei + "_img_water_temp.png");
                    Helper.getTempImage(water_temp).Save(Server.MapPath("~/Images/" + imei + "_img_water_temp.png"));
                    Helper.getTempImage(air_temp).Save(Server.MapPath("~/Images/" + imei + "_img_air_temp.png"));
                }
            }
            catch
            {
                int a = 0;
                a++;
                Debug.WriteLine("Problem1");
            }
        }