From dd59997420576e46bedeca165f9b6c4d7bf93cfb Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 14:24:58 -0700 Subject: [PATCH 1/9] added comments --- src/Main.java | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..77286dd 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,25 +6,34 @@ public class Main { public static void main(String[] args) { + + // create scanner and get the csv file from the user Scanner s = new Scanner(System.in); System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - List> dta = new ArrayList<>(); + // create a list of maps called dta + List> data = new ArrayList<>(); + + // iterate through the csv file try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); while (fs.hasNextLine()) { + //split each line by comma and put in string array String[] v = fs.nextLine().split(","); + // get the integer from the 3rd position in the line 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); + // each map is a line in the file + // add map line to the list + Map lineMap = new HashMap<>(); + lineMap.put("id", v[0]); + lineMap.put("tm", v[1]); + lineMap.put("chg", String.valueOf(chg)); + data.add(lineMap); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); @@ -32,8 +41,9 @@ public static void main(String[] args) { return; } + Map>> mp2 = new HashMap<>(); - for (Map d : dta) { + for (Map d : data) { String id = d.get("id"); List> lst = mp2.get(id); if (lst == null) { @@ -50,7 +60,7 @@ 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); From 5e832360aa07bd0e79a98a329509d0a8c254e2fc Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 14:34:06 -0700 Subject: [PATCH 2/9] help --- src/Main.java | 62 ++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/Main.java b/src/Main.java index 77286dd..8a69802 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,36 +11,11 @@ public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print("Enter the CSV filename: "); - String f = s.nextLine(); + //String f = s.nextLine(); - // create a list of maps called dta - List> data = new ArrayList<>(); - - // iterate through the csv file - try (Scanner fs = new Scanner(new File(f))) { - fs.nextLine(); - - while (fs.hasNextLine()) { - //split each line by comma and put in string array - String[] v = fs.nextLine().split(","); - - // get the integer from the 3rd position in the line - int chg = Integer.parseInt(v[2]); - - // each map is a line in the file - // add map line to the list - Map lineMap = new HashMap<>(); - lineMap.put("id", v[0]); - lineMap.put("tm", v[1]); - lineMap.put("chg", String.valueOf(chg)); - data.add(lineMap); - } - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); - s.close(); - return; - } + List> data = parseCSV(s.nextLine()); + s.close(); Map>> mp2 = new HashMap<>(); for (Map d : data) { @@ -110,4 +85,35 @@ public static void main(String[] args) { s.close(); } + + public static List> parseCSV(String filename){ + // create a list of maps called dta + List> data = new ArrayList<>(); + + // iterate through the csv file + try (Scanner fs = new Scanner(new File(filename))) { + fs.nextLine(); + + while (fs.hasNextLine()) { + //split each line by comma and put in string array + String[] v = fs.nextLine().split(","); + + // get the integer from the 3rd position in the line + int chg = Integer.parseInt(v[2]); + + // each map is a line in the file + // add map line to the list + Map lineMap = new HashMap<>(); + lineMap.put("id", v[0]); + lineMap.put("tm", v[1]); + lineMap.put("chg", String.valueOf(chg)); + data.add(lineMap); + } + } catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + + return; + } + return + } } From 7a742df097b51635acf844e1818791c833b71100 Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 14:37:18 -0700 Subject: [PATCH 3/9] helper method fixed --- src/Main.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Main.java b/src/Main.java index 8a69802..8506db4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -15,7 +15,7 @@ public static void main(String[] args) { List> data = parseCSV(s.nextLine()); - s.close(); + Map>> mp2 = new HashMap<>(); for (Map d : data) { @@ -112,8 +112,8 @@ public static List> parseCSV(String filename){ } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); - return; + return null; } - return + return data; } } From b9c29f10442b2afa5ff023758866f7d47d92cfff Mon Sep 17 00:00:00 2001 From: Tavparsad Singh Date: Tue, 15 Oct 2024 14:45:48 -0700 Subject: [PATCH 4/9] Possible comments :( --- src/Main.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Main.java b/src/Main.java index 8a69802..6a4e6b4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -15,11 +15,12 @@ public static void main(String[] args) { List> data = parseCSV(s.nextLine()); - s.close(); - Map>> mp2 = new HashMap<>(); + // for (Map d : data) { + //Saves id into a string from d String id = d.get("id"); + //Creates a new list map called lst and gets the key value List> lst = mp2.get(id); if (lst == null) { lst = new ArrayList<>(); @@ -111,9 +112,8 @@ public static List> parseCSV(String filename){ } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); - - return; + return null; } - return + return data; } } From 8da9678627e5da6ba327bba437b56b9b7cb17c40 Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 14:48:56 -0700 Subject: [PATCH 5/9] merging --- src/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 8506db4..59c2780 100644 --- a/src/Main.java +++ b/src/Main.java @@ -16,7 +16,6 @@ public static void main(String[] args) { List> data = parseCSV(s.nextLine()); - Map>> mp2 = new HashMap<>(); for (Map d : data) { String id = d.get("id"); From 10b407bf267cb0339893013cf3b12a676456dc1a Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 15:05:11 -0700 Subject: [PATCH 6/9] added more comments --- src/Main.java | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Main.java b/src/Main.java index 2e0d9bb..f41b088 100644 --- a/src/Main.java +++ b/src/Main.java @@ -16,38 +16,49 @@ public static void main(String[] args) { List> data = parseCSV(s.nextLine()); + // creates new map containing the lists of maps with the same id Map>> mp2 = new HashMap<>(); - // + // loops through list of maps for (Map d : data) { //Saves id into a string from d String id = d.get("id"); //Creates a new list map called lst and gets the key value List> lst = mp2.get(id); + // if there isn't a lst, it create the list if (lst == null) { lst = new ArrayList<>(); + // adds the list into the map mp2.put(id, lst); } + // adds the data lst.add(d); } - int cnt = mp2.size(); - System.out.println("There are " + cnt + " forks available (fork1 to fork" + cnt + ")."); + // gets count of forks and displays to user + int count = mp2.size(); + + System.out.println("There are " + count + " forks available (fork1 to fork" + count + ")."); System.out.print("Enter the fork number to analyze (or 'all' for all forks): "); - String inp = s.nextLine(); - - List> sel; - if (inp.equalsIgnoreCase("all")) { - sel = data; - } else { - String id = "fork" + inp; - sel = mp2.get(id); + String input = s.nextLine(); + + // creates a list of maps for the selection (all of the forks) + List> selection; + + // if user picks "all" get all the data + if (input.equalsIgnoreCase("all")) { + selection = data; + } + // otherwise select the fork from the id + else { + String id = "fork" + input; + selection = mp2.get(id); } - int sz = sel.size(); + int size = selection.size(); DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime lat = null; - for (Map d : sel) { + for (Map d : selection) { LocalDateTime t = LocalDateTime.parse(d.get("tm"), f1); if (lat == null || t.isAfter(lat)) { lat = t; @@ -58,16 +69,16 @@ public static void main(String[] args) { double tot = 0.0; int tlc = 0; - for (Map d : sel) { + for (Map d : selection) { int lc = Integer.parseInt(d.get("chg")); tot += lc; tlc += lc; } - double avg = tot / sz; + double avg = tot / size; int mx = Integer.MIN_VALUE; int mn = Integer.MAX_VALUE; - for (Map d : sel) { + for (Map d : selection) { int chg = Integer.parseInt(d.get("chg")); if (chg > mx) { mx = chg; @@ -78,7 +89,7 @@ public static void main(String[] args) { } System.out.println("\nStatistics:"); - System.out.println("Number of commits: " + sz); + System.out.println("Number of commits: " + size); 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); From 90b4a450c0cf0d98ddce0e8451dd0ccd128e5662 Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 15:06:04 -0700 Subject: [PATCH 7/9] merge changes --- src/Main.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Main.java b/src/Main.java index f41b088..6959286 100644 --- a/src/Main.java +++ b/src/Main.java @@ -124,15 +124,8 @@ public static List> parseCSV(String filename){ } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); -<<<<<<< HEAD return null; } return data; -======= - - return null; - } - return data; ->>>>>>> 7a742df097b51635acf844e1818791c833b71100 - } + } From 826ef56df99aa59226f7855c7eb9f4993f8d344d Mon Sep 17 00:00:00 2001 From: Tavparsad Singh Date: Tue, 15 Oct 2024 15:07:36 -0700 Subject: [PATCH 8/9] New comments --- src/Main.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 6959286..a5fcb8f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -128,4 +128,5 @@ public static List> parseCSV(String filename){ } return data; -} + } +} \ No newline at end of file From 1c0e1da1edbb74e1b31d2d438853f5baca146393 Mon Sep 17 00:00:00 2001 From: Augy Markham Date: Tue, 15 Oct 2024 15:08:17 -0700 Subject: [PATCH 9/9] merging --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 6959286..a465241 100644 --- a/src/Main.java +++ b/src/Main.java @@ -127,5 +127,5 @@ public static List> parseCSV(String filename){ return null; } return data; - + } }