diff --git a/FEEDBACK.md b/FEEDBACK.md index 010fecd..e0251f6 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -1,13 +1,14 @@ # Feedback -1. Your team: -2. Name of each individual participating: -3. How many unit tests were you able to pass? +1. Your team: Shawn Scott shawnscott@shawnscott.tech +2. Name of each individual participating: Shawn Scott +3. How many unit tests were you able to pass? 9 4. Document and describe any enhancements included to help the judges properly grade your submission. - - Example One - - Example Two + - Example One api route that takes a claim handler id and returns information on them + - Example Two and another that returns basic information using "/home" route - Example Three 5. Any feedback for the coding competition? Things you would like to see in future events? +I enjoyed it and think being able to here other's thought would be cool 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. diff --git a/python/application.py b/python/application.py index 50cb38a..9fea23e 100644 --- a/python/application.py +++ b/python/application.py @@ -1 +1,25 @@ -print("I'm working") \ No newline at end of file +print("I'm working") +from simple_data_tool import SimpleDataTool as sdt; + +sd = sdt() + +from flask import Flask + +app = Flask(__name__) + +# Define a route that takes an argument in the URL +@app.route('/') +def main(): + return Flask.redirect('/home') + +# Define a route that takes an argument in the URL +@app.route('/claimHandler/') +def hello(id): + return "number of claims for this handler is: " + str(sd.get_num_claims_for_claim_handler_id(id)) + "
avergae cost of claims is: " + str(sd.get_average_claim_cost_for_claim_handler(id)) + +@app.route('/home') +def home(): + return "number of closed claims: " + str(sd.get_num_closed_claims()) + "
state with the most disasters: " + str(sd.get_state_with_most_disasters()) + "
state with the least disasters: " + str(sd.get_state_with_least_disasters()) + "
number of claims delcared after it already ended: " + str(sd.get_num_disasters_declared_after_end_date())+ "

