public async Task<IHttpActionResult> main() { CloudTable table = getWeatherTable(); table.CreateIfNotExists(); WUConditionsResponseEntity locationConditions = await getWundergroundDataTest(); double latitude = locationConditions.current_observation.observation_location.latitude; double longitude = locationConditions.current_observation.observation_location.longitude; IEnumerable<OWStationsResponseEntity> stations = await getOpenWeatherData(latitude, longitude); List<double> temperatures = new List<double>(); List<double> feelTemperatures = new List<double>(); List<double> windSpeeds = new List<double>(); //Add Wunderground's data temperatures.Add((5.0/9.0) * (locationConditions.current_observation.temp_f + 459.67)); feelTemperatures.Add((5.0 / 9.0) * (locationConditions.current_observation.feelslike_f + 459.67)); windSpeeds.Add(locationConditions.current_observation.wind_mph); //Add OpenWeather's data temperatures.AddRange(stations.Where(stationLocation => stationLocation.last != null && stationLocation.last.main != null).Select(stationLocation => stationLocation.last.main.temp)); windSpeeds.AddRange(stations.Where(stationLocation => stationLocation.last != null && stationLocation.last.wind != null).Select(stationLocation => stationLocation.last.wind.speed)); WeatherEntity weather = new WeatherEntity(latitude, longitude); weather.temperature = temperatures.Average(); weather.feelTemperature = feelTemperatures.Average(); weather.windSpeed = windSpeeds.Average(); weather.stationsCount = stations.Count() + 1; TableOperation insertOperation = TableOperation.InsertOrReplace(weather); table.Execute(insertOperation); return Ok(weather); }
public async Task<HttpResponseMessage> Get([FromUri]CoordinatesModel coordinates) { CloudTable table = getWeatherTable(); WUConditionsResponseEntity locationConditions = await getWundergroundData(coordinates.latitude, coordinates.longitude); if (locationConditions.current_observation == null) { var message = string.Format("Unable to find location with latitude: {0} and longitude: {1}!", coordinates.latitude.ToString(), coordinates.longitude.ToString()); HttpError err = new HttpError(message); return Request.CreateResponse(HttpStatusCode.NotFound, err); } double latitude = locationConditions.current_observation.observation_location.latitude; double longitude = locationConditions.current_observation.observation_location.longitude; IEnumerable<OWStationsResponseEntity> stations = await getOpenWeatherData(latitude, longitude); List<double> temperatures = new List<double>(); List<double> feelTemperatures = new List<double>(); List<double> windSpeeds = new List<double>(); List<double> distances = new List<double>(); //Add Wunderground's data temperatures.Add((5.0 / 9.0) * (locationConditions.current_observation.temp_f + 459.67)); feelTemperatures.Add((5.0 / 9.0) * (locationConditions.current_observation.feelslike_f + 459.67)); windSpeeds.Add(locationConditions.current_observation.wind_mph); //Add OpenWeather's data temperatures.AddRange(stations.Where(stationLocation => stationLocation.last != null && stationLocation.last.main != null).Select(stationLocation => stationLocation.last.main.temp)); windSpeeds.AddRange(stations.Where(stationLocation => stationLocation.last != null && stationLocation.last.wind != null).Select(stationLocation => stationLocation.last.wind.speed)); distances.AddRange(stations.Select(stationLocation => stationLocation.distance)); WeatherEntity weather = new WeatherEntity(latitude, longitude); weather.temperature = temperatures.Average(); weather.feelTemperature = feelTemperatures.Average(); weather.windSpeed = windSpeeds.Average(); weather.closestStationMiles = distances.Min(); weather.stationsCount = stations.Count() + 1; TableOperation insertOperation = TableOperation.InsertOrReplace(weather); table.Execute(insertOperation); return Request.CreateResponse(HttpStatusCode.OK, weather); }