首页 > 其他分享 >基于Flask框架的大数据看板前端学习

基于Flask框架的大数据看板前端学习

时间:2022-12-12 03:44:05浏览次数:67  
标签:name 框架 get Flask 前端 title value data self

[^目录]:回到目录

目录[^目录]

目录

后端代码

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2020/8/26 14:48
# @Author : way
# @Site :
# @Describe:

from flask import Flask, render_template
from data import SourceData
from data_corp import CorpData
from data_job import JobData

app = Flask(__name__)


@app.route('/')
def index():
    data = SourceData() #数据源
    return render_template('index.html', form=data, title=data.title)


@app.route('/corp')
def corp():
    data = CorpData()
    return render_template('index.html', form=data, title=data.title)


@app.route('/job')
def job():
    data = JobData()
    return render_template('index.html', form=data, title=data.title)


if __name__ == "__main__":
    app.run(host='127.0.0.1', debug=False)

SourceData()

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2020/8/26 14:48
# @Author : way
# @Site : 
# @Describe:
from pandas import *


class SourceDataDemo:

    def __init__(self):
        self.title = '大数据可视化展板通用模板'
        self.counter = {'name': '2018年总收入情况', 'value': 12581189}
        self.counter2 = {'name': '2018年总支出情况', 'value': 3912410}
        self.echart1_data = {
            'title': '行业分布',
            'data': [
                {"name": "商超门店", "value": 47},
                {"name": "教育培训", "value": 52},
                {"name": "房地产", "value": 90},
                {"name": "生活服务", "value": 84},
                {"name": "汽车销售", "value": 99},
                {"name": "旅游酒店", "value": 37},
                {"name": "五金建材", "value": 2},
            ]
        }
        self.echart2_data = {
            'title': '省份分布',
            'data': [
                {"name": "浙江", "value": 47},
                {"name": "上海", "value": 52},
                {"name": "江苏", "value": 90},
                {"name": "广东", "value": 84},
                {"name": "北京", "value": 99},
                {"name": "深圳", "value": 37},
                {"name": "安徽", "value": 150},
            ]
        }
        self.echarts3_1_data = {
            'title': '年龄分布',
            'data': [
                {"name": "0岁以下", "value": 47},
                {"name": "20-29岁", "value": 52},
                {"name": "30-39岁", "value": 90},
                {"name": "40-49岁", "value": 84},
                {"name": "50岁以上", "value": 99},
            ]
        }
        self.echarts3_2_data = {
            'title': '职业分布',
            'data': [
                {"name": "电子商务", "value": 10},
                {"name": "教育", "value": 20},
                {"name": "IT/互联网", "value": 20},
                {"name": "金融", "value": 30},
                {"name": "学生", "value": 40},
                {"name": "其他", "value": 50},
            ]
        }
        self.echarts3_3_data = {
            'title': '兴趣分布',
            'data': [
                {"name": "汽车", "value": 4},
                {"name": "旅游", "value": 5},
                {"name": "财经", "value": 9},
                {"name": "教育", "value": 8},
                {"name": "软件", "value": 9},
                {"name": "其他", "value": 9},
            ]
        }
        self.echart4_data = {
            'title': '时间趋势',
            'data': [
                {"name": "安卓", "value": [3, 4, 3, 4, 3, 4, 3, 6, 2, 4, 2, 4, 3, 4, 3, 4, 3, 4, 3, 6, 2, 4, 4]},
                {"name": "IOS", "value": [5, 3, 5, 6, 1, 5, 3, 5, 6, 4, 6, 4, 8, 3, 5, 6, 1, 5, 3, 7, 2, 5, 8]},
            ],
            'xAxis': ['01', '02', '03', '04', '05', '06', '07', '08', '09', '11', '12', '13', '14', '15', '16', '17',
                      '18', '19', '20', '21', '22', '23', '24'],
        }
        self.echart5_data = {
            'title': '省份TOP',
            'data': [
                {"name": "浙江", "value": 2},
                {"name": "上海", "value": 3},
                {"name": "江苏", "value": 3},
                {"name": "广东", "value": 9},
                {"name": "北京", "value": 15},
                {"name": "深圳", "value": 18},
                {"name": "安徽", "value": 20},
                {"name": "四川", "value": 13},
            ]
        }
        self.echart6_data = {
            'title': '一线城市情况',
            'data': [
                {"name": "浙江", "value": 80, "value2": 20, "color": "01", "radius": ['59%', '70%']},
                {"name": "上海", "value": 70, "value2": 30, "color": "02", "radius": ['49%', '60%']},
                {"name": "广东", "value": 65, "value2": 35, "color": "03", "radius": ['39%', '50%']},
                {"name": "北京", "value": 60, "value2": 40, "color": "04", "radius": ['29%', '40%']},
                {"name": "深圳", "value": 50, "value2": 50, "color": "05", "radius": ['20%', '30%']},
            ]
        }
        self.map_1_data = {
            'symbolSize': 100,
            'data': [
                {'name': '海门', 'value': 239},
                {'name': '鄂尔多斯', 'value': 231},
                {'name': '招远', 'value': 203},
            ]
        }

    @property
    def echart1(self):
        data = self.echart1_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'series': [i.get("value") for i in data.get('data')]
        }
        return echart

    @property
    def echart2(self):
        data = self.echart2_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'series': [i.get("value") for i in data.get('data')]
        }
        return echart

    @property
    def echarts3_1(self):
        data = self.echarts3_1_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'data': data.get('data'),
        }
        return echart

    @property
    def echarts3_2(self):
        data = self.echarts3_2_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'data': data.get('data'),
        }
        return echart

    @property
    def echarts3_3(self):
        data = self.echarts3_3_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'data': data.get('data'),
        }
        return echart

    @property
    def echart4(self):
        data = self.echart4_data
        echart = {
            'title': data.get('title'),
            'names': [i.get("name") for i in data.get('data')],
            'xAxis': data.get('xAxis'),
            'data': data.get('data'),
        }
        return echart

    @property
    def echart5(self):
        data = self.echart5_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'series': [i.get("value") for i in data.get('data')],
            'data': data.get('data'),
        }
        return echart

    @property
    def echart6(self):
        data = self.echart6_data
        echart = {
            'title': data.get('title'),
            'xAxis': [i.get("name") for i in data.get('data')],
            'data': data.get('data'),
        }
        return echart

    @property
    def map_1(self):
        data = self.map_1_data
        echart = {
            'symbolSize': data.get('symbolSize'),
            'data': data.get('data'),
        }
        return echart


