Ejemplo n.º 1
0
        public object GetWeatherForecastByIdNode(int idNode)
        {
            SmartIrrigationModels.Models.DTOS.Node node = _nodeDomain.GetAllActiveNodes()
                                                          .Where(x => x.IdNode == idNode).FirstOrDefault();
            Location nodeLocation = _locationDomain.RetrieveLocationByNodeId(node.IdNode);

            return(_weatherForecastDomain.GetWeatherForecast(nodeLocation.Latitude, nodeLocation.Longitude));
        }
        public void AddNewNode(AddNewNodeQueryParams parameters)
        {
            GeocodingAddressModelQueryParams address = new GeocodingAddressModelQueryParams(parameters.Street, parameters.DoorNumber, parameters.PostalCode, parameters.County, parameters.District);

            Station stationAdded = new Station();
            //TODO: REFACTOR THIS
            RootGeocodingDataModel <GeocodingAddressResponseModel> coords =
                _geocodingDomain.GetCoordsFromAddress(address);

            Location location = _locationDomain.RetrieveLocation(coords.Data.FirstOrDefault().Latitude,
                                                                 coords.Data.FirstOrDefault().Longitude);

            if (location == null)
            {
                District district = _districtDomain.GetDistrictByDistrictName(address.District);
                County   county   = _countyDomain.GetCountyByCountyName(address.County);
                _locationDomain.InsertLocationData(location, district.Id_District, county.CountyId);
                location = _locationDomain.RetrieveLocation(coords.Data.FirstOrDefault().Latitude,
                                                            coords.Data.FirstOrDefault().Longitude);
            }



            //SE nao for um sensor real procurar a estação metereologica mais proxima, adicionar a bd, e depois adiconar o no a apontar para a estação
            if (parameters.IsRealSensor != true)
            {
                var stationAddedInfo = _weatherStationApplication
                                       .AddWeatherStationToDatabase(address);
                stationAdded =
                    _weatherStationApplication.RetrieveStationByStationName(stationAddedInfo.station.Name);

                Location locationStationAddded = stationAddedInfo.locationStations;

                SmartIrrigationModels.Models.DTOS.Node nodeAdded = _nodeDomain.AddNewNode(parameters, location.Id_Location,
                                                                                          stationAdded.Id_Station ?? -1);

                _weatherStationApplication.AddWeatherStationDataToDatabase(stationAdded, locationStationAddded, nodeAdded);
            }
            else
            {
                //se for um sensor real, adiciona o no com o IdNearStation a -1 e depois adiciona os sensores a apontar para o no No

                _nodeDomain.AddNewNode(parameters, location.Id_Location, -1);

                foreach (var sensor in parameters.SensorsImplemented)
                {
                    _sensorDomain.AddNewSensor(parameters.Street, sensor, location.Id_Location ?? -1);
                }
            }
        }
Ejemplo n.º 3
0
        public int SaveHourlyDataOfStationInDatabaseBasedOnCoords(string latitude, string longitude)
        {
            WeatherStationWithParamsModel nearbyWeatherStation =
                _weatherStationDomain.FindNearByStationFromLatLong(new FindNearbyStationModel(float.Parse(latitude, CultureInfo.InvariantCulture.NumberFormat),
                                                                                              float.Parse(longitude, CultureInfo.InvariantCulture.NumberFormat), 8, null));



            HourlyDataOfAPointQueryParams data = new HourlyDataOfAPointQueryParams(
                float.Parse(latitude, CultureInfo.InvariantCulture.NumberFormat), float.Parse(longitude, CultureInfo.InvariantCulture.NumberFormat), null,
                DateTime.Now.AddDays(-9).ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd"), null);
            var hourlyData = _weatherHistoryDomain.GetHourlyDataOfPoint(data, nearbyWeatherStation.Name.En);

            SmartIrrigationModels.Models.DTOS.Node node = _nodeDomain.GetNodeByLatLong(latitude, longitude);
            return(_weatherHistoryDomain.AddHourlyDataOfPointToDatabase(hourlyData, nearbyWeatherStation.Name.En, node.IdNode));
        }
        public void AddWeatherStationDataToDatabase(Station stationAdded, Location locationStation, SmartIrrigationModels.Models.DTOS.Node node)
        {
            HourlyDataOfAPointQueryParams data = new HourlyDataOfAPointQueryParams(
                float.Parse(locationStation.Latitude.Replace(",", "."), CultureInfo.InvariantCulture.NumberFormat), float.Parse(locationStation.Longitude.Replace(",", "."), CultureInfo.InvariantCulture.NumberFormat), null,
                DateTime.Now.AddDays(-9).ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd"), null);
            var hourlyData = _weatherHistoryDomain.GetHourlyDataOfPoint(data, stationAdded.Name);

            _weatherHistoryDomain.AddHourlyDataOfPointToDatabase(hourlyData, stationAdded.Name, node.IdNode);
        }