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
9 changes: 6 additions & 3 deletions feedback.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Your team (name of each individual participating):
How many JUnits were you able to get to pass?
Your team (name of each individual participating): Cameron Anundson, Jessica Huber
How many JUnits were you able to get to pass? 7

Document and describe any enhancements included to help the judges properly grade your submission.
Step 1:
Step 1: All code is properly formatted
Step 2:


Feedback for the coding competition? Things you would like to see in future events?

One of the JUnit tests (getCustomersRetainedForYearsByPlcyCostAsc) fails due to the following error:
org.junit.ComparisonFailure: expected:<$388[]> but was:<$388[ ]>. Not sure if this is intentional.
183 changes: 173 additions & 10 deletions src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package sf.codingcompetition2020;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.lang.Integer;
import java.lang.Float;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.xml.validation.Schema;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
Expand All @@ -22,17 +37,38 @@
import sf.codingcompetition2020.structures.Vendor;

public class CodingCompCsvUtil {
CsvMapper csvMapper = new CsvMapper();
CsvSchema schema = CsvSchema.emptySchema().withHeader();

public CodingCompCsvUtil() {
super();
}

/* #1
* readCsvFile() -- Read in a CSV File and return a list of entries in that file.
* @param filePath -- Path to file being read in.
* @param classType -- Class of entries being read in.
* @return -- List of entries being returned.
*/
public <T> List<T> readCsvFile(String filePath, Class<T> classType) {

ObjectReader objReader = csvMapper.reader(classType).with(schema);

List<T> list = new ArrayList<>();

try (Reader reader = new FileReader(filePath)) {
MappingIterator<T> mi = objReader.readValues(reader);

while (mi.hasNext()) {
list.add(mi.next());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return list;
}


/* #2
* getAgentCountInArea() -- Return the number of agents in a given area.
Expand All @@ -41,7 +77,16 @@ public <T> List<T> readCsvFile(String filePath, Class<T> classType) {
* @return -- The number of agents in a given area
*/
public int getAgentCountInArea(String filePath,String area) {

List<Agent> agentList = readCsvFile(filePath, Agent.class);

int count = 0;
for (Agent agent: agentList) {
if (agent.getArea().equals(area)) {
count ++;
}
}

return count;
}


Expand All @@ -53,7 +98,16 @@ public int getAgentCountInArea(String filePath,String area) {
* @return -- The number of agents in a given area
*/
public List<Agent> getAgentsInAreaThatSpeakLanguage(String filePath, String area, String language) {

List<Agent> agentList = readCsvFile(filePath, Agent.class);
List<Agent> agentsInAreaThatSpeakLanguage = new ArrayList<>();

for (Agent agent: agentList) {
if (agent.getArea().equals(area) && agent.getLanguage().equals(language)) {
agentsInAreaThatSpeakLanguage.add(agent);
}
}

return agentsInAreaThatSpeakLanguage;
}


Expand All @@ -66,9 +120,25 @@ public List<Agent> getAgentsInAreaThatSpeakLanguage(String filePath, String area
* @return -- The number of customers that use a certain agent in a given area.
*/
public short countCustomersFromAreaThatUseAgent(Map<String,String> csvFilePaths, String customerArea, String agentFirstName, String agentLastName) {
short countCustomers = 0;
int agentId = -1;
List<Agent> agentList = readCsvFile(csvFilePaths.get("agentList"), Agent.class);

for (Agent a : agentList) {
if (a.getFirstName().equals(agentFirstName) && a.getLastName().equals(agentLastName)) {
agentId = a.getAgentId();
break;
}
}

List<Customer> customerList = readCsvFile(csvFilePaths.get("customerList"), Customer.class);
for (Customer c : customerList) {
if (c.getArea().equals(customerArea) && c.getAgentId() == agentId) {
countCustomers++;
}
}
return countCustomers;
}


/* #5
* getCustomersRetainedForYearsByPlcyCostAsc() -- Return a list of customers retained for a given number of years, in ascending order of their policy cost.
Expand All @@ -77,7 +147,19 @@ public short countCustomersFromAreaThatUseAgent(Map<String,String> csvFilePaths,
* @return -- List of customers retained for a given number of years, in ascending order of policy cost.
*/
public List<Customer> getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath, short yearsOfService) {

List<Customer> customerList = readCsvFile(customerFilePath, Customer.class);
List<Customer> yearsList = new ArrayList();

for (Customer c : customerList) {
if (c.getYearsOfService() == yearsOfService) {
yearsList.add(c);
}
}
Collections.sort(yearsList, (Customer c1, Customer c2) ->{
return c1.getTotalMonthlyPremium().compareToIgnoreCase(c2.getTotalMonthlyPremium());
});

return yearsList;
}


Expand All @@ -88,7 +170,16 @@ public List<Customer> getCustomersRetainedForYearsByPlcyCostAsc(String customerF
* @return -- List of customers who’ve made an inquiry for a policy but have not signed up.
*/
public List<Customer> getLeadsForInsurance(String filePath) {

List<Customer> customerList = readCsvFile(filePath, Customer.class);
List<Customer> leadList = new ArrayList<>();

for (Customer customer: customerList) {
if (!customer.isAutoPolicy() && !customer.isHomePolicy() && !customer.isRentersPolicy()) {
leadList.add(customer);
}
}

return leadList;
}


Expand All @@ -103,7 +194,22 @@ b. Whether that vendor is in scope of the insurance (if inScope == false, return
* @return -- List of vendors within a given area, filtered by scope and vendor rating.
*/
public List<Vendor> getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, int vendorRating) {

List<Vendor> vendorList = readCsvFile(filePath, Vendor.class);
List<Vendor> vendorsWithGivenRatingInScope = new ArrayList<>();

for (Vendor vendor: vendorList) {
if (vendor.getArea().equals(area) && vendor.getVendorRating() >= vendorRating) {
if (inScope) {
if (vendor.isInScope()) {
vendorsWithGivenRatingInScope.add(vendor);
}
} else {
vendorsWithGivenRatingInScope.add(vendor);
}
}
}

return vendorsWithGivenRatingInScope;
}


Expand All @@ -117,7 +223,19 @@ public List<Vendor> getVendorsWithGivenRatingThatAreInScope(String filePath, Str
* @return -- List of customers filtered by age, number of vehicles insured and the number of dependents.
*/
public List<Customer> getUndisclosedDrivers(String filePath, int vehiclesInsured, int dependents) {

List<Customer> customerList = readCsvFile(filePath, Customer.class);
List<Customer> undisclosedDrivers = new ArrayList<>();

for (Customer customer: customerList) {
if (customer.getAge() >= 40
&& customer.getAge() <= 50
&& customer.getVehiclesInsured() > vehiclesInsured
&& customer.getDependents().size() <= dependents) {
undisclosedDrivers.add(customer);
}
}

return undisclosedDrivers;
}


Expand All @@ -130,7 +248,35 @@ public List<Customer> getUndisclosedDrivers(String filePath, int vehiclesInsured
* @return -- Agent ID of agent with the given rank.
*/
public int getAgentIdGivenRank(String filePath, int agentRank) {
List<Customer> customerList = readCsvFile(filePath, Customer.class);

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

for (Customer customer: customerList) {
Integer agentId = customer.getAgentId();
Float agentRating = (float) customer.getAgentRating();
Float currentSumOfAgentRatings = sumOfAgentRatings.get(agentId) != null ? sumOfAgentRatings.get(agentId) : 0;
Integer currentCountOfAgentRatings = countOfAgentRatings.get(agentId) != null ? countOfAgentRatings.get(agentId) : 0;

Float newSumOfAgentRatings = currentSumOfAgentRatings + agentRating;
Integer newCountOfAgentRatings = currentCountOfAgentRatings + 1;

sumOfAgentRatings.put(agentId, newSumOfAgentRatings);
countOfAgentRatings.put(agentId, newCountOfAgentRatings);
}

Map<Integer, Float> averageAgentRating = new HashMap<>();
for (Integer agentId: sumOfAgentRatings.keySet()) {
averageAgentRating.put(agentId, sumOfAgentRatings.get(agentId) / countOfAgentRatings.get(agentId));
}

List<Integer> sortedAgentIdsByRating = averageAgentRating.entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getValue, Comparator.reverseOrder()))
.map(Map.Entry::getKey)
.collect(Collectors.toList());

return sortedAgentIdsByRating.get(agentRank);
}


Expand All @@ -141,7 +287,24 @@ public int getAgentIdGivenRank(String filePath, int agentRank) {
* @return -- List of customers who’ve filed a claim within the last <numberOfMonths>.
*/
public List<Customer> getCustomersWithClaims(Map<String,String> csvFilePaths, short monthsOpen) {

Map<Integer, Boolean> ids = new HashMap<>();

List<Customer> customerList = readCsvFile(csvFilePaths.get("customerList"), Customer.class);
List<Claim> claimList = readCsvFile(csvFilePaths.get("claimList"), Claim.class);
List<Customer> customersWithClaim = new ArrayList();

for (Claim claim: claimList) {
if (claim.getMonthsOpen() <= monthsOpen) {
if (ids.get(claim.getCustomerId()) == null) {
ids.put(claim.getCustomerId(), true);
Customer c = customerList.get(claim.getCustomerId() - 1);
customersWithClaim.add(c);
}

}
}

return customersWithClaim;
}

}
43 changes: 43 additions & 0 deletions src/main/java/sf/codingcompetition2020/structures/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,47 @@ public class Agent {
private String firstName;
private String lastName;

public Agent(int agentId, String area, String language, String firstName, String lastName) {
super();
this.agentId = agentId;
this.area = area;
this.language = language;
this.firstName = firstName;
this.lastName = lastName;
}

public Agent() {
}

public int getAgentId() {
return agentId;
}
public void setAgentId(int agentId) {
this.agentId = agentId;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}

}
38 changes: 38 additions & 0 deletions src/main/java/sf/codingcompetition2020/structures/Claim.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,42 @@ public class Claim {
private boolean closed;
private int monthsOpen;


public Claim(int claimId, int customerId, boolean closed, int monthsOpen) {
super();
this.claimId = claimId;
this.customerId = customerId;
this.closed = closed;
this.monthsOpen = monthsOpen;
}

public Claim() {
// TODO Auto-generated constructor stub
}

public int getClaimId() {
return claimId;
}
public void setClaimId(int claimId) {
this.claimId = claimId;
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public boolean isClosed() {
return closed;
}
public void setClosed(boolean closed) {
this.closed = closed;
}
public int getMonthsOpen() {
return monthsOpen;
}
public void setMonthsOpen(int monthsOpen) {
this.monthsOpen = monthsOpen;
}

}
Loading