コード例 #1
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
        }])
コード例 #2
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)),
            ]))
コード例 #3
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)
コード例 #4
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))
コード例 #5
0
 def test_parse(self):
     p = graph.Property('month',
                        0,
                        parse=lambda t: datetime.strptime(t, "%d-%m-%Y"))
     self.assertTrue(p.value(['01-01-2018', 2]), datetime(2018, 1, 1))
コード例 #6
0
 def test_simple(self):
     p = graph.Property('month', 0)
     self.assertTrue(p.value([100, 2]), 100)
コード例 #7
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)
コード例 #8
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)