Esempio n. 1
0
 def get(self, customer_id):
     customer = database_helpers.query_table_by_value(
         self.db, "customer", "CustomerID", customer_id)
     claims = database_helpers.query_table_by_value(self.db, "claims",
                                                    "CustomerID",
                                                    customer_id)
     vehicles = database_helpers.query_table_by_value(
         self.db, "vehicle", "CustomerID", customer_id)
     policy = database_helpers.query_table_by_value(self.db, "policy",
                                                    "PolicyID",
                                                    customer[0]['PolicyID'])
     vehicles_list = []
     for v in vehicles:
         vehicle_type = database_helpers.query_table_by_value(
             self.db, "vehicletype", "VehicleTypeID", v['VehicleTypeID'])
         vehicles_list.append(vehicle_type[0])
     reply = {
         "customer_name": customer[0]['Name'],
         "customer_id": customer_id,
         "premium": customer[0]['Premium'],
         "deductible": policy[0]['Deductible'],
         "policy_details": policy[0]['PolicyDetails'],
         "number_vehicles": len(vehicles),
         "number_claims": len(claims),
         "risk_score": customer[0]['RiskScore'],
         "vehicles": vehicles_list
     }
     self.write(json.dumps(reply))
Esempio n. 2
0
 def get(self, customer_id):
     vehicles = database_helpers.query_table_by_value(
         self.db, "vehicle", "CustomerID", customer_id)
     out = []
     for v in vehicles:
         vehicle_type = database_helpers.query_table_by_value(
             self.db, "vehicletype", "VehicleTypeID", v['VehicleTypeID'])
         out.append((v, vehicle_type[0]))
     # returns list of tuples containing vehicle and vehicletype
     self.write(json.dumps(out))
Esempio n. 3
0
def claims_toward_deductible(db, customer_id):
    claims = database_helpers.query_table_by_value(db, "claims", "CustomerID",
                                                   customer_id)
    no_old_claims = len(claims) - 1
    total_paid = 0
    print("Total claims {}".format(len(claims)))
    if len(claims) > 1:
        for claim in claims[:-1]:
            vehicle_id = claim['VehicleID']
            severity = claim['Severity']
            vehicle = database_helpers.query_table_by_value(
                db, "vehicle", "VehicleID", vehicle_id)[0]
            vehicle_type_id = vehicle['VehicleTypeID']
            vehicle_type = database_helpers.query_table_by_value(
                db, "vehicletype", "VehicleTypeID", vehicle_type_id)[0]
            book_value = vehicle_type['BookValue']
            total_paid += claim_cost_to_repair(int(severity),
                                               float(book_value))
    return (total_paid, no_old_claims)
Esempio n. 4
0
def generate_report(db, input_data):
    # query database to gather all of the info we need to make calculations for the report
    # get customer info from table
    customer_info = database_helpers.query_table_by_value(
        db, "customer", "CustomerID", input_data['CustomerID'])
    # get claim info from table
    claim_info = database_helpers.query_table_by_value(db, "claims", "id",
                                                       input_data['ClaimID'])
    # get vehicle info from table
    vehicle_info = database_helpers.query_table_by_value(
        db, "vehicle", "VehicleID", input_data['VehicleID'])
    # get vehicle type info from table (assumes one element in vehicle_info)
    vehicle_type_info = database_helpers.query_table_by_value(
        db, "vehicletype", "VehicleTypeID", vehicle_info[0]['VehicleTypeID'])
    # get policy info from table (assumes one element in customer_info)
    policy_info = database_helpers.query_table_by_value(
        db, "policy", "PolicyID", customer_info[0]['PolicyID'])
    # find number of vehicles for customer id
    num_vehicles = len(
        database_helpers.query_table_by_value(db, "vehicle", "CustomerID",
                                              input_data['CustomerID']))

    # call helper calculation functions to compute all of the new numbers
    #...

    # Cost to repair
    customer_claim_cost_to_repair = claim_cost_to_repair(
        int(claim_info[0]["Severity"]),
        float(vehicle_type_info[0]["BookValue"]))
    new_risk_score = risk_score_change(db, input_data['CustomerID'])

    new_premium = -1
    if new_risk_score[0]:
        # update the databases
        update_risk_score(db, new_risk_score[1],
                          customer_info[0]['CustomerID'])
        new_premium = round((update_premium(db, customer_info[0]['Premium'],
                                            customer_info[0]['CustomerID'])),
                            0)
    print("The new premuim is {}".format(new_premium))

    total_paid_into_deductible = claims_toward_deductible(
        db, customer_info[0]['CustomerID'])[0]
    total_prior_claims = claims_toward_deductible(
        db, customer_info[0]['CustomerID'])[1]

    print("total paid {}".format(total_paid_into_deductible))
    claim_remaining_deductible = max(
        0, (float(policy_info[0]['Deductible']) - total_paid_into_deductible))
    claim_covered_repair_value = max(
        0, customer_claim_cost_to_repair - claim_remaining_deductible)
    claim_out_of_pocket_expense = customer_claim_cost_to_repair - claim_covered_repair_value

    print("Total exisitng claims {}".format(total_prior_claims))

    # populate output data structure to send to front end
    report_data = {}
    report_data['customer_name'] = customer_info[0]['Name']
    report_data['customer_id'] = customer_info[0]['CustomerID']
    report_data['policy_details'] = policy_info[0]['PolicyDetails']
    report_data['deductible'] = policy_info[0]['Deductible']
    report_data['premium'] = customer_info[0]['Premium']
    report_data['customer_number_of_vehicles'] = num_vehicles
    report_data['customer_risk_score'] = customer_info[0]['RiskScore']
    report_data['claim_id'] = input_data['ClaimID']
    report_data['claim_description'] = claim_info[0]['ClaimDescription']
    report_data['claim_cost_to_repair'] = customer_claim_cost_to_repair
    report_data['claim_vehicle_make_model'] = "{} {}".format(
        vehicle_type_info[0]['Make'], vehicle_type_info[0]['Model'])
    report_data['claim_vehicle_year'] = vehicle_type_info[0]['Year']
    report_data['claim_vehicle_image_url'] = vehicle_type_info[0]['ImageURL']
    report_data['claim_vehicle_value'] = vehicle_type_info[0]['BookValue']
    report_data['claim_out_of_pocket_expense'] = claim_out_of_pocket_expense
    report_data['claim_covered_repair_value'] = claim_covered_repair_value
    report_data['claim_deductible_contributions'] = total_paid_into_deductible
    report_data['claim_remaining_deductible'] = claim_remaining_deductible
    report_data['claim_new_risk_score'] = round(new_risk_score[1], 1)
    report_data['claim_new_premium'] = round(new_premium, 0)
    report_data['no_prior_claims'] = total_prior_claims
    return report_data