Exemplo n.º 1
0
    def get_echarts_instance(self, *args, **kwargs):
        device_data = models.Device.objects.values('device_type').annotate(count=Count('device_type'))
        device_types, counters = fetch(device_data, 'device_type', 'count')
        pie = Pie("设备分类", page_title='设备分类', width='100%')
        pie.add("设备分类", device_types, counters, is_label_show=True)

        battery_lifes = models.Device.objects.values('name', 'battery_life')
        names, lifes = fetch(battery_lifes, 'name', 'battery_life')
        bar = Bar('设备电量', page_title='设备电量', width='100%')
        bar.add("设备电量", names, lifes)
        charts = NamedCharts().add_chart(pie, name='pie').add_chart(bar, name='bar')
        return charts
Exemplo n.º 2
0
    def test_fetch(self):
        names = fetch(DICT_LIST_DATA, 'name')
        self.assertListEqual(names, ['Alice', 'Bob', 'Charlie'])

        sexs = fetch(DICT_LIST_DATA, 'sex', default='male')
        self.assertListEqual(sexs, ['female', 'male', 'male'])

        names, ages = fetch(DICT_LIST_DATA, 'name', 'age')
        self.assertListEqual(names, ['Alice', 'Bob', 'Charlie'])
        self.assertListEqual(ages, [30, 56, 56])

        names, ages, sexs = fetch(DICT_LIST_DATA, 'name', 'age', 'sex', defaults={'sex': 'male'})
        self.assertListEqual(names, ['Alice', 'Bob', 'Charlie'])
        self.assertListEqual(ages, [30, 56, 56])
        self.assertListEqual(sexs, ['female', 'male', 'male'])
Exemplo n.º 3
0
 def test_with_dict(self):
     """
     Use dict.get(key) to pick item.
     """
     names, ages = fetch(DICT_LIST_DATA, 'name', 'age', getter=lambda item, key: item.get(key))
     self.assertListEqual(names, ['Alice', 'Bob', 'Charlie'])
     self.assertListEqual(ages, [30, 56, 56])
Exemplo n.º 4
0
    def get_echarts_instance(self, *args, **kwargs):
        decimal_places = 1
        film_datas = FilmLen.objects.all().order_by('id')[:200]
        ids = fetch(film_datas.values("id"), "id")

        # bar
        bar_mix = Bar("Film 長度", page_title='(BarMix)', width='100%')
        for i in range(0, 5):
            bar_data = fetch(film_datas.values(f"{self.len_map[i]}"), f"{self.len_map[i]}")
            bar_mix.add(
                f"{self.len_map[i]}",
                ids,
                list(map(lambda x:round(x, decimal_places), bar_data)),
                is_stack=True,
                is_datazoom_show=True
            )

        page = Page.from_charts(bar_mix)
        return page
Exemplo n.º 5
0
def archive_create_bar_mix(num):
    """
    Ready to delete
    """
    film_datas = FilmGap.objects.all().order_by('-id')[:num]

    ids = fetch(film_datas.values("id"), "id")
    ids.reverse()

    bar_mix = Bar("全部間距", page_title='ALL', width='100%')
    for i in range(0, 6):
        bar_data = fetch(film_datas.values(f"gap{i}"), f"gap{i}")
        bar_data.reverse()  # reverse data, change order
        bar_mix.add(f"gap{i}",
                    ids,
                    list(map(lambda x: round(x, decimal_places), bar_data)),
                    is_stack=True,
                    is_datazoom_show=True)
    return bar_mix
Exemplo n.º 6
0
def create_bar_mix(num):
    len_map = ['pink', 'orange', 'yellow', 'green', 'blue']
    decimal_places = 1
    film_datas = FilmLen.objects.all().order_by('-id')[:num]
    ids = fetch(film_datas.values("id"), "id")
    #ids = [ str(f.film) for f in film_datas]
    ids.reverse()
    bar_mix = Bar("膠條長度", page_title='(BarMix)', width='100%')
    for i in range(0, 5):
        bar_data = fetch(film_datas.values(f"{len_map[i]}"), f"{len_map[i]}")
        bar_data.reverse()
        bar_mix.add(
            f"{len_map[i]}",
            ids,
            list(map(lambda x:round(x, decimal_places), bar_data)),
            is_stack=True,
            is_datazoom_show=True
        )

    return bar_mix
Exemplo n.º 7
0
 def as_axis_values(self, *keys, **kwargs):
     return fetch(self, *keys, **kwargs)
Exemplo n.º 8
0
 def test_custom_getter(self):
     data_list = [MockItem(1, 2, 3), MockItem(4, 5, 6), MockItem(7, 8, 9)]
     xs, ys, zs = fetch(data_list, 'x', 'y', 'z', getter=lambda item, key: item.get(key))
     self.assertListEqual([1, 4, 7], xs)