public void fetchData(int interval, WindData wd) { try { DateTime endInterval = DateTime.Now; DateTime beginInterval = GetStartInterval(interval, endInterval); 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>(); List <WindRecord> windData = wd.GetListBetweenDate2(beginInterval, endInterval); 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); } this.dirValues = dirValues.ToArray(); this.speedValues = speedValues.ToArray(); this.timeLabels = timeLabels.ToArray(); this.minSpeedValues = minValues.ToArray(); this.maxSpeedValues = maxValues.ToArray(); }catch { } }
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(); }
/* Set the correct arguments to the applet */ private void setAppletLocation(WindData wd) { List <Location> loc = wd.GetLocations(); loc.Sort(); if (loc.Count > 0) { applet.Attributes["src"] = "http://www.surfvind.se/Applet.aspx?location=" + loc.ToArray()[ddlWhere.SelectedIndex].imei.ToString();; } }
/* There are two ways of using this site. Either no parameters, then all graphs for all locations will * be generated, or with arguments (e.g. location=12345&duration=0) and only one graph will be generated */ public void update(String location, String duration) { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); placeholder.InnerHtml += "Thomas " + loc.Count; if (!checkArguments(location, duration, loc)) { /* Update everything */ foreach (Location l in loc) { // Response.Write(l.imei.ToString()); this.location = l.imei.ToString(); wd.SetImei(this.location); for (int i = 0; i < 5; i++) { int interval = i; fetchData(i, wd); System.Web.UI.WebControls.Image a = new System.Web.UI.WebControls.Image(); a.Width = 800; a.Height = 200; a.ImageUrl = generateGraphOnServer(interval, 800, 200); placeholder.Controls.Add(a); } } } else { this.location = location; // Safe, we know this value can be parsed, we've tried it before int interval = int.Parse(duration); wd.SetImei(this.location); // Response.Write("Generate Graph"); fetchData(interval, wd); // Response.Write("Create Graph"); System.Web.UI.WebControls.Image a = new System.Web.UI.WebControls.Image(); a.Width = 800; a.Height = 200; a.ImageUrl = generateGraphOnServer(interval, 800, 200); placeholder.Controls.Add(a); } }
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"); } }
public void update2(String location) { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); wd.SetImei(location); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); for (int i = 0; i < 3 /*5*/; i++) { this.interval = i; generateGraph(this.interval, location, wd); } }
/* Set the correct arguments to the applet */ private void setAppletLocation() { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); String html; if (loc.Count > 0) { html = "http://www.surfvind.se/Applet.aspx?location=" + loc.ToArray()[ddlWhere.SelectedIndex].imei.ToString(); applet.Attributes["src"] = html; } }
/* There are two ways of using this site. Either no parameters, then all graphs for all locations will * be generated, or with arguments (e.g. location=12345&duration=0) and only one graph will be generated */ public void update(String location, String duration) { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); if (!checkArguments(location, duration, loc)) { /* Update everything */ foreach (Location l in loc) { this.location = l.imei.ToString(); wd.SetImei(this.location); for (int i = 0; i < 5; i++) { this.interval = i; generateGraph(this.interval, this.location, wd); createGraph(); } } } else { this.location = location; /* Safe, we know this value can be parsed, we've tried it before */ this.interval = int.Parse(duration); wd.SetImei(this.location); generateGraph(this.interval, this.location, wd); createGraph(); } }
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; } }
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"); } }
float[] GetDirectionValuesToTime(int cntIntervals, DateTime begin, DateTime end, WindData wd) { List <float> result = new List <float>(); TimeSpan t = end.Subtract(begin); double minutesStep = t.TotalMinutes / cntIntervals; // start with 1, because first value is 'current' for (int i = 0; i < cntIntervals; i++) { // begin of date interval DateTime first = begin.AddMinutes(minutesStep * i); // end of date interval DateTime last = begin.AddMinutes(minutesStep * (i + 1)); if (last < first) { last = first.AddSeconds(5); } result.Add(wd.GetTopDirectionValueBetweenDate(first, last)); } return(result.ToArray()); }
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"); } }