def get_readings_by_date_test(): termometer = Sensor.find("Termometer") expected_readings_len = 24 - 12 + 1 begin = datetime(2020, 11, 26, 17, 12) end = datetime(2020, 11, 26, 17, 24) readings = termometer.get_readings_by_date(begin, end) if len(readings) != expected_readings_len: print("get_readings_by_date_test: FAILED") print(f"Expected outcome {expected_readings_len}, " f"Actual outcome {len(readings)}") else: print("get_readings_by_date_test: PASSED")
"Termometer (mock)": ("Celsius", "Temperature"), "Hygrometer (mock)": ("%", "Humidity"), "Manometer (mock)": ("bar", "Pressure") } users = ["John", "Alex", "Rob", "Matt"] for sensor_name, (unit, quantity) in sensors.items(): Sensor.create(sensor_name, quantity) # For the sake of tests for sensor_name, (unit, quantity) in sensors.items(): for i in range(120, 180, 1): t = datetime(2020, 11, 26, 17, i % 60, 0) Reading.create(str(random.randint(20, 27)), unit, Sensor.find(sensor_name).id, timestamp=t) # Let's have 4 readings per hour start_date = datetime.utcnow() - timedelta(days=4) now = datetime.utcnow() sampling_interval = timedelta(minutes=15) for sensor_name, (unit, quantity) in sensors.items(): sample_date = start_date while sample_date < now: Reading.create(str(random.randint(20, 27)), unit, Sensor.find(sensor_name).id, timestamp=sample_date) sample_date = sample_date + sampling_interval