2023-10-12 17:46:05 +04:00
import os
2023-10-26 16:05:43 +04:00
import secrets
from flask import Flask , redirect , url_for , request , render_template , session
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-10-25 22:39:10 +04:00
from LabWork01 . LabWork4 . SiteSearch import SiteSearch
2023-09-14 17:46:46 +04:00
app = Flask ( __name__ )
2023-10-26 16:05:43 +04:00
# Для работы session
secret = secrets . token_urlsafe ( 32 )
app . secret_key = secret
2023-09-23 14:27:08 +04:00
#сразу загружаем весь док, чтобы потом просто прыгать по нему
listShops = createDataFrame ( )
#список типов данных по столбцам
listTypes = listShops . dtypes . to_list ( )
#формируем записи о кол-ве пустых ячеек в каждом столбце
countNull = listShops . isnull ( ) . sum ( )
2023-10-25 22:39:10 +04:00
# для фильтра Блума
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 " ] )
2023-10-26 16:05:43 +04:00
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 " ] )
2023-10-25 22:39:10 +04:00
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
2023-10-25 22:39:10 +04:00
@app.route ( ' /findURL ' , methods = [ ' GET ' ] )
def get_page_findURL ( ) :
2023-10-26 16:05:43 +04:00
return render_template ( ' findURL.html ' , find = False , notFind = False )
2023-10-25 22:39:10 +04:00
@app.route ( ' /findURL ' , methods = [ ' POST ' ] )
def findURL ( ) :
word = request . form [ " word " ]
if ( search_engine . contains ( word ) ) :
2023-10-26 16:05:43 +04:00
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 )
2023-10-25 22:39:10 +04:00
2023-09-14 17:46:46 +04:00
if __name__ == " __main__ " :
app . run ( debug = True )
2023-09-14 14:30:19 +04:00