Офигеть, работает ;)
This commit is contained in:
parent
f7c9a0b58b
commit
046f7619ba
46
LabWork01/LabWork3/CreateGraphics.py
Normal file
46
LabWork01/LabWork3/CreateGraphics.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import os
|
||||||
|
import glob
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib
|
||||||
|
matplotlib.use('Agg')
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
def createGraphics(df: pd.DataFrame):
|
||||||
|
# для сохранения диаграммы в конкретной папке
|
||||||
|
script_dir = os.path.dirname(__file__)
|
||||||
|
results_dir = os.path.join(script_dir, '../static/')
|
||||||
|
|
||||||
|
if not os.path.isdir(results_dir):
|
||||||
|
os.makedirs(results_dir)
|
||||||
|
|
||||||
|
# ax = plt.gca()
|
||||||
|
#
|
||||||
|
# df.plot(kind='line', x='Store_Area', y='Items_Available', color='red', ax=ax)
|
||||||
|
# df.plot(kind='line', x='Store_Area', y='Daily_Customer_Count', color='yellow', ax=ax)
|
||||||
|
|
||||||
|
df.plot(x="Items_Available", y="Store_Area", kind="bar")
|
||||||
|
|
||||||
|
plt.savefig(results_dir + 'file' + str(1) + '.jpg')
|
||||||
|
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
df.boxplot(column=['Store_Area', 'Items_Available', 'Daily_Customer_Count'])
|
||||||
|
|
||||||
|
plt.savefig(results_dir + 'file' + str(2) + '.jpg')
|
||||||
|
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
df.boxplot(column=['Store_Sales'])
|
||||||
|
|
||||||
|
plt.savefig(results_dir + 'file' + str(3) + '.jpg')
|
||||||
|
|
||||||
|
plt.close()
|
||||||
|
|
||||||
|
# # сразу загружаем все созданные png файлы
|
||||||
|
# results_dir = os.path.join(script_dir, 'static/*')
|
||||||
|
#
|
||||||
|
# files = glob.glob(results_dir)
|
||||||
|
#
|
||||||
|
# return files
|
||||||
|
|
||||||
|
return True
|
13
LabWork01/LabWork3/DeletePng.py
Normal file
13
LabWork01/LabWork3/DeletePng.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import os
|
||||||
|
import glob
|
||||||
|
|
||||||
|
# функция для уудаления всех предыдущих png с графиками
|
||||||
|
def deleteAllPng():
|
||||||
|
script_dir = os.path.dirname(__file__)
|
||||||
|
results_dir = os.path.join(script_dir, 'images/*')
|
||||||
|
|
||||||
|
files = glob.glob(results_dir)
|
||||||
|
for f in files:
|
||||||
|
os.remove(f)
|
||||||
|
|
||||||
|
return True
|
@ -6,6 +6,9 @@ from LabWork01.AnalysSalesCustomers import analysSalesCustomersDataFrame
|
|||||||
from LabWork01.DataFrameAnalys import analysItemsDataFrame
|
from LabWork01.DataFrameAnalys import analysItemsDataFrame
|
||||||
from LabWork01.FuncLoad import createDataFrame
|
from LabWork01.FuncLoad import createDataFrame
|
||||||
from LabWork01.LabWork3.AddData import addData
|
from LabWork01.LabWork3.AddData import addData
|
||||||
|
from LabWork01.LabWork3.CreateGraphics import createGraphics
|
||||||
|
from LabWork01.LabWork3.DeletePng import deleteAllPng
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -20,11 +23,17 @@ countNull = listShops.isnull().sum()
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
listShops = addData(createDataFrame())
|
additionListShops = addData(createDataFrame())
|
||||||
|
|
||||||
print(listShops)
|
# удаляем текущие диаграммы
|
||||||
|
deleteAllPng()
|
||||||
|
|
||||||
return render_template('main_page.html', context=[], tableAnalys=[], titles=[''], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
|
# создаём новые диаграммы
|
||||||
|
createGraphics(additionListShops)
|
||||||
|
|
||||||
|
image_names = ['file1.jpg', 'file2.jpg', 'file3.jpg']
|
||||||
|
|
||||||
|
return render_template('main_page.html', context=[], image_names=image_names, tableAnalys=[], titles=[''], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
|
||||||
|
|
||||||
@app.route("/showDiapason", methods=['GET','POST'])
|
@app.route("/showDiapason", methods=['GET','POST'])
|
||||||
def numtext():
|
def numtext():
|
||||||
@ -62,7 +71,7 @@ def numtext():
|
|||||||
totalList.append(listStoreSales)
|
totalList.append(listStoreSales)
|
||||||
|
|
||||||
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
|
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
|
||||||
return render_template('main_page.html', context=totalList, listTypes=listTypes, countNull=countNull,
|
return render_template('main_page.html', context=totalList, image_names=[], listTypes=listTypes, countNull=countNull,
|
||||||
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
|
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
|
||||||
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
|
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
|
||||||
|
|
||||||
@ -81,7 +90,8 @@ def analysis():
|
|||||||
|
|
||||||
print(firstAnalys)
|
print(firstAnalys)
|
||||||
|
|
||||||
return render_template('main_page.html', context=[], tableAnalysOne=[firstAnalys.to_html()],
|
return render_template('main_page.html', context=[], image_names=[],
|
||||||
|
tableAnalysOne=[firstAnalys.to_html()],
|
||||||
tableAnalysTwo=[secondAnalys.to_html()],
|
tableAnalysTwo=[secondAnalys.to_html()],
|
||||||
tableAnalysThree=[thirdAnalys.to_html()],
|
tableAnalysThree=[thirdAnalys.to_html()],
|
||||||
tableAnalysFour=[fourthAnalys.to_html()],
|
tableAnalysFour=[fourthAnalys.to_html()],
|
||||||
|
@ -52,6 +52,11 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
{% for image_name in image_names %}
|
||||||
|
<img src="{{ url_for('static', filename=image_name) }}" alt="{{ image_name }}">
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h3>
|
<h3>
|
||||||
Результаты первого анализа
|
Результаты первого анализа
|
||||||
|
Loading…
x
Reference in New Issue
Block a user