Skip to content

Commit

Permalink
Put bill check option in scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Aug 13, 2024
1 parent f771b04 commit 5f1276e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 209 deletions.
92 changes: 12 additions & 80 deletions chellow/reports/report_247.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,13 @@ def write_spreadsheet(
site_rows,
era_rows,
read_rows,
bill_check_site_rows,
bill_check_era_rows,
is_bill_check,
):
fl.seek(0)
fl.truncate()
with odio.create_spreadsheet(fl, "1.2", compressed=compressed) as f:
f.append_table("Site Level", site_rows)
f.append_table("Era Level", era_rows)
f.append_table("Normal Reads", read_rows)
if is_bill_check:
f.append_table("Bill Check Site", bill_check_site_rows)
f.append_table("Bill Check Era", bill_check_era_rows)


def make_bill_row(titles, bill):
Expand Down Expand Up @@ -721,14 +715,7 @@ class Object:
pass


def content(
scenario_props,
base_name,
user_id,
compression,
now,
is_bill_check,
):
def content(scenario_props, base_name, user_id, compression, now):
report_context = {}

try:
Expand All @@ -750,8 +737,6 @@ def content(
site_rows = []
era_rows = []
normal_read_rows = []
bill_check_site_rows = []
bill_check_era_rows = []
try:
with RSession() as sess:
start_year = scenario_props["scenario_start_year"]
Expand Down Expand Up @@ -821,9 +806,6 @@ def content(

user = User.get_by_id(sess, user_id)

if is_bill_check:
base_name.append("bill_check")

rf = open_file("_".join(base_name) + ".ods", user, mode="wb")

for rate_script in scenario_props.get("rates", []):
Expand Down Expand Up @@ -1023,16 +1005,17 @@ def content(
)
site_rows.append(site_header_titles + summary_titles)
era_rows.append(era_titles)
bill_check_site_rows.append(site_header_titles + summary_titles)
bill_check_era_rows.append(era_titles)

sites = sites.all()
normal_reads = set()

for month_start, month_finish in month_pairs:
data_source_bill = Object()
data_source_bill.start_date = month_start
data_source_bill.finish_date = month_finish
if scenario_props.get("is_bill_check", False):
data_source_bill = Object()
data_source_bill.start_date = month_start
data_source_bill.finish_date = month_finish
else:
data_source_bill = None
for site in sites:
if by_hh:
sf = [
Expand All @@ -1058,25 +1041,8 @@ def content(
title_dict,
era_rows,
site_rows,
None,
data_source_bill,
)
if is_bill_check:
_process_site(
sess,
report_context,
forecast_from,
start,
finish,
site,
scenario_props,
supply_ids,
now,
summary_titles,
title_dict,
bill_check_era_rows,
bill_check_site_rows,
data_source_bill,
)
except BadRequest as e:
raise BadRequest(f"Site Code {site.code}: {e.description}")

Expand All @@ -1088,29 +1054,13 @@ def content(
normal_read_rows.append(row)

write_spreadsheet(
rf,
compression,
site_rows,
era_rows,
normal_read_rows,
bill_check_site_rows,
bill_check_era_rows,
is_bill_check,
rf, compression, site_rows, era_rows, normal_read_rows
)
except BadRequest as e:
msg = e.description + traceback.format_exc()
sys.stderr.write(msg + "\n")
site_rows.append(["Problem " + msg])
write_spreadsheet(
rf,
compression,
site_rows,
era_rows,
normal_read_rows,
bill_check_site_rows,
bill_check_era_rows,
is_bill_check,
)
write_spreadsheet(rf, compression, site_rows, era_rows, normal_read_rows)
except BaseException:
msg = traceback.format_exc()
sys.stderr.write(msg + "\n")
Expand All @@ -1121,16 +1071,7 @@ def content(
ef.write(msg + "\n")
ef.close()
else:
write_spreadsheet(
rf,
compression,
site_rows,
era_rows,
normal_read_rows,
bill_check_site_rows,
bill_check_era_rows,
is_bill_check,
)
write_spreadsheet(rf, compression, site_rows, era_rows, normal_read_rows)
finally:
if rf is not None:
rf.close()
Expand Down Expand Up @@ -1193,18 +1134,9 @@ def do_post(sess):
else:
compression = True

is_bill_check = req_bool("is_bill_check")

user = g.user

args = (
scenario_props,
base_name,
user.id,
compression,
now,
is_bill_check,
)
args = (scenario_props, base_name, user.id, compression, now)
threading.Thread(target=content, args=args).start()
return chellow_redirect("/downloads", 303)
except BadRequest as e:
Expand Down
3 changes: 0 additions & 3 deletions chellow/templates/e/ods_monthly_duration.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<label>Site Codes</label>
{{input_textarea('site_codes', '', 5, 40, placeholder='One on each line, includes all if left blank')}}

<label>Include bill check tabs?</label>
{{input_checkbox('is_bill_check')}}

<input type="submit" value="Download">
</fieldset>
</form>
Expand Down
1 change: 1 addition & 0 deletions chellow/templates/e/scenario_docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ <h3>Template Scenario Properties</h3>
2017-10-09 11:00, 3.5"
}
}
"is_bill_check": false, /* Use the bill check rates */
}</pre>

<h3>HH Data</h3>
Expand Down
Loading

0 comments on commit 5f1276e

Please sign in to comment.