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
54 changes: 32 additions & 22 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,15 @@ public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);

// reads data from file and puts into data structures
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>> forkDirectory = parseCSV(f);


Map<String, List<Map<String, String>>> mp2 = new HashMap<>();
for (Map<String, String> d : dta) {
for (Map<String, String> d : forkDirectory) {
String id = d.get("id");
List<Map<String, String>> lst = mp2.get(id);
if (lst == null) {
Expand All @@ -44,20 +27,22 @@ public static void main(String[] args) {
}
int cnt = mp2.size();

// number of forks in the data and select which fork to view
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();

List<Map<String, String>> sel;
if (inp.equalsIgnoreCase("all")) {
sel = dta;
sel = forkDirectory;
} else {
String id = "fork" + inp;
sel = mp2.get(id);
}

int sz = sel.size();

// formats date
DateTimeFormatter f1 = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime lat = null;
for (Map<String, String> d : sel) {
Expand All @@ -78,6 +63,7 @@ public static void main(String[] args) {
}
double avg = tot / sz;

// for max and min lines of code changed in a commit
int mx = Integer.MIN_VALUE;
int mn = Integer.MAX_VALUE;
for (Map<String, String> d : sel) {
Expand All @@ -90,6 +76,7 @@ public static void main(String[] args) {
}
}

// display results
System.out.println("\nStatistics:");
System.out.println("Number of commits: " + sz);
System.out.println("Most recent commit timestamp: " + latT);
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>> forkDirectory = 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> initialToken = new HashMap<>();
initialToken.put("id", v[0]);
initialToken.put("tm", v[1]);
initialToken.put("chg", String.valueOf(chg));

forkDirectory.add(initialToken);
}
} catch (FileNotFoundException e) {
System.out.println("Error reading the file: " + e.getMessage());
}
return forkDirectory;
}
}