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