diff --git a/python/simple_data_tool.py b/python/simple_data_tool.py index 5391073..211ad3f 100644 --- a/python/simple_data_tool.py +++ b/python/simple_data_tool.py @@ -59,7 +59,12 @@ def get_num_closed_claims(self): Returns: int: number of closed claims """ - pass + claim_list = self.__claim_data + closed_claim_counter = 0 + for claim in claim_list: + if claim["status"] == "Closed": + closed_claim_counter += 1 + return closed_claim_counter def get_num_claims_for_claim_handler_id(self, claim_handler_id): """Calculates the number of claims assigned to a specific claim handler @@ -70,7 +75,12 @@ def get_num_claims_for_claim_handler_id(self, claim_handler_id): Returns: int: number of claims assigned to claim handler """ - pass + claim_list = self.__claim_data + claim_counter = 0 + for claim in claim_list: + if claim["claim_handler_assigned_id"] == claim_handler_id: + claim_counter += 1 + return claim_counter def get_num_disasters_for_state(self, state): """Calculates the number of disasters for a specific state @@ -82,13 +92,19 @@ def get_num_disasters_for_state(self, state): Returns: int: number of disasters for state """ - pass + disaster_list = self.__disaster_data + disaster_counter = 0 + for disaster in disaster_list: + if disaster["state"] == state: + disaster_counter += 1 + return disaster_counter # endregion # region Test Set Two def get_total_claim_cost_for_disaster(self, disaster_id): + """Sums the estimated cost of a specific disaster by its claims Args: @@ -98,8 +114,14 @@ def get_total_claim_cost_for_disaster(self, disaster_id): float | None: estimate cost of disaster, rounded to the nearest hundredths place returns None if no claims are found """ - - pass + claim_list = self.__claim_data + total_cost = 0 + for claim in claim_list: + if claim["disaster_id"] == disaster_id: + total_cost += claim["estimate_cost"] + if total_cost: + return total_cost + return None def get_average_claim_cost_for_claim_handler(self, claim_handler_id): """Gets the average estimated cost of all claims assigned to a claim handler @@ -111,8 +133,15 @@ def get_average_claim_cost_for_claim_handler(self, claim_handler_id): float | None : average cost of claims, rounded to the nearest hundredths place or None if no claims are found """ - - pass + claim_list = self.__claim_data + cost_list = [] + for claim in claim_list: + if claim["claim_handler_assigned_id"] == claim_handler_id: + cost_list.append(claim["estimate_cost"]) + if cost_list: + average = mean(cost_list) + return round(average, 2) + return None def get_state_with_most_disasters(self): """Returns the name of the state with the most disasters based on disaster data @@ -127,7 +156,12 @@ def get_state_with_most_disasters(self): Returns: string: single name of state """ - pass + disaster_list = self.__disaster_data + state_list = [] + for disaster in disaster_list: + state_list.append(disaster['state']) + state_set = sorted(set(state_list)) + return max(state_set, key=state_list.count) def get_state_with_least_disasters(self): """Returns the name of the state with the least disasters based on disaster data @@ -142,7 +176,12 @@ def get_state_with_least_disasters(self): Returns: string: single name of state """ - pass + disaster_list = self.__disaster_data + state_list = [] + for disaster in disaster_list: + state_list.append(disaster['state']) + state_set = sorted(set(state_list)) + return min(state_set, key=state_list.count) def get_most_spoken_agent_language_by_state(self, state): """Returns the name of the most spoken language by agents (besides English) for a specific state @@ -154,7 +193,18 @@ def get_most_spoken_agent_language_by_state(self, state): string: name of language or empty string if state doesn't exist """ - pass + agent_list = self.__agent_data + language_list = [] + for agent in agent_list: + if agent["state"] == state: + language_list.append(agent["primary_language"]) + if agent["secondary_language"]: + language_list.append(agent["secondary_language"]) + language_set = set(language_list) + language_set.discard("English") + if language_set: + return max(language_set, key=language_list.count) + return '' def get_num_of_open_claims_for_agent_and_severity(self, agent_id, min_severity_rating): """Returns the number of open claims for a specific agent and for a minimum severity level and higher @@ -170,9 +220,18 @@ def get_num_of_open_claims_for_agent_and_severity(self, agent_id, min_severity_r -1 if severity rating out of bounds None if agent does not exist, or agent has no claims (open or not) """ - - pass - + claim_list = self.__claim_data + claim_counter = 0 + if min_severity_rating < 1 or min_severity_rating > 10: + return -1 + for claim in claim_list: + if (claim["agent_assigned_id"] == agent_id + and claim["status"] != "Closed" + and claim["severity_rating"] >= min_severity_rating): + claim_counter += 1 + if claim_counter: + return claim_counter + return None # endregion # region TestSetThree @@ -183,8 +242,16 @@ def get_num_disasters_declared_after_end_date(self): Returns: int: number of disasters where the declared date is after the end date """ - - pass + disaster_list = self.__disaster_data + disaster_counter = 0 + for disaster in disaster_list: + end_date = int(disaster["end_date"][:4] + disaster["end_date"][5:7] + disaster["end_date"][8:]) + declared_date = int(disaster["declared_date"][:4] + + disaster["declared_date"][5:7] + + disaster["declared_date"][8:]) + if declared_date > end_date: + disaster_counter += 1 + return disaster_counter def build_map_of_agents_to_total_claim_cost(self): """Builds a map of agent and their total claim cost @@ -197,34 +264,53 @@ def build_map_of_agents_to_total_claim_cost(self): Returns: dict: key is agent id, value is total cost of claims associated to the agent """ - - pass + claim_list = self.__claim_data + agent_list = self.__agent_data + agent_claim_cost = dict.fromkeys(range(1, 101)) + for agent in agent_list: + agent_claim_cost[agent["id"]] = 0 + + for claim in claim_list: + agent_id = claim["agent_assigned_id"] + if agent_claim_cost[agent_id] is not None: + agent_claim_cost[agent_id] += claim["estimate_cost"] + agent_claim_cost[agent_id] = round(agent_claim_cost[agent_id], 2) + return agent_claim_cost def calculate_disaster_claim_density(self, disaster_id): - """Calculates density of a diaster based on the number of claims and impact radius + """Calculates density of a disaster based on the number of claims and impact radius Hints: Assume uniform spacing between claims Assume disaster impact area is a circle Args: - disaster_id (int): id of diaster + disaster_id (int): id of disaster Returns: float: density of claims to disaster area, rounded to the nearest thousandths place None if disaster does not exist """ - pass + disaster_list = self.__disaster_data + claim_list = self.__claim_data + claim_count = 0 + try: + disaster_area = math.pi * disaster_list[disaster_id - 1]["radius_miles"] ** 2 + except IndexError: + return None + for claim in claim_list: + if claim["disaster_id"] == disaster_id: + claim_count += 1 + if claim_count: + return round(claim_count / disaster_area, 5) + return None # endregion # region TestSetFour def get_top_three_months_with_highest_num_of_claims_desc(self): - """Gets the top three months with the highest number of claims - - OPTIONAL! OPTIONAL! OPTIONAL! - AS OF 9:21CDT, TEST IS OPTIONAL. SEE GITHUB ISSUE #8 FOR MORE DETAILS + """Gets the top three months with the highest total claim cost Hint: Month should be full name like 01 is January and 12 is December @@ -235,6 +321,4 @@ def get_top_three_months_with_highest_num_of_claims_desc(self): list: three strings of month and year, descending order of highest claims """ - pass - # endregion