Пример #1
0
    def test_data_collection_with_one_item_list_and_no_properties(self):
        dc = graph.DataCollection([0, 1, 2, 3, 4])
        p = dc.get_property('default')

        self.assertEqual(dc.properties.default, p)
        self.assertEqual(dc.meta.default.min, 0)
        self.assertEqual(dc.meta.default.max, 4)
Пример #2
0
    def test_geometry_items(self):
        dc = graph.DataCollection([(0, 0), (0, 1), (0, 10)],
                                  graph.Property('first_property', 1))
        items = dc.to_dc_items(None)

        self.assertEqual(items[0].dc, dc)
        self.assertEqual(items[0].datum, (0, 0))
        self.assertEqual(items[2].datum, (0, 10))
Пример #3
0
    def test_create_line(self):
        data = [(0, 0), (5, 1), (10, 10)]
        dc = graph.DataCollection(data, graph.Property('month', 1),
                                  graph.Property('count', 0))
        self.g.create.line(dc, 'counts', graph.X(dc.properties.count),
                           graph.Y(dc.properties.month))

        self.assertEqual(
            r_struct_to_dict(self.g.plot_objects['counts']),
            r_struct_to_dict([
                Line(start=Struct(X=30, Y=270),
                     end=Struct(X=400, Y=((240 * .9) + 30))),
                Line(start=Struct(X=400, Y=((240 * .9) + 30)),
                     end=Struct(X=770, Y=30)),
            ]))
Пример #4
0
    def test_property_hash(self):
        dc = graph.DataCollection([(0, 0), (0, 1), (0, 10)],
                                  graph.Property('first_property', 0),
                                  graph.Property('second_property', 1))

        self.assertEqual(dc.to_dict(), [{
            'first_property': 0,
            'second_property': 0
        }, {
            'first_property': 0,
            'second_property': 1
        }, {
            'first_property': 0,
            'second_property': 10
        }])
Пример #5
0
    def test_create_line_with_datetimes(self):
        data = [["01-01-2018", 0], ["01-02-2018", 5], ["01-03-2018", 10]]

        month_prop = graph.Property(
            'month',
            0,
            parse=lambda t: datetime.strptime(t, "%d-%m-%Y"),
            convert=lambda t: t.timestamp())
        dc = graph.DataCollection(data, month_prop, graph.Property('count', 1))

        self.g.create.line(dc, 'counts', graph.X(dc.properties.month),
                           graph.Y(dc.properties.count))

        self.assertEqual(self.g.plot_objects['counts'][0].start.X, 30)
        self.assertEqual(self.g.plot_objects['counts'][0].end.X, 418)
        self.assertEqual(self.g.plot_objects['counts'][1].start.X, 418)
        self.assertEqual(self.g.plot_objects['counts'][1].end.X, 770)
Пример #6
0
 def test_properties_lookup(self):
     p = graph.Property('first_property', 1)
     dc = graph.DataCollection([(0, 0), (0, 1), (0, 10)], p)
     self.assertEqual(dc.properties.first_property, p)
Пример #7
0
 def test_get_property_min(self):
     dc = graph.DataCollection([(0, 0), (0, 1), (0, 10)],
                               graph.Property('first_property', 1))
     self.assertEqual(dc.meta.first_property.min, 0)