diag_11.py
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
sys.path.insert(0, "F:/data-report/data-process")
from app import app, db
from models import ReportLightReformInshop, ReportLightReformPark
from sqlalchemy import func, text
with app.app_context():
# how many rows / task linkage
print("== inshop rows ==")
inshop_all = db.session.query(ReportLightReformInshop).all()
print("inshop total rows:", len(inshop_all))
# distinct task_id / period
q = db.session.query(ReportLightReformInshop.task_id,
func.min(ReportLightReformInshop.period_start),
func.max(ReportLightReformInshop.period_end),
func.count(),
func.sum(ReportLightReformInshop.total_output_value))\
.group_by(ReportLightReformInshop.task_id).all()
for tid, ps, pe, cnt, s in q:
print(f" task_id={tid} period={ps}~{pe} rows={cnt} SUM(合计总产值)={float(s) if s is not None else None}")
print("== park rows ==")
park_all = db.session.query(ReportLightReformPark).all()
print("park total rows:", len(park_all))
q2 = db.session.query(ReportLightReformPark.task_id,
func.min(ReportLightReformPark.period_start),
func.max(ReportLightReformPark.period_end),
func.count(),
func.sum(ReportLightReformPark.total_output_value))\
.group_by(ReportLightReformPark.task_id).all()
for tid, ps, pe, cnt, s in q2:
print(f" task_id={tid} period={ps}~{pe} rows={cnt} SUM(合计总产值)={float(s) if s is not None else None}")
# Also check a few sample rows' total_output_value to see if non-zero
print("== sample inshop total_output_value (first 5) ==")
for r in inshop_all[:5]:
print(f" store={r.store_name!r} 合计总产值={float(r.total_output_value) if r.total_output_value is not None else None} 门店总产值={float(r.store_output_value) if r.store_output_value is not None else None}")
print("== sample park total_output_value (first 5) ==")
for r in park_all[:5]:
print(f" store={r.store_name!r} 合计总产值={float(r.total_output_value) if r.total_output_value is not None else None} 门店总产值={float(r.store_output_value) if r.store_output_value is not None else None}")