""" TestSensorsFactory test and validate the city model structure schedules SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2021 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ from pathlib import Path from unittest import TestCase import pandas as pd from city_model_structure.city import City from city_model_structure.building import Building from imports.sensors_factory import SensorsFactory class TestSensorsFactory(TestCase): """ TestSchedulesFactory TestCase """ def setUp(self) -> None: """ Configure test environment :return: """ self._city = TestSensorsFactory._mockup_city() self._end_point = (Path(__file__).parent / 'tests_data/EV-GM energy demand weekly report_01-26-20_04-30.csv').resolve() @staticmethod def _mockup_city(): lower_corner = [0, 0, 0] upper_corner = [10, 10, 10] srs_name = 'Mockup_city' buildings = [] lod = 2 surfaces = [] year_of_construction = 2021 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) 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') # 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'] print(row["Energy consumption"][0]) self.assertTrue(row[0]["Energy consumption"] is '12345.0')