From 55ded4f0758576ef3d1d567108ca7f40ccc8887b Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:24:05 -0700 Subject: [PATCH 1/7] Started Wave 1 --- src/Main.java | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..89f18b8 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,12 +6,18 @@ public class Main { public static void main(String[] args) { + + //Instantiating new scanner Scanner s = new Scanner(System.in); + //Ask user for the file name System.out.print("Enter the CSV filename: "); + //variable f stores the input from the user String f = s.nextLine(); - List> dta = new ArrayList<>(); + + //List of maps created to store commit info + List> data = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); @@ -20,11 +26,11 @@ public static void main(String[] args) { 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 mp2 = new HashMap<>(); + mp2.put("id", v[0]); + mp2.put("tm", v[1]); + mp2.put("chg", String.valueOf(chg)); + data.add(mp2); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); @@ -32,17 +38,17 @@ public static void main(String[] args) { return; } - Map>> mp2 = new HashMap<>(); - for (Map d : dta) { + Map>> forkCommits = new HashMap<>(); + for (Map d : data) { String id = d.get("id"); - List> lst = mp2.get(id); + List> lst = forkCommits.get(id); if (lst == null) { lst = new ArrayList<>(); - mp2.put(id, lst); + forkCommits.put(id, lst); } lst.add(d); } - int cnt = mp2.size(); + int cnt = forkCommits.size(); System.out.println("There are " + cnt + " forks available (fork1 to fork" + cnt + ")."); System.out.print("Enter the fork number to analyze (or 'all' for all forks): "); @@ -50,10 +56,10 @@ public static void main(String[] args) { List> sel; if (inp.equalsIgnoreCase("all")) { - sel = dta; + sel = data; } else { String id = "fork" + inp; - sel = mp2.get(id); + sel = forkCommits.get(id); } int sz = sel.size(); @@ -90,6 +96,7 @@ public static void main(String[] args) { } } + //Print Results System.out.println("\nStatistics:"); System.out.println("Number of commits: " + sz); System.out.println("Most recent commit timestamp: " + latT); From 1b43e3ec495dc9b63d83d415dab85f44ac44e5b4 Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:33:47 -0700 Subject: [PATCH 2/7] Completed Wave 1 --- src/Main.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Main.java b/src/Main.java index 89f18b8..3959783 100644 --- a/src/Main.java +++ b/src/Main.java @@ -38,6 +38,7 @@ public static void main(String[] args) { return; } + //Create new map that organize commits by ID Map>> forkCommits = new HashMap<>(); for (Map d : data) { String id = d.get("id"); @@ -50,10 +51,12 @@ public static void main(String[] args) { } int cnt = forkCommits.size(); + //Print out the forks avalaible System.out.println("There are " + cnt + " forks available (fork1 to fork" + cnt + ")."); System.out.print("Enter the fork number to analyze (or 'all' for all forks): "); String inp = s.nextLine(); + // Select which commits to analyze dependent on the user input List> sel; if (inp.equalsIgnoreCase("all")) { sel = data; @@ -64,6 +67,7 @@ public static void main(String[] args) { int sz = sel.size(); + // Determine the most recent commit DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime lat = null; for (Map d : sel) { @@ -75,6 +79,7 @@ public static void main(String[] args) { DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String latT = lat.format(f2); + //Calculate statistics from the commits chosen double tot = 0.0; int tlc = 0; for (Map d : sel) { @@ -105,6 +110,7 @@ public static void main(String[] args) { System.out.println("Max lines changed in a commit: " + mx); System.out.println("Min lines changed in a commit: " + mn); + //Close scanner s.close(); } } From e1147d9d4338c93c7a75708c71657a2e6a1051cf Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:38:56 -0700 Subject: [PATCH 3/7] Added comments --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index 3959783..b9b39fe 100644 --- a/src/Main.java +++ b/src/Main.java @@ -87,12 +87,16 @@ public static void main(String[] args) { tot += lc; tlc += lc; } + //Calculate average lines changes double avg = tot / sz; int mx = Integer.MIN_VALUE; int mn = Integer.MAX_VALUE; for (Map d : sel) { + //Calculate changed lines in csv int chg = Integer.parseInt(d.get("chg")); + //Check if change is greater than max + //If change is greater than max, max = change if (chg > mx) { mx = chg; } From ae0f779fcf587781f1320d9b670bf6b264c0986a Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:42:55 -0700 Subject: [PATCH 4/7] Start parseCSV helper method --- src/Main.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Main.java b/src/Main.java index b9b39fe..d9e197c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -117,4 +117,10 @@ public static void main(String[] args) { //Close scanner s.close(); } + + public static List> parseCSV(String filename){ + List> data = new ArrayList<>(); + + return data; + } } From 766e20406f59d9a0e46afe96a9597b2796cfba6d Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:45:41 -0700 Subject: [PATCH 5/7] Start Wave 2 --- src/Main.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Main.java b/src/Main.java index d9e197c..f0b5a8d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -13,7 +13,7 @@ public static void main(String[] args) { //Ask user for the file name System.out.print("Enter the CSV filename: "); //variable f stores the input from the user - String f = s.nextLine(); + //List of maps created to store commit info @@ -121,6 +121,23 @@ public static void main(String[] args) { public static List> parseCSV(String filename){ List> data = new ArrayList<>(); - return data; + 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 mp2 = new HashMap<>(); + mp2.put("id", v[0]); + mp2.put("tm", v[1]); + mp2.put("chg", String.valueOf(chg)); + data.add(mp2); + } + } catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + fs.close(); + return data; + } } } From 2a58d8a31181312f4330b4e4fcbd64c7463b6bf4 Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:53:47 -0700 Subject: [PATCH 6/7] Error when calling helper method --- src/Main.java | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/Main.java b/src/Main.java index f0b5a8d..19e2e62 100644 --- a/src/Main.java +++ b/src/Main.java @@ -12,33 +12,13 @@ public static void main(String[] args) { //Ask user for the file name System.out.print("Enter the CSV filename: "); - //variable f stores the input from the user - - //List of maps created to store commit info - List> data = new ArrayList<>(); - try (Scanner fs = new Scanner(new File(f))) { - fs.nextLine(); + List> data = parseCSV(f); - while (fs.hasNextLine()) { - String[] v = fs.nextLine().split(","); - - int chg = Integer.parseInt(v[2]); - - Map mp2 = new HashMap<>(); - mp2.put("id", v[0]); - mp2.put("tm", v[1]); - mp2.put("chg", String.valueOf(chg)); - data.add(mp2); - } - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); - s.close(); - return; - } //Create new map that organize commits by ID + //If list is empty, it will add it into a new arrayList Map>> forkCommits = new HashMap<>(); for (Map d : data) { String id = d.get("id"); @@ -117,7 +97,8 @@ public static void main(String[] args) { //Close scanner s.close(); } - + + //Helper method for parsing the CSV file that the user inputs public static List> parseCSV(String filename){ List> data = new ArrayList<>(); @@ -127,17 +108,17 @@ public static List> parseCSV(String filename){ String[] v = fs.nextLine().split(","); int chg = Integer.parseInt(v[2]); - Map mp2 = new HashMap<>(); mp2.put("id", v[0]); mp2.put("tm", v[1]); mp2.put("chg", String.valueOf(chg)); data.add(mp2); } + //Throw error if file is not found } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); - fs.close(); + } + //return the data List return data; } } -} From b0fbd552f1153d26c71520b77116cc6009f08f00 Mon Sep 17 00:00:00 2001 From: Danny McCarragher Date: Wed, 16 Oct 2024 17:59:06 -0700 Subject: [PATCH 7/7] Wave 2 Completed --- src/Main.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 19e2e62..f96ac12 100644 --- a/src/Main.java +++ b/src/Main.java @@ -12,7 +12,7 @@ public static void main(String[] args) { //Ask user for the file name System.out.print("Enter the CSV filename: "); - + String f = s.nextLine(); List> data = parseCSV(f); @@ -80,6 +80,7 @@ public static void main(String[] args) { if (chg > mx) { mx = chg; } + //If change is less than minimum, min = change if (chg < mn) { mn = chg; } @@ -102,11 +103,14 @@ public static void main(String[] args) { public static List> parseCSV(String filename){ List> data = new ArrayList<>(); + //Read in the csv files try (Scanner fs = new Scanner(new File(filename))) { fs.nextLine(); while (fs.hasNextLine()) { + //Split the data apart by "," String[] v = fs.nextLine().split(","); + //split values and store them into data int chg = Integer.parseInt(v[2]); Map mp2 = new HashMap<>(); mp2.put("id", v[0]);