Skip to content
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
58 changes: 35 additions & 23 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,18 @@
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
parseCSV("commit_data.csv");

//takes input from the user
System.out.print("Enter the CSV filename: ");
String f = s.nextLine();

List<Map<String, String>> dta = new ArrayList<>();
try (Scanner fs = new Scanner(new File(f))) {
fs.nextLine();

while (fs.hasNextLine()) {
String[] v = fs.nextLine().split(",");

int chg = Integer.parseInt(v[2]);

Map<String, String> mp1 = new HashMap<>();
mp1.put("id", v[0]);
mp1.put("tm", v[1]);
mp1.put("chg", String.valueOf(chg));
dta.add(mp1);
}
} catch (FileNotFoundException e) {
System.out.println("Error reading the file: " + e.getMessage());
s.close();
return;
}
//call helper method
List<Map<String, String>> dataList = parseCSV(f);

//store info for "id"
Map<String, List<Map<String, String>>> mp2 = new HashMap<>();
for (Map<String, String> d : dta) {
for (Map<String, String> d : dataList) {
String id = d.get("id");
List<Map<String, String>> lst = mp2.get(id);
if (lst == null) {
Expand All @@ -50,7 +35,7 @@ public static void main(String[] args) {

List<Map<String, String>> sel;
if (inp.equalsIgnoreCase("all")) {
sel = dta;
sel = dataList;
} else {
String id = "fork" + inp;
sel = mp2.get(id);
Expand Down Expand Up @@ -90,6 +75,7 @@ public static void main(String[] args) {
}
}

//print statistics
System.out.println("\nStatistics:");
System.out.println("Number of commits: " + sz);
System.out.println("Most recent commit timestamp: " + latT);
Expand All @@ -100,4 +86,30 @@ public static void main(String[] args) {

s.close();
}
}

public static List<Map<String, String>> parseCSV(String filename) {
//store the info from the text file
List<Map<String, String>> dataList = new ArrayList<>();
try (Scanner fs = new Scanner(new File(filename))) {
fs.nextLine();

while (fs.hasNextLine()) {
String[] v = fs.nextLine().split(",");

int chg = Integer.parseInt(v[2]);

Map<String, String> dataMap = new HashMap<>();
dataMap.put("id", v[0]);
dataMap.put("tm", v[1]);
dataMap.put("chg", String.valueOf(chg));
dataList.add(dataMap);
}
} catch (FileNotFoundException e) {
System.out.println("Error reading the file: " + e.getMessage());
// s.close();
// return;
}
return dataList;
}

}
6 changes: 5 additions & 1 deletion src/MainTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.junit.jupiter.api.Test;

Expand All @@ -13,6 +14,8 @@ void testParseCSV() {
// You will finish implementing this method in Wave 3
// TODO: Call Main.parseCSV("data/small_commit_data.csv") here and set it to an actual variable

// Call Main.parseCSV
List<Map<String, String>> actualCommits = Main.parseCSV("data/small_commit_data.csv");

// Sets up the expected value for you. You do not need to edit this part
List<Map<String, String>> expectedCommits = new ArrayList<>();
Expand All @@ -37,5 +40,6 @@ void testParseCSV() {
// Finish expected value setup

// TODO: Assert that the expected equals the actual
assertEquals(expectedCommits, actualCommits);
}
}