fixing sensor tests (not working version)

This commit is contained in:
Pilar 2021-06-03 13:34:41 -04:00
parent de471ee88a
commit 673c809dd4
3 changed files with 28 additions and 11 deletions

View File

@ -5,6 +5,8 @@ Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.mons
"""
from abc import ABC
from typing import List
from city_model_structure.attributes.sensor import Sensor
class CityObjectsCluster(ABC):
@ -15,6 +17,7 @@ class CityObjectsCluster(ABC):
self._name = name
self._cluster_type = cluster_type
self._city_objects = city_objects
self._sensors = []
@property
def name(self):
@ -34,3 +37,19 @@ class CityObjectsCluster(ABC):
else:
self._city_objects.append(city_object)
return self._city_objects
@property
def sensors(self) -> List[Sensor]:
"""
Sensor list belonging to the city objects cluster
:return: [Sensor]
"""
return self._sensors
@sensors.setter
def sensors(self, value):
"""
Sensor list belonging to the city objects cluster
:param value: [Sensor]
"""
self._sensors = value

View File

@ -8,7 +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 city_model_structure.parts_consisting_building import PartsConsistingBuilding
from imports.sensors_factory import SensorsFactory
@ -39,12 +39,12 @@ class TestSensorsFactory(TestCase):
city = City(lower_corner, upper_corner, srs_name)
buildings.append(Building("EV", lod, surfaces, year_of_construction, function, lower_corner))
buildings.append(Building("GM", lod, surfaces, year_of_construction, function, lower_corner))
buildings.append(Building("MB", lod, surfaces, year_of_construction, function, lower_corner))
for building in buildings:
city.add_city_object(building)
buildings_cluster = PartsConsistingBuilding("GM_MB_EV", buildings)
city.add_city_objects_cluster(buildings_cluster)
return city
#virtual_building = CityObject("GM_MB_EV", lod, surfaces, lower_corner)
#virtual_building.type = 'Virtual'
#city.add_city_object(virtual_building)
def test_city_with_sensors(self):
SensorsFactory('cec', self._city, self._end_point).enrich()
@ -52,10 +52,8 @@ class TestSensorsFactory(TestCase):
SensorsFactory('ct', self._city, self._end_point).enrich()
for city_object in self._city.city_objects:
for sensor in city_object.sensors:
# 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'})
sensor.add_period(update)
row = sensor.measures.loc[sensor.measures["Date time"] == '2020-01-19 23:55:00']['Energy consumption'].iloc[0]
self.assertTrue(f'{row}' == '12345.0')
for city_objects_cluster in self._city.city_objects_clusters:
for sensor in city_objects_cluster.sensors:
self.assertTrue(f'{row}' == '12345.0')