All agents and their total cost: " + str(sd.build_map_of_agents_to_total_claim_cost()) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/python/simple_data_tool.py b/python/simple_data_tool.py index 5391073..2880a79 100644 --- a/python/simple_data_tool.py +++ b/python/simple_data_tool.py @@ -59,6 +59,14 @@ def get_num_closed_claims(self): Returns: int: number of closed claims """ + + closedClaims = 0 + for claim in self.get_claim_data(): + if claim.get("status") == 'Closed': + closedClaims += 1 + + return closedClaims + pass def get_num_claims_for_claim_handler_id(self, claim_handler_id): @@ -70,6 +78,14 @@ def get_num_claims_for_claim_handler_id(self, claim_handler_id): Returns: int: number of claims assigned to claim handler """ + + theirClaims = 0 + for claim in self.get_claim_data(): + if claim.get("claim_handler_assigned_id")==claim_handler_id: + theirClaims += 1 + + return theirClaims + pass def get_num_disasters_for_state(self, state): @@ -82,6 +98,14 @@ def get_num_disasters_for_state(self, state): Returns: int: number of disasters for state """ + + statesDisasters = 0 + for disaster in self.get_disaster_data(): + if disaster.get("state") == state: + statesDisasters += 1 + + return statesDisasters + pass # endregion @@ -98,6 +122,17 @@ 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 """ + totalCost = 0 + + for claim in self.get_claim_data(): + if claim.get("disaster_id") == disaster_id: + totalCost += claim.get("estimate_cost") + + if totalCost==0: + return None + + return totalCost + pass @@ -111,6 +146,19 @@ 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 """ + + averageCost = 0 + totalClaims = 0 + + for claim in self.get_claim_data(): + if claim.get("claim_handler_assigned_id") == claim_handler_id: + averageCost += claim.get("estimate_cost") + totalClaims += 1 + + if totalClaims == 0: + return None + + return round(averageCost/totalClaims, 2) pass @@ -127,6 +175,30 @@ def get_state_with_most_disasters(self): Returns: string: single name of state """ + states = [] + for region in self.REGION_MAP: + states+= self.REGION_MAP.get(region).split(",") + + statesDisasters = {} + for disaster in self.get_disaster_data(): + if disaster.get("state") in statesDisasters: + statesDisasters[disaster.get("state")] +=1 + else: + statesDisasters[disaster.get("state")] = 1 + + max = 0 + maxStates=[] + for state in statesDisasters: + if statesDisasters.get(state) > max: + maxStates = [] + maxStates.append(state) + max = statesDisasters.get(state) + elif statesDisasters.get(state) == max: + maxStates.append(state) + + return sorted(maxStates)[0] + + pass def get_state_with_least_disasters(self): @@ -142,6 +214,29 @@ def get_state_with_least_disasters(self): Returns: string: single name of state """ + + states = [] + for region in self.REGION_MAP: + states+= self.REGION_MAP.get(region).split(",") + + statesDisasters = {} + for disaster in self.get_disaster_data(): + if disaster.get("state") in statesDisasters: + statesDisasters[disaster.get("state")] +=1 + else: + statesDisasters[disaster.get("state")] = 1 + + min = statesDisasters.get(list(statesDisasters.keys())[0]) + minStates=[list(statesDisasters.keys())[0]] + for state in statesDisasters: + if statesDisasters.get(state) < min: + minStates = [] + minStates.append(state) + min = statesDisasters.get(state) + elif statesDisasters.get(state) == min: + minStates.append(state) + + return sorted(minStates)[0] pass def get_most_spoken_agent_language_by_state(self, state): @@ -154,6 +249,24 @@ def get_most_spoken_agent_language_by_state(self, state): string: name of language or empty string if state doesn't exist """ + + language = "" + max = 0 + languageMaxes = {} + + for agent in self.get_agent_data(): + if agent.get("state") == state: + if agent.get("secondary_language") in languageMaxes: + languageMaxes[agent.get("secondary_language")] += 1 + else: + languageMaxes[agent.get("secondary_language")] = 1 + + if len(languageMaxes) == 0: + return '' + values = list(languageMaxes.keys()) + for single in values: + return single + pass def get_num_of_open_claims_for_agent_and_severity(self, agent_id, min_severity_rating): @@ -170,6 +283,20 @@ 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) """ + if min_severity_rating > 0 or min_severity_rating < 10: + return -1 + + allClaims = 0 + openClaims = 0 + for claim in self.get_claim_data(): + if claim.get("agent_assigned_id") == agent_id: + allClaims += 1 + if claim.get("severity_rating") >= min_severity_rating and claim.get("status") != "Closed": + openClaims += 1 + + if allClaims == 0: + return None + return openClaims pass @@ -183,6 +310,17 @@ def get_num_disasters_declared_after_end_date(self): Returns: int: number of disasters where the declared date is after the end date """ + num = 0 + for disaster in self.get_disaster_data(): + endDate = disaster.get("end_date").split("-") + endDate = (int(endDate[0])*365) + (int(endDate[1])*30) + (int(endDate[2])) + declared = disaster.get("declared_date").split("-") + declared = (int(declared[0])*365) + (int(declared[1])*30) + (int(declared[2])) + if declared > endDate: + num += 1 + + return num + pass @@ -197,6 +335,20 @@ 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 """ + + agentClaims = {} + + for claim in self.get_claim_data(): + if claim.get("claim_handler_assigned_id") in agentClaims: + agentClaims[claim.get("claim_handler_assigned_id")] += claim.get("estimate_cost") + else: + agentClaims[claim.get("claim_handler_assigned_id")] = claim.get("estimate_cost") + + for agent in self.get_agent_data(): + if agent.get("id") not in agentClaims: + agentClaims[agent.get("id")] = 0 + + return agentClaims pass @@ -214,6 +366,20 @@ 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 """ + + count = 0 + area = 0 + + for disaster in self.get_disaster_data(): + if disaster.get("id") == disaster_id: + count+= 1 + area += (disaster.get("radius_miles"))*3.14 + + if count == 0: + return None + return count/area + + pass # endregion @@ -221,10 +387,7 @@ def calculate_disaster_claim_density(self, disaster_id): # 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 @@ -238,3 +401,4 @@ def get_top_three_months_with_highest_num_of_claims_desc(self): pass # endregion + #get_num_closed_claims(self=self)