Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,16 @@
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();

List<Map<String, String>> dta = 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<String, String> mp1 = new HashMap<>();
mp1.put("id", v[0]);
mp1.put("tm", v[1]);
mp1.put("chg", String.valueOf(chg));
dta.add(mp1);
}
} catch (FileNotFoundException e) {
System.out.println("Error reading the file: " + e.getMessage());
s.close();
return;
}
List<Map<String, String>> data = parseCSV(f);


//goes through our map, if our list is empty it adds it into a new array list
Map<String, List<Map<String, String>>> mp2 = new HashMap<>();
for (Map<String, String> d : dta) {
for (Map<String, String> d : data) {
String id = d.get("id");
List<Map<String, String>> lst = mp2.get(id);
if (lst == null) {
Expand All @@ -43,21 +26,23 @@ 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();

// if the user input is "all", it prints out everything. Else, it prints out the input
List<Map<String, String>> sel;
if (inp.equalsIgnoreCase("all")) {
sel = dta;
sel = data;
} else {
String id = "fork" + inp;
sel = mp2.get(id);
}

int sz = sel.size();

//calculates the time of the fork
DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime lat = null;
for (Map<String, String> d : sel) {
Expand All @@ -69,6 +54,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<String, String> d : sel) {
Expand All @@ -78,6 +64,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<String, String> d : sel) {
Expand All @@ -100,4 +87,27 @@ public static void main(String[] args) {

s.close();
}
public static List<Map<String, String>> parseCSV(String filename){
List<Map<String, String>> 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<String, String> 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;
}
}