Example #1
0
    def get_line_opts(results, title):
        import datetime
        time = []
        minimum = []
        maximum = []
        if not results:
            return {}
        for result in json.loads(results):
            d = datetime.datetime.fromtimestamp(result['timestamp'] / 1000)
            str1 = d.strftime("%Y/%m/%d %H:%M:%S")  # "%Y/%m/%d %H:%M:%S"
            time.append(str1)
            minimum.append(round(result['Minimum'],2))
            maximum.append(round(result['Maximum'],2))

            # average.append(result['Average'])
        from pyecharts import Line
        from pyecharts.base import TRANSLATOR
        line = Line(title)
        line.add("最小值", time, minimum, mark_point=['max'], mark_line=["average",], is_smooth=True, is_liquid_animation=True)
        # line.add("平均值", time, average, mark_point=["average", "min"])
        line.add("最大值", time, maximum, mark_point=['max'], mark_line=["average",], is_smooth=True, is_liquid_animation=True)
        snippet = TRANSLATOR.translate(line.options)
        response = json.loads(snippet.as_snippet())
        # :TODO pyecharts参数修改
        #pyecharts没有具体的参数可以指定scale暂时这么处理
        response['yAxis'][0]['scale'] = True
        response['tooltip']['trigger'] = 'axis'
        return response
Example #2
0
File: cms.py Project: worksk/DevOps
 def get_line_opts(results, title):
     import datetime
     time = []
     minimum = []
     maximum = []
     for result in json.loads(results):
         d = datetime.datetime.fromtimestamp(result['timestamp']/1000)
         str1 = d.strftime("%Y-%m-%d %H:%M")
         time.append(str1)
         minimum.append(result['Minimum'])
         maximum.append(result['Maximum'])
         # average.append(result['Average'])
     from pyecharts import Line
     from pyecharts.base import TRANSLATOR
     line = Line(title)
     line.add("最小值", time, minimum, mark_point=['max'], mark_line=["average",], )
     # line.add("平均值", time, average, mark_point=["average", "min"])
     line.add("最大值", time, maximum, mark_point=['max'], mark_line=["average",], )
     snippet = TRANSLATOR.translate(line.options)
     return json.loads(snippet.as_snippet())
Example #3
0
 def get(self, request, *args, **kwargs):
     connect = redis.StrictRedis(host=settings.REDIS_HOST,
                                 port=settings.REDIS_PORT,
                                 db=settings.REDIS_SPACE,
                                 password=settings.REDIS_PASSWD)
     SYSTEMTYPE_STATUS = str(connect.get('SYSTEMTYPE_STATUS'),
                             encoding='utf-8').replace('\'', '"')
     try:
         SYSTEMTYPE_STATUS = json.loads(SYSTEMTYPE_STATUS)
     except TypeError as e:
         SYSTEMTYPE_STATUS = {"name": [], "value": []}
     from pyecharts import Pie
     from pyecharts.base import TRANSLATOR
     p = Pie('操作系统类型', title_pos='center')
     p.add(
         "操作系统",
         SYSTEMTYPE_STATUS.get('name'),
         SYSTEMTYPE_STATUS.get('value'),
         radius=[20, 65],
         legend_orient='vertical',
     )  #is_legend_show=False,)
     snippet = TRANSLATOR.translate(p.options)
     return Response(json.loads((snippet.as_snippet())), status.HTTP_200_OK)