public override void Init() { Task.Run(async() => { Temperature = await ClimateModel.GetTemperature(); }); }
public ActionResult GetCurrentStatus() { // TemperatureData.Instance().currentDashModel = new DashboardModel(5, 6, "June 28, 2019", "9:54"); ClimateModel dm = ClimateData.Instance().currentClimateModel; return(Json(dm)); }
public void initPlanet(double _densityMul = 1.0, double rel_mass = 1.0, List <double> percentage = null) { //elementsDistribution = percentage; NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; Function hydrostaticEquilibrium = ParametriUtente.Science.hydrostaticEquilibrium; //mass in grammi / 18.015 = moles double pressione; this.Volume = ((Math.Pow(this.planetRadius, 3) * (4.0 / 3.0)) * Math.PI); //km3 this.mass = rel_mass * ParametriUtente.Science.m_t; this.meanDensity = (this.mass * 1000 / (Math.Pow(10, 15) * Volume)) * _densityMul; pressione = ((ParametriUtente.Science.G * mass * (this.meanDensity * 1000)) / (this.planetRadius * this.planetRadius)); this.Core_temperature = ((0.84 * Math.Pow(10, -27)) * pressione) / (this.meanDensity * (1.380649 * Math.Pow(10, -23))); this.Surface_temperature = this.Core_temperature / 2543.37; double areaOfAbstoRadiationArea_ratio = 4; // 4 for fast rotation 2 for slow/tidal lock surfaceGravity = (ParametriUtente.Science.G * this.mass) / Math.Pow(this.planetRadius * 1000, 2); //https://en.wikipedia.org/wiki/Effective_temperature this.setRelativeValues(); this.initAtmoSphere(); this.planetRegions = ClimateEngine.createLatitudinalRegions(4, this.Surface_temperature); if (this.hasAtmosphere) { for (int i = 0; i < 2; i++) { this.applyChemicalBonds(); } Atmosphere = new Atmosphere(this.body_composition.getCompositionFromElements(body_composition.get_gas_elements())); Atmosphere.get_set_Pressure(ParametriUtente.Science.atm_t * (this.surfaceGravity / ParametriUtente.Science.g_t)); double atmMass = (4 * Math.PI * Math.Pow(this.planetRadius * 1000, 2) * Converter.atm_to_PA(Atmosphere.get_set_Pressure())) / this.surfaceGravity; Atmosphere.get_set_Masspercentage(this.planetMass / atmMass); //TODO: Create ClimateModel programmatically this.climateModel = new ClimateModel_TerrestrialPlanet(this.Surface_temperature, 0, this.planetRegions); this.climateModel.distributeHeat(); this.averageTemperature = this.climateModel.getRealTemperature(); this.waterBoilingPoint = ChemicalEngine.getElementBoilingPoint(null, Converter.K_to_C(this.averageTemperature), Converter.atm_to_mmHg(this.Atmosphere.get_set_Pressure())); this.waterBoilingPoint = Converter.C_to_K(this.waterBoilingPoint); this.waterMeltingPoint = ChemicalEngine.getWaterMeltingPoint_AtP(this.Atmosphere.get_set_Pressure()); } this.InitPlanetClassification(); }
public async Task <ClimateModel> Create(ClimateModel climate) { try { await _climates.InsertOneAsync(climate); return(climate); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
public static void UpdateDashboard(ClimateModel climateMod) { // don't add the first model with empty data to the list if (climateMod != null && climateMod.date != null) { Console.WriteLine("ClimateData updateDashboard: " + climateMod.temperature); ClimateModel cData = ClimateData.Instance().currentClimateModel; if (cData.humidity != 0) { ClimateData.Instance().dashboardModels.Add(instance.currentClimateModel); } } instance.currentClimateModel = new ClimateModel(climateMod.temperature, climateMod.humidity); }
public ClimateModel FillCity() { ClimateModel openWeatherMap = new ClimateModel(); openWeatherMap.cities = new Dictionary <string, string>(); openWeatherMap.cities.Add("Mumbai", "1275339"); openWeatherMap.cities.Add("New Delhi", "1261481"); openWeatherMap.cities.Add("Bangalore", "1277333"); openWeatherMap.cities.Add("Bhubaneshwar", "1275817"); openWeatherMap.cities.Add("Khurda", "1266616"); openWeatherMap.cities.Add("Cuttack", "1273780"); openWeatherMap.cities.Add("Hyderabad", "1269843"); openWeatherMap.cities.Add("Philadelphia", "4560349"); return(openWeatherMap); }
public ActionResult Index(string cities) { ClimateModel openWeatherMap = FillCity(); if (cities != null) { string apiKey = "61cb374e7df0bee2ff6d3cc46f278eb1"; HttpWebRequest apiRequest = WebRequest.Create("https://api.openweathermap.org/data/2.5/weather?id=" + cities + "&appid=" + apiKey + "&units=metric") as HttpWebRequest; //apiRequest.UseDefaultCredentials = true;// added by me to solve the error //apiRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;// added by me to solve the error string apiResponse = ""; using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); apiResponse = reader.ReadToEnd(); } ResponseWeather rootObject = JsonConvert.DeserializeObject <ResponseWeather>(apiResponse);// StringBuilder sb = new StringBuilder(); sb.Append("<table><tr><th>Weather Description</th></tr>"); sb.Append("<tr><td>City:</td><td>" + rootObject.name + "</td></tr>"); sb.Append("<tr><td>Country:</td><td>" + rootObject.sys.country + "</td></tr>"); sb.Append("<tr><td>Country Sun Rise:</td><td>" + rootObject.sys.sunrise + "</td></tr>"); sb.Append("<tr><td>Country Sun Sete:</td><td>" + rootObject.sys.sunset + "</td></tr>"); sb.Append("<tr><td>Wind:</td><td>" + rootObject.wind.speed + " Km/h</td></tr>"); sb.Append("<tr><td>Current Temperature:</td><td>" + rootObject.main.temp + " °C</td></tr>"); sb.Append("<tr><td>Max. Temperature:</td><td>" + rootObject.main.temp_max + " °C</td></tr>"); sb.Append("<tr><td>Min. Temperature:</td><td>" + rootObject.main.temp_min + " °C</td></tr>"); sb.Append("<tr><td>Pressure:</td><td>" + rootObject.main.pressure + "</td></tr>"); sb.Append("<tr><td>Humidity:</td><td>" + rootObject.main.humidity + "</td></tr>"); sb.Append("<tr><td>Weather:</td><td>" + rootObject.weather[0].description + "</td></tr>"); sb.Append("</table>"); openWeatherMap.apiResponse = sb.ToString(); } else { if (Request.Form["submit"] != null) { TempData["SelectOption"] = -1; } } return(View(openWeatherMap)); }
public void SetTemp() { Console.WriteLine("GET::SetTemp"); var temp = float.Parse(base.QueryString["temp"] as string); Console.WriteLine($"New desired temp: {temp}"); var desiredTemp = new ClimateModel() { DesiredTemperature = temp }; ClimateModelManager.Instance.UpdateDesiredClimate(desiredTemp); this.Context.Response.ContentType = ContentTypes.Application_Text; this.Context.Response.StatusCode = 200; _ = this.Send($"{temp} received"); }
public async Task <ActionResult> UpdateCurrentStatus([FromBody] ClimateModel dashModel) { if (dashModel != null) { // creates the id dashModel.populateFields(); // insert into the database var before = await this._climateService.Create(dashModel); Console.WriteLine("\nBefore:" + before.temperature); // test that the data is in the database var results = _climateService.Get(dashModel.key); Console.WriteLine("After " + results.temperature); ClimateData.UpdateDashboard(dashModel); Console.WriteLine(ClimateData.Instance().currentClimateModel.temperature); //_hub.Clients.All.SendAsync("transfertemperaturedata",dashModel); return(Json(new ResponseModel(ResponseModel.Responses.Success))); } return(Json(new ResponseModel(ResponseModel.Responses.Error))); }
// GET: ClimateMap //public ActionResult Index() //{ // return View(); //} public ActionResult Index() { ClimateModel openWeatherMap = FillCity(); return(View(openWeatherMap)); }
public void Remove(ClimateModel climateIn) => _climates.DeleteOne(climate => climate.key.Equals(climateIn.key));
public void Update(string key, ClimateModel climateIn) => _climates.ReplaceOne(climate => climate.key.Equals(key), climateIn);