-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
168 lines (130 loc) · 5.25 KB
/
App.java
File metadata and controls
168 lines (130 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package app;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import analysis.AnalysisType;
import artifact.Artifact;
import codeOwnership.CodeOwnership;
import exception.StudentNotFoundException;
import extractor.Extractor;
import expertise.Expertise;
import git.GitRepository;
import pair.PairStudentArtifact;
import student.Student;
import student.StudentExpertise;
import org.eclipse.jgit.api.errors.GitAPIException;
import com.github.javaparser.utils.Pair;
import util.Util;
import static util.Util.LS;
public class App {
private static CodeOwnership co;
private static Scanner in = new Scanner(System.in);
public static void main(String[] args) throws Exception {
String repoPath = inputRepositoryPath();
AnalysisType analysisType = chooseAnalysisType();
co = new CodeOwnership(analysisType, repoPath);
printAllStudentsNames();
System.out.println(generateExpertiseData(co));
generateTSV();
displayStudentInformation();
in.close();
}
private static void printPairs(CodeOwnership co2) {
List<PairStudentArtifact> aa = co.getPairRepository().getPairs();
for(PairStudentArtifact pair : aa) {
System.out.println(pair.toString());
System.out.println();
}
}
private static String inputRepositoryPath() {
System.out.print("Enter the path to your repository: ");
return in.nextLine();
}
private static void printArtifacts(CodeOwnership co) {
List<Artifact> list = co.getArtifactRepository().getArtifacts();
for (Artifact artifact : list) {
System.out.println(artifact.toString());
}
}
private static AnalysisType chooseAnalysisType() {
System.out
.println("Choose the type of analysis:" + LS + "1) Creation" + LS + "2) LOC" + LS + "3) Co-authorship");
int input = Integer.parseInt(in.nextLine());
for (AnalysisType type : AnalysisType.values()) {
if (type.getIndex() == input) {
System.out.println("Analysis by " + type + " was chosen." + LS);
return type;
}
}
System.out.println("Your input is invalid. Please, try again." + LS);
return chooseAnalysisType();
}
private static void displayStudentInformation() {
System.out.println("Which student contributions would you like to see?");
System.out.println(co.listStudents());
System.out.println("Choose a valid number (an invalid number will end this program):");
int input = Integer.parseInt(in.nextLine());
try {
String studentName = co.getStudentByIndex(input - 1).getName();
System.out.println(co.getStudentContributionInfo(studentName));
displayStudentInformation();
} catch (IndexOutOfBoundsException e) {
System.out.println(LS + "See ya!");
} catch (StudentNotFoundException e) {
System.out.println(e.getMessage());
System.out.println("Try another student.");
}
}
private static void generateTSV() {
if (Util.generateTSV(co.getPairRepository().getPairs())) {
System.out.println("TSV successfully generated! Check outputs/analysis-result.tsv ;)" + LS);
} else {
System.out.println("There occurred an error during the generation of this project's TSV. :(" + LS);
}
}
private static void printAllStudentsNames() throws GitAPIException, IOException {
System.out.println("Students names in the system:");
System.out.println(co.listAllStudentsNames().toString() + LS);
}
// Alterandoooo --------------------------------------
private static String generateExpertiseData(CodeOwnership co) {
List<Student> students = co.getAllStudents();
String resp = "";
List<PairStudentArtifact> pairs = co.getPairRepository().getPairs();
int[] totalOfClassesOfEachExpertise = co.totalOfClassOfEachExpertise();
for (Student student : students) {
double[] counterOfExpertises = new double[8];
for (PairStudentArtifact pairStudentArtifact : pairs) {
Student studentOfTheCurrentPair = pairStudentArtifact.getStudent();
Artifact artifact = pairStudentArtifact.getArtifact();
if (student.equals(studentOfTheCurrentPair)) {
countExpertise(counterOfExpertises, artifact, pairStudentArtifact.getOwnershipPercentage());
}
}
StudentExpertise studentExpertise = new StudentExpertise(student, counterOfExpertises,
totalOfClassesOfEachExpertise);
resp += studentExpertise.toString();
}
return resp;
}
private static void countExpertise(double[] counterOfExpertises, Artifact artifact, double ownershipPercentege) {
if (artifact.getExpertise().contains(Expertise.INTERFACE))
counterOfExpertises[0] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.INHERITANCE))
counterOfExpertises[1] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.TESTS))
counterOfExpertises[2] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.EXCEPTION_HIERARCHY))
counterOfExpertises[3] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.EXCEPTIONS))
counterOfExpertises[4] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.EXCEPTION_HANDLING))
counterOfExpertises[5] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.PERSISTENCE))
counterOfExpertises[6] += ownershipPercentege;
if (artifact.getExpertise().contains(Expertise.ABSTRACT_CLASSES))
counterOfExpertises[7] += ownershipPercentege;
}
}