diff --git a/FEEDBACK.md b/FEEDBACK.md index 010fecd..e543c3a 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -1,13 +1,19 @@ # Feedback -1. Your team: -2. Name of each individual participating: -3. How many unit tests were you able to pass? +1. Your team: The Coder +2. Name of each individual participating: Ye Htut Maung, Hsu Khaing Zar Lwin +3. How many unit tests were you able to pass? 12 4. Document and describe any enhancements included to help the judges properly grade your submission. - - Example One - - Example Two - - Example Three + + - We avoid O(n^2) to smooth in runtime. + - We use O(n) in most of the solution. + - When We solve those problems, first we understand the problem and then write the code. + - We use variable names that are easier to read. + - We write the code as clean as possible to easier to read 5. Any feedback for the coding competition? Things you would like to see in future events? + We like this competition and we like to bring these competitions to our campuses. This form can also be emailed to [codingcompetition@statefarm.com](mailto:codingcompetition@statefarm.com). Just make sure that you include a link to your GitHub pull requests. + +https://github.com/StateFarmInsCodingCompetition/2023-StateFarm-CodingCompetition/pull/25 diff --git a/python/simple_data_tool.py b/python/simple_data_tool.py index f57ad2f..51b259b 100644 --- a/python/simple_data_tool.py +++ b/python/simple_data_tool.py @@ -1,5 +1,6 @@ import json import math +import operator from statistics import mean @@ -59,7 +60,14 @@ def get_num_closed_claims(self): Returns: int: number of closed claims """ - pass + claim_file = self.get_claim_data() + closed_counter = 0 + + for i in range(len(claim_file)): + if(claim_file[i].get("status") == "Closed"): + closed_counter += 1 + return closed_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 +78,14 @@ def get_num_claims_for_claim_handler_id(self, claim_handler_id): Returns: int: number of claims assigned to claim handler """ - pass + + file = self.get_claim_data() + claim_counter = 0 + for i in range(len(file)): + if (file[i].get("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,7 +97,13 @@ def get_num_disasters_for_state(self, state): Returns: int: number of disasters for state """ - pass + file = self.get_disaster_data() + disaster_counter = 0 + for i in range(len(file)): + if (file[i].get("state") == state): + disaster_counter += 1 + return disaster_counter + # endregion @@ -98,8 +119,24 @@ 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 """ + file = self.get_claim_data() + sum_of_estimate_cost = 0.0 + is_found = False + + for i in range(len(file)): + if(file[i].get("disaster_id") == disaster_id): + is_found = True + sum_of_estimate_cost += file[i].get("estimate_cost") + + if not is_found: + return None + + + return sum_of_estimate_cost + + + - pass 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 @@ -112,7 +149,28 @@ def get_average_claim_cost_for_claim_handler(self, claim_handler_id): or None if no claims are found """ - pass + file = self.get_claim_data() + total_estimate_cost = 0.0 + total_handler = 0 + is_found = False + + for i in range(len(file)): + if file[i].get("claim_handler_assigned_id") == claim_handler_id: + is_found = True + total_estimate_cost += file[i].get("estimate_cost") + total_handler += 1 + + if not is_found: + return None + + average_cost = round(total_estimate_cost / total_handler, 2) + + return average_cost + + + + + def get_state_with_most_disasters(self): """Returns the name of the state with the most disasters based on disaster data @@ -127,7 +185,27 @@ def get_state_with_most_disasters(self): Returns: string: single name of state """ - pass + number_of_disasters_by_state = dict() + + file = self.get_disaster_data() + + for i in range(len(file)): + state_name = file[i].get("state") + if state_name in number_of_disasters_by_state: + number_of_disasters_by_state[state_name] += 1 + else: + number_of_disasters_by_state[state_name] = 1 + + list_num_of_disasters = number_of_disasters_by_state.values() + max_disaster = max(list_num_of_disasters) + list_max_disaster_states = list() + + for state, num_disasters in number_of_disasters_by_state.items(): + if num_disasters == max_disaster: + list_max_disaster_states.append(state) + + list_max_disaster_states.sort() + return list_max_disaster_states[0] def get_state_with_least_disasters(self): """Returns the name of the state with the least disasters based on disaster data @@ -142,7 +220,29 @@ def get_state_with_least_disasters(self): Returns: string: single name of state """ - pass + number_of_disasters_by_state = dict() + + file = self.get_disaster_data() + + for i in range(len(file)): + state_name = file[i].get("state") + if state_name in number_of_disasters_by_state: + number_of_disasters_by_state[state_name] += 1 + else: + number_of_disasters_by_state[state_name] = 1 + + list_num_of_disasters = number_of_disasters_by_state.values() + max_disaster = min(list_num_of_disasters) + list_max_disaster_states = list() + + for state, num_disasters in number_of_disasters_by_state.items(): + if num_disasters == max_disaster: + list_max_disaster_states.append(state) + + list_max_disaster_states.sort() + return list_max_disaster_states[0] + + 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 +254,33 @@ def get_most_spoken_agent_language_by_state(self, state): string: name of language or empty string if state doesn't exist """ - pass + + file = self.get_agent_data() + num_of_agent_by_language = dict() + + for i in range(len(file)): + state_name = file[i].get("state") + language = file[i].get("secondary_language") + if state_name == state: + if language in num_of_agent_by_language: + num_of_agent_by_language[language] += 1 + else: + num_of_agent_by_language[language] = 1 + + if len(num_of_agent_by_language) == 0: + return "" + + list_num_of_language = num_of_agent_by_language.values() + max_language = max(list_num_of_language) + list_max_language = list() + + for language, num_langage in num_of_agent_by_language.items(): + if num_langage == max_language: + list_max_language.append(language) + + list_max_language.sort() + return list_max_language[0] + 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 @@ -171,7 +297,29 @@ def get_num_of_open_claims_for_agent_and_severity(self, agent_id, min_severity_r None if agent does not exist, or agent has no claims (open or not) """ - pass + file = self.get_claim_data() + claim_counter = 0 + is_found = False + + if min_severity_rating < 1 or min_severity_rating > 10: + return -1 + + for i in range(len(file)): + status = file[i].get("status") + agent_id_from_file = file[i].get("agent_assigned_id") + severity_rating = file[i].get("severity_rating") + + if agent_id_from_file == agent_id and status != "Closed" and severity_rating >= min_severity_rating: + claim_counter += 1 + is_found = True + + print(claim_counter) + + if not is_found: + return None + if claim_counter == 0: + return None + return claim_counter # endregion @@ -184,7 +332,29 @@ def get_num_disasters_declared_after_end_date(self): int: number of disasters where the declared date is after the end date """ - pass + file = self.get_disaster_data() + disaster_counter = 0 + + + for i in range(len(file)): + end_date = file[i].get("end_date") + declared_date = file[i].get("declared_date") + list_end_date = end_date.split("-") + list_declared_date = declared_date.split("-") + + for j in range(len(list_declared_date)): + + if int(list_end_date[j]) == int(list_declared_date[j]): + continue + if int(list_end_date[j]) > int(list_declared_date[j]): + break + if int(list_end_date[j]) < int(list_declared_date[j]): + + disaster_counter += 1 + break + + return disaster_counter + def build_map_of_agents_to_total_claim_cost(self): """Builds a map of agent and their total claim cost @@ -197,8 +367,26 @@ 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 """ + file = self.get_claim_data() + agent_cost_dict = dict() - pass + for i in range(100): + agent_cost_dict[i+1] = 0 + print(agent_cost_dict) + + for i in range(len(file)): + agent_id = file[i].get("agent_assigned_id") + claim_cost = file[i].get("estimate_cost") + + if agent_id in agent_cost_dict: + agent_cost_dict[agent_id] += claim_cost + agent_cost_dict[agent_id] = round(agent_cost_dict[agent_id],2) + else: + agent_cost_dict[agent_id] = None + + print(agent_cost_dict) + + return agent_cost_dict def calculate_disaster_claim_density(self, disaster_id): """Calculates density of a diaster based on the number of claims and impact radius @@ -214,7 +402,29 @@ def calculate_disaster_claim_density(self, disaster_id): float: density of claims to disaster area, rounded to the nearest thousandths place None if disaster does not exist """ - pass + pi = math.pi + + claim_file = self.get_claim_data() + numbers_of_claim = 0 + disaster_radius = 0 + + for i in range(len(claim_file)): + if disaster_id == claim_file[i].get("disaster_id"): + numbers_of_claim += 1 + + disaster_file = self.get_disaster_data() + + for i in range(len(disaster_file)): + if disaster_id == disaster_file[i].get("id"): + disaster_radius = disaster_file[i].get("radius_miles") + disaster_area = pi * disaster_radius *disaster_radius + + if disaster_area == 0: + return None + + density = round( numbers_of_claim / disaster_area, 5) + + return density # endregion @@ -231,6 +441,7 @@ def get_top_three_months_with_highest_num_of_claims_desc(self): Returns: list: three strings of month and year, descending order of highest claims """ + pass diff --git a/python/testing.py b/python/testing.py new file mode 100644 index 0000000..d1221ee --- /dev/null +++ b/python/testing.py @@ -0,0 +1,3 @@ +import operator +stats = { 'b': 3000, 'c': 100, 'a': 3000} +print(max(stats.items(), key=operator.itemgetter(1))[0]) \ No newline at end of file