From 3b0a74e8dfbf9824ac413471337f0ce29ad35fc0 Mon Sep 17 00:00:00 2001 From: Jameson Farmer Date: Tue, 15 Oct 2024 14:14:38 -0700 Subject: [PATCH 01/10] pushing comments --- src/Main.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index e5571ea..c3bfc88 100644 --- a/src/Main.java +++ b/src/Main.java @@ -7,7 +7,7 @@ public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); - + //instantiate scanner and read file System.out.print("Enter the CSV filename: "); String f = s.nextLine(); @@ -26,6 +26,7 @@ public static void main(String[] args) { mp1.put("chg", String.valueOf(chg)); dta.add(mp1); } + //converts string from file to int and then puts all data into hasmap then adds map to an array } catch (FileNotFoundException e) { System.out.println("Error reading the file: " + e.getMessage()); s.close(); From 537f59fc1fec38e2c2fe332e75d69ff17bae659e Mon Sep 17 00:00:00 2001 From: Lizock Date: Tue, 15 Oct 2024 14:17:37 -0700 Subject: [PATCH 02/10] Added a comment --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index c3bfc88..fca1a91 100644 --- a/src/Main.java +++ b/src/Main.java @@ -33,6 +33,7 @@ public static void main(String[] args) { return; } + //goes through our map, if our list is empty it adds it into a new array list Map>> mp2 = new HashMap<>(); for (Map d : dta) { String id = d.get("id"); From 2748126179913346db35d411315f6fe818420472 Mon Sep 17 00:00:00 2001 From: Jameson Farmer Date: Tue, 15 Oct 2024 14:19:58 -0700 Subject: [PATCH 03/10] more comments --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index fca1a91..73cd458 100644 --- a/src/Main.java +++ b/src/Main.java @@ -45,7 +45,7 @@ public static void main(String[] args) { lst.add(d); } int cnt = mp2.size(); - + //tells the user how many forks they have and prompts for which one to check 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(); From eedb5045f9e8d0fcbcb1ccb308e45affd7949471 Mon Sep 17 00:00:00 2001 From: Lizock Date: Tue, 15 Oct 2024 14:23:24 -0700 Subject: [PATCH 04/10] Added a comment --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index fca1a91..60b3c36 100644 --- a/src/Main.java +++ b/src/Main.java @@ -50,6 +50,7 @@ public static void main(String[] args) { System.out.print("Enter the fork number to analyze (or 'all' for all forks): "); String inp = s.nextLine(); + // if the user input is "all", it prints out everything. Else, it prints out the input List> sel; if (inp.equalsIgnoreCase("all")) { sel = dta; From 16f21a77d1ed49a0de07c62a1dbac1b1d29cb8d1 Mon Sep 17 00:00:00 2001 From: Jameson Farmer Date: Tue, 15 Oct 2024 14:27:41 -0700 Subject: [PATCH 05/10] more comments --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index 0d45d89..3202087 100644 --- a/src/Main.java +++ b/src/Main.java @@ -61,6 +61,7 @@ public static void main(String[] args) { int sz = sel.size(); + //calculates the time of the fork DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime lat = null; for (Map d : sel) { From 809243707c578e13470e4d9e3a8a9173bc99b8cc Mon Sep 17 00:00:00 2001 From: Lizock Date: Tue, 15 Oct 2024 14:28:08 -0700 Subject: [PATCH 06/10] Added a comment --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index 0d45d89..7604b0d 100644 --- a/src/Main.java +++ b/src/Main.java @@ -72,6 +72,7 @@ public static void main(String[] args) { DateTimeFormatter f2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String latT = lat.format(f2); + // calculates the total commits and colculates the average double tot = 0.0; int tlc = 0; for (Map d : sel) { From 772cb68c6b6e3f780b975948fda703c355f048db Mon Sep 17 00:00:00 2001 From: Jameson Farmer Date: Tue, 15 Oct 2024 14:31:18 -0700 Subject: [PATCH 07/10] final comments hopefully --- src/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main.java b/src/Main.java index d2685af..fdef64f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -83,6 +83,7 @@ public static void main(String[] args) { } double avg = tot / sz; + //calcultes min and max value though mx and mn int mx = Integer.MIN_VALUE; int mn = Integer.MAX_VALUE; for (Map d : sel) { From 0366666b91d93ef106e6ccaad339b22467824fdb Mon Sep 17 00:00:00 2001 From: Jameson Farmer Date: Tue, 15 Oct 2024 14:44:02 -0700 Subject: [PATCH 08/10] variable change --- src/Main.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Main.java b/src/Main.java index fdef64f..ab34bc5 100644 --- a/src/Main.java +++ b/src/Main.java @@ -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 fileOutput = new HashMap<>(); + fileOutput.put("id", v[0]); + fileOutput.put("tm", v[1]); + fileOutput.put("chg", String.valueOf(chg)); + dta.add(fileOutput); } //converts string from file to int and then puts all data into hasmap then adds map to an array } catch (FileNotFoundException e) { From e158173a7d30d00794fcfc6d82468f1277750874 Mon Sep 17 00:00:00 2001 From: Lizock Date: Tue, 15 Oct 2024 14:46:00 -0700 Subject: [PATCH 09/10] Renamed dta --- src/Main.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Main.java b/src/Main.java index ab34bc5..565df7a 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(); - List> dta = new ArrayList<>(); + List> data = new ArrayList<>(); try (Scanner fs = new Scanner(new File(f))) { fs.nextLine(); @@ -24,7 +24,7 @@ public static void main(String[] args) { fileOutput.put("id", v[0]); fileOutput.put("tm", v[1]); fileOutput.put("chg", String.valueOf(chg)); - dta.add(fileOutput); + data.add(fileOutput); } //converts string from file to int and then puts all data into hasmap then adds map to an array } catch (FileNotFoundException e) { @@ -35,7 +35,7 @@ public static void main(String[] args) { //goes through our map, if our list is empty it adds it into a new array list 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) { @@ -53,7 +53,7 @@ public static void main(String[] args) { // if the user input is "all", it prints out everything. Else, it prints out the input List> sel; if (inp.equalsIgnoreCase("all")) { - sel = dta; + sel = data; } else { String id = "fork" + inp; sel = mp2.get(id); From fcd60eddebac7ec7ab2fedc3cb73bd7214201311 Mon Sep 17 00:00:00 2001 From: Jameson Farmer Date: Tue, 15 Oct 2024 15:02:07 -0700 Subject: [PATCH 10/10] finished --- src/Main.java | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Main.java b/src/Main.java index 565df7a..bb1c06c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,27 +11,8 @@ public static void main(String[] args) { System.out.print("Enter the CSV filename: "); String f = s.nextLine(); - List> data = 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 fileOutput = new HashMap<>(); - fileOutput.put("id", v[0]); - fileOutput.put("tm", v[1]); - fileOutput.put("chg", String.valueOf(chg)); - data.add(fileOutput); - } - //converts string from file to int and then puts all data into hasmap then adds map to an array - } catch (FileNotFoundException e) { - System.out.println("Error reading the file: " + e.getMessage()); - s.close(); - return; - } + List> data = parseCSV(f); + //goes through our map, if our list is empty it adds it into a new array list Map>> mp2 = new HashMap<>(); @@ -106,4 +87,27 @@ public static void main(String[] args) { s.close(); } + public static List> parseCSV(String filename){ + List> data = 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 fileOutput = new HashMap<>(); + fileOutput.put("id", v[0]); + fileOutput.put("tm", v[1]); + fileOutput.put("chg", String.valueOf(chg)); + data.add(fileOutput); + } + //converts string from file to int and then puts all data into hasmap then adds map to an array + } catch (FileNotFoundException e) { + System.out.println("Error reading the file: " + e.getMessage()); + return null; + } + return data; + } }