Сдал лабу, это пипец
This commit is contained in:
parent
046f7619ba
commit
89b63e0cd6
@ -10,14 +10,29 @@ def analysCustomersDataFrame(df: pandas.DataFrame):
|
||||
table_three = df.query("Size == 'Big'").groupby('Size')
|
||||
|
||||
minMaxMean_one = table_one.agg({'Daily_Customer_Count': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_one.columns = minMaxMean_one.columns.droplevel()
|
||||
minMaxMean_two = table_two.agg({'Daily_Customer_Count': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_two.columns = minMaxMean_two.columns.droplevel()
|
||||
minMaxMean_two = minMaxMean_two.iloc[:, 1:4]
|
||||
minMaxMean_three = table_three.agg({'Daily_Customer_Count': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_three.columns = minMaxMean_three.columns.droplevel()
|
||||
minMaxMean_three = minMaxMean_three.iloc[:, 1:4]
|
||||
|
||||
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
|
||||
df1 = pd.DataFrame()
|
||||
df1['small'] = minMaxMean_one['min']
|
||||
df1['average'] = minMaxMean_two['min']
|
||||
df1['big'] = minMaxMean_three['min']
|
||||
|
||||
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
|
||||
df2 = pd.DataFrame()
|
||||
df2['small'] = minMaxMean_one['max']
|
||||
df2['average'] = minMaxMean_two['max']
|
||||
df2['big'] = minMaxMean_three['max']
|
||||
|
||||
# for data in roundedListShops.items():
|
||||
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
|
||||
df3 = pd.DataFrame()
|
||||
df3['small'] = minMaxMean_one['mean']
|
||||
df3['average'] = minMaxMean_two['mean']
|
||||
df3['big'] = minMaxMean_three['mean']
|
||||
|
||||
totalTable = [df1, df2, df3]
|
||||
|
||||
return totalTable
|
@ -10,14 +10,29 @@ def analysSalesDataFrame(df: pandas.DataFrame):
|
||||
table_three = df.query("Size == 'Big'").groupby('Size')
|
||||
|
||||
minMaxMean_one = table_one.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_one.columns = minMaxMean_one.columns.droplevel()
|
||||
minMaxMean_two = table_two.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_two.columns = minMaxMean_two.columns.droplevel()
|
||||
minMaxMean_two = minMaxMean_two.iloc[:, 1:4]
|
||||
minMaxMean_three = table_three.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_three.columns = minMaxMean_three.columns.droplevel()
|
||||
minMaxMean_three = minMaxMean_three.iloc[:, 1:4]
|
||||
|
||||
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
|
||||
df1 = pd.DataFrame()
|
||||
df1['small'] = minMaxMean_one['min']
|
||||
df1['average'] = minMaxMean_two['min']
|
||||
df1['big'] = minMaxMean_three['min']
|
||||
|
||||
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
|
||||
df2 = pd.DataFrame()
|
||||
df2['small'] = minMaxMean_one['max']
|
||||
df2['average'] = minMaxMean_two['max']
|
||||
df2['big'] = minMaxMean_three['max']
|
||||
|
||||
# for data in roundedListShops.items():
|
||||
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
|
||||
df3 = pd.DataFrame()
|
||||
df3['small'] = minMaxMean_one['mean']
|
||||
df3['average'] = minMaxMean_two['mean']
|
||||
df3['big'] = minMaxMean_three['mean']
|
||||
|
||||
totalTable = [df1, df2, df3]
|
||||
|
||||
return totalTable
|
@ -10,14 +10,29 @@ def analysSalesCustomersDataFrame(df: pandas.DataFrame):
|
||||
table_three = df.query("SaleCustomer == 'Big'").groupby('SaleCustomer')
|
||||
|
||||
minMaxMean_one = table_one.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_one.columns = minMaxMean_one.columns.droplevel()
|
||||
minMaxMean_two = table_two.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_two.columns = minMaxMean_two.columns.droplevel()
|
||||
minMaxMean_two = minMaxMean_two.iloc[:, 1:4]
|
||||
minMaxMean_three = table_three.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_three.columns = minMaxMean_three.columns.droplevel()
|
||||
minMaxMean_three = minMaxMean_three.iloc[:, 1:4]
|
||||
|
||||
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
|
||||
df1 = pd.DataFrame()
|
||||
df1['small'] = minMaxMean_one['min']
|
||||
df1['average'] = minMaxMean_two['min']
|
||||
df1['big'] = minMaxMean_three['min']
|
||||
|
||||
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
|
||||
df2 = pd.DataFrame()
|
||||
df2['small'] = minMaxMean_one['max']
|
||||
df2['average'] = minMaxMean_two['max']
|
||||
df2['big'] = minMaxMean_three['max']
|
||||
|
||||
# for data in roundedListShops.items():
|
||||
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
|
||||
df3 = pd.DataFrame()
|
||||
df3['small'] = minMaxMean_one['mean']
|
||||
df3['average'] = minMaxMean_two['mean']
|
||||
df3['big'] = minMaxMean_three['mean']
|
||||
|
||||
totalTable = [df1, df2, df3]
|
||||
|
||||
return totalTable
|
@ -2,7 +2,6 @@ import pandas
|
||||
import pandas as pd
|
||||
|
||||
#или как analysDataFrame(df)->pandas.DataFrame:
|
||||
|
||||
def analysItemsDataFrame(df: pandas.DataFrame):
|
||||
|
||||
df['Size'] = df['Store_Area'].apply(lambda x: 'Small' if x <= 1100 else ('Average' if 1100 < x <= 1800 else 'Big'))
|
||||
@ -12,14 +11,29 @@ def analysItemsDataFrame(df: pandas.DataFrame):
|
||||
table_three = df.query("Size == 'Big'").groupby('Size')
|
||||
|
||||
minMaxMean_one = table_one.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_one.columns = minMaxMean_one.columns.droplevel()
|
||||
minMaxMean_two = table_two.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_two.columns = minMaxMean_two.columns.droplevel()
|
||||
minMaxMean_two = minMaxMean_two.iloc[:, 1:4]
|
||||
minMaxMean_three = table_three.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
|
||||
minMaxMean_three.columns = minMaxMean_three.columns.droplevel()
|
||||
minMaxMean_three = minMaxMean_three.iloc[:, 1:4]
|
||||
|
||||
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
|
||||
df1 = pd.DataFrame()
|
||||
df1['small'] = minMaxMean_one['min']
|
||||
df1['average'] = minMaxMean_two['min']
|
||||
df1['big'] = minMaxMean_three['min']
|
||||
|
||||
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
|
||||
df2 = pd.DataFrame()
|
||||
df2['small'] = minMaxMean_one['max']
|
||||
df2['average'] = minMaxMean_two['max']
|
||||
df2['big'] = minMaxMean_three['max']
|
||||
|
||||
# for data in roundedListShops.items():
|
||||
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
|
||||
df3 = pd.DataFrame()
|
||||
df3['small'] = minMaxMean_one['mean']
|
||||
df3['average'] = minMaxMean_two['mean']
|
||||
df3['big'] = minMaxMean_three['mean']
|
||||
|
||||
totalTable = [df1, df2, df3]
|
||||
|
||||
return totalTable
|
@ -1,11 +1,10 @@
|
||||
import os
|
||||
import glob
|
||||
import pandas as pd
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def createGraphics(df: pd.DataFrame):
|
||||
def createGraphics(df: list[pd.DataFrame], nameFile):
|
||||
# для сохранения диаграммы в конкретной папке
|
||||
script_dir = os.path.dirname(__file__)
|
||||
results_dir = os.path.join(script_dir, '../static/')
|
||||
@ -13,34 +12,13 @@ def createGraphics(df: pd.DataFrame):
|
||||
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
|
||||
for i in range(len(df)):
|
||||
dataFrame = df[i]
|
||||
dataFrame.plot.bar()
|
||||
plt.xlabel('Здесь чё-то')
|
||||
plt.ylabel('Тоже чё-то')
|
||||
plt.title('Диаграмма про чё-то')
|
||||
plt.savefig(results_dir + nameFile + str(i) + '.jpg')
|
||||
plt.close()
|
||||
|
||||
return True
|
47
LabWork01/LabWork3/CustomGraphics.py
Normal file
47
LabWork01/LabWork3/CustomGraphics.py
Normal file
@ -0,0 +1,47 @@
|
||||
import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def createCusGraphics(df: pd.DataFrame, newDf: 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)
|
||||
df.rename(columns={'small': 'small_1', 'average': 'average_1', 'big': 'big_1'}, inplace=True)
|
||||
newDf.rename(columns={'small': 'small_2', 'average': 'average_2', 'big': 'big_2'}, inplace=True)
|
||||
|
||||
# Объединяем две группы в один DataFrame
|
||||
merged_df = pd.concat([df, newDf], axis=1, ignore_index=False)
|
||||
# Создаем массив с индексами для каждой компании
|
||||
index = np.arange(len(merged_df))
|
||||
print(merged_df)
|
||||
# Задаем ширину каждого столбца
|
||||
bar_width = 0.2
|
||||
# Построение столбчатой гистограммы с увеличенным расстоянием между столбцами
|
||||
plt.bar(index, merged_df['small_1'], bar_width, label='Min 1', color='b')
|
||||
plt.bar(index + bar_width, merged_df['average_1'], bar_width, label='Mean 1', color='g')
|
||||
plt.bar(index + 2 * bar_width, merged_df['big_1'], bar_width, label='Max 1', color='r')
|
||||
plt.bar(index + 3 * bar_width, merged_df['small_2'], bar_width, label='Min 2', color='c')
|
||||
plt.bar(index + 4 * bar_width, merged_df['average_2'], bar_width, label='Mean 2', color='m')
|
||||
plt.bar(index + 5 * bar_width, merged_df['big_2'], bar_width, label='Max 2', color='y')
|
||||
|
||||
# Устанавливаем подписи на оси x
|
||||
plt.xlabel('Company')
|
||||
plt.ylabel('Valuation')
|
||||
plt.title('Company Valuation Comparison')
|
||||
plt.xticks(index + 2.5 * bar_width, merged_df.index)
|
||||
|
||||
# Добавляем легенду
|
||||
plt.legend()
|
||||
|
||||
plt.savefig(results_dir + 'CustomJPG' + str(0) + '.jpg')
|
||||
|
||||
plt.close()
|
||||
|
||||
return True
|
@ -1,4 +1,7 @@
|
||||
import os
|
||||
|
||||
from flask import Flask, redirect, url_for, request, render_template
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
from LabWork01.AnalysCustomers import analysCustomersDataFrame
|
||||
from LabWork01.AnalysSales import analysSalesDataFrame
|
||||
@ -7,6 +10,7 @@ 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.CustomGraphics import createCusGraphics
|
||||
from LabWork01.LabWork3.DeletePng import deleteAllPng
|
||||
|
||||
|
||||
@ -23,17 +27,7 @@ countNull = listShops.isnull().sum()
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
additionListShops = addData(createDataFrame())
|
||||
|
||||
# удаляем текущие диаграммы
|
||||
deleteAllPng()
|
||||
|
||||
# создаём новые диаграммы
|
||||
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)
|
||||
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)
|
||||
|
||||
@app.route("/showDiapason", methods=['GET','POST'])
|
||||
def numtext():
|
||||
@ -71,7 +65,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, image_names=[], listTypes=listTypes, countNull=countNull,
|
||||
return render_template('main_page.html', context=totalList, main_img=[], image_names=[], listTypes=listTypes, countNull=countNull,
|
||||
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
|
||||
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
|
||||
|
||||
@ -81,20 +75,70 @@ def numtext():
|
||||
@app.route("/analysis", methods=['GET', 'POST'])
|
||||
def analysis():
|
||||
firstAnalys = analysItemsDataFrame(listShops)
|
||||
|
||||
secondAnalys = analysCustomersDataFrame(listShops)
|
||||
|
||||
thirdAnalys = analysSalesDataFrame(listShops)
|
||||
|
||||
fourthAnalys = analysSalesCustomersDataFrame(listShops)
|
||||
|
||||
print(firstAnalys)
|
||||
# удаляем все текущие диаграммы
|
||||
deleteAllPng()
|
||||
|
||||
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()],
|
||||
# начинаем создавать диаграммы
|
||||
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']
|
||||
|
||||
|
||||
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,
|
||||
titles=[''],
|
||||
listTypes=listTypes, countNull=countNull, firstRow=1,
|
||||
secondRow=4, firstColumn=1, secondColumn=4)
|
||||
|
@ -53,7 +53,26 @@
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
{% for image_name in image_names %}
|
||||
<h3>
|
||||
Данные до дополнения:
|
||||
</h3>
|
||||
{% for image_name in image_names_start %}
|
||||
<img src="{{ url_for('static', filename=image_name) }}" alt="{{ image_name }}">
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>
|
||||
<h3>
|
||||
Данные после дополнения:
|
||||
</h3>
|
||||
{% for image_name in image_names_addition %}
|
||||
<img src="{{ url_for('static', filename=image_name) }}" alt="{{ image_name }}">
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>
|
||||
<h3>
|
||||
По заданию:
|
||||
</h3>
|
||||
{% for image_name in main_img %}
|
||||
<img src="{{ url_for('static', filename=image_name) }}" alt="{{ image_name }}">
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user