finished the new sensors and added to the factory (concordia_temperature and concordia_gas_flow)

This commit is contained in:
Pilar 2021-06-02 11:56:38 -04:00
parent fec7f79d20
commit f5e32e16ea
7 changed files with 89 additions and 11 deletions

View File

@ -25,7 +25,7 @@ class Building(CityObject):
"""
def __init__(self, name, lod, surfaces, year_of_construction, function,
city_lower_corner, terrains=None, zones_surfaces_ids=None):
super().__init__(lod, surfaces, name, city_lower_corner)
super().__init__(name, lod, surfaces, city_lower_corner)
self._basement_heated = None
self._attic_heated = None
self._terrains = terrains

View File

@ -38,6 +38,7 @@ class City:
self._latitude = None
self._longitude = None
self._time_zone = None
self._generic_city_object = None
def _get_location(self) -> Location:
if self._location is None:
@ -158,11 +159,14 @@ class City:
:param new_city_object:CityObject
:return: None
"""
if new_city_object.type != 'building':
raise NotImplementedError(new_city_object.type)
if self._buildings is None:
self._buildings = []
self._buildings.append(new_city_object)
if new_city_object.type == 'building':
if self._buildings is None:
self._buildings = []
self._buildings.append(new_city_object)
else:
if self._generic_city_object is None:
self._generic_city_object = []
self._generic_city_object.append(new_city_object)
def remove_city_object(self, city_object):
"""

View File

@ -16,7 +16,7 @@ class CityObject:
"""
class CityObject
"""
def __init__(self, lod, surfaces, name, city_lower_corner):
def __init__(self, name, lod, surfaces, city_lower_corner):
self._name = name
self._lod = lod
self._surfaces = surfaces

View File

@ -0,0 +1,31 @@
"""
Concordia gas flow
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import pandas as pd
from imports.sensors.concordia_file_report import ConcordiaFileReport
from city_model_structure.attributes.concordia_gas_flow_sensor import ConcordiaGasFlowSensor
class ConcordiaGasFlow(ConcordiaFileReport):
def __init__(self, city, end_point, base_path):
super().__init__(city, end_point, base_path, 'concordia_gas_flow_db.json')
for city_object in city.city_objects:
for i in range(len(self._city_object)):
if self._city_object[i] == city_object.name and self._sensors[i] in self._sensor_point:
building_measures = [self._measures["Date time"], self._measures[self._sensor_point[self._sensors[i]]]]
building_headers = ["Date time", "Gas Flow Cumulative Monthly"]
building_gas_flow = pd.concat(building_measures, keys=building_headers, axis=1)
sensor = ConcordiaGasFlowSensor(self._sensors[i])
sensor_exist = False
for j in range(len(city_object.sensors)):
if city_object.sensors[j].name is sensor.name:
city_object.sensors[j].add_period(building_gas_flow)
sensor_exist = True
break
if not sensor_exist:
sensor.add_period(building_gas_flow)
city_object.sensors.append(sensor)

View File

@ -0,0 +1,31 @@
"""
Concordia temperature
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import pandas as pd
from imports.sensors.concordia_file_report import ConcordiaFileReport
from city_model_structure.attributes.concordia_temperature_sensor import ConcordiaTemperatureSensor
class ConcordiaTemperature(ConcordiaFileReport):
def __init__(self, city, end_point, base_path):
super().__init__(city, end_point, base_path, 'concordia_temperature_db.json')
for city_object in city.city_objects:
for i in range(len(self._city_object)):
if self._city_object[i] == city_object.name and self._sensors[i] in self._sensor_point:
building_measures = [self._measures["Date time"], self._measures[self._sensor_point[self._sensors[i]]]]
building_headers = ["Date time", "Temperature"]
building_temperature = pd.concat(building_measures, keys=building_headers, axis=1)
sensor = ConcordiaTemperatureSensor(self._sensors[i])
sensor_exist = False
for j in range(len(city_object.sensors)):
if city_object.sensors[j].name is sensor.name:
city_object.sensors[j].add_period(building_temperature)
sensor_exist = True
break
if not sensor_exist:
sensor.add_period(building_temperature)
city_object.sensors.append(sensor)

View File

@ -2,9 +2,12 @@
SensorsFactory retrieve sensors information
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from imports.sensors.concordia_energy_consumption import ConcordiaEnergyConsumption
from imports.sensors.concordia_gas_flow import ConcordiaGasFlow
from imports.sensors.concordia_temperature import ConcordiaTemperature
class SensorsFactory:
@ -23,6 +26,9 @@ class SensorsFactory:
def _cgf(self):
ConcordiaGasFlow(self._city, self._end_point, self._base_path)
def _ct(self):
ConcordiaTemperature(self._city, self._end_point, self._base_path)
def enrich(self):
"""
Enrich the city with the usages information

View File

@ -8,6 +8,7 @@ from unittest import TestCase
import pandas as pd
from city_model_structure.city import City
from city_model_structure.building import Building
from city_model_structure.city_object import CityObject
from imports.sensors_factory import SensorsFactory
@ -36,13 +37,18 @@ class TestSensorsFactory(TestCase):
function = "office"
buildings.append(Building("EV", lod, surfaces, year_of_construction, function, lower_corner))
buildings.append(Building("GM", lod, surfaces, year_of_construction, function, lower_corner))
return City(lower_corner, upper_corner, srs_name, buildings)
city = City(lower_corner, upper_corner, srs_name, buildings)
city.add_city_object(CityObject("GM_MB_EV", lod, surfaces, lower_corner))
return city
def test_city_with_sensors(self):
SensorsFactory('cec', self._city, self._end_point).enrich()
for building in self._city.buildings:
for sensor in building.sensors:
self.assertTrue(sensor.type is 'ConcordiaEnergySensor')
SensorsFactory('cgf', self._city, self._end_point).enrich()
SensorsFactory('ct', self._city, self._end_point).enrich()
for city_object in self._city.city_objects:
print(city_object.name)
for sensor in city_object.sensors:
print(sensor.name)
# force update last row
update = pd.DataFrame([['2020-01-19 23:55:00', '12345.0']], columns=["Date time", "Energy consumption"])
update = update.astype({"Date time": 'datetime64', "Energy consumption": 'float64'})