From c2197f52229ae5bd634febefd0b685874336766d Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 21:36:24 -0500 Subject: [PATCH 01/11] init my branch --- .../controller/SimpleDataTool.java | 320 +++++++++++++++++- 1 file changed, 307 insertions(+), 13 deletions(-) diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java index 046dd56..0438eb6 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java @@ -1,5 +1,11 @@ package com.statefarm.codingcompetition.simpledatatool.controller; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +64,14 @@ public List getDisasters() { * @return number of closed claims */ public int getNumClosedClaims() { - return 0; + List claims = getClaims(); + int numClosedClaims = 0; + for (Claim claim : claims) { + if (claim.getStatus().equals("Closed")) { + numClosedClaims++; + } + } + return numClosedClaims; } /** @@ -68,7 +81,14 @@ public int getNumClosedClaims() { * @return number of claims assigned to claim handler */ public int getNumClaimsForClaimHandlerId(int id) { - return 0; + List claims = getClaims(); + int numClaimsForClaimHandlerId = 0; + for (Claim claim : claims) { + if (claim.getClaim_handler_assigned_id() == id) { + numClaimsForClaimHandlerId++; + } + } + return numClaimsForClaimHandlerId; } /** @@ -79,7 +99,14 @@ public int getNumClaimsForClaimHandlerId(int id) { * @return number of disasters for state */ public int getNumDisastersForState(String stateName) { - return -1; + List disasters = getDisasters(); + int numDisastersForState = 0; + for (Disaster disaster : disasters) { + if (disaster.getState().equals(stateName)) { + numDisastersForState++; + } + } + return numDisastersForState; } // endregion @@ -94,9 +121,33 @@ public int getNumDisastersForState(String stateName) { * returns null if no claims are found */ public Float getTotalClaimCostForDisaster(int id) { - return -0.01f; + List claims = getClaims(); + + // Map of disaster to cost + Map disasterToCost = new HashMap(); + + for (Claim claim : claims) { + int disasterId = claim.getDisaster_id(); + float claimCost = claim.getEstimate_cost(); + + if (disasterToCost.containsKey(disasterId)) { + float newCost = disasterToCost.get(disasterId) + claimCost; + disasterToCost.put(disasterId, newCost); + } else { + disasterToCost.put(disasterId, claimCost); + } + } + + if (disasterToCost.containsKey(id)) { + BigDecimal bd = new BigDecimal(Float.toString(disasterToCost.get(id))); + bd = bd.setScale(2, RoundingMode.HALF_UP); + return bd.floatValue(); + } else { + return null; + } } + /** * Gets the average estimated cost of all claims assigned to a claim handler * @@ -105,7 +156,34 @@ public Float getTotalClaimCostForDisaster(int id) { * or null if no claims are found */ public Float getAverageClaimCostforClaimHandler(int id) { - return -0.01f; + List claims = getClaims(); + + // Map of claim handler to cost + Map claimHandlerToCost = new HashMap(); + + for (Claim claim : claims) { + int claimHandlerId = claim.getClaim_handler_assigned_id(); + float claimCost = claim.getEstimate_cost(); + + if (claimHandlerToCost.containsKey(claimHandlerId)) { + float newCost = claimHandlerToCost.get(claimHandlerId) + claimCost; + claimHandlerToCost.put(claimHandlerId, newCost); + } else { + claimHandlerToCost.put(claimHandlerId, claimCost); + } + } + + if (claimHandlerToCost.containsKey(id)) { + int numClaims = getNumClaimsForClaimHandlerId(id); + float totalCost = claimHandlerToCost.get(id); + float averageCost = totalCost / numClaims; + + BigDecimal bd = new BigDecimal(Float.toString(averageCost)); + bd = bd.setScale(2, RoundingMode.HALF_UP); + return bd.floatValue(); + } else { + return null; + } } /** @@ -121,7 +199,39 @@ public Float getAverageClaimCostforClaimHandler(int id) { * @return single name of state */ public String getStateWithTheMostDisasters() { - return null; + List statesWithMostDisasters = new ArrayList(); + List disasters = getDisasters(); + + // Map of state to number of disasters + Map stateToNumDisasters = new HashMap(); + + for (Disaster disaster : disasters) { + String state = disaster.getState(); + + if (stateToNumDisasters.containsKey(state)) { + int newNumDisasters = stateToNumDisasters.get(state) + 1; + stateToNumDisasters.put(state, newNumDisasters); + } else { + stateToNumDisasters.put(state, 1); + } + } + + int maxNumDisasters = 0; + + for (String state : stateToNumDisasters.keySet()) { + int numDisasters = stateToNumDisasters.get(state); + + if (numDisasters > maxNumDisasters) { + maxNumDisasters = numDisasters; + statesWithMostDisasters.clear(); + statesWithMostDisasters.add(state); + } else if (numDisasters == maxNumDisasters) { + statesWithMostDisasters.add(state); + } + } + + statesWithMostDisasters.sort(String::compareToIgnoreCase); + return statesWithMostDisasters.get(0); } /** @@ -137,7 +247,39 @@ public String getStateWithTheMostDisasters() { * @return single name of state */ public String getStateWithTheLeastDisasters() { - return null; + List statesWithLeastDisasters = new ArrayList(); + List disasters = getDisasters(); + + // Map of state to number of disasters + Map stateToNumDisasters = new HashMap(); + + for (Disaster disaster : disasters) { + String state = disaster.getState(); + + if (stateToNumDisasters.containsKey(state)) { + int newNumDisasters = stateToNumDisasters.get(state) + 1; + stateToNumDisasters.put(state, newNumDisasters); + } else { + stateToNumDisasters.put(state, 1); + } + } + + int maxNumDisasters = Integer.MAX_VALUE; + + for (String state : stateToNumDisasters.keySet()) { + int numDisasters = stateToNumDisasters.get(state); + + if (numDisasters < maxNumDisasters) { + maxNumDisasters = numDisasters; + statesWithLeastDisasters.clear(); + statesWithLeastDisasters.add(state); + } else if (numDisasters == maxNumDisasters) { + statesWithLeastDisasters.add(state); + } + } + + statesWithLeastDisasters.sort(String::compareToIgnoreCase); + return statesWithLeastDisasters.get(0); } /** @@ -149,7 +291,51 @@ public String getStateWithTheLeastDisasters() { * or empty string if state doesn't exist */ public String getMostSpokenAgentLanguageByState(String string) { - return null; + List agents = getAgents(); + Map languageToNumAgents = new HashMap(); + + for (Agent agent : agents) { + String state = agent.getState(); + String language1 = agent.getPrimary_language(); + String language2 = agent.getSecondary_language(); + + if (state.equalsIgnoreCase(string)) { + // Add primary language to map + if (!language1.equalsIgnoreCase("English")) { + if (languageToNumAgents.containsKey(language1)) { + int newNumAgents = languageToNumAgents.get(language1) + 1; + languageToNumAgents.put(language1, newNumAgents); + } else { + languageToNumAgents.put(language1, 1); + } + } + + // Add secondary language to map + if (!language2.equalsIgnoreCase("English")) { + if (languageToNumAgents.containsKey(language2)) { + int newNumAgents = languageToNumAgents.get(language2) + 1; + languageToNumAgents.put(language2, newNumAgents); + } else { + languageToNumAgents.put(language2, 1); + } + } + } + } + + int maxNumAgents = 0; + String mostSpokenLanguage = ""; + + for (String language : languageToNumAgents.keySet()) { + int numAgents = languageToNumAgents.get(language); + + if (numAgents > maxNumAgents) { + maxNumAgents = numAgents; + mostSpokenLanguage = language; + } + } + + return mostSpokenLanguage; + } /** @@ -166,7 +352,35 @@ public String getMostSpokenAgentLanguageByState(String string) { * null if agent does not exist, or agent has no claims (open or not) */ public Integer getNumOfOpenClaimsForAgentAndSeverity(int agentId, int minSeverityRating) { - return -2; + if (minSeverityRating < 1 || minSeverityRating > 10) { + return -1; + } + + List claims = getClaims(); + + // Map of agent to number of open claims + Map agentToNumOpenClaims = new HashMap(); + + for (Claim claim : claims) { + int claimAgentId = claim.getAgent_assigned_id(); + int claimSeverityRating = claim.getSeverity_rating(); + String claimStatus = claim.getStatus(); + + if (claimAgentId == agentId && claimSeverityRating >= minSeverityRating && !claimStatus.equals("Closed")) { + if (agentToNumOpenClaims.containsKey(claimAgentId)) { + int newNumOpenClaims = agentToNumOpenClaims.get(claimAgentId) + 1; + agentToNumOpenClaims.put(claimAgentId, newNumOpenClaims); + } else { + agentToNumOpenClaims.put(claimAgentId, 1); + } + } + } + + if (agentToNumOpenClaims.containsKey(agentId)) { + return agentToNumOpenClaims.get(agentId); + } else { + return null; + } } // endregion @@ -179,7 +393,18 @@ public Integer getNumOfOpenClaimsForAgentAndSeverity(int agentId, int minSeverit * @return number of disasters where the declared date is after the end date */ public int getNumDisastersDeclaredAfterEndDate() { - return -1; + List disasters = getDisasters(); + int numDisastersDeclaredAfterEndDate = 0; + + for (Disaster disaster : disasters) { + LocalDate declaredDate = disaster.getDeclared_date(); + LocalDate endDate = disaster.getEnd_date(); + + if (declaredDate.isAfter(endDate)) { + numDisastersDeclaredAfterEndDate++; + } + } + return numDisastersDeclaredAfterEndDate; } /** @@ -194,7 +419,33 @@ public int getNumDisastersDeclaredAfterEndDate() { * to the agent */ public Map buildMapOfAgentsToTotalClaimCost() { - return null; + Map agentToTotalClaimCost = new HashMap(); + List claims = getClaims(); + List agents = getAgents(); + + // Pre-Populate map with all agents + for (Agent agent : agents) { + Integer agentId = agent.getId(); + agentToTotalClaimCost.put(agentId, 0.0f); + } + + for (Claim claim : claims) { + int agentId = claim.getAgent_assigned_id(); + Float claimCost = claim.getEstimate_cost(); + + if (agentToTotalClaimCost.containsKey(agentId)) { + // DecimalFormat df = new DecimalFormat("0.00"); + // String claimCostString = df.format(claimCost); + // claimCost = Float.parseFloat(claimCostString); + // float newTotalClaimCost = agentToTotalClaimCost.get(agentId) + claimCost; + Float newTotalClaimCost = Float.sum(agentToTotalClaimCost.get(agentId), claimCost); + agentToTotalClaimCost.put(agentId, newTotalClaimCost); + } else { + agentToTotalClaimCost.put(agentId, claimCost); + } + } + + return agentToTotalClaimCost; } /** @@ -210,8 +461,50 @@ public Map buildMapOfAgentsToTotalClaimCost() { * thousandths place * null if disaster does not exist */ - public float calculateDisasterClaimDensity(int id) { - return -0.01f; + public Float calculateDisasterClaimDensity(int id) { + List claims = getClaims(); + List disasters = getDisasters(); + + // Map of disaster to claims + Map> disasterToClaims = new HashMap>(); + + for (Claim claim : claims) { + int disasterId = claim.getDisaster_id(); + + if (disasterToClaims.containsKey(disasterId)) { + List newClaims = disasterToClaims.get(disasterId); + newClaims.add(claim); + disasterToClaims.put(disasterId, newClaims); + } else { + List newClaims = new ArrayList(); + newClaims.add(claim); + disasterToClaims.put(disasterId, newClaims); + } + } + + // Map of disaster to impact radius + Map disasterToImpactRadius = new HashMap(); + + for (Disaster disaster : disasters) { + int disasterId = disaster.getId(); + float impactRadius = disaster.getRadius_miles(); + + disasterToImpactRadius.put(disasterId, impactRadius); + } + + if (disasterToClaims.containsKey(id)) { + List claimsForDisaster = disasterToClaims.get(id); + float impactRadius = disasterToImpactRadius.get(id); + float area = (float) (Math.PI * Math.pow(impactRadius, 2)); + float density = claimsForDisaster.size() / area; + + BigDecimal bd = new BigDecimal(Float.toString(density)); + bd = bd.setScale(5, RoundingMode.HALF_UP); + return bd.floatValue(); + } else { + return null; + } + } // endregion @@ -229,6 +522,7 @@ public float calculateDisasterClaimDensity(int id) { * @return three strings of month and year, descending order of highest claims */ public String[] getTopThreeMonthsWithHighestNumOfClaimsDesc() { + return new String[1]; } From 765eeeb6bfa7aac0a67014d04af79a1fe07a83ca Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 22:13:23 -0500 Subject: [PATCH 02/11] 11 test cases passed --- .vscode/settings.json | 3 ++ FEEDBACK.md | 21 +++++++--- java/pom.xml | 26 +++++++++++- .../statefarm/codingcompetition/RestApi.java | 11 +++++ .../codingcompetition/RestEntryPoint.java | 40 +++++++++++++++++++ 5 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 java/src/main/java/com/statefarm/codingcompetition/RestApi.java create mode 100644 java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..385f27a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} diff --git a/FEEDBACK.md b/FEEDBACK.md index 010fecd..9be5f22 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -1,13 +1,22 @@ # Feedback -1. Your team: -2. Name of each individual participating: -3. How many unit tests were you able to pass? +1. Your team: Preston Roesslet +2. Name of each individual participating: Preston Roesslet +3. How many unit tests were you able to pass? 4. Document and describe any enhancements included to help the judges properly grade your submission. - - Example One - - Example Two - - Example Three + + I implemented a REST Api to interact with the data from the problem set. I utilized Spring Boot. + + The Spring Boot application runs from the RestApi class. I then created all of the endpoints inside of the RestEntryPoint.java file. + + To run the Spring Boot application, run `mvn spring-boot:run`. It runs on localhost:8080 and below are a list of the available endpoints: + + - /numberClosedClaims - returns the number of claims where the status is closed + - /numClaims/{id} - returns the number of claims associated with the given claim handler ID + - /numDisasters/{state} - returns the number of disasters in the given state + - /disasterTotalCost/{id} - returns the total claim cost for the given disaster ID 5. Any feedback for the coding competition? Things you would like to see in future events? + One thing in particular that I think could be better is ensuring that the test cases and skeleton code are bug free. While I know that programming certainly comes along with bugs, it felt as though there were many issues, some of which weren't being resolved until towards the end of the competition. 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/java/pom.xml b/java/pom.xml index 2f928ee..cecd240 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -3,6 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.1.4 + + + com.statefarm.codingcompetition Round1Java 1.0.0.0-SNAPSHOT @@ -24,7 +31,24 @@ gson 2.10.1 - + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/java/src/main/java/com/statefarm/codingcompetition/RestApi.java b/java/src/main/java/com/statefarm/codingcompetition/RestApi.java new file mode 100644 index 0000000..0e1a9a3 --- /dev/null +++ b/java/src/main/java/com/statefarm/codingcompetition/RestApi.java @@ -0,0 +1,11 @@ +package com.statefarm.codingcompetition; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestApi { + public static void main(String[] args) { + SpringApplication.run(RestApi.class, args); + } +} diff --git a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java b/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java new file mode 100644 index 0000000..a1cebd6 --- /dev/null +++ b/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java @@ -0,0 +1,40 @@ +package com.statefarm.codingcompetition; + + +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import com.statefarm.codingcompetition.simpledatatool.controller.SimpleDataTool; + +@RestController +public class RestEntryPoint { + + SimpleDataTool dataService = new SimpleDataTool(); + + + @GetMapping("/numberClosedClaims") + public int getNumClosedClaims() { + return dataService.getNumClosedClaims(); + } + + @GetMapping("/numClaims/{id}") + public int getNumClaims(@PathVariable("id") int id) { + return dataService.getNumClaimsForClaimHandlerId(id); + } + + @GetMapping("/numDisasters/{state}") + public int getNumDisasters(@PathVariable("state") String state) { + return dataService.getNumDisastersForState(state); + } + + @GetMapping("/disasterTotalCost/{id}") + public Float getDisasterTotalCost(@PathVariable("id") int id) { + return dataService.getTotalClaimCostForDisaster(id); + } +} + From 63227816995d7993bc64b801c4cd59b6e0c276d3 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 22:14:23 -0500 Subject: [PATCH 03/11] removed unnecessary imports --- .../java/com/statefarm/codingcompetition/RestEntryPoint.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java b/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java index a1cebd6..d4fef83 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java +++ b/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java @@ -1,12 +1,7 @@ package com.statefarm.codingcompetition; - -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import com.statefarm.codingcompetition.simpledatatool.controller.SimpleDataTool; From a1e4a8bd9ccf4951cae01fc96f51356158fe7c67 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 22:32:49 -0500 Subject: [PATCH 04/11] Started REST API --- FEEDBACK.md | 6 +++ .../codingcompetition/RestEntryPoint.java | 37 +++++++++++++++++++ .../controller/SimpleDataTool.java | 3 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/FEEDBACK.md b/FEEDBACK.md index 9be5f22..0f72be6 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -15,6 +15,12 @@ - /numClaims/{id} - returns the number of claims associated with the given claim handler ID - /numDisasters/{state} - returns the number of disasters in the given state - /disasterTotalCost/{id} - returns the total claim cost for the given disaster ID + - /averageClaimCost/{id} - returns the average claim cost for the given claim handler ID + - /stateWithMostDisasters - returns the state with the highest number of disasters + - /stateWithLeastDisasters - returns the state with the highest number of disasters + - /mostSpokenLanguage/{state} - returns the language spoken most by claim handlers in the given state + - /numOpenClaims/{id}/{minSeverity} - returns the number of open claims for the given agent ID and above the given minimum severity + - /numDistastersDeclaredAfterEndDate - returns the number of disasters where it was declared after it ended 5. Any feedback for the coding competition? Things you would like to see in future events? One thing in particular that I think could be better is ensuring that the test cases and skeleton code are bug free. While I know that programming certainly comes along with bugs, it felt as though there were many issues, some of which weren't being resolved until towards the end of the competition. diff --git a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java b/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java index d4fef83..175e91b 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java +++ b/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java @@ -31,5 +31,42 @@ public int getNumDisasters(@PathVariable("state") String state) { public Float getDisasterTotalCost(@PathVariable("id") int id) { return dataService.getTotalClaimCostForDisaster(id); } + + @GetMapping("/averageClaimCost/{id}") + public Float getAverageClaimCost(@PathVariable("id") int id) { + return dataService.getAverageClaimCostforClaimHandler(id); + } + + @GetMapping("/stateWithMostDisasters") + public String getStateWithMostDisasters() { + return dataService.getStateWithTheMostDisasters(); + } + + @GetMapping("/stateWithLeastDisasters") + public String getStateWithLeastDisasters() { + return dataService.getStateWithTheLeastDisasters(); + } + + @GetMapping("/mostSpokenLanguage/{state}") + public String getMostSpokenLanguage(@PathVariable("state") String state) { + return dataService.getMostSpokenAgentLanguageByState(state); + } + + @GetMapping("/numOpenClaims/{id}/{minSeverity}") + public int getNumOpenClaims(@PathVariable("id") int id, @PathVariable("minSeverity") int minSeverity) { + return dataService.getNumOfOpenClaimsForAgentAndSeverity(id, minSeverity); + } + + @GetMapping("/numDistastersDeclaredAfterEndDate") + public int getNumDistastersDeclaredAfterEndDate() { + return dataService.getNumDisastersDeclaredAfterEndDate(); + } + + // Map method?? + + @GetMapping("/disasterClaimDensity/{id}") + public Float getDisasterClaimDensity(@PathVariable("id") int id) { + return dataService.calculateDisasterClaimDensity(id); + } } diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java index 53687bd..8fa2e4a 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java @@ -525,8 +525,7 @@ public Float calculateDisasterClaimDensity(int id) { * @return three strings of month and year, descending order of highest claims */ public String[] getTopThreeMonthsWithHighestNumOfClaimsDesc() { - - return new String[1]; + return new String[3]; } // endregion From 255876ebd260ed05069de6acf1e8b396e8b4b9fa Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:15:17 -0500 Subject: [PATCH 05/11] completed REST API --- FEEDBACK.md | 12 +++--- java/pom.xml | 17 ++++---- ...RestEntryPoint.java => ApiController.java} | 13 ++++-- .../controller/SimpleDataTool.java | 41 +++++++++---------- .../simpledatatool/model/Claim.java | 6 +-- 5 files changed, 48 insertions(+), 41 deletions(-) rename java/src/main/java/com/statefarm/codingcompetition/{RestEntryPoint.java => ApiController.java} (86%) diff --git a/FEEDBACK.md b/FEEDBACK.md index 0f72be6..468c294 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -2,14 +2,12 @@ 1. Your team: Preston Roesslet 2. Name of each individual participating: Preston Roesslet -3. How many unit tests were you able to pass? +3. How many unit tests were you able to pass? 13 4. Document and describe any enhancements included to help the judges properly grade your submission. - I implemented a REST Api to interact with the data from the problem set. I utilized Spring Boot. + I implemented a REST Api to interact with the data from the problem set. I utilized Spring Boot. The Spring Boot application is initialized in the RestApi class. I then created all of the endpoints inside of the ApiController.java file. - The Spring Boot application runs from the RestApi class. I then created all of the endpoints inside of the RestEntryPoint.java file. - - To run the Spring Boot application, run `mvn spring-boot:run`. It runs on localhost:8080 and below are a list of the available endpoints: + To run the Spring Boot application, run `mvn spring-boot:run`. The required packages have already been added to my pom.xml file. It runs on localhost:8080 and below is a list of the available endpoints: - /numberClosedClaims - returns the number of claims where the status is closed - /numClaims/{id} - returns the number of claims associated with the given claim handler ID @@ -21,6 +19,10 @@ - /mostSpokenLanguage/{state} - returns the language spoken most by claim handlers in the given state - /numOpenClaims/{id}/{minSeverity} - returns the number of open claims for the given agent ID and above the given minimum severity - /numDistastersDeclaredAfterEndDate - returns the number of disasters where it was declared after it ended + - /agentsTotalClaimCost - returns a map of agent ID's and their total claim cost + - /disasterClaimDensity/{id} - returns the density of the given disaster ID based on the number of claims and the impact radius + + This could be further extended to include persistent data through a database rather than json files, or even creating a front end to view/edit the data. However, given the time constraints for this competition, this were not feasible to implement. 5. Any feedback for the coding competition? Things you would like to see in future events? One thing in particular that I think could be better is ensuring that the test cases and skeleton code are bug free. While I know that programming certainly comes along with bugs, it felt as though there were many issues, some of which weren't being resolved until towards the end of the competition. diff --git a/java/pom.xml b/java/pom.xml index cecd240..96f2b5b 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -3,13 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.1.4 - - - com.statefarm.codingcompetition Round1Java 1.0.0.0-SNAPSHOT @@ -34,12 +27,21 @@ org.springframework.boot spring-boot-starter-web + 3.1.4 org.springframework.boot spring-boot-starter-test test + 3.1.4 + + + org.junit.vintage + junit-vintage-engine + 5.10.0 + test + @@ -47,6 +49,7 @@ org.springframework.boot spring-boot-maven-plugin + 3.1.4 diff --git a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java b/java/src/main/java/com/statefarm/codingcompetition/ApiController.java similarity index 86% rename from java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java rename to java/src/main/java/com/statefarm/codingcompetition/ApiController.java index 175e91b..9947228 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/RestEntryPoint.java +++ b/java/src/main/java/com/statefarm/codingcompetition/ApiController.java @@ -1,5 +1,7 @@ package com.statefarm.codingcompetition; +import java.util.Map; + import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -7,7 +9,7 @@ import com.statefarm.codingcompetition.simpledatatool.controller.SimpleDataTool; @RestController -public class RestEntryPoint { +public class ApiController { SimpleDataTool dataService = new SimpleDataTool(); @@ -28,12 +30,12 @@ public int getNumDisasters(@PathVariable("state") String state) { } @GetMapping("/disasterTotalCost/{id}") - public Float getDisasterTotalCost(@PathVariable("id") int id) { + public Double getDisasterTotalCost(@PathVariable("id") int id) { return dataService.getTotalClaimCostForDisaster(id); } @GetMapping("/averageClaimCost/{id}") - public Float getAverageClaimCost(@PathVariable("id") int id) { + public Double getAverageClaimCost(@PathVariable("id") int id) { return dataService.getAverageClaimCostforClaimHandler(id); } @@ -62,7 +64,10 @@ public int getNumDistastersDeclaredAfterEndDate() { return dataService.getNumDisastersDeclaredAfterEndDate(); } - // Map method?? + @GetMapping("/agentsTotalClaimCost") + public Map getAgentsTotalClaimCost() { + return dataService.buildMapOfAgentsToTotalClaimCost(); + } @GetMapping("/disasterClaimDensity/{id}") public Float getDisasterClaimDensity(@PathVariable("id") int id) { diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java index 8fa2e4a..310cda7 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java @@ -120,18 +120,18 @@ public int getNumDisastersForState(String stateName) { * @return estimate cost of disaster, rounded to the nearest hundredths place * returns null if no claims are found */ - public Float getTotalClaimCostForDisaster(int id) { + public Double getTotalClaimCostForDisaster(int id) { List claims = getClaims(); // Map of disaster to cost - Map disasterToCost = new HashMap(); + Map disasterToCost = new HashMap(); for (Claim claim : claims) { int disasterId = claim.getDisaster_id(); - float claimCost = claim.getEstimate_cost(); + Double claimCost = claim.getEstimate_cost(); if (disasterToCost.containsKey(disasterId)) { - float newCost = disasterToCost.get(disasterId) + claimCost; + Double newCost = disasterToCost.get(disasterId) + claimCost; disasterToCost.put(disasterId, newCost); } else { disasterToCost.put(disasterId, claimCost); @@ -139,9 +139,9 @@ public Float getTotalClaimCostForDisaster(int id) { } if (disasterToCost.containsKey(id)) { - BigDecimal bd = new BigDecimal(Float.toString(disasterToCost.get(id))); + BigDecimal bd = new BigDecimal(disasterToCost.get(id)); bd = bd.setScale(2, RoundingMode.HALF_UP); - return bd.floatValue(); + return bd.doubleValue(); } else { return null; } @@ -155,18 +155,18 @@ public Float getTotalClaimCostForDisaster(int id) { * @return average cost of claims, rounded to the nearest hundredths place, * or null if no claims are found */ - public Float getAverageClaimCostforClaimHandler(int id) { + public Double getAverageClaimCostforClaimHandler(int id) { List claims = getClaims(); // Map of claim handler to cost - Map claimHandlerToCost = new HashMap(); + Map claimHandlerToCost = new HashMap(); for (Claim claim : claims) { int claimHandlerId = claim.getClaim_handler_assigned_id(); - float claimCost = claim.getEstimate_cost(); + Double claimCost = claim.getEstimate_cost(); if (claimHandlerToCost.containsKey(claimHandlerId)) { - float newCost = claimHandlerToCost.get(claimHandlerId) + claimCost; + Double newCost = claimHandlerToCost.get(claimHandlerId) + claimCost; claimHandlerToCost.put(claimHandlerId, newCost); } else { claimHandlerToCost.put(claimHandlerId, claimCost); @@ -175,12 +175,12 @@ public Float getAverageClaimCostforClaimHandler(int id) { if (claimHandlerToCost.containsKey(id)) { int numClaims = getNumClaimsForClaimHandlerId(id); - float totalCost = claimHandlerToCost.get(id); - float averageCost = totalCost / numClaims; + Double totalCost = claimHandlerToCost.get(id); + Double averageCost = totalCost / numClaims; - BigDecimal bd = new BigDecimal(Float.toString(averageCost)); + BigDecimal bd = new BigDecimal(averageCost); bd = bd.setScale(2, RoundingMode.HALF_UP); - return bd.floatValue(); + return bd.doubleValue(); } else { return null; } @@ -431,17 +431,14 @@ public Map buildMapOfAgentsToTotalClaimCost() { for (Claim claim : claims) { int agentId = claim.getAgent_assigned_id(); - Float claimCost = claim.getEstimate_cost(); + Double claimCost = claim.getEstimate_cost(); if (agentToTotalClaimCost.containsKey(agentId)) { - // DecimalFormat df = new DecimalFormat("0.00"); - // String claimCostString = df.format(claimCost); - // claimCost = Float.parseFloat(claimCostString); - // float newTotalClaimCost = agentToTotalClaimCost.get(agentId) + claimCost; - Float newTotalClaimCost = Float.sum(agentToTotalClaimCost.get(agentId), claimCost); - agentToTotalClaimCost.put(agentId, newTotalClaimCost); + Float prevCost = agentToTotalClaimCost.get(agentId); + Float newCost = prevCost + claimCost.floatValue(); + agentToTotalClaimCost.put(agentId, newCost); } else { - agentToTotalClaimCost.put(agentId, claimCost); + agentToTotalClaimCost.put(agentId, claimCost.floatValue()); } } diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java index db223d9..70e943e 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/model/Claim.java @@ -7,7 +7,7 @@ public class Claim { private static final Gson GSON = new Gson(); private int id, disaster_id, severity_rating, agent_assigned_id, claim_handler_assigned_id; - private float estimate_cost; + private Double estimate_cost; private boolean total_loss, loss_of_life; private String status, type; @@ -51,11 +51,11 @@ public void setClaim_handler_assigned_id(int claim_handler_assigned_id) { this.claim_handler_assigned_id = claim_handler_assigned_id; } - public float getEstimate_cost() { + public Double getEstimate_cost() { return this.estimate_cost; } - public void setEstimate_cost(float estimate_cost) { + public void setEstimate_cost(Double estimate_cost) { this.estimate_cost = estimate_cost; } From 8a962d3b1d44d68c4d14737d492d274130378584 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:21:09 -0500 Subject: [PATCH 06/11] Added logger for Spring --- java/pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/java/pom.xml b/java/pom.xml index 96f2b5b..6ddd6fe 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -42,6 +42,16 @@ 5.10.0 test + + org.slf4j + slf4j-api + 2.0.9 + + + org.slf4j + slf4j-simple + 2.0.9 + From 8f1ea0f773de7acd4be9e02f255e90090a6615f3 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:28:34 -0500 Subject: [PATCH 07/11] code cleanup --- .../controller/SimpleDataTool.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java index 310cda7..ba53d77 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java @@ -2,7 +2,6 @@ import java.math.BigDecimal; import java.math.RoundingMode; -import java.text.DecimalFormat; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; @@ -66,11 +65,14 @@ public List getDisasters() { public int getNumClosedClaims() { List claims = getClaims(); int numClosedClaims = 0; + + // If claim is closed, increment counter for (Claim claim : claims) { if (claim.getStatus().equals("Closed")) { numClosedClaims++; } } + return numClosedClaims; } @@ -83,11 +85,14 @@ public int getNumClosedClaims() { public int getNumClaimsForClaimHandlerId(int id) { List claims = getClaims(); int numClaimsForClaimHandlerId = 0; + + // If claim handler id matches, increment counter for (Claim claim : claims) { if (claim.getClaim_handler_assigned_id() == id) { numClaimsForClaimHandlerId++; } } + return numClaimsForClaimHandlerId; } @@ -101,11 +106,14 @@ public int getNumClaimsForClaimHandlerId(int id) { public int getNumDisastersForState(String stateName) { List disasters = getDisasters(); int numDisastersForState = 0; + + // If state name matches, increment counter for (Disaster disaster : disasters) { if (disaster.getState().equals(stateName)) { numDisastersForState++; } } + return numDisastersForState; } @@ -126,6 +134,7 @@ public Double getTotalClaimCostForDisaster(int id) { // Map of disaster to cost Map disasterToCost = new HashMap(); + // Populate map with all disasters for (Claim claim : claims) { int disasterId = claim.getDisaster_id(); Double claimCost = claim.getEstimate_cost(); @@ -138,6 +147,7 @@ public Double getTotalClaimCostForDisaster(int id) { } } + // Return cost if disaster exists, otherwise return null if (disasterToCost.containsKey(id)) { BigDecimal bd = new BigDecimal(disasterToCost.get(id)); bd = bd.setScale(2, RoundingMode.HALF_UP); @@ -161,6 +171,7 @@ public Double getAverageClaimCostforClaimHandler(int id) { // Map of claim handler to cost Map claimHandlerToCost = new HashMap(); + // Populate map with all claim handlers for (Claim claim : claims) { int claimHandlerId = claim.getClaim_handler_assigned_id(); Double claimCost = claim.getEstimate_cost(); @@ -173,6 +184,7 @@ public Double getAverageClaimCostforClaimHandler(int id) { } } + // Return average cost if claim handler exists, otherwise return null if (claimHandlerToCost.containsKey(id)) { int numClaims = getNumClaimsForClaimHandlerId(id); Double totalCost = claimHandlerToCost.get(id); @@ -180,6 +192,7 @@ public Double getAverageClaimCostforClaimHandler(int id) { BigDecimal bd = new BigDecimal(averageCost); bd = bd.setScale(2, RoundingMode.HALF_UP); + return bd.doubleValue(); } else { return null; @@ -205,6 +218,7 @@ public String getStateWithTheMostDisasters() { // Map of state to number of disasters Map stateToNumDisasters = new HashMap(); + // Populate map with all states and number of disasters for (Disaster disaster : disasters) { String state = disaster.getState(); @@ -216,6 +230,7 @@ public String getStateWithTheMostDisasters() { } } + // Find max number of disasters. Uses a list in case of ties int maxNumDisasters = 0; for (String state : stateToNumDisasters.keySet()) { @@ -230,6 +245,7 @@ public String getStateWithTheMostDisasters() { } } + // If there is a tie, we will have a list of states. Sort and return the first one alphabetically statesWithMostDisasters.sort(String::compareToIgnoreCase); return statesWithMostDisasters.get(0); } @@ -253,6 +269,7 @@ public String getStateWithTheLeastDisasters() { // Map of state to number of disasters Map stateToNumDisasters = new HashMap(); + // Populate map with all states and number of disasters for (Disaster disaster : disasters) { String state = disaster.getState(); @@ -264,6 +281,7 @@ public String getStateWithTheLeastDisasters() { } } + // Find the minimum number of disasters. Uses a list in case of ties int maxNumDisasters = Integer.MAX_VALUE; for (String state : stateToNumDisasters.keySet()) { @@ -278,6 +296,7 @@ public String getStateWithTheLeastDisasters() { } } + // If there is a tie, we will have a list of states. Sort and return the first one alphabetically statesWithLeastDisasters.sort(String::compareToIgnoreCase); return statesWithLeastDisasters.get(0); } @@ -294,13 +313,17 @@ public String getMostSpokenAgentLanguageByState(String string) { List agents = getAgents(); Map languageToNumAgents = new HashMap(); + // Loop through all agents to populate the map for (Agent agent : agents) { String state = agent.getState(); + + // Gets the primary and secondary language of the agent String language1 = agent.getPrimary_language(); String language2 = agent.getSecondary_language(); + // If state matches, add languages to map if (state.equalsIgnoreCase(string)) { - // Add primary language to map + // Add primary language to map - ignore English if (!language1.equalsIgnoreCase("English")) { if (languageToNumAgents.containsKey(language1)) { int newNumAgents = languageToNumAgents.get(language1) + 1; @@ -310,7 +333,7 @@ public String getMostSpokenAgentLanguageByState(String string) { } } - // Add secondary language to map + // Add secondary language to map ignore English if (!language2.equalsIgnoreCase("English")) { if (languageToNumAgents.containsKey(language2)) { int newNumAgents = languageToNumAgents.get(language2) + 1; @@ -322,6 +345,7 @@ public String getMostSpokenAgentLanguageByState(String string) { } } + // Find the most spoken language int maxNumAgents = 0; String mostSpokenLanguage = ""; @@ -352,6 +376,7 @@ public String getMostSpokenAgentLanguageByState(String string) { * null if agent does not exist, or agent has no claims (open or not) */ public Integer getNumOfOpenClaimsForAgentAndSeverity(int agentId, int minSeverityRating) { + // If rating is out of bounds, return -1 if (minSeverityRating < 1 || minSeverityRating > 10) { return -1; } @@ -396,6 +421,7 @@ public int getNumDisastersDeclaredAfterEndDate() { List disasters = getDisasters(); int numDisastersDeclaredAfterEndDate = 0; + // Loop through disasters and increment counter if declared date is after end date for (Disaster disaster : disasters) { LocalDate declaredDate = disaster.getDeclared_date(); LocalDate endDate = disaster.getEnd_date(); @@ -404,6 +430,7 @@ public int getNumDisastersDeclaredAfterEndDate() { numDisastersDeclaredAfterEndDate++; } } + return numDisastersDeclaredAfterEndDate; } @@ -429,6 +456,7 @@ public Map buildMapOfAgentsToTotalClaimCost() { agentToTotalClaimCost.put(agentId, 0.0f); } + // Loop through claims and add cost to agent's total claim cost for (Claim claim : claims) { int agentId = claim.getAgent_assigned_id(); Double claimCost = claim.getEstimate_cost(); @@ -465,6 +493,7 @@ public Float calculateDisasterClaimDensity(int id) { // Map of disaster to claims Map> disasterToClaims = new HashMap>(); + // Populate map with all disasters for (Claim claim : claims) { int disasterId = claim.getDisaster_id(); @@ -489,6 +518,7 @@ public Float calculateDisasterClaimDensity(int id) { disasterToImpactRadius.put(disasterId, impactRadius); } + // If disaster exists, calculate density, otherwise return null if (disasterToClaims.containsKey(id)) { List claimsForDisaster = disasterToClaims.get(id); float impactRadius = disasterToImpactRadius.get(id); From 62433b312036814e42b4a07cb8617ed10e2bb7c0 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:35:20 -0500 Subject: [PATCH 08/11] Final comments --- .../simpledatatool/controller/SimpleDataTool.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java index ba53d77..1b4bceb 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java @@ -446,6 +446,12 @@ public int getNumDisastersDeclaredAfterEndDate() { * to the agent */ public Map buildMapOfAgentsToTotalClaimCost() { + /* + Note - I believe the return type here should be a Map due to Issue #9, however + I left it as is since we are not allowed to change the test files and the test case expects + a Map to be returned + */ + Map agentToTotalClaimCost = new HashMap(); List claims = getClaims(); List agents = getAgents(); From 79744d0164ab58d7d22a9d3685bdcf47bbd416e4 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:37:59 -0500 Subject: [PATCH 09/11] Feedback form completed --- FEEDBACK.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/FEEDBACK.md b/FEEDBACK.md index 468c294..471594d 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -2,7 +2,7 @@ 1. Your team: Preston Roesslet 2. Name of each individual participating: Preston Roesslet -3. How many unit tests were you able to pass? 13 +3. How many unit tests were you able to pass? 13 - However, I believe that I would pass all 14 of them if Issue #9 had been resolved. At the time of my submission, Issue #9 had yet to be resolved. 4. Document and describe any enhancements included to help the judges properly grade your submission. I implemented a REST Api to interact with the data from the problem set. I utilized Spring Boot. The Spring Boot application is initialized in the RestApi class. I then created all of the endpoints inside of the ApiController.java file. @@ -22,9 +22,12 @@ - /agentsTotalClaimCost - returns a map of agent ID's and their total claim cost - /disasterClaimDensity/{id} - returns the density of the given disaster ID based on the number of claims and the impact radius - This could be further extended to include persistent data through a database rather than json files, or even creating a front end to view/edit the data. However, given the time constraints for this competition, this were not feasible to implement. + This could be further extended to include persistent data through a database rather than just json files, or even creating a front end to view/edit the data. However, given the time constraints for this competition, these were not feasible to implement. 5. Any feedback for the coding competition? Things you would like to see in future events? - One thing in particular that I think could be better is ensuring that the test cases and skeleton code are bug free. While I know that programming certainly comes along with bugs, it felt as though there were many issues, some of which weren't being resolved until towards the end of the competition. + + One thing in particular that I think could be better is ensuring that the test cases and skeleton code are bug free. While I know that programming certainly comes along with bugs, it felt as though there were many issues, some of which weren't being resolved until towards the end of the competition. This made it difficult to complete all tasks in an efficient manner and I could not complete one of the test cases at all prior to submission due to this. + + Overall though this was a very fun competition! 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. From d7ea93d162cae0dad7a383b2c83e2b75b7d05046 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:50:32 -0500 Subject: [PATCH 10/11] Additional methods --- FEEDBACK.md | 5 +++++ .../codingcompetition/ApiController.java | 16 +++++++++++++++ .../controller/SimpleDataTool.java | 20 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/FEEDBACK.md b/FEEDBACK.md index 471594d..7c49d2b 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -22,6 +22,11 @@ - /agentsTotalClaimCost - returns a map of agent ID's and their total claim cost - /disasterClaimDensity/{id} - returns the density of the given disaster ID based on the number of claims and the impact radius + I also implemented some additional methods which can be utilized with the following endpoints: + + - /agents - returns a list of all agents + - /claimHandlers - returns a list of all agents + This could be further extended to include persistent data through a database rather than just json files, or even creating a front end to view/edit the data. However, given the time constraints for this competition, these were not feasible to implement. 5. Any feedback for the coding competition? Things you would like to see in future events? diff --git a/java/src/main/java/com/statefarm/codingcompetition/ApiController.java b/java/src/main/java/com/statefarm/codingcompetition/ApiController.java index 9947228..e10616c 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/ApiController.java +++ b/java/src/main/java/com/statefarm/codingcompetition/ApiController.java @@ -1,5 +1,6 @@ package com.statefarm.codingcompetition; +import java.util.List; import java.util.Map; import org.springframework.web.bind.annotation.GetMapping; @@ -7,6 +8,10 @@ import org.springframework.web.bind.annotation.RestController; import com.statefarm.codingcompetition.simpledatatool.controller.SimpleDataTool; +import com.statefarm.codingcompetition.simpledatatool.model.Agent; +import com.statefarm.codingcompetition.simpledatatool.model.Claim; +import com.statefarm.codingcompetition.simpledatatool.model.ClaimHandler; +import com.statefarm.codingcompetition.simpledatatool.model.Disaster; @RestController public class ApiController { @@ -73,5 +78,16 @@ public Map getAgentsTotalClaimCost() { public Float getDisasterClaimDensity(@PathVariable("id") int id) { return dataService.calculateDisasterClaimDensity(id); } + + // Additional endpoints + @GetMapping("/agents") + public List getAgents() { + return dataService.getAgents(); + } + + @GetMapping("/claimHandlers") + public List getClaimHandlers() { + return dataService.getClaimHandlers(); + } } diff --git a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java index 1b4bceb..338cdf8 100644 --- a/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java +++ b/java/src/main/java/com/statefarm/codingcompetition/simpledatatool/controller/SimpleDataTool.java @@ -561,5 +561,25 @@ public String[] getTopThreeMonthsWithHighestNumOfClaimsDesc() { return new String[3]; } + // Additional Methods (not required for competition) + + /** + * Gets all agents + * + * @return list of all agents + */ + public List getAllAgents() { + return getAgents(); + } + + /** + * Gets all claim handlers + * + * @return list of all claim handlers + */ + public List getAllClaimHandlers() { + return getClaimHandlers(); + } + // endregion } From 4228eb298daa9e659bc8e526260868a611081c60 Mon Sep 17 00:00:00 2001 From: Preston Roesslet Date: Sat, 14 Oct 2023 23:51:45 -0500 Subject: [PATCH 11/11] Final changes --- FEEDBACK.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FEEDBACK.md b/FEEDBACK.md index 7c49d2b..3953048 100644 --- a/FEEDBACK.md +++ b/FEEDBACK.md @@ -2,7 +2,7 @@ 1. Your team: Preston Roesslet 2. Name of each individual participating: Preston Roesslet -3. How many unit tests were you able to pass? 13 - However, I believe that I would pass all 14 of them if Issue #9 had been resolved. At the time of my submission, Issue #9 had yet to be resolved. +3. How many unit tests were you able to pass? 13 - However, I believe that I would pass all 14 of them if Issue #9 had been resolved. At the time of my submission, Issue #9 had yet to be resolved, so I wasn't sure how to move forward with Test Set 3 - Test 10 4. Document and describe any enhancements included to help the judges properly grade your submission. I implemented a REST Api to interact with the data from the problem set. I utilized Spring Boot. The Spring Boot application is initialized in the RestApi class. I then created all of the endpoints inside of the ApiController.java file.