public CurrentViewModel(string city) { currentModel = new Model.CurrentModel(city); UserCity = city; weatherDB = currentModel.getWeeklyForecast(city); SearchCommand = new Command.SearchCommand(this); }
public WeeklyViewModel() { weeklyModel = new Model.WeeklyModel(userCity); UserCity = "jerusalem"; weatherDB = weeklyModel.getWeeklyForecast(UserCity); SearchCommand = new Command.SearchCommand(this); }
public CurrentViewModel() { currentModel = new Model.CurrentModel(userCity); UserCity = "jerusalem"; weatherDB = currentModel.getWeeklyForecast(UserCity); SearchCommand = new Command.SearchCommand(this); }
public void Exec() { using (var context = new WeatherDB()) { context.Database.Initialize(false); } }
public WeeklyViewModel(string city) { weeklyModel = new Model.WeeklyModel(city); UserCity = city; weatherDB = weeklyModel.getWeeklyForecast(city); SearchCommand = new Command.SearchCommand(this); }
private async Task RunAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var Weather = await WeatherClient.CurrentWeather.GetByName(TargetCity, MetricSystem.Metric); WeatherDB.Record(ReadingType.Temperature, WeatherInfoSource.WeatherService, Weather.Temperature.Value); WeatherDB.Record(ReadingType.Pressure, WeatherInfoSource.WeatherService, Weather.Pressure.Value); WeatherDB.Record(ReadingType.Humidity, WeatherInfoSource.WeatherService, Weather.Humidity.Value); await Task.Delay(1000 *60 *NumMinutes); } }
protected void Page_Load(object sender, EventArgs e) { ReadingType t = ReadingType.Temperature; DateTime fr = DateTime.Now.AddYears(-1); switch (ddTimePeriod.SelectedValue) { case "Day": fr = DateTime.Now.AddDays(-1); break; case "Month": fr = DateTime.Now.AddMonths(-1); break; case "Year": fr = DateTime.Now.AddYears(-1); break; case "Week": fr = DateTime.Now.AddDays(-7); break; } switch (ddDispType.SelectedValue) { case "Temperature": t = ReadingType.Temperature; break; case "Pressure": t = ReadingType.Pressure; break; case "Humidity": t = ReadingType.Humidity; break; case "Luminocity": t = ReadingType.Luminocity; break; } var db = WeatherDB.GetDataAfter(fr); var data = from z in db where z.WeatherInfoSource == WeatherInfoSource.WeatherService where z.ReadingType == t where z.When > fr orderby z.When descending select new { When = z.When, Data = z.Reading }; MainChart.Series[0].Points.DataBind(data, "When", "Data", ""); var rdata = from z in db where z.WeatherInfoSource == WeatherInfoSource.Device where z.ReadingType == t where z.When > fr orderby z.When descending select new { When = z.When, Data = z.Reading }; MainChart.Series[1].Points.DataBind(rdata, "When", "Data", ""); }
private void CurrentViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "userCity") { weatherDB = currentModel.getWeeklyForecast(UserCity); CityN = weatherDB.cityN; Temp = weatherDB.temp_0.ToString() + "\u00B0" + " C"; Humdity = weatherDB.humdity.ToString() + " %"; WindSpeed = weatherDB.windSpeed_0.ToString() + " meter/sec"; WeatherDesc = weatherDB.description_0; Coords = "Geo Coordinates: " + "[" + weatherDB.latCoord.ToString() + " , " + weatherDB.lonCoord.ToString() + "]"; string ic = weatherDB.icon_0; Icon = setIcon(ic); } }
public MapViewModel() { mapModel = new Model.MapModel(); HaifaWeatherDB = mapModel.getWeeklyForecast("Haifa"); TiberiasWeatherDB = mapModel.getWeeklyForecast("Tiberias"); Kiryat_ShmonaWeatherDB = mapModel.getWeeklyForecast("Kiryat Shmona"); Tel_AvivWeatherDB = mapModel.getWeeklyForecast("Tel Aviv"); Beer_ShevaWeatherDB = mapModel.getWeeklyForecast("Beer Sheva"); JerusalemWeatherDB = mapModel.getWeeklyForecast("Jerusalem"); EilatWeatherDB = mapModel.getWeeklyForecast("Eilat"); UserControl = new SmallWeeklyViewModel(city); SearchCommand = new Command.SearchCommand(this); }
public void Exec() { BestHolidayPlace relaxingHoliday; BestHolidayPlace activeHoliday; using (WeatherDB weatherDB = new WeatherDB()) { relaxingHoliday = weatherDB.Database.SqlQuery <BestHolidayPlace>("" + "SELECT S.Name, MONTH(D.Date) AS Month, AVG(D.Tavg) AS MonthAvgTemp, AVG(D.Precipitation) AS MonthAvgPrecipitation " + "FROM Stations AS S " + "JOIN Data AS D " + "ON S.Id = D.StationId " + "GROUP BY S.Name, MONTH(D.Date) " + "HAVING AVG(D.Precipitation) < 2 " + "ORDER BY MonthAvgTemp DESC, MonthAvgPrecipitation " ).FirstOrDefault(); activeHoliday = weatherDB.Database.SqlQuery <BestHolidayPlace>("" + "SELECT S.Name, MONTH(D.Date) AS Month, AVG(D.Tavg) AS MonthAvgTemp, AVG(D.Precipitation) AS MonthAvgPrecipitation " + "FROM Stations AS S " + "JOIN Data AS D " + "ON S.Id = D.StationId " + "GROUP BY S.Name, MONTH(D.Date) " + "HAVING AVG(D.Tavg) > 10 " + "ORDER BY MonthAvgPrecipitation, MonthAvgTemp DESC" ).FirstOrDefault(); } if (activeHoliday != null) { Console.WriteLine($"Best place for active holiday is area weather station {activeHoliday.Name} in {activeHoliday.Month}"); Console.WriteLine($" with the smallest avarage daily precipitation {Math.Round(activeHoliday.MonthAvgPrecipitation, 2)}mm"); Console.WriteLine($" and >10C average daily temperature ({Math.Round(activeHoliday.MonthAvgTemp, 2)}C)"); Console.WriteLine(""); } if (relaxingHoliday != null) { Console.WriteLine($"Best place for relaxing holiday is area weather station {relaxingHoliday.Name} in {relaxingHoliday.Month}"); Console.WriteLine($" with the biggest average daily temperature {Math.Round(relaxingHoliday.MonthAvgTemp, 2)}C"); Console.WriteLine($" and <2mm average daily precipitation ({Math.Round(relaxingHoliday.MonthAvgPrecipitation, 2)}mm)"); } Console.WriteLine(""); Console.WriteLine("-Press any key-"); Console.ReadKey(); }
public void Exec() { using (WeatherDB weatherDB = new WeatherDB()) { Console.WriteLine("Stations:"); Console.WriteLine("---------"); weatherDB.Stations.Select(x => x.Name).OrderBy(x => x).ToList().ForEach(x => Console.WriteLine(x)); Console.WriteLine(""); Console.WriteLine("Date range:"); Console.WriteLine("-----------"); Console.WriteLine($"{weatherDB.Datas.Min(x => x.Date)} - {weatherDB.Datas.Max(x => x.Date)}"); } Console.WriteLine(""); Console.WriteLine("-Press any key-"); Console.ReadKey(); }
private void SmallWeeklyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "userCity") { weatherDB = smallWeeklyModel.getWeeklyForecast(UserCity); string ic; CityN = weatherDB.cityN; ic = weatherDB.icon_0; Icon_0 = setIcon(ic); //day0 Day_0 = weatherDB.day_0; Temp_0 = weatherDB.temp_0.ToString() + "\u00B0" + " C"; //day1 Day_1 = weatherDB.day_1; Temp_1 = weatherDB.temp_1.ToString() + "\u00B0" + " C"; //day2 Day_2 = weatherDB.day_2; Temp_2 = weatherDB.temp_2.ToString() + "\u00B0" + " C"; //day3 Day_3 = weatherDB.day_3; Temp_3 = weatherDB.temp_3.ToString() + "\u00B0" + " C"; //day4 Day_4 = weatherDB.day_4; Temp_4 = weatherDB.temp_4.ToString() + "\u00B0" + " C"; //day5 Day_5 = weatherDB.day_5; Temp_5 = weatherDB.temp_5.ToString() + "\u00B0" + " C"; //day6 Day_6 = weatherDB.day_6; Temp_6 = weatherDB.temp_6.ToString() + "\u00B0" + " C"; } }
/// <summary> /// Reset entire database and Load data /// </summary> public static bool InitialLoad() { bool isLoaded = false; WeatherDB wdb = new WeatherDB(); //Truncate tables wdb.TruncateTable("WeatherFileDownload"); wdb.TruncateTable("WeatherData"); //Reset WeatherFileDownload table wdb.ResetFileDownloadTable(); //Download all data WeatherDownload.DownloadAll(); //Insert or update data foreach (Region region in Enum.GetValues(typeof(Region))) { foreach (ClimateType ct in Enum.GetValues(typeof(ClimateType))) { var filename = FileDownloadHelper.getDBFileName(ct, region); // get filename from table based on region & climate bool isLatestFile = WeatherParser.isLatestFile(filename, wdb); // Verify if downloaded file is latest if (isLatestFile) { var list = WeatherParser.FormatWeatherData(filename, ct, region); // Parse the latest file into WeatherDataEntity Log.Information($"\n Loading : {ct} , {region}"); var count = wdb.BulkInsertOrUpdate(list); //Insert or Update data Log.Information(count["insert"] + " inserted"); Log.Information(count["update"] + " updated"); Log.Information(count["nochange"] + " no change"); wdb.UpdateFileTimeStamp(filename); } } } return(isLoaded); }
/// <summary> /// Verify if the downloaded file is latest or old. /// </summary> /// <param name="fileName">Name of the file which is verified</param> /// <param name="wdb">The database object. It is needed for persistent connection</param> /// <returns>result of file verification</returns> public static bool isLatestFile(string fileName, WeatherDB wdb) { IEnumerable <string> TextLines = File.ReadLines(WeatherDownload.filepath + fileName); foreach (var line in TextLines) { if (line.Contains("Last updated")) { DateTime dateLatest = getDateFromFile(line); DateTime dateDB = wdb.getFileTimeStamp(fileName); if (dateLatest.Date > dateDB.Date) { return(true); } else { return(false); } } } return(false); }
// GET api/<controller>/5 public async Task <string> Get(int id) { await WeatherDB.RecordSuccess(ReadingType.Luminocity, WeatherInfoSource.Device, id); return(DateTime.Now.ToString()); }
// GET api/<controller> public WeatherRecord[] Get() { return(WeatherDB.GetCurrentReading(ReadingType.Luminocity)); }
// GET api/<controller> public WeatherRecord[] Get() { return(WeatherDB.GetCurrentReading(ReadingType.Temperature)); }
public void SaveData() { WeatherDB.RecordList(WeatherList); }
} //possible to set in inherited class public WeatherExporter() { WeatherDbContext = new WeatherDB(); }
// GET api/<controller>/5 public async Task <string> Get(int id) { await WeatherDB.RecordSuccess(ReadingType.Temperature, WeatherInfoSource.Device, id / 100.0); return(DateTime.Now.ToString()); }
private void WeeklyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "userCity") { weatherDB = weeklyModel.getWeeklyForecast(UserCity); string ic; CityN = weatherDB.cityN; //day0 Day_0 = weatherDB.day_0; Temp_0 = weatherDB.temp_0.ToString() + "\u00B0" + " C"; Condition_0 = weatherDB.cond_0.ToString(); WindSpeed_0 = weatherDB.windSpeed_0.ToString() + " km/h"; WeatherDesc_0 = weatherDB.description_0; ic = weatherDB.icon_0; Icon_0 = setIcon(ic); //day1 Day_1 = weatherDB.day_1; Temp_1 = weatherDB.temp_1.ToString() + "\u00B0" + " C"; Condition_1 = weatherDB.cond_1.ToString(); WindSpeed_1 = weatherDB.windSpeed_1.ToString() + " km/h"; WeatherDesc_1 = weatherDB.description_1; ic = weatherDB.icon_1; Icon_1 = setIcon(ic); //day2 Day_2 = weatherDB.day_2; Temp_2 = weatherDB.temp_2.ToString() + "\u00B0" + " C"; Condition_2 = weatherDB.cond_2.ToString(); WindSpeed_2 = weatherDB.windSpeed_2.ToString() + " km/h"; WeatherDesc_2 = weatherDB.description_2; ic = weatherDB.icon_2; Icon_2 = setIcon(ic); //day3 Day_3 = weatherDB.day_3; Temp_3 = weatherDB.temp_3.ToString() + "\u00B0" + " C"; Condition_3 = weatherDB.cond_3.ToString(); WindSpeed_3 = weatherDB.windSpeed_3.ToString() + " km/h"; WeatherDesc_3 = weatherDB.description_3; ic = weatherDB.icon_3; Icon_3 = setIcon(ic); //day4 Day_4 = weatherDB.day_4; Temp_4 = weatherDB.temp_4.ToString() + "\u00B0" + " C"; Condition_4 = weatherDB.cond_4.ToString(); WindSpeed_4 = weatherDB.windSpeed_4.ToString() + " km/h"; WeatherDesc_4 = weatherDB.description_4; ic = weatherDB.icon_4; Icon_4 = setIcon(ic); //day5 Day_5 = weatherDB.day_5; Temp_5 = weatherDB.temp_5.ToString() + "\u00B0" + " C"; Condition_5 = weatherDB.cond_5.ToString(); WindSpeed_5 = weatherDB.windSpeed_5.ToString() + " km/h"; WeatherDesc_5 = weatherDB.description_5; ic = weatherDB.icon_5; Icon_5 = setIcon(ic); //day6 Day_6 = weatherDB.day_6; Temp_6 = weatherDB.temp_6.ToString() + "\u00B0" + " C"; Condition_6 = weatherDB.cond_6.ToString(); WindSpeed_6 = weatherDB.windSpeed_6.ToString() + " km/h"; WeatherDesc_6 = weatherDB.description_6; ic = weatherDB.icon_6; Icon_6 = setIcon(ic); } }
public WeatherDB getWeather(String city)///noy { using (WebClient web = new WebClient()) { try { ///for current String url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&&units=metric", city, appid); var json = web.DownloadString(url); var result = JsonConvert.DeserializeObject <WeatherInfo.WeatherRoot>(json); WeatherInfo.WeatherRoot output = result; string cityN = output.name; double humdity = output.main.humidity; double lonCoord = output.coord.lon; double latCoord = output.coord.lat; /// <summary> /// for a week /// </summary> String weeklyUrl = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&appid={1}&units=metric&cnt=7", city, appid); var weeklyJson = web.DownloadString(weeklyUrl); var weeklyResult = JsonConvert.DeserializeObject <WeeklyWeatherInfo>(weeklyJson); WeeklyWeatherInfo forecast = weeklyResult; string day_0 = trim(getDate(forecast.list[0].dt.ToString()).DayOfWeek.ToString()); double temp_0 = forecast.list[0].temp.day; double windSpeed_0 = forecast.list[0].speed; string description_0 = forecast.list[0].weather[0].description; string icon_0 = forecast.list[0].weather[0].icon; string cond_0 = forecast.list[0].weather[0].main; string day_1 = trim(getDate(forecast.list[1].dt.ToString()).DayOfWeek.ToString()); double temp_1 = forecast.list[1].temp.day; double windSpeed_1 = forecast.list[1].speed; string description_1 = forecast.list[1].weather[0].description; string icon_1 = forecast.list[1].weather[0].icon; string cond_1 = forecast.list[1].weather[0].main; string day_2 = trim(getDate(forecast.list[2].dt.ToString()).DayOfWeek.ToString()); double temp_2 = forecast.list[2].temp.day; double windSpeed_2 = forecast.list[2].speed; string description_2 = forecast.list[2].weather[0].description; string icon_2 = forecast.list[2].weather[0].icon; string cond_2 = forecast.list[2].weather[0].main; string day_3 = trim(getDate(forecast.list[3].dt.ToString()).DayOfWeek.ToString()); double temp_3 = forecast.list[3].temp.day; double windSpeed_3 = forecast.list[3].speed; string description_3 = forecast.list[3].weather[0].description; string icon_3 = forecast.list[3].weather[0].icon; string cond_3 = forecast.list[3].weather[0].main; string day_4 = trim(getDate(forecast.list[4].dt.ToString()).DayOfWeek.ToString()); double temp_4 = forecast.list[4].temp.day; double windSpeed_4 = forecast.list[4].speed; string description_4 = forecast.list[4].weather[0].description; string icon_4 = forecast.list[4].weather[0].icon; string cond_4 = forecast.list[4].weather[0].main; string day_5 = trim(getDate(forecast.list[5].dt.ToString()).DayOfWeek.ToString()); double temp_5 = forecast.list[5].temp.day; double windSpeed_5 = forecast.list[5].speed; string description_5 = forecast.list[5].weather[0].description; string icon_5 = forecast.list[5].weather[0].icon; string cond_5 = forecast.list[5].weather[0].main; string day_6 = trim(getDate(forecast.list[6].dt.ToString()).DayOfWeek.ToString()); double temp_6 = forecast.list[6].temp.day; double windSpeed_6 = forecast.list[6].speed; string description_6 = forecast.list[6].weather[0].description; string icon_6 = forecast.list[6].weather[0].icon; string cond_6 = forecast.list[6].weather[0].main; WeatherDB weatherDBinst = new WeatherDB(cityN, humdity, lonCoord, latCoord, day_0, temp_0, windSpeed_0, description_0, icon_0, cond_0, day_1, temp_1, windSpeed_1, description_1, icon_1, cond_1, day_2, temp_2, windSpeed_2, description_2, icon_2, cond_2, day_3, temp_3, windSpeed_3, description_3, icon_3, cond_3, day_4, temp_4, windSpeed_4, description_4, icon_4, cond_4, day_5, temp_5, windSpeed_5, description_5, icon_5, cond_5, day_6, temp_6, windSpeed_6, description_6, icon_6, cond_6); /* * using (var db = new WeatherContext()) * { * if (db.forc.Any(W => W.cityN == city)) * { * var query = (from b in db.forc * where b.cityN == city * select b).FirstOrDefault(); * * db.forc.Remove(query); * * db.forc.Add(weatherDBinst); * db.SaveChanges(); * * } * else//if the city isn't exist in the data base * { * db.forc.Add(weatherDBinst); * db.SaveChanges(); * * } * * }*/ return(weatherDBinst); } catch (Exception)//if there isn't connection to internet { using (var db = new WeatherContext()) { var query = (from b in db.forc where b.cityN == city select b).FirstOrDefault(); return(query); } } DateTime getDate(string milisconds) { DateTime day = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToLocalTime(); day = day.AddSeconds(Convert.ToDouble(milisconds)).ToLocalTime(); return(day); } string trim(string day) { string shortDay = ""; if (day == "Sunday") { shortDay = "Sun"; } if (day == "Monday") { shortDay = "Mon"; } if (day == "Tuesday") { shortDay = "Tue"; } if (day == "Wednesday") { shortDay = "Wed"; } if (day == "Thursday") { shortDay = "Thur"; } if (day == "Friday") { shortDay = "Fri"; } if (day == "Saturday") { shortDay = "Sat"; } return(shortDay); } } }