Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Final Submission #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .idea/.gitignore

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

1 change: 1 addition & 0 deletions .idea/.name

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

16 changes: 16 additions & 0 deletions .idea/compiler.xml

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

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

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

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

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

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__junit_junit_4_12.xml

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

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml

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

11 changes: 11 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.

21 changes: 21 additions & 0 deletions coding-competition.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.11.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.2" level="project" />
</component>
</module>
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>coding-competition</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<groupId>sf.codingcompetition2020</groupId>

<name>coding-competition</name>
Expand Down
118 changes: 95 additions & 23 deletions src/main/java/sf/codingcompetition2020/CodingCompCsvUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package sf.codingcompetition2020;

import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
Expand All @@ -16,21 +13,60 @@
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
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.Vendor;
import sf.codingcompetition2020.structures.*;

public class CodingCompCsvUtil {
/* #1

/* #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) {

String[] reader = new String[0];
try {
reader = Files.readAllLines(new File(filePath).toPath()).toArray(new String[0]);
} catch (IOException e) {
e.printStackTrace();
}
LinkedList<T> ret = new LinkedList<>();
if(filePath.toUpperCase().contains("AGENT")) {
for(int i = 1; i < reader.length; i++) {
String[] insert = reader[i].split(",");
ret.add((T) new Agent(Integer.parseInt(insert[0]), insert[1], insert[2], insert[3], insert[4]));
}
}
else if(filePath.toUpperCase().contains("CLAIM")) {
for(int i = 1; i < reader.length; i++) {
String[] insert = reader[i].split(",");
ret.add((T) new Claim(Integer.parseInt(insert[0]), Integer.parseInt(insert[1]), Boolean.parseBoolean(insert[2]), Integer.parseInt(insert[3])));
}
}
else if(filePath.toUpperCase().contains("CUSTOMER")) {
for(int i = 1; i < reader.length; i++) {
String[] insert = reader[i].split(",");
Customer add = new Customer();
add.setCustomerId(Integer.parseInt(insert[0]));
add.setFirstName(insert[1]);
add.setLastName(insert[2]);
add.setAge(Integer.parseInt(insert[3]));
add.setArea(insert[4]);
add.setAgentId(Integer.parseInt(insert[5]));
add.setAgentRating(Short.parseShort(insert[6]));
add.setPrimaryLanguage(insert[7]);
/*LinkedList<Dependent> put = new LinkedList<>();
String[] dependents = reader[i].split(", ");*/
ret.add((T) add);
}
}
else if(filePath.toUpperCase().contains("VENDOR")) {
for(int i = 1; i < reader.length; i++) {
String[] insert = reader[i].split(",");
ret.add((T) new Vendor(Integer.parseInt(insert[0]), insert[1], Integer.parseInt(insert[2]), Boolean.parseBoolean(insert[3])));
}
}
return ret;
}


Expand All @@ -40,8 +76,15 @@ public <T> List<T> readCsvFile(String filePath, Class<T> classType) {
* @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) {
LinkedList<Agent> counter = (LinkedList<Agent>) readCsvFile(filePath, Agent.class);
int ret = 0;
for(int i = 0; i < counter.size(); i++) {
if(counter.get(i).getArea().equals(area)) {
ret++;
}
}
return ret;
}


Expand All @@ -53,7 +96,14 @@ 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) {

LinkedList<Agent> matcher = (LinkedList<Agent>) readCsvFile(filePath, Agent.class);
LinkedList<Agent> ret = new LinkedList<>();
for(int i = 0; i < matcher.size(); i++) {
if(matcher.get(i).getArea().equals(area) && matcher.get(i).getLanguage().equals(language)) {
ret.add(matcher.get(i));
}
}
return ret;
}


Expand All @@ -66,7 +116,20 @@ 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) {

LinkedList<Agent> agents = (LinkedList<Agent>) readCsvFile(csvFilePaths.get("agentList"), Agent.class);
LinkedList<Customer> customers = (LinkedList<Customer>) readCsvFile(csvFilePaths.get("customerList"), Customer.class);
short ret = 0;
for(int i = 0; i < customers.size(); i++) {
if(customers.get(i).getArea().equals(customerArea)) {
for(int j = 0; j < agents.size(); j++) {
Agent comparator = agents.get(j);
if(comparator.getFirstName().equals(agentFirstName) && comparator.getLastName().equals(agentLastName) && comparator.getAgentId() == customers.get(i).getAgentId()) {
ret++;
}
}
}
}
return ret;
}


Expand All @@ -77,7 +140,8 @@ 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) {

LinkedList<Customer> match = (LinkedList<Customer>) readCsvFile(customerFilePath, Customer.class);
return null;
}


Expand All @@ -88,7 +152,15 @@ 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) {

LinkedList<Customer> match = (LinkedList<Customer>) readCsvFile(filePath, Customer.class);
LinkedList<Customer> ret = new LinkedList<>();
for(int i = 0; i < match.size(); i++) {
Customer temp = match.get(i);
if(!temp.isAutoPolicy() && !temp.isHomePolicy() && !temp.isRentersPolicy()) {
ret.add(temp);
}
}
return ret;
}


Expand All @@ -103,7 +175,7 @@ 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) {

return null;
}


Expand All @@ -117,7 +189,7 @@ 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) {

return null;
}


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


Expand All @@ -141,7 +213,7 @@ 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) {

return null;
}

}
Loading