def test_summary_overview_aggregate(self): data_tools = [ { "field": "number", "method": "line" }, ] units_d = {"field": "number", "unit": "scalar"} C = DictConnection() topic_id = C.add_topic("topic", description="description", fields=["number"], data_tools=data_tools, units=[units_d]) for i in range(10): C.add_data(topic_id, {"number": i}) result = C.get_overview(aggregate_to=3) data = result["statistics"][0]["payload"]["data"]["datasets"][0][ "data"] self.assertEqual(len(data), 3) result = C.get_summary(topic_id, aggregate_to=3) data = result["statistics"][0]["payload"]["data"]["datasets"][0][ "data"] self.assertEqual(len(data), 3)
def test_overview_and_comparison_include_units(self): data_tools = [ { "field": "number", "method": "latest" }, ] units_d = {"field": "number", "unit": "scalar"} C = DictConnection() for i in range(3): topic_id = C.add_topic("topic_" + str(i), description="description", fields=["number"], data_tools=data_tools, units=[units_d]) C.add_data(topic_id, {"number": i}) overview = C.get_overview() self.assertEqual(overview["topic_names"], ["topic_0", "topic_1", "topic_2"]) self.assertEqual(overview["fields"], ["number"]) self.assertEqual(len(overview["statistics"]), 3) self.assertEqual(overview["statistics"][0]["payload"]["unit"], "scalar")
def test_run_data_tools_topic_not_found(self): C = DictConnection() result = C.get_overview(['invalid_id']) self.assertEqual(result.get('statistics'), []) warnings = result.get('warnings') self.assertEqual(warnings[0], topic_not_found('invalid_id'))
def _test_run_data_tools_for_many(self, fn, data_tools): topic_ids = [] C = DictConnection() for i in range(3): topic_ids.append( C.add_topic("topic_" + str(i), description="description", fields=["number"], data_tools=data_tools)) C.add_data(topic_ids[-1], {"number": 3}) C.add_data(topic_ids[-1], {"number": 4}) C.add_data(topic_ids[-1], {"number": 2}) if fn == "get_comparison": result = C.get_overview(topic_ids) elif fn == "get_overview": result = C.get_overview() self.assertEqual(result["topic_names"], ["topic_0", "topic_1", "topic_2"]) self.assertEqual(result["fields"], ["number"]) return result
def test_overview_ignores_templates(self): data_tools = [ { "field": "number", "method": "line" }, ] units_d = {"field": "number", "unit": "scalar"} C = DictConnection() C.add_topic("Test template", type_str="template", fields=['number'], units=[units_d], data_tools=data_tools) C.add_topic("Test topic", template="Test template") data = C.get_overview() self.assertEqual(len(data["warnings"]), 1) self.assertNotIn(data["warnings"][0], "template")