def timeline(): val = request.args.get('select') isMap = request.args.get('isMap') fileName = val if isMap != 'true': fileName += fileSuffix print(fileName) with open(dataDir + "/" + fileName) as f: f_csv = csv.reader(f) head = [] city = {} cityX = [] i = 0 rows = [] for row in f_csv: if i == 0: head = row[1:len(row)] print(head) else: rows.append(row) cityX.append(row[0]) i = +1 k = 1 city = {} for year in head: city[year] = [row[k] for row in rows] k = k + 1 x = cityX tl = Timeline() for year in head: if isMap == 'true': cityMap = [] i = 0 maxInt = 0 t = Timeline() for c in x: if city[year][i] and city[year][i] != '': if maxInt == 0: maxInt = int(city[year][i]) else: ci = int(city[year][i]) if ci > maxInt: maxInt = ci cityMap.append([c, city[year][i]]) i = i + 1 map0 = (Map().add(mapTips, cityMap, "china").set_global_opts( title_opts=opts.TitleOpts(title=val), visualmap_opts=opts.VisualMapOpts(max_=maxInt), )) tl.add(map0, year) else: bar = (Bar().add_xaxis(x).add_yaxis( val, city[year]).set_global_opts(title_opts=opts.TitleOpts(val))) tl.add(bar, year) # return Markup(tl.render_embed()) return tl.dump_options_with_quotes()
def member_month_workhour(): p = PJinfo() m = p.member_workhour_get() tl = Timeline() li_month = sorted(m.keys(), reverse=True) for i in li_month: month = m[i].sort_values(0, axis=1, ascending=False) fig = Bar() fig.add_xaxis(month.columns.tolist()) fig.add_yaxis('投入工时', month.values.flatten().tolist()) fig.set_global_opts( title_opts=opts.TitleOpts(title=f"2020年{i}月人员工时投入"), yaxis_opts=opts.AxisOpts(name='工时'), ) tl.add(fig, time_point=f'{i}月') return tl.dump_options_with_quotes()
def ChinaMaptime(): data = pd.read_excel(savePath + '中国各省市(区)合成表.xlsx', index_col=False) data['date'] = str('2020/') + data['date'] data['date'] = pd.to_datetime(data['date']) data['date'] = pd.PeriodIndex(data['date'], freq='D') # 转换为时间 class_list = list(data['date'].drop_duplicates()) class_list = sorted(class_list) t1 = Timeline() for i in class_list: data1 = pd.read_excel(savePath + '中国时间轴/%s.xlsx' % (i), index=False) data_name = data1['country'] data_confirm = data1['confirm'] chinaMap = ( Map() .add("累计确诊", [list(z) for z in zip(data_name, data_confirm)], maptype="china") .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="{}中国累计确诊数据".format(i)), visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=[{"max": 0, "label": '0人', "color": "#FFFAFA"}, {"min": 1, "max": 9, "label": '1-9人', "color": "#F08080"}, {"min": 10, "max": 99, "label": '10-99人', "color": "#BC8F8F"}, {"min": 100, "max": 499, "label": '100-499人', "color": "#A52A2A"}, {"min": 500, "max": 999, "label": '500-999人', "color": "#B22222"}, {"min": 1000, "max": 9999, "label": '1000-9999人', "color": "#8B0000"}, {"min": 10000, "label": '10000人及以上', "color": "#800000"}]), ) ) t1.add(chinaMap, "".format(i)) path = savePath + '时间轴图像/' isExists = os.path.exists(path) # 判断当前目录是否有时间轴图像文件夹,如果没有则创建 if not isExists: os.mkdir(path) # 在当前路径创建新文件夹analisis,用于存放生成的图像数据 # t1.render(path+'中国总体疫情变化.html') if flag: dwf.write_to_file(path + '中国总体疫情变化.txt', str(t1.dump_options_with_quotes()))