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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/2023-StateFarm-CodingCompetition.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions FEEDBACK.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Feedback

1. Your team:
2. Name of each individual participating:
3. How many unit tests were you able to pass?
2. Name of each individual participating: Mahlangu Nzunda, Jaylon Nelson
3. How many unit tests were you able to pass? All unit tests except for the last value for test #4
4. Document and describe any enhancements included to help the judges properly grade your submission.
- Example One
- We had to change the data type of estimate cost for the claims Class from Float to Double because of accuracy errors for one of the tests
- Example Two
- Example Three

5. Any feedback for the coding competition? Things you would like to see in future events?
Participating in this competition has been a wonderful learning experience for us.

Having mentors to offer guidance and feedback on our implementations before we make the final submission would be really helpful for next. Additionally, it would be fantastic to gain exposure to cloud technologies, which are becoming increasingly important in software development.

This form can also be emailed to [[email protected]](mailto:[email protected]). Just make sure that you include a link to your GitHub pull requests.
3 changes: 3 additions & 0 deletions java/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions java/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions java/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions java/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.statefarm.codingcompetition.simpledatatool;

import com.statefarm.codingcompetition.simpledatatool.controller.SimpleDataTool;
import com.statefarm.codingcompetition.simpledatatool.model.Agent;

