From b5ed677956f4a35aba7a67510778edb4db41d59d Mon Sep 17 00:00:00 2001 From: ye-htut-maung Date: Sun, 15 Oct 2023 00:15:23 -0400 Subject: [PATCH 1/4] Adding problems without test 11 and 12 --- python/simple_data_tool.py | 210 +++++++++++++++++++++++++++++++++++-- python/testing.py | 3 + 2 files changed, 202 insertions(+), 11 deletions(-) create mode 100644 python/testing.py diff --git a/python/simple_data_tool.py b/python/simple_data_tool.py index f57ad2f..ecbad83 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 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 From 24f9035839ebc7e7d9bb4659a31dcdd05b3ca2ac Mon Sep 17 00:00:00 2001 From: ye-htut-maung Date: Sun, 15 Oct 2023 00:38:20 -0400 Subject: [PATCH 2/4] All Test 11 done. --- python/simple_data_tool.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/python/simple_data_tool.py b/python/simple_data_tool.py index ecbad83..11224e2 100644 --- a/python/simple_data_tool.py +++ b/python/simple_data_tool.py @@ -402,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 From 43be6e5b0ca7166ad511839b2a715f8f9105eb27 Mon Sep 17 00:00:00 2001 From: ye-htut-maung Date: Sun, 15 Oct 2023 00:56:25 -0400 Subject: [PATCH 3/4] Added Team Name and Participants --- FEEDBACK.md | 11 +++++------ python/simple_data_tool.py | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FEEDBACK.md b/FEEDBACK.md index 010fecd..c0feb60 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -1,13 +1,12 @@ # 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 5. Any feedback for the coding competition? Things you would like to see in future events? 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 11224e2..51b259b 100644 --- a/python/simple_data_tool.py +++ b/python/simple_data_tool.py @@ -441,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 From e9f0e7b499b8962102592dba9d6d04a50b7913b4 Mon Sep 17 00:00:00 2001 From: ye-htut-maung Date: Sun, 15 Oct 2023 01:05:46 -0400 Subject: [PATCH 4/4] Added Document and Describtion and feedback in feedback.md --- FEEDBACK.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/FEEDBACK.md b/FEEDBACK.md index c0feb60..e543c3a 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -5,7 +5,14 @@ 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. + - 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.