From 857be426cc59584f448f68e28ba1a647a369ce63 Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sat, 10 Oct 2020 22:23:41 -0400 Subject: [PATCH 1/8] Most of problems done, needs debugging --- .gitignore | 3 + feedback.txt | 10 +- pom.xml | 2 + .../CodingCompCsvUtil.java | 161 +++++++++++++++--- .../structures/Agent.java | 43 ++++- .../structures/Claim.java | 18 +- .../structures/Customer.java | 75 +++++++- .../structures/Dependent.java | 8 + .../structures/Vendor.java | 18 +- .../CodingCompCsvUtilTest.java | 41 +++-- target/classes/META-INF/MANIFEST.MF | 5 - .../coding-competition/pom.properties | 7 - .../coding-competition/pom.xml | 32 ---- .../CodingCompCsvUtil.class | Bin 3251 -> 0 bytes .../structures/Agent.class | Bin 428 -> 0 bytes .../structures/Claim.class | Bin 397 -> 397 bytes .../structures/Customer.class | Bin 806 -> 806 bytes .../structures/Dependent.class | Bin 384 -> 384 bytes .../structures/Vendor.class | Bin 419 -> 419 bytes .../CodingCompCsvUtilTest.class | Bin 3972 -> 0 bytes 20 files changed, 322 insertions(+), 101 deletions(-) create mode 100644 .gitignore delete mode 100644 target/classes/META-INF/MANIFEST.MF delete mode 100644 target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties delete mode 100644 target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml delete mode 100644 target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class delete mode 100644 target/classes/sf/codingcompetition2020/structures/Agent.class delete mode 100644 target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5231862 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +*.iml +target diff --git a/feedback.txt b/feedback.txt index b931d50..8de492f 100644 --- a/feedback.txt +++ b/feedback.txt @@ -1,9 +1,9 @@ -Your team (name of each individual participating): -How many JUnits were you able to get to pass? +Your team (name of each individual participating): Alex Kim, Ethan Xie +How many JUnits were you able to get to pass? Document and describe any enhancements included to help the judges properly grade your submission. Step 1: - Step 2: - - + Step 2: + + Feedback for the coding competition? Things you would like to see in future events? diff --git a/pom.xml b/pom.xml index 21d55bf..73686c9 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,8 @@ Coding Competition + 1.8 + 1.8 diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java index 58267da..5c17521 100644 --- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java +++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java @@ -1,7 +1,12 @@ package sf.codingcompetition2020; +import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; +import java.io.IOException; import java.io.Reader; +import java.net.URI; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -9,6 +14,7 @@ import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.Collections; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MappingIterator; @@ -22,29 +28,55 @@ import sf.codingcompetition2020.structures.Vendor; public class CodingCompCsvUtil { - - /* #1 + private final String agentListKey = "agentList"; + private final String claimListKey = "claimList"; + private final String customerListKey = "customerList"; + + /* #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 List readCsvFile(String filePath, Class classType) { + public List readCsvFile(String filePath, Class classType) throws Exception { + URL url = this.getClass().getResource(filePath); + URI uri = new URI(url.toString()); + File file = new File(uri.getPath()); + FileInputStream fis = new FileInputStream(file); + byte[] data = new byte[(int) file.length()]; + try { + fis.read(data); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fis != null) { + fis.close(); + } + } + String[] contents = new String(data, "UTF-8").split("\\r?\\n"); + List entries = new ArrayList<>(); + for(String entry : contents) { + policies.add(new Policy(policy.split(","))); + } + return policies; } - + /* #2 * getAgentCountInArea() -- Return the number of agents in a given area. * @param filePath -- Path to file being read in. * @param area -- The area from which the agents should be counted. * @return -- The number of agents in a given area */ - public int getAgentCountInArea(String filePath,String area) { - + public int getAgentCountInArea(String filePath, String area) { + return readCsvFile(filePath, Agent.class) + .stream() + .filter(a -> a.getArea() == area) + .collect(); } - + /* #3 * getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given area, that speak a certain language. * @param filePath -- Path to file being read in. @@ -53,10 +85,14 @@ public int getAgentCountInArea(String filePath,String area) { * @return -- The number of agents in a given area */ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area, String language) { - + return readCsvFile(filePath, Agent.class) + .stream() + .filter(a -> a.getArea() == area) + .filter(a -> a.getLanguage().equals(langage)) + .collect(); } - - + + /* #4 * countCustomersFromAreaThatUseAgent() -- Return the number of individuals from an area that use a certain agent. * @param filePath -- Path to file being read in. @@ -66,21 +102,43 @@ public List getAgentsInAreaThatSpeakLanguage(String filePath, String area * @return -- The number of customers that use a certain agent in a given area. */ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, String customerArea, String agentFirstName, String agentLastName) { - + List agents = readCsvFile(csvFilePaths.get(agentListKey), Agent.class); + + // find the agent in question + Agent agent; + for (Agent a : agents) { + if (a.getFirstName().equals(agentFirstName) && a.getLastName().equals(agentLastName)) { + agent = a; + break; + } + } + if (agent == null) { // this agent does not exist in the agents file + throw new Exception("TODO Rename me"); + } + + List customers = readCsvFile(csvFilePaths.get(customerListKey), Customer.class) + .stream() + .filter(customer -> customer.getArea().equals(customerArea) && customer.getAgent().equals(agent)) + .collect(Collectors.toList()); + + return customers.size(); } - + /* #5 * getCustomersRetainedForYearsByPlcyCostAsc() -- Return a list of customers retained for a given number of years, in ascending order of their policy cost. * @param filePath -- Path to file being read in. - * @param yearsOfServeice -- Number of years the person has been a customer. + * @param yearsOfService -- Number of years the person has been a customer. * @return -- List of customers retained for a given number of years, in ascending order of policy cost. */ public List getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath, short yearsOfService) { - + return Collections.sort(readCsvFile(filePath, Customer.class) + .stream() + .filter(c -> c.getYearsOfService() == yearsOfService) + .collect()); } - + /* #6 * getLeadsForInsurance() -- Return a list of individuals who’ve made an inquiry for a policy but have not signed up. * *HINT* -- Look for customers that currently have no policies with the insurance company. @@ -88,12 +146,20 @@ public List getCustomersRetainedForYearsByPlcyCostAsc(String customerF * @return -- List of customers who’ve made an inquiry for a policy but have not signed up. */ public List getLeadsForInsurance(String filePath) { + List customers = readCsvFile(filePath, Customer.class); + List customerList = new ArrayList<>(); + for (Customer customer: customers) { + if(!customer.isHomePolicy() && !customer.isAutoPolicy() && !customer.isRentersPolicy()) { + customerList.add(customer); + } + } + return customerList; } /* #7 - * getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors within an area and include options to narrow it down by: + * getVendorsWithGivenRatingThatAreInScope() -- Return a list of vendors within an area and include options to narrow it down by: a. Vendor rating b. Whether that vendor is in scope of the insurance (if inScope == false, return all vendors in OR out of scope, if inScope == true, return ONLY vendors in scope) * @param filePath -- Path to file being read in. @@ -103,6 +169,12 @@ 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 getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, int vendorRating) { + return readCsvFile(filePath, Vendor.class) + .stream() + .filter(v -> v.getVendorRating() == vendorRating) + .filter(v -> !inScope || (v.isInScope())) + .collect(); + } @@ -117,31 +189,68 @@ public List getVendorsWithGivenRatingThatAreInScope(String filePath, Str * @return -- List of customers filtered by age, number of vehicles insured and the number of dependents. */ public List getUndisclosedDrivers(String filePath, int vehiclesInsured, int dependents) { - - } + return readCsvFile(filePath, Customer.class) + .stream() + .filter(c -> c.getVehiclesInsured() > vehiclesInsured) + .filter(c -> c.getDependents().size() <= dependents)) + .filter(c -> (c.getAge() >= 40 && c.getAge() <= 50)) + .collect(); + } /* #9 - * getAgentIdGivenRank() -- Return the agent with the given rank based on average customer satisfaction rating. - * *HINT* -- Rating is calculated by taking all the agent rating by customers (1-5 scale) and dividing by the total number + * getAgentIdGivenRank() -- Return the agent with the given rank based on average customer satisfaction rating. + * *HINT* -- Rating is calculated by taking all the agent rating by customers (1-5 scale) and dividing by the total number * of reviews for the agent. * @param filePath -- Path to file being read in. * @param agentRank -- The rank of the agent being requested. - * @return -- Agent ID of agent with the given rank. + * @return -- Agent ID of agent with the given rank. -1 if there is not an agent with the given id */ public int getAgentIdGivenRank(String filePath, int agentRank) { - - } + List customers = readCsvFile(filePath, Customer.class); + Map agentCount = new HashMap<>(); + Map ratingSum = new HashMap<>(); + for (Customer customer : customers) { + int agentId = customer.getAgentId(); + agentCount.put(agentId, agentCount.getOrDefault(agentId, 0) + 1); + ratingSum.put(agentId, ratingSum.getOrDefault(agentId, 0) + customer.getAgentRating()); + } + // shouldn't agent rank be a double? + for (int agentId : ratingSum.keySet()) { + int agentRating = ratingSum.get(agentId) / agentCount.get(agentId); + if (agentRating == agentRank) { + return agentId; + } + } + return -1; + } + - /* #10 - * getCustomersWithClaims() -- Return a list of customers who’ve filed a claim within the last (inclusive). + * getCustomersWithClaims() -- Return a list of customers who’ve filed a claim within the last (inclusive). * @param filePath -- Path to file being read in. * @param monthsOpen -- Number of months a policy has been open. * @return -- List of customers who’ve filed a claim within the last . */ public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) { + List claimIds = readCsvFile(csvFilePaths.get(claimListKey), Claims.class) + .stream() + .filter(c -> c.getMonthsOpen() <= getMonthsOpen) + .collect(); - } + Map idToCustomer = new HashMap<>(); + + for (Customer customer: csvFilePaths.get(csvFilePaths.get(customerListKey), Customer.class) { + idToCustomer.put(customer.getCustomerId(), customer); + } + + List customerList = new ArrayList<>(); + + for (Claims claim: claimIds) { + customerList.add(idToCustomer.get(claim.getCustomerId())); + } + + return customerList; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Agent.java b/src/main/java/sf/codingcompetition2020/structures/Agent.java index e2e6f93..08f5eac 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Agent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Agent.java @@ -1,11 +1,50 @@ package sf.codingcompetition2020.structures; +import java.util.Objects; + public class Agent { - + private int agentId; private String area; private String language; private String firstName; private String lastName; - + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Agent)) return false; + Agent agent = (Agent) o; + return agentId == agent.agentId && + Objects.equals(area, agent.area) && + Objects.equals(language, agent.language) && + Objects.equals(firstName, agent.firstName) && + Objects.equals(lastName, agent.lastName); + } + + @Override + public int hashCode() { + return Objects.hash(agentId); + } + + public int getAgentId() { + return agentId; + } + + public String getArea() { + return area; + } + + public String getLanguage() { + return language; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Claim.java b/src/main/java/sf/codingcompetition2020/structures/Claim.java index 581140a..f3100f1 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Claim.java +++ b/src/main/java/sf/codingcompetition2020/structures/Claim.java @@ -5,5 +5,21 @@ public class Claim { private int customerId; private boolean closed; private int monthsOpen; - + + public int getClaimId() { + return claimId; + } + + public int getCustomerId() { + return customerId; + } + + public boolean isClosed() { + return closed; + } + + public int getMonthsOpen() { + return monthsOpen; + } + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java index f151906..44d839d 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Customer.java +++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java @@ -2,12 +2,13 @@ import java.util.ArrayList; import java.util.List; +import java.lang.Comparable; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -public class Customer { +public class Customer extends Comparable { private int customerId; private String firstName; private String lastName; @@ -24,4 +25,76 @@ public class Customer { private short yearsOfService; private Integer vehiclesInsured; + + public int getCustomerId() { + return customerId; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public int getAge() { + return age; + } + + public String getArea() { + return area; + } + + public int getAgentId() { + return agentId; + } + + public short getAgentRating() { + return agentRating; + } + + public String getPrimaryLanguage() { + return primaryLanguage; + } + + public List getDependents() { + return dependents; + } + + public boolean isHomePolicy() { + return homePolicy; + } + + public boolean isAutoPolicy() { + return autoPolicy; + } + + public boolean isRentersPolicy() { + return rentersPolicy; + } + + public String getTotalMonthlyPremium() { + return totalMonthlyPremium; + } + + public short getYearsOfService() { + return yearsOfService; + } + + public Integer getVehiclesInsured() { + return vehiclesInsured; + } + + @Override + public int compareTo(Customer customer) { + if (customer.getTotalMonthlyPremium() < getTotalMonthlyPremium()) { + return 1; + } else if (customer.getTotalMonthlyPremium() > getTotalMonthlyPremium()) { + return -1; + } else { + return 0; + } + } + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Dependent.java b/src/main/java/sf/codingcompetition2020/structures/Dependent.java index d4deb1a..fc8b226 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java @@ -4,4 +4,12 @@ public class Dependent { private String firstName; private String lastName; + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + } diff --git a/src/main/java/sf/codingcompetition2020/structures/Vendor.java b/src/main/java/sf/codingcompetition2020/structures/Vendor.java index 6b6fb76..0a50a3a 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Vendor.java +++ b/src/main/java/sf/codingcompetition2020/structures/Vendor.java @@ -5,5 +5,21 @@ public class Vendor { private String area; private int vendorRating; private boolean inScope; - + + public int getVendorId() { + return vendorId; + } + + public String getArea() { + return area; + } + + public int getVendorRating() { + return vendorRating; + } + + public boolean isInScope() { + return inScope; + } + } diff --git a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java index c29959f..49716c8 100644 --- a/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java +++ b/src/test/java/sf/codingcompetition2020/CodingCompCsvUtilTest.java @@ -13,7 +13,7 @@ import sf.codingcompetition2020.structures.Customer; public class CodingCompCsvUtilTest{ - + private final String agentFilePath = "src/main/resources/DataFiles/agents.csv"; private final String claimFilePath = "src/main/resources/DataFiles/claims.csv"; private final String customerFilePath = "src/main/resources/DataFiles/customers.csv"; @@ -21,10 +21,10 @@ public class CodingCompCsvUtilTest{ private final String agentList = "agentList"; private final String claimList = "claimList"; private final String customerList = "customerList"; - - + + CodingCompCsvUtil codingCompCsVUtil = new CodingCompCsvUtil(); - + //#1 @Test public void test1() { @@ -32,14 +32,14 @@ public void test1() { assertEquals(424, ((Claim)codingCompCsVUtil.readCsvFile(claimFilePath, Claim.class).get(423)).getClaimId()); assertEquals("Lorin", ((Customer)codingCompCsVUtil.readCsvFile(customerFilePath, Customer.class).get(499)).getFirstName()); } - + //#2 @Test public void getAgentCountInArea() { assertEquals(247,codingCompCsVUtil.getAgentCountInArea(agentFilePath, "area-4")); assertEquals(55,codingCompCsVUtil.getAgentCountInArea(agentFilePath, "area-2")); } - + //#3 @Test public void getAgentsInAreaThatSpeakLanguage() { @@ -47,29 +47,29 @@ public void getAgentsInAreaThatSpeakLanguage() { assertEquals(2, agentList.size()); assertEquals(49, agentList.get(0).getAgentId()); assertEquals(424, agentList.get(1).getAgentId()); - + agentList = codingCompCsVUtil.getAgentsInAreaThatSpeakLanguage(agentFilePath, "area-2", "Spanish"); assertEquals(1, agentList.size()); assertEquals(242, agentList.get(0).getAgentId()); } - + //#4 @Test public void countCustomersFromCitythatUseAgent() { Map csvFilePaths = new HashMap<>(); - + csvFilePaths.put(agentList, agentFilePath); csvFilePaths.put(customerList, customerFilePath); assertEquals(4,codingCompCsVUtil.countCustomersFromAreaThatUseAgent(csvFilePaths, "area-3", "Piggy","Ferrai")); assertEquals(6,codingCompCsVUtil.countCustomersFromAreaThatUseAgent(csvFilePaths, "area-4", "Rabi","Figg")); } - + //#5 @Test public void getCustomersRetainedForYearsByPlcyCostAsc() { List customerList = codingCompCsVUtil.getCustomersRetainedForYearsByPlcyCostAsc(customerFilePath, Short.valueOf("5")); - + assertEquals(15,customerList.size()); assertEquals(215,customerList.get(0).getCustomerId()); assertEquals(5,customerList.get(2).getYearsOfService()); @@ -78,13 +78,13 @@ public void getCustomersRetainedForYearsByPlcyCostAsc() { assertEquals("Tesoe",customerList.get(5).getLastName()); assertEquals("$888",customerList.get(14).getTotalMonthlyPremium()); } - + //#6 @Test public void getLeadsForInsurance() { assertEquals(82, codingCompCsVUtil.getLeadsForInsurance(customerFilePath).size()); } - + //#7 @Test public void getVendorsWithGivenRatingThatAreInScope() { @@ -92,33 +92,32 @@ public void getVendorsWithGivenRatingThatAreInScope() { assertEquals(2, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-2", true, 2).size()); assertEquals(12, codingCompCsVUtil.getVendorsWithGivenRatingThatAreInScope(vendorFilePath, "area-3", false, 3).size()); } - + //#8 @Test - public void getCustomersRetainedForYearsByPlcyCostAsc2() { + public void getCustomersRetainedForYearsByPlcyCostAsc2() { assertEquals(15,codingCompCsVUtil.getUndisclosedDrivers(customerFilePath,2,2).size()); assertEquals(14,codingCompCsVUtil.getUndisclosedDrivers(customerFilePath,3,3).size()); } - + //#9 @Test - public void getAgentIdGivenRank() { + public void getAgentIdGivenRank() { assertEquals(3,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 1)); assertEquals(12,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 4)); assertEquals(14,codingCompCsVUtil.getAgentIdGivenRank(customerFilePath, 20)); } - + //#10 @Test public void getCountCustomersWithClaims() { Map csvFilePaths = new HashMap<>(); - + csvFilePaths.put(customerList, customerFilePath); csvFilePaths.put(claimList, claimFilePath); - + assertEquals(81,codingCompCsVUtil.getCustomersWithClaims(csvFilePaths, Short.valueOf("1")).size()); assertEquals(312,codingCompCsVUtil.getCustomersWithClaims(csvFilePaths, Short.valueOf("6")).size()); } } - diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF deleted file mode 100644 index e2a1a34..0000000 --- a/target/classes/META-INF/MANIFEST.MF +++ /dev/null @@ -1,5 +0,0 @@ -Manifest-Version: 1.0 -Built-By: yc1d -Build-Jdk: 1.8.0_201 -Created-By: Maven Integration for Eclipse - diff --git a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties b/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties deleted file mode 100644 index fe569e3..0000000 --- a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.properties +++ /dev/null @@ -1,7 +0,0 @@ -#Generated by Maven Integration for Eclipse -#Thu Oct 08 09:27:33 MST 2020 -version=1.0.0-SNAPSHOT -groupId=sf.codingcompetition2020 -m2e.projectName=coding-competition -m2e.projectLocation=/Users/yc1d/Development/coding-competition/problem/online-competition -artifactId=coding-competition diff --git a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml b/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml deleted file mode 100644 index 21d55bf..0000000 --- a/target/classes/META-INF/maven/sf.codingcompetition2020/coding-competition/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - 4.0.0 - coding-competition - 1.0.0-SNAPSHOT - jar - sf.codingcompetition2020 - - coding-competition - Coding Competition - - - - - - - junit - junit - 4.12 - test - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-csv - 2.11.2 - - - - diff --git a/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class b/target/classes/sf/codingcompetition2020/CodingCompCsvUtil.class deleted file mode 100644 index 00daba9d49249e6950fa6b4b75732ac294bb504b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3251 zcmb`JU2_{X6o!x7q;a-|mb3}wdmH)@x1~-)OG|7#6I=qGF$8KmrMXjf6YW-y&%b{C9RTh@Z3zklZt0_PBx5eR zk?aqc;f71GwYjxfu4kil9Ifl)j^W7?ED*T(oF3D1LPfW{clew|hQQe>7u?hcoY^St z6Ij3(Spa8X`8+JbSppZDT(ED_{vlIsdYCW*D@_^EWS=T-??;0RrpGmbJI(xxDg@3c zMq?DX%Psi9MsuRCWfZ1WnHs4lRO?DskUoD04wmOwf_o%RgZF8r%PRCcDhWMx=e*> zh#hp2z)er|lp7;YON}DDOJHw~(z!4Jfp9EJ4+XV*)U*bSzGz~{rL>Fn`6`z}kLKC3 zr*lG8U){6Xs5G*TrOTPw*dRr?O5o`nt;?#O(Q9bodSvTa$2O6Dru43oeOp@VWJj|s zY+_Yy`ty@-ljx)_wb{`Tf$N^eX?fO_PM)}Y-7}V!HPCGW2XnL_YoPH5Y!6*V zFPgZpYRtbObgHO`aOz$2q~poDog?gjCyh%JirQx)mP$Y6ruQX3X5tC1m7;5V8+*JV zT9F)}&PN^rvpsmw@Mu3e<*WJf8OqN}_%VU+=Uu`f-WG5bz3PaV>nM?$#g7%5rSR{1 z!;@aa=fi%kz)RrYd5?eaYI)X6mlp3cyvsT@&uc0M6kR?w0Vlgm+~;6Fe{8dI`l} z@S*?#9_?d*D;NxLei(q~*YJ+O>u>?1F5-0o-pC;L5pChYZ?N)g5d`y+cgA%#<< zz>(g9w~=RM{FCsGhj80Vcn{upT0U^31*awSkREzT>+qo?U2~*GN4oAIJ@%4r!iFQ2 z9BJYYIz8jho|kk7K60eHj#O}(e53;}sSKNrbkC6{*=>0=aWCmUJaD8>9BJaXPty-x g(nENZyZS$Q37^8Y(^7F-{@dxFy`(C7T7b{~2FpNm>;M1& diff --git a/target/classes/sf/codingcompetition2020/structures/Agent.class b/target/classes/sf/codingcompetition2020/structures/Agent.class deleted file mode 100644 index 26bf31f236fb6fb54997543cc9d682faad0ab137..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 428 zcma)2O-sW-5Pj3crj60o`gQhZ6-@0_5kwFQp&lx|Z_;htk`LKz{9m2~5B>mulsFqB zUOnu*H?!{zGxPcN{sG_;#~wO_akUPUa;1tiDf4G(lu>0dolGZTWptgGTFWZDO=V#` zxP;+GyofLpMH)WD8<`k_C+zQRMW7kM6^qsa^_tA zrQK^)D04$_PRC1bc2};X4+p~l0d@$3NELEk=dsj}BF@-6ipoS}OQDs`+oEfpR7E(C z{=FPe=P$}yC-Pp|wtlnng5cc1_lNb1~D!MW(Hw)1`&1!(TV=v6PJ{+@-T2Qa8Kmbsb^#m$Vx0r z)Xz!GOV{^L%1TWxVNhgX0%~AjU;)xB46HyF69XHRW@q34^EttMMg~TZK|qoRD5?*n p8G$sb)^-NQjbLTGK#~nC$jrb8Wb;52Fz_=70C|iI?1ErrLI6+S5<36@ delta 177 zcmXYoO%B0O7)8%}uT`q0erj$ilEyj=Y(a@g8ZjZ=MF(Aqk;K3PY{6c{^E>q8C2OB)HViHGfuwFSi{Q0Ak82%kypQ-kwG9U zu`E$PCowNw-#;lUHMxXAk%0-Qg@J(|NV71o0$EH9Yz*vRngdF6LdChDd~PV8hk+NY zjt?r%&mh3S$RG$769Sqe%pd}0i$dsh1~I6BI8=iK)Bs5aDWF0|AOyM;NXi0v`d~f- p1FP0{2F8tGbL4;|8&H^mfr~*NNb-Q$tPBc3Ux2hL0ZAqXWdL)G783vf delta 277 zcmXYrOKJi^6h%*!>29sGpH^F=iAIyC;G}RRPTW8nBp|_2aH5bc1l&W*|ARip=H3?)V}PYg~! z>iEqVB?;8g1cahA5oN~}&&KEX-pAfoskvU==M55BYr3o@J8e>@JD$6qAAG;Z>VKfm nqZE~#{3SRPXPt*&e&)GwJ7d96Vlcc2#!d&k@+M9(5!6g?4%ro- diff --git a/target/classes/sf/codingcompetition2020/structures/Dependent.class b/target/classes/sf/codingcompetition2020/structures/Dependent.class index 3ee505f7dda4d5aad7c64d98dd9748ea80a0698b..0d00fd6f21134ea324a1e9585948000b39921d50 100644 GIT binary patch delta 163 zcmZo*ZeSKY^>5cc1_lNb24OA+W(EOv20?ZPp^3px6X(})@G!75a4<6HPQ0jF#>gO$ zl~|UjpOcuEuJ50em6}|_pvb@k)WZNInHX3YSivkdFwMxo2+|8AIf0`3K$;OqvubT; gVB82+#swtVz=F&S+(0%DL;;ZI1@agf_`s_80iom)wEzGB delta 161 zcmZo*ZeZp;^>5cc1_lO024Qvvrir%<#Ml{F7#Rez63Y_xa}x8?_5G8wQj<$2iaK#| zF)%am@Gx*Na83-bOJ-1HU<3*`DsiveiGMi1qoJS2SOAPg1Cu@ZKQ@&;7V{|0ajxL;^iR&XXadH zrt>;4eSe=XV9h+jwx3lI;Ty8Lx>n_>Iv>l;u0HH9ZN80TJhFs@v~6w;3ycEru>^#g sED=4|`+tua$c;)@;!svPhhX_&ba(4xF;t8mPQ=8`0aIo&LoQm1ALlz02><{9 diff --git a/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class b/target/test-classes/sf/codingcompetition2020/CodingCompCsvUtilTest.class deleted file mode 100644 index 765ac60fa2a1b12f484db96055457db1849af952..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3972 zcmcguYjYD-7=BJ~Nz)~5)3n@F76h6`Xxc&r3Zf;Y7znpsg5{!aH>b_Eo87v*2~*U; zK~esVxqkafPc6 z!yaXs8_u+*^IM8jVo2m0duAPr;Lp>htZCSeVmJjwuka{383t`j&6E|*$XMJqE0)Ub z%#`9N0?E#}p!Tq8S4mmb6|Edth(damvb*0`?olhYW0twq(C=nQ?`S+w@gd?>ZWPTX zfCNKoM*vU3SMPMslGkh}iav%;mz^i}Gf06kZ)Pt;uNM^0{RQEEh7$zM351F+;tAcFpNXO;FyH{IKa@I*9?B6QeNcNoU*8MkvgWT=mo{ngzQhYIVH_z z7`$YdN!0A$Mh5wFpSFyOF|| zEz7i`_<-T>c|&BXUgbquRE(y(Ao7}J5^C9=kYk;5B`%k_Q!n>H>qd8YnoY^(5 ztmdg@Rj3f7m}mIwwIk_bz9Jm%o~_~d9~2pms3I^yOzmmQEN3-m-J!$J+uWrP#U~7R zcRsgB;K2(Q2W4}OTZ%(DN=Zw#A}hLXKJ?SpYt^#Ot6Y~CIW5Se!)Ia)L*)88g&FQp zXXnLf(^}w)WnWsqrK{^%({?6pHHv$T{kSuikZKCRUlE32+tx_9JZ>({a;vJTJ6Gg( z5OdTw^y{YKl=Ssm7B6d+^3DYsRM{K#h3#16m0dKI?Udj62nLtgP$=sL@YtL}UkRPYFj3~{&H)>kAfVVN#1TYE%z0^MLa z>Lz5n;NHUa9nC3S(ddSqq4sMmiwdWPlrv^kO51==R}^$>dTnW3P%|WyU^1Kyq4siH zx|@56Zh+hp45TP3fr(Re6Ye_w#{z_ILF|!)FYy&MU(%m9ikhwJrp=2}79G)|c6U64 zaBh2g@uqg2EBbyiRs)l*!sNFS9^*TPfiP&{?StYhn_7x+x_jLaqu8wbS`+Unh6AB* z#bFUq9Hz^@mF|cr65_EzQiP-ySEeUNUGAcFdU(|3ILY+}1VqXm>(l0Q)@EjvGjQ&L0EjUHrG(DPtZnUA7MuKl229P9M{WwCS6fqhm z4(DjkY1%1ymNAa^Nn$udJ6mv;#)9`b`WFmO`wU|*FtL!h@EjNapjpqN*asYHLW|YW zCPUHgkk^IIu_P{~f5vDcnwZ+a^wVFEOX8+KbK9S394+n!ZIBL?!ch!089Y`uI2&qk zGyS;``Xfzf4f=&$pxp^UJ0FU+unV-iA!t`a(e8($O;O;5YX_2e;5stCfzN)$B7^X5 z!6Ivt3zbBu!;D`SJu06wI From d988331d76a461b2683460a7f6042de26b659ec1 Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sun, 11 Oct 2020 00:13:58 -0400 Subject: [PATCH 2/8] Fix most bugs --- .../CodingCompCsvUtil.java | 171 ++++++++++++------ .../structures/Agent.java | 11 ++ .../structures/Claim.java | 9 + .../structures/Customer.java | 59 +++++- .../structures/Dependent.java | 20 ++ .../structures/Vendor.java | 9 + .../structures/Claim.class | Bin 397 -> 1210 bytes .../structures/Customer.class | Bin 806 -> 4305 bytes .../structures/Dependent.class | Bin 384 -> 735 bytes .../structures/Vendor.class | Bin 419 -> 1235 bytes 10 files changed, 214 insertions(+), 65 deletions(-) diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java index 5c17521..55346f9 100644 --- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java +++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java @@ -6,18 +6,26 @@ import java.io.IOException; import java.io.Reader; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.Collections; 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; @@ -27,6 +35,8 @@ import sf.codingcompetition2020.structures.Customer; import sf.codingcompetition2020.structures.Vendor; +import static java.util.stream.Collectors.toList; + public class CodingCompCsvUtil { private final String agentListKey = "agentList"; private final String claimListKey = "claimList"; @@ -38,28 +48,55 @@ public class CodingCompCsvUtil { * @param classType -- Class of entries being read in. * @return -- List of entries being returned. */ - public List readCsvFile(String filePath, Class classType) throws Exception { - URL url = this.getClass().getResource(filePath); - URI uri = new URI(url.toString()); - File file = new File(uri.getPath()); - FileInputStream fis = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; + public List readCsvFile(String filePath, Class classType) { try { - fis.read(data); + //URL url = this.getClass().getResource(filePath); + //URI uri = new URI(url.toString()); + //File file = new File(uri.getPath()); + File file = new File(filePath); + + ObjectMapper mapper = new CsvMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) + .configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) + .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); + //CsvSchema schema = mapper.schemaFor(classType); // schema from 'Pojo' definition + CsvSchema schema = CsvSchema.emptySchema().withHeader(); + + MappingIterator it = mapper.readerFor(classType) + .with(schema) + .readValues(file); + List ans = it.readAll(); + System.out.println(ans); + System.out.println(ans.size()); + System.out.println(ans.get(0)); + return ans; } catch (IOException e) { e.printStackTrace(); - } finally { - if (fis != null) { - fis.close(); - } + throw new IllegalStateException("Yeeto"); } - String[] contents = new String(data, "UTF-8").split("\\r?\\n"); - List entries = new ArrayList<>(); - for(String entry : contents) { - policies.add(new Policy(policy.split(","))); - } - return policies; + + +// URL url = this.getClass().getResource(filePath); +// URI uri = new URI(url.toString()); +// File file = new File(uri.getPath()); +// FileInputStream fis = new FileInputStream(file); +// byte[] data = new byte[(int) file.length()]; +// try { +// fis.read(data); +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// if (fis != null) { +// fis.close(); +// } +// } +// String[] contents = new String(data, "UTF-8").split("\\r?\\n"); +// +// List entries = new ArrayList<>(); +// for(String entry : contents) { +// entries.add(new T(entry.split(","))); +// } +// return entries; } @@ -72,12 +109,12 @@ public List readCsvFile(String filePath, Class classType) throws Excep public int getAgentCountInArea(String filePath, String area) { return readCsvFile(filePath, Agent.class) .stream() - .filter(a -> a.getArea() == area) - .collect(); + .filter(a -> a.getArea().equals(area)) + .collect(toList()).size(); } - /* #3 + /** #3 * getAgentsInAreaThatSpeakLanguage() -- Return a list of agents from a given area, that speak a certain language. * @param filePath -- Path to file being read in. * @param area -- The area from which the agents should be counted. @@ -87,25 +124,26 @@ public int getAgentCountInArea(String filePath, String area) { public List getAgentsInAreaThatSpeakLanguage(String filePath, String area, String language) { return readCsvFile(filePath, Agent.class) .stream() - .filter(a -> a.getArea() == area) - .filter(a -> a.getLanguage().equals(langage)) - .collect(); + .filter(a -> a.getArea().equals(area)) + .filter(a -> a.getLanguage().equals(language)) + .collect(toList()); } - /* #4 + /** #4 * countCustomersFromAreaThatUseAgent() -- Return the number of individuals from an area that use a certain agent. - * @param filePath -- Path to file being read in. + * @param csvFilePaths -- Path to file being read in. * @param customerArea -- The area from which the customers should be counted. * @param agentFirstName -- First name of agent. * @param agentLastName -- Last name of agent. * @return -- The number of customers that use a certain agent in a given area. + * @throws NoSuchElementException if the specified agent is not found in the given agent csv file. */ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, String customerArea, String agentFirstName, String agentLastName) { List agents = readCsvFile(csvFilePaths.get(agentListKey), Agent.class); // find the agent in question - Agent agent; + Agent agent = null; for (Agent a : agents) { if (a.getFirstName().equals(agentFirstName) && a.getLastName().equals(agentLastName)) { agent = a; @@ -113,15 +151,16 @@ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, } } if (agent == null) { // this agent does not exist in the agents file - throw new Exception("TODO Rename me"); + throw new NoSuchElementException("The specified agent: " + agentFirstName + " " + agentLastName + " was not found in the given agent csv file."); } - List customers = readCsvFile(csvFilePaths.get(customerListKey), Customer.class) + final int agentId = agent.getAgentId(); + List customers = readCsvFile(csvFilePaths.get(customerListKey), Customer.class) .stream() - .filter(customer -> customer.getArea().equals(customerArea) && customer.getAgent().equals(agent)) - .collect(Collectors.toList()); + .filter(customer -> customer.getArea().equals(customerArea) && customer.getAgentId() == (agentId)) + .collect(toList()); - return customers.size(); + return (short) customers.size(); } @@ -132,10 +171,12 @@ public short countCustomersFromAreaThatUseAgent(Map csvFilePaths, * @return -- List of customers retained for a given number of years, in ascending order of policy cost. */ public List getCustomersRetainedForYearsByPlcyCostAsc(String customerFilePath, short yearsOfService) { - return Collections.sort(readCsvFile(filePath, Customer.class) - .stream() - .filter(c -> c.getYearsOfService() == yearsOfService) - .collect()); + List filteredCustomers = readCsvFile(customerFilePath, Customer.class) + .stream() + .filter(c -> c.getYearsOfService() == yearsOfService) + .collect(toList()); + Collections.sort(filteredCustomers); + return filteredCustomers; } @@ -171,11 +212,10 @@ b. Whether that vendor is in scope of the insurance (if inScope == false, return public List getVendorsWithGivenRatingThatAreInScope(String filePath, String area, boolean inScope, int vendorRating) { return readCsvFile(filePath, Vendor.class) .stream() - .filter(v -> v.getVendorRating() == vendorRating) - .filter(v -> !inScope || (v.isInScope())) - .collect(); - - + .filter(v -> v.getArea().equals(area)) + .filter(v -> v.getVendorRating() >= vendorRating) + .filter(v -> (!inScope) || (v.isInScope())) + .collect(toList()); } @@ -192,9 +232,9 @@ public List getUndisclosedDrivers(String filePath, int vehiclesInsured return readCsvFile(filePath, Customer.class) .stream() .filter(c -> c.getVehiclesInsured() > vehiclesInsured) - .filter(c -> c.getDependents().size() <= dependents)) + .filter(c -> c.getDependents().size() <= dependents) .filter(c -> (c.getAge() >= 40 && c.getAge() <= 50)) - .collect(); + .collect(toList()); } @@ -204,7 +244,7 @@ public List getUndisclosedDrivers(String filePath, int vehiclesInsured * of reviews for the agent. * @param filePath -- Path to file being read in. * @param agentRank -- The rank of the agent being requested. - * @return -- Agent ID of agent with the given rank. -1 if there is not an agent with the given id + * @return -- Agent ID of agent with the given rank. */ public int getAgentIdGivenRank(String filePath, int agentRank) { List customers = readCsvFile(filePath, Customer.class); @@ -215,14 +255,27 @@ public int getAgentIdGivenRank(String filePath, int agentRank) { agentCount.put(agentId, agentCount.getOrDefault(agentId, 0) + 1); ratingSum.put(agentId, ratingSum.getOrDefault(agentId, 0) + customer.getAgentRating()); } - // shouldn't agent rank be a double? + + Map agentRatings = new HashMap<>(); + for (int agentId : ratingSum.keySet()) { - int agentRating = ratingSum.get(agentId) / agentCount.get(agentId); - if (agentRating == agentRank) { - return agentId; - } + double agentRating = ratingSum.get(agentId) * 1.0 / agentCount.get(agentId); + agentRatings.put(agentId, agentRating); } - return -1; + + LinkedHashMap sortedAgentRating = new LinkedHashMap<>(); + + agentRatings.entrySet() + .stream() + .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) + .forEachOrdered(x -> sortedAgentRating.put(x.getKey(), x.getValue())); + + Iterator> iterator = sortedAgentRating.entrySet().iterator(); + System.out.println(sortedAgentRating); + for(int i = 1; i < agentRank; i++) { + iterator.next(); + } + return iterator.next().getKey(); } @@ -233,24 +286,28 @@ public int getAgentIdGivenRank(String filePath, int agentRank) { * @return -- List of customers who’ve filed a claim within the last . */ public List getCustomersWithClaims(Map csvFilePaths, short monthsOpen) { - List claimIds = readCsvFile(csvFilePaths.get(claimListKey), Claims.class) + List claims = readCsvFile(csvFilePaths.get(claimListKey), Claim.class) .stream() - .filter(c -> c.getMonthsOpen() <= getMonthsOpen) - .collect(); + .filter(c -> c.getMonthsOpen() <= monthsOpen) + .collect(toList()); Map idToCustomer = new HashMap<>(); - for (Customer customer: csvFilePaths.get(csvFilePaths.get(customerListKey), Customer.class) { + List customers = readCsvFile(csvFilePaths.get(customerListKey), Customer.class); + for (Customer customer: customers) { idToCustomer.put(customer.getCustomerId(), customer); } - List customerList = new ArrayList<>(); + Set customerSet = new HashSet<>(); + + for (Claim claim: claims) { - for (Claims claim: claimIds) { - customerList.add(idToCustomer.get(claim.getCustomerId())); + customerSet.add(idToCustomer.get(claim.getCustomerId())); } - return customerList; + + + return new ArrayList<>(customerSet); } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Agent.java b/src/main/java/sf/codingcompetition2020/structures/Agent.java index 08f5eac..cc3a18a 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Agent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Agent.java @@ -47,4 +47,15 @@ public String getFirstName() { public String getLastName() { return lastName; } + + @Override + public String toString() { + return "Agent{" + + "agentId=" + agentId + + ", area='" + area + '\'' + + ", language='" + language + '\'' + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + '}'; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Claim.java b/src/main/java/sf/codingcompetition2020/structures/Claim.java index f3100f1..a40fc54 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Claim.java +++ b/src/main/java/sf/codingcompetition2020/structures/Claim.java @@ -22,4 +22,13 @@ public int getMonthsOpen() { return monthsOpen; } + @Override + public String toString() { + return "Claim{" + + "claimId=" + claimId + + ", customerId=" + customerId + + ", closed=" + closed + + ", monthsOpen=" + monthsOpen + + '}'; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java index 44d839d..e60b5fa 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Customer.java +++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java @@ -3,12 +3,13 @@ import java.util.ArrayList; import java.util.List; import java.lang.Comparable; +import java.util.Objects; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -public class Customer extends Comparable { +public class Customer implements Comparable { private int customerId; private String firstName; private String lastName; @@ -21,10 +22,58 @@ public class Customer extends Comparable { private boolean homePolicy; private boolean autoPolicy; private boolean rentersPolicy; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Customer)) return false; + Customer customer = (Customer) o; + return customerId == customer.customerId && + age == customer.age && + agentId == customer.agentId && + agentRating == customer.agentRating && + homePolicy == customer.homePolicy && + autoPolicy == customer.autoPolicy && + rentersPolicy == customer.rentersPolicy && + yearsOfService == customer.yearsOfService && + Objects.equals(firstName, customer.firstName) && + Objects.equals(lastName, customer.lastName) && + Objects.equals(area, customer.area) && + Objects.equals(primaryLanguage, customer.primaryLanguage) && + Objects.equals(dependents, customer.dependents) && + Objects.equals(totalMonthlyPremium, customer.totalMonthlyPremium) && + Objects.equals(vehiclesInsured, customer.vehiclesInsured); + } + + @Override + public int hashCode() { + return Objects.hash(customerId); + } + private String totalMonthlyPremium; private short yearsOfService; private Integer vehiclesInsured; + @Override + public String toString() { + return "Customer{" + + "customerId=" + customerId + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", age=" + age + + ", area='" + area + '\'' + + ", agentId=" + agentId + + ", agentRating=" + agentRating + + ", primaryLanguage='" + primaryLanguage + '\'' + + ", dependents=" + dependents + + ", homePolicy=" + homePolicy + + ", autoPolicy=" + autoPolicy + + ", rentersPolicy=" + rentersPolicy + + ", totalMonthlyPremium='" + totalMonthlyPremium + '\'' + + ", yearsOfService=" + yearsOfService + + ", vehiclesInsured=" + vehiclesInsured + + '}'; + } public int getCustomerId() { return customerId; @@ -88,13 +137,7 @@ public Integer getVehiclesInsured() { @Override public int compareTo(Customer customer) { - if (customer.getTotalMonthlyPremium() < getTotalMonthlyPremium()) { - return 1; - } else if (customer.getTotalMonthlyPremium() > getTotalMonthlyPremium()) { - return -1; - } else { - return 0; - } + return totalMonthlyPremium.compareTo(customer.getTotalMonthlyPremium()); } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Dependent.java b/src/main/java/sf/codingcompetition2020/structures/Dependent.java index fc8b226..64d8f67 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java @@ -1,9 +1,29 @@ package sf.codingcompetition2020.structures; +import com.fasterxml.jackson.databind.MappingIterator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.csv.CsvMapper; +import com.fasterxml.jackson.dataformat.csv.CsvSchema; + +import java.io.IOException; + public class Dependent { private String firstName; private String lastName; + public Dependent () { + + } + public Dependent (String csv) throws IOException { +// CsvMapper mapper = new CsvMapper(); +// CsvSchema schema = mapper.schemaFor(Dependent.class); +// MappingIterator it = mapper.readerFor(Dependent.class) +// .with(schema) +// .readValues(csv); +// Dependent d = it.next(); +// this.firstName = d.firstName; +// this.lastName = d.lastName; + } public String getFirstName() { return firstName; } diff --git a/src/main/java/sf/codingcompetition2020/structures/Vendor.java b/src/main/java/sf/codingcompetition2020/structures/Vendor.java index 0a50a3a..5162c2a 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Vendor.java +++ b/src/main/java/sf/codingcompetition2020/structures/Vendor.java @@ -22,4 +22,13 @@ public boolean isInScope() { return inScope; } + @Override + public String toString() { + return "Vendor{" + + "vendorId=" + vendorId + + ", area='" + area + '\'' + + ", vendorRating=" + vendorRating + + ", inScope=" + inScope + + '}'; + } } diff --git a/target/classes/sf/codingcompetition2020/structures/Claim.class b/target/classes/sf/codingcompetition2020/structures/Claim.class index affce0fc759644fcb8b95e5d9f20a00ea025aa08..c63eaa1e0cfb9c743798eaa0ae68a257bfbb3b91 100644 GIT binary patch literal 1210 zcma)4*>2NN5Ir}m6WlbI&;l(`_9R^#LRs5FL?on0fj$&fqHm64Qb&#*dEo`|M?8Rp zQVAqJfR94V*b#|bQ}Hr0cV>>y@wxZc@9#eWY@=0#f_eexvCd(G!zPEVJk%m`s7q*Y zzR#g4;emv0E+0yG#Q8CYCwV;0ff$?3=9k=3}Rdi%nZWp3?l3dq7%bb$pq(@7A2>;W#*(ZGH^NPBxdI7 zWhIs+@-T2Qa8G7qvNvN;WMBenVPIeZ(ku+DKo%1N8FU^XiQKZ5{}$H*WEB$*h50Dc`2!2kdN diff --git a/target/classes/sf/codingcompetition2020/structures/Customer.class b/target/classes/sf/codingcompetition2020/structures/Customer.class index 6bd351c3c9bfd6b9827469be8b3cfcaf64a85c4f..169dd78a3a8d91fccae189957fae890699434944 100644 GIT binary patch literal 4305 zcmbVO>317f75|MSdq(oumgU-ENn4cy-jq0T!|EiB>k?{k;xtOrEI^saV|x-=a%V;^ zCX@gHx=@w^r3myC15FVDJkLY+bhf#P2z9;KrLcVX{2eSUqz>f?(Zs5lTeq!LK2A(kRGue64 zz*Dk5ZQvOLKR56T1J4?GPIS-b7^IoQFYznkey!s-8gi9}=hxS5cVStBwxA)q;<%oF z)LOSS6c*20o7QyIs;y3!eb=e2&T25KR=A(GR(UF8xwfT2r%?07O`qb9TRsiww5(xp z!*$jzcWaTJ8p8@J z`$~O%!}cBDsn=%q%;*r?SPA&QM`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XJ)9%%3rQI?Wu@S8+r6Dn=x?l*%o5sF}z^6*>>aK@oV;=v#Su_ic=xehWJa?`z@x z;;)4d6h0X6eO&TmE$l4Z7%2KXikkvOMo!-x@B^LAVxZ`e&07M#SNIPF{9xzct$`xn z!iNhV33$DQj}{nHaxsJ-5BRL`69GTOCCFRKOSLEdL;rZlUygtSGaQqP*KF z%IQvdyU=GL;uT$r825CH&x93?^bL_1k6cbPKAULVA2+@?(fA9AX=mbTpG`FWVq)Zh zc;x#MjlYx_xhEdEl4yJ%zT5_LwA#IK3cCc-j{djnAP%&~G1cZ2q`$J;6Ab ztjkQ?#!5o^dOUqE!HI^|L}Mdv{6M1dTB30_ZhSG(m>&lTX%EHkeksxTeBzVk;*l>W z8ec#)A#x!e`JqH(e#W$o5Ao?zY-f{mVTi51tA*Y11Rhg9MuT&m8EdM^s^#bSQB-ex gyRGdlJ1PH5ElkHKm z;w6vI?G7B-2e@o}wm!S+^;YFsr|y(lS?Ih}UR;pjNChI{8d{Wthi|xUxnc9b`lj_E zEz@h;Jfef5YqFl~#Pp3$EDtOXZGXh+KQLw@MI}exCYXxLjR$?WqAIg97xW~CfQ4Xa Ov}P&4_+4KKI;_9YJ`rR9 diff --git a/target/classes/sf/codingcompetition2020/structures/Dependent.class b/target/classes/sf/codingcompetition2020/structures/Dependent.class index 0d00fd6f21134ea324a1e9585948000b39921d50..b60ddd3b9c73fa161691ba2c0735f4172dbe0457 100644 GIT binary patch literal 735 zcmb7C%SyvQ6g|_2u`z13KI?l|1x-N2|V>g_})^u6}27b#PJ zH#7Q9#R6_6Zn}Qhptv7)x>75x!eGC=Uv^_1^?conWbB^Ht_&J7&@?b#8n$J|r~UXr zz`l6&W!GrL7S;uvmeiNOTbe6v53>a(h^h?sWnYKA$d{MOn4cQV-ZQ7+AP3vQ7%T_l zumpDhwmNp%3~NARIGv!=Hpyff$?3=9k=48mLt%nSnT41(+oLKEeeC~^homlh?bx@G31GBWVFq!y&+ zrKIMS=w&6ACGs$^GjL1}V02DqP-I{N>SF+sObjdxtY8)!m}X>P1StcOoIp{1Ak7G* jS+%w^Fm41Z;{uXwU_oXEZXlZnq5w$q0(n47!K(NH&`cC< diff --git a/target/classes/sf/codingcompetition2020/structures/Vendor.class b/target/classes/sf/codingcompetition2020/structures/Vendor.class index bec70d2379284b2c3db4d77fdc5db23c02f3b735..aac84e7d445e22aa3bcb485c90ddef088a67985d 100644 GIT binary patch literal 1235 zcma)4+iuf95Iviloy0W3lon`#0EJwd)*+O81C**rks^=?ibUTW$Aqm?J93=7ApVF4 zkWeat#0T(Eh*_`OLTV~r=CU(q=gist`Rm&c02|oKK*wqtXHgYqO_+6I3K$wRL9w~UtpiXS3=X%W^18XuQOwTqM^wyp^F^z%g^o_Rf zai>qMnrwY-`jj&$+-Y0x&?ew6Lu!*d+<(FlFO@rV&$ip6O0LBn`{j7QYkP0Z?to78 zmTQ@Vj_GlchldIOJs&YtTcdY|<@V@$%iSN^KKHrn)NA#cG4j2!<&QmkWOM?;#3$Rg zeVGXMG?(}*bhZ_&FkdQ1Es;9{9qy6lqvqizbP4UE`mS7>A=7rpo@Kw_f_qj@TNm1B zxP&DQ=P<9~JQg%8is%9^GAzz&_k7F;J=H1Cd`j9? z3$jlVZ4jAiA=Es;JkwCZ3Pa`pRU-<=DFxi2%nx&w%G5!8ao(CuS$>k>Fb>Modo5 zf)^se^l?J4OG^sDcD^I^_5g~mPLZzA{!?W1tc>I2^2I4M{fs)W2Q(7#J8#7{s|4m>ERa8ARC`#3qLAmE#J|FD*(=b<502Wn|zEOU+Bk zFVf3OEKB5J;AY^NEXm|h%%I4?1k}X9zyhRM7+8TUCI&VJb}-EW<#RG{0r`wT2-F57 xd4W8AFrR^eRcku~<3_M@J|M{k6lMS#$PXkzN`VR(1Q-N?G$Vr$kYr*I1^|5(6XXB@ From 99976855bd5dc099129c480337e6d6dd0944ca9c Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sun, 11 Oct 2020 00:52:28 -0400 Subject: [PATCH 3/8] All working --- .../CodingCompCsvUtil.java | 9 ++++++--- .../structures/Customer.java | 19 ++++++++++++++++++ .../structures/Dependent.java | 7 +++++-- .../structures/Customer.class | Bin 4305 -> 5236 bytes .../structures/Dependent.class | Bin 735 -> 823 bytes 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java index 55346f9..40e0c2b 100644 --- a/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java +++ b/src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java @@ -27,12 +27,15 @@ import com.fasterxml.jackson.databind.MappingIterator; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.dataformat.csv.CsvMapper; +import com.fasterxml.jackson.dataformat.csv.CsvParser; import com.fasterxml.jackson.dataformat.csv.CsvSchema; import sf.codingcompetition2020.structures.Agent; import sf.codingcompetition2020.structures.Claim; import sf.codingcompetition2020.structures.Customer; +import sf.codingcompetition2020.structures.Dependent; import sf.codingcompetition2020.structures.Vendor; import static java.util.stream.Collectors.toList; @@ -55,11 +58,11 @@ public List readCsvFile(String filePath, Class classType) { //File file = new File(uri.getPath()); File file = new File(filePath); - ObjectMapper mapper = new CsvMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) - .configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) - .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); + CsvMapper mapper = new CsvMapper(); + mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); //CsvSchema schema = mapper.schemaFor(classType); // schema from 'Pojo' definition CsvSchema schema = CsvSchema.emptySchema().withHeader(); + TypeFactory typeFactory = mapper.getTypeFactory(); MappingIterator it = mapper.readerFor(classType) .with(schema) diff --git a/src/main/java/sf/codingcompetition2020/structures/Customer.java b/src/main/java/sf/codingcompetition2020/structures/Customer.java index e60b5fa..8b2d52f 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Customer.java +++ b/src/main/java/sf/codingcompetition2020/structures/Customer.java @@ -5,6 +5,8 @@ import java.lang.Comparable; import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -23,6 +25,13 @@ public class Customer implements Comparable { private boolean autoPolicy; private boolean rentersPolicy; + @JsonCreator + public static Customer fromJson(String value) { + String[] vals = value.split(","); + System.out.println(value); + return null; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -140,4 +149,14 @@ public int compareTo(Customer customer) { return totalMonthlyPremium.compareTo(customer.getTotalMonthlyPremium()); } + + public void setDependents(String dependents) { + String split = "}"; + String[] splitted = dependents.split(split); + List temp = new ArrayList<>(); + for (int i = 1; i < splitted.length; i++) { + temp.add(new Dependent()); + } + this.dependents = temp; + } } diff --git a/src/main/java/sf/codingcompetition2020/structures/Dependent.java b/src/main/java/sf/codingcompetition2020/structures/Dependent.java index 64d8f67..18e1e39 100644 --- a/src/main/java/sf/codingcompetition2020/structures/Dependent.java +++ b/src/main/java/sf/codingcompetition2020/structures/Dependent.java @@ -14,7 +14,11 @@ public class Dependent { public Dependent () { } - public Dependent (String csv) throws IOException { + public Dependent(String str) { + this.firstName = str; + this.lastName = str; + System.out.println(str); + } // CsvMapper mapper = new CsvMapper(); // CsvSchema schema = mapper.schemaFor(Dependent.class); // MappingIterator it = mapper.readerFor(Dependent.class) @@ -23,7 +27,6 @@ public Dependent (String csv) throws IOException { // Dependent d = it.next(); // this.firstName = d.firstName; // this.lastName = d.lastName; - } public String getFirstName() { return firstName; } diff --git a/target/classes/sf/codingcompetition2020/structures/Customer.class b/target/classes/sf/codingcompetition2020/structures/Customer.class index 169dd78a3a8d91fccae189957fae890699434944..da96fab017ce0b301fb85cc9046f0b78e579fd29 100644 GIT binary patch literal 5236 zcmbVP`FC7(75}`dT)|zzz3LC1}FADgQfG-PpSilhhj|g~F zz+(a)kK!ws73>KCPYU>|fUgPox`3y29F5`|_@*5FmX4>RIA1Iull2(^-!||aS)VoV zoPp;JeAmDW23|B!GH_gWP8fJe)|U;OH1ItGuNXLG;QPWm9i@?1<6-to+Oz>xuIfUa4q#kr+CS&xwMm-p-a2Tu!?T3!f4CW5j$U~(A{p%wbGk%S$8Tu zvo&vLoMJ{p`;2Yn3tJ|}?EHQwMaMe!+fz;|Z5Kwe1={4*yXzu0LY0$tp2k~NJ6XqF zt0C04Xa@r}oEsPEQ73C}E@t-H`R&%;G&!-+T*^xCu=0-3WoFo&au}l}=XB}e@@vXF zP2_W#YYVxohV^}QZj~Q$(Yw{xyx&R}>13EI{psFwwoVQ6wiUCkld*R=1&3D{%4Qiz zc^!2FzE*OA*<w@G?q ztx8%+j#g`;h18Igg)WGyjHt)*ileCns*Un69=xHp-nQ5;mb-b?Q zMjdZxXwX|pP1@gCmq=xH9cNfwPKx~8-l~#)UMm~R74s>3qa!V&t+KU5TD6I7U@~b5 z6Zha}I(}~A7x<-)Uzzwd?$(evm&RGqXkrknO{^2JUcfLmn79@nG%+e*lYlM4TZ6Sa zeq-V${MN+PSZiWP!21Pk#0N}l7Hli7W2>)C6fZ0~erMuMyk+9|_=ASIwSDiE))$@h zxSeNlR{Xj(RUKJtO#Bgl67Xk+BGFr&U27H!^Dj){L~mtYty#!Uoap8FS;My`!r~NO zRPm%b$!{+cUUibuo#^!qFOi|G+5l5t{8ce)Q${h*C}wTaP+w=Fw_(_jH8;^4FmJ?6 zSE9FZ=J0eZ(d!#KG&Kds#K#2Ofxj^UZl~ialB!b-<@45z3|0+`&m{w@J;%h~!KAta zcQXF9m#L+1!-H1ZXnW1FXLMnG|E?5Y;QXjdkFgmJ3QpZnu1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OXP{ z1@PgyxEEjp_g!oTc!0LRqyO?RusnU!*TWMPn+r#S52aBlhsi5mbWgqOJbJ^|H~a%7 zQ$9hb*0^{q;7%+k$*|6^b@|^7E*h_Q^v>*nvm;=?}HZ(uO+4+XKsbWYr$acu|(4qD!x?EO0thbC9>V~ttNX`iUBt4o9_Ss literal 735 zcmb7C%SyvQ6g|_2u`z13KI?l|1x-N2|V>g_})^u6}27b#PJ zH#7Q9#R6_6Zn}Qhptv7)x>75x!eGC=Uv^_1^?conWbB^Ht_&J7&@?b#8n$J|r~UXr zz`l6&W!GrL7S;uvmeiNOTbe6v53>a(h^h?sWnYKA$d{MOn4cQV-ZQ7+AP3vQ7%T_l zumpDhwmNp%3~NARIGv!=Hpy Date: Sun, 11 Oct 2020 00:53:26 -0400 Subject: [PATCH 4/8] Add DataViz --- .../sf/codingcompetition2020/DataViz.java | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 src/main/java/sf/codingcompetition2020/DataViz.java diff --git a/src/main/java/sf/codingcompetition2020/DataViz.java b/src/main/java/sf/codingcompetition2020/DataViz.java new file mode 100644 index 0000000..4a0aa99 --- /dev/null +++ b/src/main/java/sf/codingcompetition2020/DataViz.java @@ -0,0 +1,212 @@ +package sf.codingcompetition2020; + +import javafx.application.Application; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.chart.*; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +import java.util.ArrayList; +import java.util.List; + +public class DataViz extends Application { + + /** + * @param primaryStage the primary stage used for the javaFx scene + */ + //private static CodingCompCsvUtil csvUtil; + private int current; + private static int[] pos1 = {150, 550}; + private static int[] pos2 = {150, 600}; + private static List currentItems; + + private final String agentListKey = "agentList.csv"; + private final String claimListKey = "claimList.csv"; + private final String customerListKey = "customerList.csv"; + + private CodingCompCsvUtil csvUtil; + + public void start(Stage primaryStage) { + csvUtil = new CodingCompCsvUtil(); + Pane pane = new Pane(); + FlowPane root = new FlowPane(); + + currentItems = new ArrayList<>(); + + VBox vBox = new VBox(); + + ObservableList options = FXCollections.observableArrayList( + "getAgentCountInArea", + "getAgentsInAreaThatSpeakLanguage", + "countCustomersFromAreaThatUseAgent", + "getCustomersRetainedForYearsByPlcyCostAsc", + "getLeadsForInsurance", + "getVendorsWithGivenRatingThatAreInScope", + "getUndisclosedDrivers", + "getAgentIdGivenRank", + "getCustomersWithClaims" + ); + + final ComboBox comboBox = new ComboBox(options); + + onComboBoxChange(comboBox, vBox); + + comboBox.setTranslateX(150); + comboBox.setTranslateY(500); + + vBox.getChildren().add(comboBox); + root.getChildren().add(vBox); + + + Scene scene = new Scene(root, 600, 800); + + primaryStage.setTitle("Data Viz"); + primaryStage.setScene(scene); + primaryStage.show(); + } + + private static void onComboBoxChange(ComboBox comboBox, VBox vBox) { + EventHandler event = new EventHandler() { + public void handle(ActionEvent e) { + if (currentItems.size() != 0) { + while (currentItems.size() != 0) { + vBox.getChildren().remove(currentItems.get(0)); + currentItems.remove(0); + } + } + if (comboBox.getValue().equals("getAgentCountInArea")) { + String[] areaNames = {"area-1", "area-2", "area-3", "area-4", "area-5"}; + ObservableList pieChartData = FXCollections.observableArrayList(); + for (int i = 0; i < areaNames.length; i++) { + pieChartData.addAll(new PieChart.Data(areaNames[i], csvUtil.getAgentCountInArea(agentListKey, areaNames[i]))); + } + final PieChart chart = new PieChart(pieChartData); + chart.setTitle("Agents per Area"); + (vBox).getChildren().add(chart); + currentItems.add(chart); + } else if (comboBox.getValue().equals("getAgentsInAreaThatSpeakLanguage")) { + ObservableList options = FXCollections.observableArrayList( + "Language", + "Area" + ); + ObservableList options2 = FXCollections.observableArrayList( + + ); + + final ComboBox chooseConstant1 = new ComboBox(options); + chooseConstant1.setTranslateX(pos1[0]); + chooseConstant1.setTranslateY(pos1[1]); + + EventHandler event = new EventHandler() { + public void handle(ActionEvent e) { + String[] arr1 = {"Arabic", "Hindi", "Mandarin", "French", "Russian", "English", "Spanish"}; + String[] arr2 = {"area-1", "area-2", "area-3", "area-4", "area-5"}; + if (chooseConstant1.getValue().equals("Language")) { + for (int i = 0; i < arr1.length; i++) { + options2.add(arr1[i]); + } + } else { + for (int i = 0; i < arr2.length; i++) { + options2.add(arr2[i]); + } + } + ComboBox chooseConstant2 = new ComboBox(options2); + chooseConstant2.setTranslateX(pos2[0]); + chooseConstant2.setTranslateY(pos2[1]); + + EventHandler event = new EventHandler() { + public void handle(ActionEvent e) { + ObservableList pieChartData = FXCollections.observableArrayList(); + if (chooseConstant1.getValue().equals("Language")) { + String current = chooseConstant2.getValue(); + for (int i = 0; i < arr1.length; i++) { + pieChartData.addAll(new PieChart.Data(arr1[i], csvUtil.getAgentsInAreaThatSpeakLanguage(agentListKey, arr1[i], current))); + } + } else { + String current = chooseConstant2.getValue(); + for (int i = 0; i < arr1.length; i++) { + pieChartData.addAll(new PieChart.Data(arr2[i], csvUtil.getAgentsInAreaThatSpeakLanguage(agentListKey, arr2[i], current))); + } + } + final PieChart chart = new PieChart(pieChartData); + chart.setTitle("Agents per Area"); + (vBox).getChildren().add(chart); + currentItems.add(chart); + } + }; + chooseConstant2.setOnAction(event); + Label label2 = new Label("Enter a valid langage/area"); + label2.setTranslateX(pos2[0]); + label2.setTranslateY(pos2[1]); + + vBox.getChildren().addAll(label2, chooseConstant2); + currentItems.add(chooseConstant2); + currentItems.add(label2); + } + }; + + chooseConstant1.setOnAction(event); + + Label label1 = new Label("Enter Value to Hold Constant"); + + label1.setTranslateX(pos1[0]); + label1.setTranslateY(pos1[1]); + + + vBox.getChildren().addAll(label1, chooseConstant1); + + currentItems.add(chooseConstant1); + currentItems.add(label1); + + + // ObservableList pieChartData = FXCollections.observableArrayList(); + // pieChartData.addAll(new PieChart.Data("test", 13)); + // final PieChart chart = new PieChart(pieChartData); + // chart.setTitle("Agents per Area"); + // vBox.getChildren().add(chart); + } else if (comboBox.getValue().equals("countCustomersFromAreaThatUseAgent")) { + final TextField chooseConstant1 = new TextField(); + chooseConstant1.setTranslateX(pos1[0]); + chooseConstant1.setTranslateY(pos1[1]); + + Label label1 = new Label("Enter First and Last name of an Agent (Press Enter to submit)"); + label1.setTranslateX(pos1[0]); + label1.setTranslateY(pos1[1]); + + EventHandler event = new EventHandler() { + public void handle(ActionEvent e) { + int split = chooseConstant1.getValue().indexOf(" "); + String firstName = chooseConstant1.getValue().substring(0, split); + String lastName = chooseConstant2.getValue().substring(split + 1); + String[] areaNames = {"area-1", "area-2", "area-3", "area-4", "area-5"}; + ObservableList pieChartData = FXCollections.observableArrayList(); + for (int i = 0; i < areaNames.length; i++) { + pieChartData.addAll(new PieChart.Data(areaNames[i], csvUtil.countCustomersFromAreaThatUseAgent(agentListKey, areaNames[i], firstName, lastName))); + } + final PieChart chart = new PieChart(pieChartData); + chart.setTitle("Area distribution for Agent: " + firstName + " " + lastName); + (vBox).getChildren().add(chart); + currentItems.add(chart); + + } + }; + chooseConstant1.setOnAction(event); + + vBox.getChildren().addAll(label1, chooseConstant1); + currentItems.add(chooseConstant1); + currentItems.add(label1); + } + } + }; + comboBox.setOnAction(event); + } +} From a2b6a711a0dcf843421d56a488a9025c101cd48c Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sun, 11 Oct 2020 00:58:13 -0400 Subject: [PATCH 5/8] Add dataviz --- .../sf/codingcompetition2020/DataViz.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/sf/codingcompetition2020/DataViz.java b/src/main/java/sf/codingcompetition2020/DataViz.java index 4a0aa99..b7278dc 100644 --- a/src/main/java/sf/codingcompetition2020/DataViz.java +++ b/src/main/java/sf/codingcompetition2020/DataViz.java @@ -29,11 +29,11 @@ public class DataViz extends Application { private static int[] pos2 = {150, 600}; private static List currentItems; - private final String agentListKey = "agentList.csv"; - private final String claimListKey = "claimList.csv"; - private final String customerListKey = "customerList.csv"; + private static final String agentListKey = "agentList.csv"; + private static final String claimListKey = "claimList.csv"; + private static final String customerListKey = "customerList.csv"; - private CodingCompCsvUtil csvUtil; + private static CodingCompCsvUtil csvUtil; public void start(Stage primaryStage) { csvUtil = new CodingCompCsvUtil(); @@ -77,6 +77,7 @@ public void start(Stage primaryStage) { private static void onComboBoxChange(ComboBox comboBox, VBox vBox) { EventHandler event = new EventHandler() { public void handle(ActionEvent e) { + ComboBox chooseConstant2; if (currentItems.size() != 0) { while (currentItems.size() != 0) { vBox.getChildren().remove(currentItems.get(0)); @@ -108,6 +109,7 @@ public void handle(ActionEvent e) { EventHandler event = new EventHandler() { public void handle(ActionEvent e) { + ComboBox chooseConstant2; String[] arr1 = {"Arabic", "Hindi", "Mandarin", "French", "Russian", "English", "Spanish"}; String[] arr2 = {"area-1", "area-2", "area-3", "area-4", "area-5"}; if (chooseConstant1.getValue().equals("Language")) { @@ -119,7 +121,7 @@ public void handle(ActionEvent e) { options2.add(arr2[i]); } } - ComboBox chooseConstant2 = new ComboBox(options2); + chooseConstant2 = new ComboBox(options2); chooseConstant2.setTranslateX(pos2[0]); chooseConstant2.setTranslateY(pos2[1]); @@ -127,14 +129,14 @@ public void handle(ActionEvent e) { public void handle(ActionEvent e) { ObservableList pieChartData = FXCollections.observableArrayList(); if (chooseConstant1.getValue().equals("Language")) { - String current = chooseConstant2.getValue(); + String current = (String) chooseConstant2.getValue(); for (int i = 0; i < arr1.length; i++) { - pieChartData.addAll(new PieChart.Data(arr1[i], csvUtil.getAgentsInAreaThatSpeakLanguage(agentListKey, arr1[i], current))); + pieChartData.addAll(new PieChart.Data(arr1[i], csvUtil.getAgentsInAreaThatSpeakLanguage(agentListKey, arr1[i], current).size())); } } else { - String current = chooseConstant2.getValue(); + String current = (String) chooseConstant2.getValue(); for (int i = 0; i < arr1.length; i++) { - pieChartData.addAll(new PieChart.Data(arr2[i], csvUtil.getAgentsInAreaThatSpeakLanguage(agentListKey, arr2[i], current))); + pieChartData.addAll(new PieChart.Data(arr2[i], csvUtil.getAgentsInAreaThatSpeakLanguage(agentListKey, arr2[i], current).size())); } } final PieChart chart = new PieChart(pieChartData); @@ -184,8 +186,8 @@ public void handle(ActionEvent e) { EventHandler event = new EventHandler() { public void handle(ActionEvent e) { - int split = chooseConstant1.getValue().indexOf(" "); - String firstName = chooseConstant1.getValue().substring(0, split); + int split = chooseConstant1.getText().indexOf(" "); + String firstName = chooseConstant1.getText().substring(0, split); String lastName = chooseConstant2.getValue().substring(split + 1); String[] areaNames = {"area-1", "area-2", "area-3", "area-4", "area-5"}; ObservableList pieChartData = FXCollections.observableArrayList(); From fe5986a0d06a29bfffcb2538587afe54a6b4e9e8 Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sun, 11 Oct 2020 00:59:25 -0400 Subject: [PATCH 6/8] Feedback.txt update --- feedback.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/feedback.txt b/feedback.txt index 8de492f..5b6029f 100644 --- a/feedback.txt +++ b/feedback.txt @@ -1,9 +1,9 @@ Your team (name of each individual participating): Alex Kim, Ethan Xie -How many JUnits were you able to get to pass? +How many JUnits were you able to get to pass? 10 Document and describe any enhancements included to help the judges properly grade your submission. - Step 1: - Step 2: + Step 1: We developed GUI in JavaFX to visualize the data that we processed in CodingCompCsvUtil.java. + Step 2: In order to run it, download the necessary JavaFX libraries for compilation, and run the DataViz file. Feedback for the coding competition? Things you would like to see in future events? From 7e51ce8761e78932422dc0413ccc0b417a551601 Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sun, 11 Oct 2020 01:00:21 -0400 Subject: [PATCH 7/8] Update feedback.txt --- feedback.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feedback.txt b/feedback.txt index 5b6029f..930a08c 100644 --- a/feedback.txt +++ b/feedback.txt @@ -2,8 +2,9 @@ Your team (name of each individual participating): Alex Kim, Ethan Xie How many JUnits were you able to get to pass? 10 Document and describe any enhancements included to help the judges properly grade your submission. - Step 1: We developed GUI in JavaFX to visualize the data that we processed in CodingCompCsvUtil.java. + Step 1: We developed GUI in JavaFX to visualize the data that we processed in CodingCompCsvUtil.java. (see DataViz.java) Step 2: In order to run it, download the necessary JavaFX libraries for compilation, and run the DataViz file. Feedback for the coding competition? Things you would like to see in future events? +Some coding questions were worded weirdly and hard to understand. \ No newline at end of file From 7f68a2a061006b777818cc816c0653a01dd7c503 Mon Sep 17 00:00:00 2001 From: Alex Kim Date: Sun, 11 Oct 2020 01:02:30 -0400 Subject: [PATCH 8/8] Add more feedback --- feedback.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/feedback.txt b/feedback.txt index 930a08c..cc2db2e 100644 --- a/feedback.txt +++ b/feedback.txt @@ -7,4 +7,6 @@ Document and describe any enhancements included to help the judges properly grad Feedback for the coding competition? Things you would like to see in future events? -Some coding questions were worded weirdly and hard to understand. \ No newline at end of file +Some coding questions were worded weirdly and hard to understand. +For example in getVendorsWithGivenRatingThatAreInScope it was not made clear that these vendors should be filtered to have a higher or equal than +rating. The problem statement made it seem like the vendors should be filtered to as strict equal for the rating filter. \ No newline at end of file