From c36aaade3e62fa75051475ba10b66931125cd93c Mon Sep 17 00:00:00 2001 From: RMarx1456 Date: Tue, 15 Oct 2024 14:20:14 -0700 Subject: [PATCH 1/4] Added two comments --- src/Main.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Main.java b/src/Main.java index e5571ea..3cdc0c4 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,6 +6,7 @@ public class Main { public static void main(String[] args) { + //Initializing scanner, taking input on the filename Scanner s = new Scanner(System.in); System.out.print("Enter the CSV filename: "); @@ -13,6 +14,7 @@ public static void main(String[] args) { List> dta = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { + //Opens file in scanner, iterates across, initializes ArrayList, coalescses stats into a hashmap, then places in an array list fs.nextLine(); while (fs.hasNextLine()) { From fdffb2d684e7ec28155f6deb6d87a37726b55b02 Mon Sep 17 00:00:00 2001 From: Ben Mojo <155706745+oakes777@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:34:20 -0700 Subject: [PATCH 2/4] changed variable names to allData and valueMap --- src/Main.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Main.java b/src/Main.java index 3cdc0c4..c169eb3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -12,7 +12,7 @@ public static void main(String[] args) { System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - List> dta = new ArrayList<>(); + List> allData = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { //Opens file in scanner, iterates across, initializes ArrayList, coalescses stats into a hashmap, then places in an array list fs.nextLine(); @@ -22,11 +22,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 valueMap = new HashMap<>(); + valueMap.put("id", v[0]); + valueMap.put("tm", v[1]); + valueMap.put("chg", String.valueOf(chg)); + allData.add(valueMap); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); @@ -35,7 +35,7 @@ public static void main(String[] args) { } Map>> mp2 = new HashMap<>(); - for (Map d : dta) { + for (Map d : allData) { String id = d.get("id"); List> lst = mp2.get(id); if (lst == null) { @@ -52,7 +52,7 @@ public static void main(String[] args) { List> sel; if (inp.equalsIgnoreCase("all")) { - sel = dta; + sel = allData; } else { String id = "fork" + inp; sel = mp2.get(id); From e3179f8e5c94480bfec6e1ad339cf984cfb8566d Mon Sep 17 00:00:00 2001 From: Ben Mojo <155706745+oakes777@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:46:13 -0700 Subject: [PATCH 3/4] put parsing logic into own method which is called in main; added more comments --- src/Main.java | 60 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/Main.java b/src/Main.java index c169eb3..58e997e 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,34 +6,23 @@ public class Main { public static void main(String[] args) { - //Initializing scanner, taking input on the filename + // Initializing scanner, taking input on the filename Scanner s = new Scanner(System.in); System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - List> allData = new ArrayList<>(); - try (Scanner fs = new Scanner(new File(f))) { - //Opens file in scanner, iterates across, initializes ArrayList, coalescses stats into a hashmap, then places in an array list - fs.nextLine(); - - while (fs.hasNextLine()) { - String[] v = fs.nextLine().split(","); + // call parseCSV method to get all data + List> allData = parseCSV(f); - int chg = Integer.parseInt(v[2]); - - Map valueMap = new HashMap<>(); - valueMap.put("id", v[0]); - valueMap.put("tm", v[1]); - valueMap.put("chg", String.valueOf(chg)); - allData.add(valueMap); - } - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); + // if allData empty then the file was not found or had problem + if (allData.isEmpty()) { + System.out.println("No data found or error reading the file."); s.close(); return; } + // grouping data by id Map>> mp2 = new HashMap<>(); for (Map d : allData) { String id = d.get("id"); @@ -54,16 +43,17 @@ public static void main(String[] args) { if (inp.equalsIgnoreCase("all")) { sel = allData; } else { - String id = "fork" + inp; + String id = "fork" + inp; sel = mp2.get(id); } int sz = sel.size(); + // format timestamp 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; } @@ -71,6 +61,7 @@ public static void main(String[] args) { DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String latT = lat.format(f2); + // manipulating chg data double tot = 0.0; int tlc = 0; for (Map d : sel) { @@ -92,6 +83,7 @@ public static void main(String[] args) { } } + // printing out report of requested forks System.out.println("\nStatistics:"); System.out.println("Number of commits: " + sz); System.out.println("Most recent commit timestamp: " + latT); @@ -102,4 +94,30 @@ public static void main(String[] args) { s.close(); } -} + + public static List> parseCSV(String f) { + List> allData = new ArrayList<>(); + try (Scanner fs = new Scanner(new File(f))) { + // Opens file in scanner, iterates across, initializes ArrayList, coalescses + // stats into a hashmap, then places in an array list + fs.nextLine(); + + while (fs.hasNextLine()) { + String[] v = fs.nextLine().split(","); + + int chg = Integer.parseInt(v[2]); + // one HashMap = one commit + Map valueMap = new HashMap<>(); + valueMap.put("id", v[0]); + valueMap.put("tm", v[1]); + valueMap.put("chg", String.valueOf(chg)); + allData.add(valueMap); + } + } + + catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + } + return allData; + } +} \ No newline at end of file From b88d471048872594627aa1f9d47562e2c91208c7 Mon Sep 17 00:00:00 2001 From: RMarx1456 Date: Thu, 17 Oct 2024 10:19:40 -0700 Subject: [PATCH 4/4] Committing so I can pull --- src/Main.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Main.java b/src/Main.java index 3cdc0c4..23661a0 100644 --- a/src/Main.java +++ b/src/Main.java @@ -22,11 +22,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 valueMap = new HashMap<>(); + valueMap.put("id", v[0]); + valueMap.put("tm", v[1]); + valueMap.put("chg", String.valueOf(chg)); + dta.add(valueMap); } } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage());