Типо сделал, но вывод нулевых значений это зашквар.
This commit is contained in:
parent
884f3a821d
commit
bf8c3fd34a
@ -1,16 +1,9 @@
|
||||
import csv
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from LabWork01.Shop import Shop
|
||||
|
||||
def createList():
|
||||
newListShop = []
|
||||
def createDataFrame():
|
||||
df = pd.read_csv('../res/Stores.csv')
|
||||
|
||||
file = open("../res/Stores.csv", "r")
|
||||
data = list(csv.reader(file, delimiter=","))
|
||||
file.close()
|
||||
|
||||
for elem in data:
|
||||
newListShop.append(Shop(elem[1], elem[2], elem[3], elem[4]))
|
||||
|
||||
newListShop.pop(0)
|
||||
|
||||
return newListShop
|
||||
return df
|
@ -1,22 +1,64 @@
|
||||
from flask import Flask, redirect, url_for, request, render_template
|
||||
from LabWork01.FuncLoad import createList
|
||||
from LabWork01.FuncLoad import createDataFrame
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
#сразу загружаем весь док, чтобы потом просто прыгать по нему
|
||||
listShops = createDataFrame()
|
||||
|
||||
#список типов данных по столбцам
|
||||
listTypes = listShops.dtypes.to_list()
|
||||
|
||||
#формируем записи о кол-ве пустых ячеек в каждом столбце
|
||||
countNull = listShops.isnull().sum()
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return render_template('main_page.html', firstColumn=1, secondColumn=4)
|
||||
return render_template('main_page.html', context=[], listTypes=listTypes, countNull=countNull, firstColumn=1, secondColumn=4)
|
||||
|
||||
@app.route("/showDiapason", methods=['GET','POST'])
|
||||
def numtext():
|
||||
data = request.args
|
||||
|
||||
listShops = createList()
|
||||
#получаем срез и таблицы по введёным параметрам
|
||||
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']):
|
||||
listShops = listShops[int(data['firstRow']):int(data['secondRow'])+1:1]
|
||||
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()
|
||||
|
||||
return render_template('main_page.html', context=listShops, firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']))
|
||||
|
||||
if __name__=="__main__":
|
||||
app.run(debug=True)
|
||||
|
@ -23,34 +23,28 @@
|
||||
</div>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
{{ countNull }}
|
||||
</tr>
|
||||
<tr>
|
||||
{% if firstColumn == 1 %}
|
||||
<th class="head">Площадь магазина, кв. м, double</th>
|
||||
<th class="head">Площадь магазина, кв. м, {{ listTypes[1] }}</th>
|
||||
{% endif %}
|
||||
{% if firstColumn <= 2 and secondColumn >= 2 %}
|
||||
<th class="head">Кол-во продукции, шт, int</th>
|
||||
<th class="head">Кол-во продукции, шт, {{ listTypes[2] }}</th>
|
||||
{% endif %}
|
||||
{% if firstColumn <= 3 and secondColumn >= 3 %}
|
||||
<th class="head">Кол-во посетителей в день, чел., int</th>
|
||||
<th class="head">Кол-во посетителей в день, чел., {{ listTypes[3] }}</th>
|
||||
{% endif %}
|
||||
{% if secondColumn == 4 %}
|
||||
<th class="head">Кол-во проданных товаров, шт., int</th>
|
||||
<th class="head">Кол-во проданных товаров, шт., {{ listTypes[4] }}</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% for elem in context %}
|
||||
{% for i in range(secondRow - firstRow + 1) %}
|
||||
<tr>
|
||||
{% if firstColumn == 1 %}
|
||||
<td>{{ elem.store_area }}</td>
|
||||
{% endif %}
|
||||
{% if firstColumn <= 2 and secondColumn >= 2 %}
|
||||
<td>{{ elem.items_available }}</td>
|
||||
{% endif %}
|
||||
{% if firstColumn <= 3 and secondColumn >= 3 %}
|
||||
<td>{{ elem.daily_customer_count }}</td>
|
||||
{% endif %}
|
||||
{% if secondColumn == 4 %}
|
||||
<td>{{ elem.store_sales }}</td>
|
||||
{% endif %}
|
||||
{% for elem in context %}
|
||||
<td> {{ elem[i] }} </td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
@ -1,4 +1,4 @@
|
||||
Store ID ,Store_Area,Items_Available,Daily_Customer_Count,Store_Sales
|
||||
Store_ID ,Store_Area,Items_Available,Daily_Customer_Count,Store_Sales
|
||||
1,1659,1961,530,66490
|
||||
2,1461,1752,210,39820
|
||||
3,1340,1609,720,54010
|
||||
|
|
Loading…
x
Reference in New Issue
Block a user