From 99f0e9823ad95a5d99a3a5641d314c27454ba22e Mon Sep 17 00:00:00 2001 From: Stefanurkal Date: Tue, 15 Oct 2024 14:15:03 -0700 Subject: [PATCH 1/3] wave 1 complete --- src/Main.java | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..5d458ca 100644 --- a/src/Main.java +++ b/src/Main.java @@ -10,21 +10,25 @@ public static void main(String[] args) { System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - - List> dta = new ArrayList<>(); + /* + * creates new map, with keys of from the data file forkID, time, + * and number of lines changed. + * + */ + List> forks = 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]); + int chg = Integer.parseInt(v[2]); - Map mp1 = new HashMap<>(); - mp1.put("id", v[0]); - mp1.put("tm", v[1]); - mp1.put("chg", String.valueOf(chg)); - dta.add(mp1); + Map commits = new HashMap<>(); + commits.put("id", v[0]); + commits.put("tm", v[1]); + commits.put("chg", String.valueOf(chg)); + forks.add(commits); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); @@ -33,7 +37,7 @@ public static void main(String[] args) { } Map>> mp2 = new HashMap<>(); - for (Map d : dta) { + for (Map d : forks) { String id = d.get("id"); List> lst = mp2.get(id); if (lst == null) { @@ -50,9 +54,9 @@ public static void main(String[] args) { List> sel; if (inp.equalsIgnoreCase("all")) { - sel = dta; + sel = forks; } else { - String id = "fork" + inp; + String id = "fork" + inp; sel = mp2.get(id); } @@ -61,7 +65,7 @@ public static void main(String[] args) { DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime lat = null; for (Map d : sel) { - LocalDateTime t = LocalDateTime.parse(d.get("tm"), f1); + LocalDateTime t = LocalDateTime.parse(d.get("tm"), f1); if (lat == null || t.isAfter(lat)) { lat = t; } From 78a4a40f030b8f9b8837c801313c8629bfba830a Mon Sep 17 00:00:00 2001 From: Madeleine Chance Date: Tue, 15 Oct 2024 14:25:14 -0700 Subject: [PATCH 2/3] wave 2 helper method --- src/Main.java | 58 +++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Main.java b/src/Main.java index 5d458ca..9b2ef75 100644 --- a/src/Main.java +++ b/src/Main.java @@ -8,33 +8,13 @@ public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); - System.out.print("Enter the CSV filename: "); - String f = s.nextLine(); - /* - * creates new map, with keys of from the data file forkID, time, - * and number of lines changed. - * - */ - List> forks = 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 commits = new HashMap<>(); - commits.put("id", v[0]); - commits.put("tm", v[1]); - commits.put("chg", String.valueOf(chg)); - forks.add(commits); - } - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); - s.close(); - return; - } + System.out.print("Enter the CSV filename: "); + String f = s.nextLine(); + //chosen file inputted into parseCVS to parse the file + List> forks = parseCVS(f); + Map>> mp2 = new HashMap<>(); for (Map d : forks) { @@ -104,4 +84,32 @@ public static void main(String[] args) { s.close(); } + + public static List> parseCVS(String filename){ + /* + * creates new map, with keys of from the data file forkID, time, + * and number of lines changed. + * + */ + List> forks = 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 commits = new HashMap<>(); + commits.put("id", v[0]); + commits.put("tm", v[1]); + commits.put("chg", String.valueOf(chg)); + forks.add(commits); + } + } catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + return null; + } + return forks; +} } From 165418597f2116cd843cec021e26f2c360f82536 Mon Sep 17 00:00:00 2001 From: Stefanurkal Date: Tue, 15 Oct 2024 14:39:58 -0700 Subject: [PATCH 3/3] wave 3 complete --- src/Main.java | 5 +++-- src/MainTest.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Main.java b/src/Main.java index 9b2ef75..e1571de 100644 --- a/src/Main.java +++ b/src/Main.java @@ -13,7 +13,7 @@ public static void main(String[] args) { System.out.print("Enter the CSV filename: "); String f = s.nextLine(); //chosen file inputted into parseCVS to parse the file - List> forks = parseCVS(f); + List> forks = parseCSV(f); Map>> mp2 = new HashMap<>(); @@ -85,13 +85,14 @@ public static void main(String[] args) { s.close(); } - public static List> parseCVS(String filename){ + public static List> parseCSV(String filename){ /* * creates new map, with keys of from the data file forkID, time, * and number of lines changed. * */ List> forks = new ArrayList<>(); + try (Scanner fs = new Scanner(new File(filename))) { fs.nextLine(); diff --git a/src/MainTest.java b/src/MainTest.java index 1141d9e..3ce6cc6 100644 --- a/src/MainTest.java +++ b/src/MainTest.java @@ -12,7 +12,7 @@ public class MainTest { 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 - + List> actualCommits = Main.parseCSV("data/small_commit_data.csv"); // Sets up the expected value for you. You do not need to edit this part List> expectedCommits = new ArrayList<>(); @@ -37,5 +37,6 @@ void testParseCSV() { // Finish expected value setup // TODO: Assert that the expected equals the actual + assertEquals (expectedCommits, actualCommits); } }