From 694715f1d51f1d06a877b9db232713cd87d1e45f Mon Sep 17 00:00:00 2001 From: Diana Date: Tue, 15 Oct 2024 14:19:55 -0700 Subject: [PATCH 1/5] Added comments with a partner for Wave 1 code --- src/Main.java | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..4fe5efc 100644 --- a/src/Main.java +++ b/src/Main.java @@ -7,10 +7,10 @@ public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); - + // Asking the user to enter the CSV filename and store their input System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - + // Creating an ArrayList and a HashMap List> dta = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); @@ -26,12 +26,13 @@ public static void main(String[] args) { mp1.put("chg", String.valueOf(chg)); dta.add(mp1); } + // Catching the error if the file is not found and close the scanner } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); s.close(); return; } - + // Creating a Hashmap and iterating through the data to get the id of the fork Map>> mp2 = new HashMap<>(); for (Map d : dta) { String id = d.get("id"); @@ -42,12 +43,14 @@ public static void main(String[] args) { } lst.add(d); } + // Counting the total number of forks int cnt = mp2.size(); - + System.out.println("There are " + cnt + " forks available (fork1 to fork" + cnt + ")."); + // Statement for the user to choose through the menu to analyze the/all forks System.out.print("Enter the fork number to analyze (or 'all' for all forks): "); String inp = s.nextLine(); - + // Selects commits based on the user input List> sel; if (inp.equalsIgnoreCase("all")) { sel = dta; @@ -57,7 +60,7 @@ public static void main(String[] args) { } int sz = sel.size(); - + // Commit Time Stamps-Format DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime lat = null; for (Map d : sel) { @@ -68,7 +71,7 @@ public static void main(String[] args) { } DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String latT = lat.format(f2); - + // Calculating the total lines changed double tot = 0.0; int tlc = 0; for (Map d : sel) { @@ -76,8 +79,9 @@ public static void main(String[] args) { tot += lc; tlc += lc; } + // Calculating average lines per commit double avg = tot / sz; - + // Finding the max and the minimum lines updated in the commit int mx = Integer.MIN_VALUE; int mn = Integer.MAX_VALUE; for (Map d : sel) { @@ -89,15 +93,15 @@ public static void main(String[] args) { mn = chg; } } - + // Statistics from the program System.out.println("\nStatistics:"); - System.out.println("Number of commits: " + sz); + System.out.println("Number of commits: " + sz); System.out.println("Most recent commit timestamp: " + latT); System.out.printf("Average lines changed per commit: %.2f\n", avg); System.out.println("Total lines changed across all commits: " + tlc); System.out.println("Max lines changed in a commit: " + mx); System.out.println("Min lines changed in a commit: " + mn); - + // Close the scanner s.close(); } } From 4b2cc36e0d912ce6191d88f09954bd31e7022b3c Mon Sep 17 00:00:00 2001 From: Alston Dsouza Date: Tue, 15 Oct 2024 14:27:56 -0700 Subject: [PATCH 2/5] Renamed mp1 to commitData and changed dta variable to dataList --- src/Main.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Main.java b/src/Main.java index 4fe5efc..e13147b 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,7 +11,7 @@ public static void main(String[] args) { System.out.print("Enter the CSV filename: "); String f = s.nextLine(); // Creating an ArrayList and a HashMap - List> dta = new ArrayList<>(); + List> dataList = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); @@ -20,11 +20,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 commitData = new HashMap<>(); + commitData.put("id", v[0]); + commitData.put("tm", v[1]); + commitData.put("chg", String.valueOf(chg)); + dataList.add(commitData); } // Catching the error if the file is not found and close the scanner } catch (FileNotFoundException e) { @@ -34,7 +34,7 @@ public static void main(String[] args) { } // Creating a Hashmap and iterating through the data to get the id of the fork Map>> mp2 = new HashMap<>(); - for (Map d : dta) { + for (Map d : dataList) { String id = d.get("id"); List> lst = mp2.get(id); if (lst == null) { @@ -53,7 +53,7 @@ public static void main(String[] args) { // Selects commits based on the user input List> sel; if (inp.equalsIgnoreCase("all")) { - sel = dta; + sel = dataList; } else { String id = "fork" + inp; sel = mp2.get(id); From a22bb6a8ad31d1b0bbbfcf4bb89dd42f7fe41615 Mon Sep 17 00:00:00 2001 From: Alston Dsouza Date: Tue, 15 Oct 2024 14:29:26 -0700 Subject: [PATCH 3/5] Finished wave 1 and added name in ReadMe file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2a7249..878c833 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# commitStats +# commitStats (Alston and Diana) A program written in poor style to help give practice with the VS Code debugger and refactoring. From 84c77e72ab4297696e31d39d33182f8aa96e3fb1 Mon Sep 17 00:00:00 2001 From: Diana Date: Tue, 15 Oct 2024 14:43:49 -0700 Subject: [PATCH 4/5] Added Wave 2 helper method header --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index e13147b..208e0ac 100644 --- a/src/Main.java +++ b/src/Main.java @@ -104,4 +104,8 @@ public static void main(String[] args) { // Close the scanner s.close(); } + // Helper method + public static List> parseCSV(String filename) { + + } } From 6cb9826990b3e0847ced737a709365d5eb43351a Mon Sep 17 00:00:00 2001 From: Diana Date: Tue, 15 Oct 2024 14:55:00 -0700 Subject: [PATCH 5/5] Finished Wave 2 code and the helper method --- src/Main.java | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/Main.java b/src/Main.java index 208e0ac..a07b230 100644 --- a/src/Main.java +++ b/src/Main.java @@ -10,28 +10,14 @@ public static void main(String[] args) { // Asking the user to enter the CSV filename and store their input System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - // Creating an ArrayList and a HashMap - List> dataList = 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 commitData = new HashMap<>(); - commitData.put("id", v[0]); - commitData.put("tm", v[1]); - commitData.put("chg", String.valueOf(chg)); - dataList.add(commitData); - } - // Catching the error if the file is not found and close the scanner - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); - s.close(); - return; + + // Call the helper method to parse the CSV file + List> dataList = parseCSV(f); + if (dataList == null) { + s.close(); + return; } + // Creating a Hashmap and iterating through the data to get the id of the fork Map>> mp2 = new HashMap<>(); for (Map d : dataList) { @@ -106,6 +92,24 @@ public static void main(String[] args) { } // Helper method public static List> parseCSV(String filename) { - + List> 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 commitData = new HashMap<>(); + commitData.put("id", v[0]); + commitData.put("tm", v[1]); + commitData.put("chg", String.valueOf(chg)); + dataList.add(commitData); + } + } catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + return null; // return null to indicate failure + } + return dataList; } }