class SourceData(SourceDataDemo):

    def __init__(self):
        """
        按照 SourceDataDemo 的格式覆盖数据即可
        """
        super().__init__()
        self.title = '大数据可视化展板通用模板'


Python使用pymysql返回字典类型的数据

参考文档链接
https://blog.csdn.net/qq_26003101/article/details/113732615

在默认情况下cursor方法返回的是BaseCursor类型对象,BaseCursor类型对象在执行查询后每条记录的结果以列表(list)表示。如果要返回字典(dict)表示的记录,就要设置cursorclass参数为MySQLdb.cursors.DictCursor类

import pymysql
import time

# 数据库
db = ""
cur = ""
# 现在年月日
today = time.strftime("%Y-%m-%d", time.localtime())
try:
  # 数据库配置
  config = {
    "host": "124.71.18.23", 
    "port": 3306, 
    "user": "root", 
    "password": "Master@test", 
    "db": 'scrapy', 
    "charset": "utf8mb4",
    "cursorclass": pymysql.cursors.DictCursor
  }
  db = pymysql.connect(**config)
  # 游标
  cur = db.cursor()
except:
  print("连接数据库失败")
  exit(-1)


# 查询今天之后的所有天气数据
def get_day_list(date):
  sql_weather_days = "SELECT*FROM weather WHERE date>='" + date + "'"
  cur.execute(sql_weather_days)
  dayList = cur.fetchall()
  print(dayList)
  pass


get_day_list(today)

标签:name,框架,get,Flask,前端,title,value,data,self
From: https://www.cnblogs.com/stayhangrystayfoolish/p/16972660.html

相关文章

  • Collection接口框架(List接口)
    Collection接口(List接口)/*1.List接口框架  |----Collection接口:单列集合,用来存储一个一个的对象      |----List接口:存储有序的、可重复的数据。--->“......
  • Collection接口框架(Set接口)
    Collection接口框架(Set接口)/*  |----Collection接口:单列集合,用来存储一个一个的对象        |----Set接口:存储无序的、不可重复的数据--->高中讲......
  • 基于I.MX6UL平台的ADS1256驱动开发三.基础驱动框架
    我们通过前两章的内容完成了驱动移植和重构的准备工作,下面我们就开始处理驱动代码了。驱动的基础架构我们采用和前面学习的platform框架一样,并且通过GPIO子系统对GPIO实现......
  • paozhu c++ web framework 框架原理
    paozhuc++webframework框架原理paozhuc++webframework使用asio网络库,如果用动态库方式还要boost库。paozhu框架使用两个线程池,一个是框架使用的解析协议,连接......
  • 前端代码自动化
    旧文章从语雀迁移过来,原日期为2022-11-24前言一个项目从0到1,再到迭代开发过程,必然会很多不同的人在项目上编写代码,而每个人输出代码的风格是不一样的。为了统一基本的......
  • flask(二)
    今日内容概要flask展示用户信息案例配置文件写法路由系统路由本质cbv写法模板语法今日内容详细flask展示用户信息案例需求:登录:返回给前端co......
  • Flask框架
    Flask框架介绍flask是基于python开发并且依赖于jinjia2模板和werkzeugwsgi服务的一个微型框架werkzeug本质是socket服务端,用于接收http请求并对其进行预处理,然后触发......
  • HarmonyOS如何实现前端跳转
    由于只想展示一下页面跳转该怎么写,所以写出来的代码中的div在页面上,因为没有可以点击的地方,所以无法通过复制代码来得到一个实现跳转的实物。hml相关代码<divon:click......
  • php里ezpdo orm框架初探
      java里有hibernate,php里有啥,这一直困绕着大家.最近发现了一个还可以的php的orm框架ezpdo,网站是​​​http://www.ezpdo.net​​​,有手册......
  • Play框架快速入门
    前,RubyonRails及Grails等动态脚本语言正发展得如火如荼,而在以Java为首的开源最大阵营中,也出现了各种框架。其中最著名的就是Play框架(http://download.playframework.org......