flask+ highcharts实现报表转换成趋势图(2)

根据上一篇继续

http://blog.csdn.net/xx123er/article/details/77945591

3.flask脚本的编写


from flask import Flask, jsonify, render_template, request,redirect,url_for
# import forms
import json
import data_view

app = Flask(__name__)
# app.jinja_env.add_extension("chartkick.ext.charts")


@ app.route ( '/' , methods =[ 'GET' , 'POST' ])
@ app.route ( '/index' , methods =[ 'GET' , 'POST' ])
def index():
    if request.method == 'GET' :
        view=data_view.viewdata()
        view.getmethod()
        time1= "2017-9-5"
        time2= "2017-9-8"
    if request.method == 'POST' :
        time1 = request.form.get( 'start_time' , 180 )
        time2 = request.form.get( 'end_time' , 180 )
        col_name = request.form.get( 'col_name' )
        view = data_view.viewdata()
        view.postmethod(time1,time2,col_name)

    return render_template( 'highcharts_line_labels.html' , tit =view.title, xax =view.xAxis, yax =view.yAxis, seri =view.series, start_time =time1, end_time =time2)

if __name__ == "__main__" :
    app.run( debug = True , host = '0.0.0.0' , port = 5000 )


4..数据组装模块data_view.py


import database_csv
import sys

class viewdata():
    def __init__ ( self ):
        self .title={}
        self .title[ "style" ]={}
        self .title[ "style" ][ "color" ]= "#ff0000"
        self .xAxis={}
        self .yAxis={}
        self .yAxis[ "title" ] = {}
        self .series=[]

    def getmethod( self ):
        self .title[ "text" ]= 'rsp'
        self .xAxis[ "categories" ]=[ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ]
        self .yAxis[ "title" ][ "text" ]= 'num'
        y1 = {}
        y1[ "name" ] = 'Tokyo'
        y1[ "data" ] = [ 3.9 , 4.2 , 5.7 , 8.5 , 11.9 , 15.2 , 17.0 , 16.6 , 14.2 , 10.3 , 6.6 , 4.8 ]
        self .series.append(y1)

    def postmethod( self ,start,end, colnu ):
        print colnu
        file,columns,y_txt= self .co2columns( str ( colnu ))
        database = database_csv.csv_data(file)
        database.select_bytime( str (start), str (end))
        data = database.select_col(columns)
        # print data
        self .title[ "text" ] = str ( colnu )
        self .xAxis[ "categories" ] = [ str (i) for i in data[ "Time" ]]
        self .yAxis[ "title" ][ "text" ] = y_txt
        for e in columns:
            y2 = {}
            y2[ "name" ] = e.split( "_" )[- 1 ]
            y2[ "data" ] = [val for val in data[e]]
            self .series.append(y2)

    def co2columns( self ,co):
        if co== "toatal_cost" :
            file= "stress.csv"
            columns = [ "toa_min" , "toa_max" , "toa_aver" , "toa_80" , "toa_90" , "toa_95" ]
            ytxt= "~ second"

        return file,columns,ytxt

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值