diff --git a/LabWork01/LabWork3/CreateGraphics.py b/LabWork01/LabWork3/CreateGraphics.py new file mode 100644 index 0000000..dfe0b6b --- /dev/null +++ b/LabWork01/LabWork3/CreateGraphics.py @@ -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 \ No newline at end of file diff --git a/LabWork01/LabWork3/DeletePng.py b/LabWork01/LabWork3/DeletePng.py new file mode 100644 index 0000000..48a9fcf --- /dev/null +++ b/LabWork01/LabWork3/DeletePng.py @@ -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 \ No newline at end of file diff --git a/LabWork01/LoadDB.py b/LabWork01/LoadDB.py index 04aba15..aa44efa 100644 --- a/LabWork01/LoadDB.py +++ b/LabWork01/LoadDB.py @@ -6,6 +6,9 @@ from LabWork01.AnalysSalesCustomers import analysSalesCustomersDataFrame from LabWork01.DataFrameAnalys import analysItemsDataFrame from LabWork01.FuncLoad import createDataFrame from LabWork01.LabWork3.AddData import addData +from LabWork01.LabWork3.CreateGraphics import createGraphics +from LabWork01.LabWork3.DeletePng import deleteAllPng + app = Flask(__name__) @@ -20,11 +23,17 @@ countNull = listShops.isnull().sum() @app.route("/") 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']) def numtext(): @@ -62,7 +71,7 @@ def numtext(): totalList.append(listStoreSales) 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']), firstRow=int(data['firstRow']), secondRow=int(data['secondRow'])) @@ -81,7 +90,8 @@ def analysis(): 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()], tableAnalysThree=[thirdAnalys.to_html()], tableAnalysFour=[fourthAnalys.to_html()], diff --git a/LabWork01/templates/main_page.html b/LabWork01/templates/main_page.html index 74ba7df..a7210a0 100644 --- a/LabWork01/templates/main_page.html +++ b/LabWork01/templates/main_page.html @@ -52,6 +52,11 @@ {% endfor %} +