Lection 2.

This commit is contained in:
ElEgEv 2023-09-25 20:43:20 +04:00
parent 7b1862cfba
commit 95d877a4e1
2 changed files with 19 additions and 81 deletions

View File

@ -1,62 +1,28 @@
from flask import Flask, redirect, url_for, request, render_template from flask import Flask, request, render_template
from LabWork01.FuncLoad import createDataFrame import numpy as np
app = Flask(__name__) app = Flask(__name__)
#сразу загружаем весь док, чтобы потом просто прыгать по нему degree = 3
listShops = createDataFrame()
#список типов данных по столбцам
listTypes = listShops.dtypes.to_list()
#формируем записи о кол-ве пустых ячеек в каждом столбце
countNull = listShops.isnull().sum()
@app.route("/") @app.route("/")
def home(): def home():
return render_template('main_page.html', context=[], listTypes=listTypes, countNull=countNull, firstColumn=1, secondColumn=4) return render_template('main_page.html')
@app.route("/showDiapason", methods=['GET','POST']) @app.route("/calculateCube", methods=['GET','POST'])
def numtext(): def numtext():
data = request.args data = request.args
#получаем срез и таблицы по введёным параметрам #проверка на int или float
newListShops = listShops.iloc[int(data['firstRow'])-1:int(data['secondRow']), int(data['firstColumn']):int(data['secondColumn'])+1] if data['number']:
if data['number'].isdigit():
result = np.power(int(data['number']), degree)
else:
result = np.power(float(data['number']), degree)
_range = range(int(data['firstColumn']), int(data['secondColumn'])+1) return render_template('main_page.html', context=result)
else:
#список списков для шаблона return render_template('main_page.html')
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, listTypes=listTypes, countNull=countNull,
firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']),
firstRow=int(data['firstRow']), secondRow=int(data['secondRow']))
home()
if __name__=="__main__": if __name__=="__main__":
app.run(debug=True) app.run(debug=True)

View File

@ -2,7 +2,7 @@
<html lang="ru"> <html lang="ru">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Список магазинов</title> <title>Ответ на вторую лекцию</title>
<style> <style>
.head { .head {
background: #fc3; background: #fc3;
@ -13,41 +13,13 @@
</head> </head>
<body> <body>
<div> <div>
<form action='http://127.0.0.1:5000/showDiapason' method=get> <form action='http://127.0.0.1:5000/calculateCube' method=get>
<input type=text size=20 name=firstRow> <input type=text size=20 name=number>
<input type=text size=20 name=secondRow> <input type=submit value='Узнать куб'>
<input type=text size=20 name=firstColumn>
<input type=text size=20 name=secondColumn>
<input type=submit value='Вывод диапазона'>
</form> </form>
</div> </div>
<div> <div>
<table> <input type=text size=20 name=answer value="{{ context }}">
<tr>
{{ countNull }}
</tr>
<tr>
{% if firstColumn == 1 %}
<th class="head">Площадь магазина, кв. м, {{ listTypes[1] }}</th>
{% endif %}
{% if firstColumn <= 2 and secondColumn >= 2 %}
<th class="head">Кол-во продукции, шт, {{ listTypes[2] }}</th>
{% endif %}
{% if firstColumn <= 3 and secondColumn >= 3 %}
<th class="head">Кол-во посетителей в день, чел., {{ listTypes[3] }}</th>
{% endif %}
{% if secondColumn == 4 %}
<th class="head">Кол-во проданных товаров, шт., {{ listTypes[4] }}</th>
{% endif %}
</tr>
{% for i in range(secondRow - firstRow + 1) %}
<tr>
{% for elem in context %}
<td> {{ elem[i] }} </td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div> </div>
</body> </body>
</html> </html>