Untitled
unknown
plain_text
a year ago
3.8 kB
10
Indexable
def after_task(memory_bus): option = '''{ "title": { "text": "Distribution of Electricity", "subtext": "Fake Data" }, "tooltip": { "trigger": "axis", "axisPointer": { "type": "cross" } }, "toolbox": { "show": true, "feature": { "saveAsImage": {} } }, "xAxis": { "type": "category", "boundaryGap": false, "data": %s }, "yAxis": { "type": "value", "axisLabel": { "formatter": "{value} MB/s" }, "axisPointer": { "snap": true } }, "visualMap": { "show": false, "dimension": 0, "pieces": [ { "lte": 6, "color": "green" }, { "gt": 6, "lte": 8, "color": "red" }, { "gt": 8, "lte": 14, "color": "green" }, { "gt": 14, "lte": 17, "color": "red" }, { "gt": 17, "color": "green" } ] }, "series": [ { "name": "Network Traffic", "type": "line", "smooth": true, "data": %s, "markArea": { "itemStyle": { "color": "rgba(255, 173, 177, 0.4)" }, "data": [ [ { "name": "Evening Peak", "xAxis": "%s" }, { "xAxis": "%s" } ] ] } } ] }''' from datetime import datetime import json source_data = memory_bus.get('task2') predict_data = memory_bus.get('task3') timeList = [] dataList = [] lastTimestamp = 0 predict_start_time = 0 predict_end_time = 0 for value in source_data['data']['result'][0]['values']: timestamp = int(value[0]) timeStr = datetime.fromtimestamp(timestamp).strftime('%H:%M') timeList.append(timeStr) data = value[1] if isinstance(data, str): data = float(data.strip('"')) dataList.append(data) lastTimestamp = timestamp predict_start_time = lastTimestamp + 300 predict_start_time_str = datetime.fromtimestamp(predict_start_time).strftime('%H:%M') for value in predict_data['result']: lastTimestamp += 300 timestamp = lastTimestamp timeStr = datetime.fromtimestamp(timestamp).strftime('%H:%M') timeList.append(timeStr) data = value[1] if isinstance(data, str): data = float(data.strip('"')) dataList.append(data) predict_end_time = lastTimestamp predict_end_time_str = datetime.fromtimestamp(predict_end_time).strftime('%H:%M') option = option % (json.dumps(timeList), dataList, predict_start_time_str, predict_end_time_str) option = json.loads(option) result = { "type": "echart", "option": option } return result
Editor is loading...
Leave a Comment