Skip to content

Commit

Permalink
basic bootstrap rate table
Browse files Browse the repository at this point in the history
  • Loading branch information
amynickolls committed May 20, 2024
1 parent 18b2b4b commit a25705d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
9 changes: 7 additions & 2 deletions dm_regional_app/charts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import django_tables2
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
Expand Down Expand Up @@ -141,5 +140,11 @@ def transistion_rate_table(data):
df.insert(0, "Age", age)
df.drop("to", axis=1, inplace=True)
df = df.round(4)
df["Age"] = df["Age"].mask(df["Age"].duplicated(), "")

return df
cols = df.columns.to_frame().T
cols = cols.transpose()
cols["Age"] = cols["Age"].mask(cols["Age"].duplicated(), "")
cols = cols.transpose()

return df, cols
6 changes: 4 additions & 2 deletions dm_regional_app/templates/dm_regional_app/views/adjusted.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ <h5 class="card-title">To make adjustments, you can view the table by:<br></h5>
</div>
<div class="collapse" id="rate_change" data-bs-parent="#tables">
<div class="card card-body">
<table id="efficiency-hub-table" class="table table-bordered dt-responsive nowrap w-100">
<div class="table-responsive">
<table id="efficiency-hub-table" class="table table-hover table-sm">
<thead>
{{ transistion_rate_table | convert_data_frame_to_html_table_headers | safe}}
{{ tran_rate_cols | convert_data_frame_to_html_table_headers | safe}}
</thead>
<tbody>
{{transistion_rate_table | convert_data_frame_to_html_table_rows | safe}}
</tbody>
</table>
</div>
</div>
</div>
</div>
Expand Down
18 changes: 13 additions & 5 deletions dm_regional_app/templatetags/table_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@


def convert_data_frame_to_html_table_headers(df):
html = "<tr>"
for col in df.columns:
html += f"<th>{col}</th>"
html += "</tr>"
html = ""
for row in df.values:
row_html = "<tr>"
for value in row:
row_html += f'<th><p style="font-size:14px;">{value.capitalize()}</p></th>'
row_html += "</tr>"
html += row_html
return html


Expand All @@ -16,7 +19,12 @@ def convert_data_frame_to_html_table_rows(df):
for row in df.values:
row_html = "<tr>"
for value in row:
row_html += f"<td>{value}</td>"
if isinstance(value, str):
row_html += (
f'<th><p style="font-size:14px;">{value.capitalize()}</p></th>'
)
else:
row_html += f'<td><p style="font-size:14px;">{value}</p></td>'
row_html += "</tr>"
html += row_html
return html
Expand Down
9 changes: 8 additions & 1 deletion dm_regional_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ def adjusted(request):
stats, prediction, **session_scenario.prediction_parameters
)

tran_rate_table = transistion_rate_table(prediction.transition_rates)
tran_rate_table, tran_rate_cols = transistion_rate_table(
prediction.transition_rates
)

tran_rate_cols = tran_rate_cols

print(type(tran_rate_cols))

return render(
request,
Expand All @@ -174,6 +180,7 @@ def adjusted(request):
"chart": chart,
"empty_dataframe": empty_dataframe,
"transistion_rate_table": tran_rate_table,
"tran_rate_cols": tran_rate_cols,
},
)
else:
Expand Down

0 comments on commit a25705d

Please sign in to comment.