190 lines
8.5 KiB
Python
190 lines
8.5 KiB
Python
import os
|
||
import secrets
|
||
from flask import Flask, redirect, url_for, request, render_template, session
|
||
from matplotlib import pyplot as plt
|
||
|
||
from LabWork01.AnalysCustomers import analysCustomersDataFrame
|
||
from LabWork01.AnalysSales import analysSalesDataFrame
|
||
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.CustomGraphics import createCusGraphics
|
||
from LabWork01.LabWork3.DeletePng import deleteAllPng
|
||
from LabWork01.LabWork4.SiteSearch import SiteSearch
|
||
|
||
app = Flask(__name__)
|
||
|
||
# Для работы session
|
||
secret = secrets.token_urlsafe(32)
|
||
app.secret_key = secret
|
||
|
||
#сразу загружаем весь док, чтобы потом просто прыгать по нему
|
||
listShops = createDataFrame()
|
||
|
||
#список типов данных по столбцам
|
||
listTypes = listShops.dtypes.to_list()
|
||
|
||
#формируем записи о кол-ве пустых ячеек в каждом столбце
|
||
countNull = listShops.isnull().sum()
|
||
|
||
# для фильтра Блума
|
||
search_engine = SiteSearch()
|
||
search_engine.add("https://www.kaggle.com/datasets/ankanhore545/100-highest-valued-unicorns", ["Company", "Valuation", "Country", "State", "City", "Industries", "Founded Year", "Name of Founders", "Total Funding", "Number of Employees"])
|
||
search_engine.add("https://www.kaggle.com/datasets/ilyaryabov/tesla-insider-trading", ["Insider Trading", "Relationship", "Date", "Transaction", "Cost", "Shares", "Value", "Shares Total", "SEC Form 4"])
|
||
search_engine.add("https://www.kaggle.com/datasets/sameepvani/nasa-nearest-earth-objects", ["NASA", "est_diameter_min", "est_diameter_max", "relative_velocity", "miss_distance", "orbiting_body", "sentry_object", "absolute_magnitude", "hazardous"])
|
||
search_engine.add("https://www.kaggle.com/datasets/surajjha101/stores-area-and-sales-data", ["Store", "Area", "Available", "Daily", "Customer", "Sales"])
|
||
search_engine.add("https://www.kaggle.com/datasets/uciml/pima-indians-diabetes-database", ["Health", "Diabetes", "India"])
|
||
search_engine.add("https://www.kaggle.com/datasets/mirichoi0218/insurance", ["age", "sex", "bmi"])
|
||
search_engine.add("https://www.kaggle.com/datasets/muhammedtausif/world-population-by-countries", ["Country", "Population", "Continent", "Capital", "Yearly Change", "Land Area", "Fertility","Density"])
|
||
search_engine.add("https://www.kaggle.com/datasets/deepcontractor/car-price-prediction-challenge", ["car", "price", "manufacturer"])
|
||
search_engine.add("https://www.kaggle.com/datasets/surajjha101/forbes-billionaires-data-preprocessed", ["Name", "Networth", "Source"])
|
||
search_engine.add("https://www.kaggle.com/datasets/fedesoriano/stroke-prediction-dataset", [ "heart_disease" , "bmi", "stroke" ])
|
||
|
||
|
||
@app.route("/")
|
||
def home():
|
||
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():
|
||
data = request.args
|
||
|
||
#получаем срез и таблицы по введёным параметрам
|
||
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)
|
||
|
||
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
|
||
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']))
|
||
|
||
return home()
|
||
|
||
#функция для проведения анализа данных
|
||
@app.route("/analysis", methods=['GET', 'POST'])
|
||
def analysis():
|
||
firstAnalys = analysItemsDataFrame(listShops)
|
||
secondAnalys = analysCustomersDataFrame(listShops)
|
||
thirdAnalys = analysSalesDataFrame(listShops)
|
||
fourthAnalys = analysSalesCustomersDataFrame(listShops)
|
||
|
||
# удаляем все текущие диаграммы
|
||
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']
|
||
|
||
|
||
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)
|
||
|
||
@app.route('/findURL', methods=['GET'])
|
||
def get_page_findURL():
|
||
return render_template('findURL.html', find=False, notFind=False)
|
||
|
||
@app.route('/findURL', methods=['POST'])
|
||
def findURL():
|
||
word = request.form["word"]
|
||
if (search_engine.contains(word)):
|
||
session["new_word"] = word
|
||
return render_template('findURL.html', find=True, notFind=False)
|
||
return render_template('findURL.html', find=False, notFind=True)
|
||
|
||
@app.route('/showFindLinks', methods=['POST'])
|
||
def get_page_showFindURL():
|
||
word = session.get("new_word", None)
|
||
|
||
links = search_engine.find_url(word)
|
||
word_links = []
|
||
for item in links:
|
||
word_links.append({item, word})
|
||
|
||
return render_template('showLinks.html', links=links)
|
||
|
||
if __name__=="__main__":
|
||
app.run(debug=True)
|
||
|