Skip to content

Commit

Permalink
sort plans by insurer then premium
Browse files Browse the repository at this point in the history
  • Loading branch information
kavwad committed Dec 16, 2024
1 parent f8b9889 commit 272b32e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,28 @@ def main():

# Generate cost curve data for each plan
cost_curve_data = []

# Group plans by insurer and sort insurers
insurers = {}
for plan_name, plan in st.session_state.plans.items():
medical_costs, out_of_pocket_costs = generate_cost_curve_data(plan)
cost_curve_data.extend([{
'Medical Costs': med,
'Out of Pocket': oop,
'Plan': plan_name,
'Insurer': plan.insurer
} for med, oop in zip(medical_costs, out_of_pocket_costs)])
if plan.insurer not in insurers:
insurers[plan.insurer] = []
insurers[plan.insurer].append(plan)

# Sort plans within each insurer by premium
for insurer in insurers:
insurers[insurer].sort(key=lambda x: x.premium)

# Generate data in sorted order
for insurer in sorted(insurers.keys()):
for plan in insurers[insurer]:
medical_costs, out_of_pocket_costs = generate_cost_curve_data(plan)
cost_curve_data.extend([{
'Medical Costs': med,
'Out of Pocket': oop,
'Plan': plan.name,
'Insurer': plan.insurer
} for med, oop in zip(medical_costs, out_of_pocket_costs)])

cost_curve_df = pd.DataFrame(cost_curve_data)

Expand Down

0 comments on commit 272b32e

Please sign in to comment.