public class Application {

public static void main(String[] args) {
SimpleDataTool sdt = new SimpleDataTool();

for (Agent agent: sdt.getAgents()) {
System.out.println(agent.getFirst_name());
}
System.out.println("working");
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.statefarm.codingcompetition.simpledatatool.controller;

import java.text.CollationElementIterator;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import com.statefarm.codingcompetition.simpledatatool.io.JsonHelper;
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;

import static java.util.stream.Collectors.toList;

public class SimpleDataTool {

private static final String JSON_FILENAME_AGENTS = "sfcc_2023_agents.json";
Expand Down Expand Up @@ -58,7 +66,7 @@ public List<Disaster> getDisasters() {
* @return number of closed claims
*/
public int getNumClosedClaims() {
return 0;
return (int) this.claims.stream().filter(claim -> claim.getStatus().equals("Closed")).count();
}

/**
Expand All @@ -68,7 +76,7 @@ public int getNumClosedClaims() {
* @return number of claims assigned to claim handler
*/
public int getNumClaimsForClaimHandlerId(int id) {
return 0;
return (int) this.claims.stream().filter(claim -> claim.getClaim_handler_assigned_id() == id ).count();
}

/**
Expand All @@ -79,7 +87,8 @@ public int getNumClaimsForClaimHandlerId(int id) {
* @return number of disasters for state
*/
public int getNumDisastersForState(String stateName) {
return -1;

return (int) this.disasters.stream().filter(disaster -> disaster.getState().equals(stateName)).count();
}

// endregion
Expand All @@ -93,8 +102,11 @@ 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) {
return -0.01f;
public Double getTotalClaimCostForDisaster(int id) {
if (this.claims.stream().anyMatch(claim -> claim.getDisaster_id() == id)) {
return this.claims.stream().filter(claim -> claim.getDisaster_id() == id).mapToDouble(Claim::getEstimate_cost).sum();
}
return null;
}

/**
Expand All @@ -105,7 +117,10 @@ public Float getTotalClaimCostForDisaster(int id) {
* or null if no claims are found
*/
public Float getAverageClaimCostforClaimHandler(int id) {
return -0.01f;
if (this.claims.stream().anyMatch(claim -> claim.getClaim_handler_assigned_id() == id)) {
return (float) this.claims.stream().filter(claim -> claim.getClaim_handler_assigned_id() == id).mapToDouble(Claim::getEstimate_cost).average().orElse(0.0);
}
return null;
}

/**
Expand All @@ -121,7 +136,15 @@ public Float getAverageClaimCostforClaimHandler(int id) {
* @return single name of state
*/
public String getStateWithTheMostDisasters() {
return null;
Map<String, Long> stateAndDisasterCount = this.disasters.stream()
.collect(Collectors.groupingBy(disaster -> disaster.getState(), Collectors.counting()));

List<String> orderedStates = stateAndDisasterCount.entrySet().stream()
.sorted(Map.Entry.<String, Long>comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
.map(Map.Entry::getKey)
.collect(toList());

return orderedStates.get(0);
}

/**
Expand All @@ -137,7 +160,15 @@ public String getStateWithTheMostDisasters() {
* @return single name of state
*/
public String getStateWithTheLeastDisasters() {
return null;
Map<String, Long> stateAndDisasterCount = this.disasters.stream()
.collect(Collectors.groupingBy(disaster -> disaster.getState(), Collectors.counting()));

List<String> orderedStates = stateAndDisasterCount.entrySet().stream()
.sorted(Map.Entry.<String, Long>comparingByValue().thenComparing(Map.Entry.comparingByKey()))
.map(Map.Entry::getKey)
.collect(toList());

return orderedStates.get(0);
}

/**
Expand All @@ -149,7 +180,19 @@ public String getStateWithTheLeastDisasters() {
* or empty string if state doesn't exist
*/
public String getMostSpokenAgentLanguageByState(String string) {
return null;
Map<String, Long> languageCount = this.agents.stream()
.filter(agent -> agent.getState().equals(string))
.collect(Collectors.groupingBy(agent -> agent.getSecondary_language(), Collectors.counting()));

List<String> orderedLanguages = languageCount.entrySet().stream()
.sorted(Map.Entry.<String, Long>comparingByValue().reversed().thenComparing(Map.Entry.comparingByKey()))
.map(Map.Entry::getKey)
.collect(toList());

if (languageCount.size() == 0 || orderedLanguages.get(0) == "null")
return "";

return orderedLanguages.get(0);
}

/**
Expand All @@ -166,7 +209,17 @@ 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;
} else if(this.agents.stream().noneMatch(agent -> agent.getId() == agentId) ||
this.claims.stream().noneMatch(claim -> claim.getAgent_assigned_id() == agentId)) {
return null;
} else {
return (int) this.claims.stream().filter(claim -> claim.getAgent_assigned_id() == agentId
&& !claim.getStatus().equals("Closed") &&
claim.getSeverity_rating() >= minSeverityRating).count();
}

}

// endregion
Expand All @@ -179,7 +232,9 @@ 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;
return (int) this.disasters.stream()
.filter(disaster -> disaster.getDeclared_date().compareTo(disaster.getEnd_date()) > 0)
.count();
}

/**
Expand All @@ -194,7 +249,16 @@ public int getNumDisastersDeclaredAfterEndDate() {
* to the agent
*/
public Map<Integer, Float> buildMapOfAgentsToTotalClaimCost() {
return null;

Map<Integer, Double> agents_WithClaims_To_ClaimCost = this.claims.stream()
.collect(Collectors.groupingBy(claim -> claim.getAgent_assigned_id(), Collectors.summingDouble(Claim::getEstimate_cost)));

Map<Integer, Float> agents_To_Total_ClaimCost = new HashMap<>();

for (Agent agent: this.agents) {
agents_To_Total_ClaimCost.put(agent.getId(), (float) agents_WithClaims_To_ClaimCost.getOrDefault(agent.getId(), Double.valueOf(0)).doubleValue());
}
return agents_To_Total_ClaimCost;
}

/**
Expand All @@ -211,7 +275,16 @@ public Map<Integer, Float> buildMapOfAgentsToTotalClaimCost() {
* null if disaster does not exist
*/
public float calculateDisasterClaimDensity(int id) {
return -0.01f;
if (this.disasters.stream().noneMatch(disaster -> disaster.getId() == id)) return -1;

List<Disaster> disasterRecord = this.disasters.stream().filter(disaster -> disaster.getId() == id).collect(Collectors.toList());

double area = Math.PI * Math.pow(disasterRecord.get(0).getRadius_miles(), 2);

double numOfClaims = this.claims.stream().filter(claim -> claim.getDisaster_id() == id).count();

return (float) ((float) numOfClaims/area);

}

// endregion
Expand All @@ -220,16 +293,51 @@ public float calculateDisasterClaimDensity(int id) {

/**
* 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
* - Year should be full four-digit year
* - List should be in descending order
*
*
* @return three strings of month and year, descending order of highest claims
*/
public String[] getTopThreeMonthsWithHighestNumOfClaimsDesc() {
return new String[1];

Map<Integer, String> id_To_monthYear = new HashMap<>();

for (Disaster disaster : this.disasters) {
id_To_monthYear.put(disaster.getId(), getMonthAndYear(disaster.getDeclared_date()));
}

Map<String, Double> monthYear_To_TotalCost = new HashMap<>();

for (Claim claim: this.claims) {
String key = id_To_monthYear.get(claim.getDisaster_id());

if (monthYear_To_TotalCost.containsKey(key)) {
monthYear_To_TotalCost.put(key, monthYear_To_TotalCost.get(key) + claim.getEstimate_cost());
} else {
monthYear_To_TotalCost.put(key, claim.getEstimate_cost());
}
}

List<String> monthYear_Desc_Order = monthYear_To_TotalCost.entrySet().stream()
.sorted(Map.Entry.<String, Double>comparingByValue().reversed())
.map(Map.Entry::getKey)
.collect(toList());


return monthYear_Desc_Order.subList(0, 3).toArray(new String[0]);
}

static String getMonthAndYear(LocalDate date) {
return convertToSupperCase(String.valueOf(date.getMonth())) + " " + date.getYear();
}

static String convertToSupperCase(String input) {
String firstLetter = input.substring(0, 1).toUpperCase();
String restOfWord = input.substring(1).toLowerCase();
return firstLetter + restOfWord;
}

// endregion
Expand Down
Loading