Untitled
unknown
plain_text
3 years ago
2.1 kB
7
Indexable
from typing import List
import sqlalchemy
from fastapi import Depends
from sqlalchemy import select
from sqlalchemy.orm import Session
from db_connection import get_db
from config import CONNECTION_URL
from models.pius_ref import PIUSBaseRatesLawyersLossCostHeadcount, PIUSBaseRatesLawyersLossCostLocationScore
engine = sqlalchemy.create_engine(CONNECTION_URL)
session = next(get_db())
location1_loc = ("United States", "Alabama", "Birmingham")
location1_headcount = 49
location2_loc = ("Canada", "Alberta", "Calgary")
location2_headcount = 12
location3_loc = ("Worldwide", "Europe", "All Europe")
location3_headcount = 12
def get_ref_data(loc):
assert len(loc) == 3
table = PIUSBaseRatesLawyersLossCostLocationScore
# statement = select(table.location1, table.location2, table.location3, table.loss_cost_rate_per_lawyer)\
# .where(table.location1 == loc[0], table.location2 == loc[1], table.location3 == loc[2])
statement = select(table.loss_cost_rate_per_lawyer).where(table.location1 == loc[0], table.location2 ==
loc[1], table.location3 == loc[2])
results = session.execute(statement).all()
# return results
return results[0][0]
# print(get_ref_data(location1_loc))
# print(get_ref_data(location2_loc))
# print(get_ref_data(location3_loc))
# print("#########")
location1_loss_cost_rate_per_lawyer = get_ref_data(location1_loc)
location2_loss_cost_rate_per_lawyer = get_ref_data(location2_loc)
location3_loss_cost_rate_per_lawyer = get_ref_data(location3_loc)
location1_loss_cost_rate = location1_loss_cost_rate_per_lawyer * location1_headcount
location2_loss_cost_rate = location2_loss_cost_rate_per_lawyer * location2_headcount
location3_loss_cost_rate = location3_loss_cost_rate_per_lawyer * location3_headcount
print(location1_loss_cost_rate)
print(location2_loss_cost_rate)
print(location3_loss_cost_rate)
print("#########")
loss_cost_total = location1_loss_cost_rate + location2_loss_cost_rate + location3_loss_cost_rate
#
print(f"Loss cost total = {loss_cost_total}")Editor is loading...