Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions FEEDBACK.md
Original file line number Diff line number Diff line change
@@ -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.
26 changes: 25 additions & 1 deletion python/application.py
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
print("I'm working")
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/<id>')
def hello(id):
return "number of claims for this handler is: " + str(sd.get_num_claims_for_claim_handler_id(id)) + "<br>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()) + "<br>state with the most disasters: " + str(sd.get_state_with_most_disasters()) + "<br>state with the least disasters: " + str(sd.get_state_with_least_disasters()) + "<br>number of claims delcared after it already ended: " + str(sd.get_num_disasters_declared_after_end_date())+ "<br><br>All agents and their total cost: " + str(sd.build_map_of_agents_to_total_claim_cost())

if __name__ == '__main__':
app.run(debug=True)
172 changes: 168 additions & 4 deletions python/simple_data_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -214,17 +366,28 @@ 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

# 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
Expand All @@ -238,3 +401,4 @@ def get_top_three_months_with_highest_num_of_claims_desc(self):
pass

# endregion
#get_num_closed_claims(self=self)