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
49 changes: 49 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
28 changes: 28 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>2019-StateFarm-CodingCompetitionProblem</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
5 changes: 5 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
7 changes: 7 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
2 changes: 2 additions & 0 deletions .settings/org.springframework.ide.eclipse.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boot.validation.initialized=true
eclipse.preferences.version=1
16 changes: 13 additions & 3 deletions feedback.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
Your team (name of each individual participating):
Brandon Galloway
How many JUnits were you able to get to pass?

10/10
Document and describe any enhancements included to help the judges properly grade your submission.
Step 1:
Step 2:
Step 1:CodingCompetitionCSVParser was created to handle direct parsing of CSV files
Step 2:CodingCompCSVUtil was programmed to utalize CSVParser and complete all JUnit test requirements
Step 3:Additional web functionality was added in the form of Spring Boot web
Step 4:A DisasterService service class was added to better modularize functionality
Step 5:Thymeleaf was brought into the project to provide visualization of data via RESTful endpoints

Example URLs:

http://localhost:8080/visualizeData?fileName=significant-earthquakes.csv&entity=Canada
http://localhost:8080/visualizeData?fileName=significant-earthquakes.csv&code=CAN
http://localhost:8080/getFileByCountry?fileName=significant-volcanic-eruptions.csv&countryName=El%20Salvador
http://localhost:8080/getFile?fileName=test.csv

Feedback for the coding competition? Things you would like to see in future events?
36 changes: 36 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,48 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>




<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>




<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>





</project>
161 changes: 143 additions & 18 deletions src/main/java/codingcompetition2019/CodingCompCSVUtil.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,138 @@
package codingcompetition2019;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

public class CodingCompCSVUtil {

public CodingCompCSVUtil()
{
}

public List<List<String>> readCSVFileByCountry(String fileName, String countryName) throws IOException {
// TODO implement this method
return null;
CodingCompetitionCSVParser parser = new CodingCompetitionCSVParser(fileName);
return parser.parseAsStringByCountry(false,countryName);
}

public List<List<String>> readCSVFileByCountryCode(String fileName, String countryCode) throws IOException {
CodingCompetitionCSVParser parser = new CodingCompetitionCSVParser(fileName);
return parser.parseAsStringByCountryCode(false,countryCode);
}

public List<DisasterDescription> readCSVFileAsDisaster(String fileName) throws IOException {
CodingCompetitionCSVParser parser = new CodingCompetitionCSVParser(fileName);
return parser.parseAsDisaster(false);
}

public List<List<String>> readCSVFileWithHeaders(String fileName) throws IOException {
// TODO implement this method
return null;
CodingCompetitionCSVParser parser = new CodingCompetitionCSVParser(fileName);
return parser.parseAsString(true);
}

public List<List<String>> readCSVFileWithoutHeaders(String fileName) throws IOException {
// TODO implement this method
return null;
CodingCompetitionCSVParser parser = new CodingCompetitionCSVParser(fileName);
return parser.parseAsString(false);
}

public DisasterDescription getMostImpactfulYear(List<List<String>> records) {
// TODO implement this method
return null;
HashMap<String,Integer> impactMap = new HashMap<String,Integer>();
String mostImp = "";
for(List<String> line : records)
{
String year = line.get(2);
if(impactMap.containsKey(year))
{
impactMap.put(year, impactMap.get(year)+Integer.parseInt(line.get(3)));
}else
{
impactMap.put(year, Integer.parseInt(line.get(3)));
}
if(mostImp.equals("") || impactMap.get(year) > impactMap.get(mostImp))
{
mostImp = year;
}
}
DisasterDescription dd = new DisasterDescription();
dd.setYear(mostImp);
return dd;
}

public DisasterDescription getMostImpactfulYearByCategory(String category, List<List<String>> records) {
// TODO implement this method
return null;
HashMap<String,Integer> impactMap = new HashMap<String,Integer>();
String mostImp = "";
for(List<String> line : records)
{
if(!line.get(0).equals(category))
continue;
String year = line.get(2);
if(impactMap.containsKey(year))
{
impactMap.put(year, impactMap.get(year)+Integer.parseInt(line.get(3)));
}else
{
impactMap.put(year, Integer.parseInt(line.get(3)));
}
if(mostImp.equals("") || impactMap.get(year) > impactMap.get(mostImp))
{
mostImp = year;
}
}
DisasterDescription dd = new DisasterDescription();
dd.setYear(mostImp);
return dd;
}

public DisasterDescription getMostImpactfulDisasterByYear(String year, List<List<String>> records) {
// TODO implement this method
return null;
HashMap<String,Integer> impactMap = new HashMap<String,Integer>();
String mostImp = "";
for(List<String> line : records)
{
if(!line.get(2).equals(year) || line.get(0).equals("All natural disasters"))
continue;
String disaster = line.get(0);
if(impactMap.containsKey(disaster))
{
impactMap.put(disaster, impactMap.get(disaster)+Integer.parseInt(line.get(3)));
}else
{
impactMap.put(disaster, Integer.parseInt(line.get(3)));
}
if(mostImp.equals("") || impactMap.get(disaster) > impactMap.get(mostImp))
{
mostImp = disaster;
}
}
DisasterDescription dd = new DisasterDescription();
dd.setEntity(mostImp);
dd.setNumQuakes((impactMap.get(mostImp)));
return dd;
}

public DisasterDescription getTotalReportedIncidentsByCategory(String category, List<List<String>> records) {
// TODO implement this method
return null;
HashMap<String,Integer> impactMap = new HashMap<String,Integer>();
String mostImp = "";
for(List<String> line : records)
{
if(!line.get(0).equals(category) || line.get(0).equals("All natural disasters"))
continue;
String disaster = line.get(0);
if(impactMap.containsKey(disaster))
{
impactMap.put(disaster, impactMap.get(disaster)+Integer.parseInt(line.get(3)));
}else
{
impactMap.put(disaster, Integer.parseInt(line.get(3)));
}
if(mostImp.equals("") || impactMap.get(disaster) > impactMap.get(mostImp))
{
mostImp = disaster;
}
}
DisasterDescription dd = new DisasterDescription();
dd.setEntity(mostImp);
dd.setNumQuakes((impactMap.get(mostImp)));
return dd;
}

/**
Expand All @@ -47,12 +143,41 @@ public DisasterDescription getTotalReportedIncidentsByCategory(String category,
* + If a max value is provided, then a max value is also needed.
*/
public int countImpactfulYearsWithReportedIncidentsWithinRange(List<List<String>> records, int min, int max) {
// TODO implement this method
return -1;
if(min == -1)
min = Integer.MIN_VALUE;

if(max == -1)
max = Integer.MAX_VALUE;

int validYears = 0;

for(List<String> line : records)
{
if(Integer.parseInt(line.get(3)) >= min && Integer.parseInt(line.get(3)) <= max)
{
validYears++;
}
}
return validYears;
}

public boolean firstRecordsHaveMoreReportedIndicents(List<List<String>> records1, List<List<String>> records2) {
// TODO implement this method
return false;
int records1Incidents = 0;
int records2Incidents = 0;



for(List<String> line : records1)
{
records1Incidents+=Integer.parseInt(line.get(3));
}
for(List<String> line : records2)
{
records2Incidents+=Integer.parseInt(line.get(3));
}



return records1Incidents > records2Incidents;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package codingcompetition2019;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CodingCompetitionApplication
{

public static void main(String[] args) {
SpringApplication.run(CodingCompetitionApplication.class, args);
}


}
Loading