Training Code python

######get_hist_to_csv.py

import pandas as pd
import tushare as ts
import os

'' '
Acquired history data and stored moutai
Data = ts.get_hist_data (' 600,519 ', Start =' 2017-10-01 ')
data.to_csv (' maotai.csv ')
' '

def gethist_tocsv(code, starttime, filename):
data = ts.get_hist_data(code, starttime, filename)
data.to_csv(filename)
if os.path.exists(filename):
print ("successfully save data!")
else:
print ("filed to save the data!")

if __name__ == '__main__':
#gethist_tocsv('600519', '2019-10-01', "maotai.csv")
data = ts.get_hist_data('600519', start='2019-10-01')
data.to_csv('maotai.csv')

 

 

 

 

##############stack.py###################

# coding:utf-8
import warnings
warnings.filterwarnings('ignore')
from pyecharts import options as opts
from pyecharts.charts import Line
import pandas as pd

get_hist DEF ():
"" "
Moutai: 2019-10-01 far
" ""
Data = pd.read_csv ( './ maotai.csv', index_col = 0, parse_dates = [0]) sort_index ().
DF = data [[ 'open']]

x_value = df.index.tolist()
y_value = df['open'].tolist()
return line_ticks(x_value, y_value)

def line_ticks(x_value:list, y_value:list):
line = (
Line()
.add_xaxis(x_value)
.add_yaxis(
series_name="",
y_axis=y_value,
is_smooth=True,
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="动态数据"),
# datazoom_opts=opts.DataZoomOpts(),
xaxis_opts=opts.AxisOpts(type_="time", max_interval=3600 * 24 * 1000), # 时间类型
yaxis_opts=opts.AxisOpts(type_="value"), # 数值类型
)
)
return line

 

 

##### flask_app.py######

from random import randrange

from flask.json import jsonify
from flask import Flask, render_template
import stack
from pyecharts.charts import Bar

app = Flask(__name__, static_folder="templates")

@app.route("/")
def get_line_chart():
# c = line_base()
c = stack.get_hist()
#c = stock.get_realtime()
#return render_template("show.html", bar_data=c.dump_options_with_quotes())
return render_template("show_chart.html", bar_data=c.dump_options())


if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port=60111)

 

<!--        show_chart.html             -->

<! DOCTYPE HTML>
<HTML lang = "EN">
<head>
<Meta charset = "UTF-8">
<title> the Title </ title>
<Script of the type = "text / JavaScript" src = "HTTPS: // assets.pyecharts.org/assets/echarts.min.js "> </ Script>
</ head>
<body>
<h1 of> analysis FIG. </ h1 of>
<div>
<-! to prepare ECharts includes a size (width high) the Dom ->
<div the above mentioned id = "main" style = "width: 600px; height: 400px;"> </ div>
<Script of the type = "text / JavaScript">
// based ready dom, initialization examples echarts
var myChart = echarts.init (document.getElementById ( 'main'));
// just use the specified configuration data items and display the chart.
myChart.setOption ({{bar_data | safe} });





Guess you like

Origin www.cnblogs.com/zmichael/p/11799254.html