pythonflask數(shù)據(jù)可視化怎么實現(xiàn)

這篇文章主要介紹了python flask數(shù)據(jù)可視化怎么實現(xiàn)的相關(guān)知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇python flask數(shù)據(jù)可視化怎么實現(xiàn)文章都會有所收獲,下面我們一起來看看吧。

創(chuàng)新互聯(lián)擁有十余年成都網(wǎng)站建設工作經(jīng)驗,為各大企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站制作服務,對于網(wǎng)頁設計、PC網(wǎng)站建設(電腦版網(wǎng)站建設)、成都APP應用開發(fā)、wap網(wǎng)站建設(手機版網(wǎng)站建設)、程序開發(fā)、網(wǎng)站優(yōu)化(SEO優(yōu)化)、微網(wǎng)站、申請域名等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設行業(yè)積累了很多網(wǎng)站制作、網(wǎng)站設計、網(wǎng)絡營銷經(jīng)驗,集策劃、開發(fā)、設計、營銷、管理等網(wǎng)站化運作于一體,具備承接各種規(guī)模類型的網(wǎng)站建設項目的能力。

flask server文件

# -*- coding: utf-8 -*-  
# 作者: lang1.xia  
# 創(chuàng)建時間: 2022-08-25 03:38:26  
# 修改時間: 2022-08-25 03:38:26  

from flask import Flask
from jinja2 import Environment, FileSystemLoader
from markupsafe import Markup
from pyecharts.globals import CurrentConfig
# echarts 外部樣式調(diào)用
CurrentConfig.GLOBAL_ENV = Environment(loader=FileSystemLoader("./templates"))
CurrentConfig.ONLINE_HOST = 'http://127.0.0.1/assets/'
from pyecharts.options import ComponentTitleOpts
from pyecharts.components  import Table
# 外部數(shù)據(jù)庫方法調(diào)用
from data_storage import one_data
# 自定義本地html模板
app = Flask(__name__, template_folder="templates")


def bar_base() -> Table:
    # 查詢數(shù)據(jù)庫信息形成大列表
    sql = "select * from ains_MySQL_base"
    res = one_data(sql)
    data_rows = [] 
    if res["code"] == 200 and res["data"]:
        for i in res["data"]:
            disk_io_info = ''.join(list(i[8]))
            disk_io_tmp = ""
            for key_d in eval(disk_io_info):
                key = list(key_d.keys())
                val = list(key_d.values())
                new_str =  key[0] + ": " + str(round(val[0],4)) + " \n"
                disk_io_tmp += new_str
            new_i = list(i[3:7]) + list(i[9:-1])
            new_i.append(disk_io_tmp)
            disk_info = ''.join(list(i[7]))
            disk_tmp = ""
            for key_d in eval(disk_info):
                key = list(key_d.keys())
                val = list(key_d.values())
                new_str =  key[0] + ": " + str(round(val[0],4)) + " \n"
                disk_tmp += new_str
            new_i.append(disk_tmp)
            data_rows.append(new_i)
    print(data_rows)
    # 定義表頭
    headers = [ "IP地址", "CPU使用率", "CPU五分鐘負載","內(nèi)存使用率", "innodb行鎖", "連接數(shù)","磁盤IO", "磁盤"]
    rows = data_rows
    # 添加標題、表數(shù)據(jù)、表樣式
    c = (
        Table()
        .add(headers, rows, attributes={"style": "margin:0% auto;font-size: 28px;text-align: left,width:100px", "class": "fl-table"})
        .set_global_opts(title_opts=ComponentTitleOpts(title="數(shù)據(jù)庫巡檢", title_style={"style": "font-size: 28px; font-weight:bold;text-align: center"}))
    )
    return c


@app.route("/")
def index():
    # 調(diào)用函數(shù)、返回到前端
    c = bar_base()
    return Markup(c.render_embed())


if __name__ == "__main__":
    app.run(host="0.0.0.0")

數(shù)據(jù)庫SQL執(zhí)行封裝文件

# -*- coding: utf-8 -*- 
# 作者: lang1.xia  
# 創(chuàng)建時間: 2022-08-22 07:06:53  
# 修改時間: 2022-08-22 07:06:53 

# 未使用
import pymysql

# 基礎連接信息
def conndb():
    conn = pymysql.connect(host="IP地址", user="賬號", passwd="密碼", database="數(shù)據(jù)庫名", port="數(shù)據(jù)庫端口")
    cur = conn.cursor()
    return conn, cur

# 關(guān)閉連接
def closedb(conn, cur):
    cur.close()
    conn.close()

# executemany方法封裝
def batch_data(sql):
    conn, cur = conndb()
    try:
        cur.executemany(sql)
        result = cur.fetchall()
    except Exception as e :
        return {"code": 400, "message": e}
    else:
        conn.commit()
    closedb(conn=conn, cur=cur)
    return {"code": 200, "message": "true", "data": result}

# execute方法封裝
def one_data(sql):
    conn, cur = conndb()
    try:
        cur.execute(sql)
        result = cur.fetchall()
    except Exception as e :
        return {"code": 400, "message": e}
    else:
        conn.commit()
    closedb(conn=conn, cur=cur)
    return {"code": 200, "message": "true", "data": result}

運行flask服務

python server.py

前端訪問

瀏覽器訪問http://127.0.0.1:5000

python flask數(shù)據(jù)可視化怎么實現(xiàn)

關(guān)于“python flask數(shù)據(jù)可視化怎么實現(xiàn)”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“python flask數(shù)據(jù)可視化怎么實現(xiàn)”知識都有一定的了解,大家如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

新聞標題:pythonflask數(shù)據(jù)可視化怎么實現(xiàn)
網(wǎng)站路徑:http://muchs.cn/article26/ihjdjg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、品牌網(wǎng)站設計、定制網(wǎng)站網(wǎng)站制作、用戶體驗品牌網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設計公司