From 673c809dd450b8f99a471046d311c3086f0e78b6 Mon Sep 17 00:00:00 2001 From: Pilar Date: Thu, 3 Jun 2021 13:34:41 -0400 Subject: [PATCH] fixing sensor tests (not working version) --- city_model_structure/city_object.py | 2 +- city_model_structure/city_objects_cluster.py | 19 +++++++++++++++++++ non_functional_tests/test_sensors_factory.py | 18 ++++++++---------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index 091cabfb..ace50dae 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -224,4 +224,4 @@ class CityObject: Sensor list belonging to the city object :param value: [Sensor] """ - self._sensors = value \ No newline at end of file + self._sensors = value diff --git a/city_model_structure/city_objects_cluster.py b/city_model_structure/city_objects_cluster.py index be5397b0..665d94b2 100644 --- a/city_model_structure/city_objects_cluster.py +++ b/city_model_structure/city_objects_cluster.py @@ -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 diff --git a/non_functional_tests/test_sensors_factory.py b/non_functional_tests/test_sensors_factory.py index 50144a6a..998d2504 100644 --- a/non_functional_tests/test_sensors_factory.py +++ b/non_functional_tests/test_sensors_factory.py @@ -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')