2023-10-12 17:46:05 +04:00
|
|
|
|
import os
|
|
|
|
|
|
2023-09-14 17:46:46 +04:00
|
|
|
|
from flask import Flask, redirect, url_for, request, render_template
|
2023-10-12 17:46:05 +04:00
|
|
|
|
from matplotlib import pyplot as plt
|
2023-09-28 20:48:51 +04:00
|
|
|
|
|
|
|
|
|
from LabWork01.AnalysCustomers import analysCustomersDataFrame
|
|
|
|
|
from LabWork01.AnalysSales import analysSalesDataFrame
|
|
|
|
|
from LabWork01.AnalysSalesCustomers import analysSalesCustomersDataFrame
|
|
|
|
|
from LabWork01.DataFrameAnalys import analysItemsDataFrame
|
2023-09-23 14:27:08 +04:00
|
|
|
|
from LabWork01.FuncLoad import createDataFrame
|
2023-10-11 21:14:43 +04:00
|
|
|
|
from LabWork01.LabWork3.AddData import addData
|
2023-10-12 12:26:41 +04:00
|
|
|
|
from LabWork01.LabWork3.CreateGraphics import createGraphics
|
2023-10-12 17:46:05 +04:00
|
|
|
|
from LabWork01.LabWork3.CustomGraphics import createCusGraphics
|
2023-10-12 12:26:41 +04:00
|
|
|
|
from LabWork01.LabWork3.DeletePng import deleteAllPng
|
|
|
|
|
|
2023-09-14 17:46:46 +04:00
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
2023-09-23 14:27:08 +04:00
|
|
|
|
#сразу загружаем весь док, чтобы потом просто прыгать по нему
|
|
|
|
|
listShops = createDataFrame()
|
|
|
|
|
|
|
|
|
|
#список типов данных по столбцам
|
|
|
|
|
listTypes = listShops.dtypes.to_list()
|
|
|
|
|
|
|
|
|
|
#формируем записи о кол-ве пустых ячеек в каждом столбце
|
|
|
|
|
countNull = listShops.isnull().sum()
|
|
|
|
|
|
2023-09-14 17:46:46 +04:00
|
|
|
|
@app.route("/")
|
|
|
|
|
def home():
|
2023-10-12 17:46:05 +04:00
|
|
|
|
return render_template('main_page.html', context=[], main_img=[], image_names=[], tableAnalys=[], titles=[''], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
|
2023-09-14 17:46:46 +04:00
|
|
|
|
|
|
|
|
|
@app.route("/showDiapason", methods=['GET','POST'])
|
|
|
|
|
def numtext():
|
|
|
|
|
data = request.args
|
|
|
|
|
|
2023-09-23 14:27:08 +04:00
|
|
|
|
#получаем срез и таблицы по введёным параметрам
|
|
|
|
|
newListShops = listShops.iloc[int(data['firstRow'])-1:int(data['secondRow']), int(data['firstColumn']):int(data['secondColumn'])+1]
|
|
|
|
|
|
|
|
|
|
_range = range(int(data['firstColumn']), int(data['secondColumn'])+1)
|
|
|
|
|
|
|
|
|
|
#список списков для шаблона
|
|
|
|
|
totalList = []
|
|
|
|
|
|
|
|
|
|
print(countNull[1])
|
|
|
|
|
|
|
|
|
|
#формирование 4-х списков для шаблонизатора
|
|
|
|
|
if 1 in _range:
|
|
|
|
|
listStoreArea = newListShops['Store_Area'].to_list()
|
|
|
|
|
|
|
|
|
|
totalList.append(listStoreArea)
|
|
|
|
|
|
|
|
|
|
if 2 in _range:
|
|
|
|
|
listItemsAvailable = newListShops['Items_Available'].to_list()
|
|
|
|
|
|
|
|
|
|
totalList.append(listItemsAvailable)
|
|
|
|
|
|
|
|
|
|
if 3 in _range:
|
|
|
|
|
listDailyCustomerCount = newListShops['Daily_Customer_Count'].to_list()
|
|
|
|
|
|
|
|
|
|
totalList.append(listDailyCustomerCount)
|
|
|
|
|
|
|
|
|
|
if 4 in _range:
|
|
|
|
|
listStoreSales = newListShops['Store_Sales'].to_list()
|
|
|
|
|
|
|
|
|
|
totalList.append(listStoreSales)
|
2023-09-14 17:46:46 +04:00
|
|
|
|
|
|
|
|
|
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
|
2023-10-12 17:46:05 +04:00
|
|
|
|
return render_template('main_page.html', context=totalList, main_img=[], image_names=[], listTypes=listTypes, countNull=countNull,
|
2023-09-23 14:27:08 +04:00
|
|
|
|
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
|
|
|
|
|
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
|
|
|
|
|
|
2023-09-28 15:14:37 +04:00
|
|
|
|
return home()
|
|
|
|
|
|
|
|
|
|
#функция для проведения анализа данных
|
|
|
|
|
@app.route("/analysis", methods=['GET', 'POST'])
|
|
|
|
|
def analysis():
|
2023-09-28 20:48:51 +04:00
|
|
|
|
firstAnalys = analysItemsDataFrame(listShops)
|
|
|
|
|
secondAnalys = analysCustomersDataFrame(listShops)
|
|
|
|
|
thirdAnalys = analysSalesDataFrame(listShops)
|
|
|
|
|
fourthAnalys = analysSalesCustomersDataFrame(listShops)
|
2023-09-28 15:14:37 +04:00
|
|
|
|
|
2023-10-12 17:46:05 +04:00
|
|
|
|
# удаляем все текущие диаграммы
|
|
|
|
|
deleteAllPng()
|
|
|
|
|
|
|
|
|
|
# начинаем создавать диаграммы
|
|
|
|
|
createGraphics(firstAnalys, 'firstAn')
|
|
|
|
|
createGraphics(secondAnalys, 'secondAn')
|
|
|
|
|
createGraphics(thirdAnalys, 'thirdAn')
|
|
|
|
|
createGraphics(fourthAnalys, 'fourthAn')
|
|
|
|
|
|
|
|
|
|
# дополняем новыми значениями
|
|
|
|
|
additionListShops = addData(createDataFrame())
|
|
|
|
|
|
|
|
|
|
# получаем новые данные
|
|
|
|
|
newfirstAnalys = analysItemsDataFrame(additionListShops)
|
|
|
|
|
secondAnalys = analysCustomersDataFrame(additionListShops)
|
|
|
|
|
thirdAnalys = analysSalesDataFrame(additionListShops)
|
|
|
|
|
fourthAnalys = analysSalesCustomersDataFrame(additionListShops)
|
|
|
|
|
|
|
|
|
|
# создаём новые диаграммы
|
|
|
|
|
createGraphics(newfirstAnalys, 'addFirstAn')
|
|
|
|
|
createGraphics(secondAnalys, 'addSecondAn')
|
|
|
|
|
createGraphics(thirdAnalys, 'addThirdAn')
|
|
|
|
|
createGraphics(fourthAnalys, 'addFourthAn')
|
|
|
|
|
|
|
|
|
|
createCusGraphics(firstAnalys[0], newfirstAnalys[0])
|
|
|
|
|
|
|
|
|
|
image_names_start = ['firstAn0.jpg', 'firstAn1.jpg', 'firstAn2.jpg',
|
|
|
|
|
'secondAn0.jpg', 'secondAn1.jpg', 'secondAn2.jpg',
|
|
|
|
|
'thirdAn0.jpg', 'thirdAn1.jpg', 'thirdAn2.jpg',
|
|
|
|
|
'fourthAn0.jpg', 'fourthAn1.jpg', 'fourthAn2.jpg']
|
|
|
|
|
|
|
|
|
|
image_names_addition = ['addFirstAn0.jpg', 'addFirstAn1.jpg', 'addFirstAn2.jpg',
|
|
|
|
|
'addSecondAn0.jpg', 'addSecondAn1.jpg', 'addSecondAn2.jpg',
|
|
|
|
|
'addThirdAn0.jpg', 'addThirdAn1.jpg', 'addThirdAn2.jpg',
|
|
|
|
|
'addFourthAn0.jpg', 'addFourthAn1.jpg', 'addFourthAn2.jpg']
|
|
|
|
|
|
|
|
|
|
main_img = ['CustomJPG0.jpg']
|
|
|
|
|
|
|
|
|
|
result = listShops[['Store_Sales']]
|
|
|
|
|
# Строим boxplot с использованием Seaborn
|
|
|
|
|
plt.title('Valuation Boxplot by Store Sales')
|
|
|
|
|
plt.xlabel('Store Sales')
|
|
|
|
|
|
|
|
|
|
plt.boxplot(result['Store_Sales'])
|
|
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(__file__)
|
|
|
|
|
results_dir = os.path.join(script_dir, 'static/')
|
|
|
|
|
|
|
|
|
|
plt.savefig(results_dir + 'NewCustomJPG' + str(0) + '.jpg')
|
|
|
|
|
|
|
|
|
|
newCustomJpg = ['NewCustomJPG0.jpg']
|
|
|
|
|
|
2023-09-28 15:14:37 +04:00
|
|
|
|
|
2023-10-12 17:46:05 +04:00
|
|
|
|
return render_template('main_page.html', context=[], image_names_start=image_names_start,
|
|
|
|
|
image_names_addition=image_names_addition,
|
|
|
|
|
tableAnalysOne=[],
|
|
|
|
|
tableAnalysTwo=[],
|
|
|
|
|
tableAnalysThree=[],
|
|
|
|
|
tableAnalysFour=[],
|
|
|
|
|
main_img=newCustomJpg,
|
2023-09-28 20:48:51 +04:00
|
|
|
|
titles=[''],
|
|
|
|
|
listTypes=listTypes, countNull=countNull, firstRow=1,
|
|
|
|
|
secondRow=4, firstColumn=1, secondColumn=4)
|
2023-09-14 17:46:46 +04:00
|
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
|
app.run(debug=True)
|
2023-09-14 14:30:19 +04:00
|
|
|
|
|