Skip to content

Commit

Permalink
More CSVs.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed Oct 6, 2023
1 parent 2ca7b9f commit 80a4bca
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public class EvaluateHybridizeFunctionRefactoringHandler extends EvaluateRefacto

private static final String TRANSFORMATIONS_CSV_FILENAME = "transformations.csv";

private static final String OPTMIZABLE_CSV_FILENAME = "optimizable.csv";

private static final String NONOPTMIZABLE_CSV_FILENAME = "nonoptimizable.csv";

private static final String FAILED_PRECONDITIONS_CSV_FILENAME = "failed_preconditions.csv";

private static final String PERFORM_CHANGE_PROPERTY_KEY = "edu.cuny.hunter.hybridize.eval.performChange";

private static String[] buildAttributeColumnNames(String... additionalColumnNames) {
Expand Down Expand Up @@ -99,7 +105,11 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
buildAttributeColumnNames("parameters", "tensor parameter", "hybrid", "refactoring", "passing precondition",
"status"));
CSVPrinter transformationsPrinter = createCSVPrinter(TRANSFORMATIONS_CSV_FILENAME,
buildAttributeColumnNames("transformation"))) {
buildAttributeColumnNames("transformation"));
CSVPrinter optimizableFunctionPrinter = createCSVPrinter(OPTMIZABLE_CSV_FILENAME, buildAttributeColumnNames());
CSVPrinter nonOptimizableFunctionPrinter = createCSVPrinter(NONOPTMIZABLE_CSV_FILENAME, buildAttributeColumnNames());
CSVPrinter errorPrinter = createCSVPrinter(FAILED_PRECONDITIONS_CSV_FILENAME,
buildAttributeColumnNames("code", "message"));) {
IProject[] pythonProjectsFromEvent = getSelectedPythonProjectsFromEvent(event);

monitor.beginTask("Analyzing projects...", pythonProjectsFromEvent.length);
Expand Down Expand Up @@ -149,16 +159,37 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
Set<Function> optimizableFunctions = processor.getOptimizableFunctions();
resultsPrinter.print(optimizableFunctions.size()); // number.

for (Function function : optimizableFunctions)
optimizableFunctionPrinter.printRecord(buildAttributeColumnValues(function));

// failed functions.
SetView<Function> failures = Sets.difference(candidates, optimizableFunctions);

for (Function function : failures)
nonOptimizableFunctionPrinter.printRecord(buildAttributeColumnValues(function));

// failed preconditions.
Collection<RefactoringStatusEntry> errorEntries = failures.parallelStream().map(Function::getStatus)
.flatMap(s -> Arrays.stream(s.getEntries())).filter(RefactoringStatusEntry::isError)
.collect(Collectors.toSet());

resultsPrinter.print(errorEntries.size()); // number.

for (RefactoringStatusEntry entry : errorEntries) {
if (!entry.isFatalError()) {
Object correspondingElement = entry.getData();

if (!(correspondingElement instanceof Function))
throw new IllegalStateException("The element: " + correspondingElement
+ " corresponding to a failed precondition is not a Function. Instead, it is a: "
+ correspondingElement.getClass());

Function failedFunction = (Function) correspondingElement;

errorPrinter.printRecord(buildAttributeColumnValues(failedFunction, entry.getCode(), entry.getMessage()));
}
}

// refactoring type counts.
for (Refactoring refactoringKind : Refactoring.values())
resultsPrinter.print(functions.parallelStream().map(Function::getRefactoring)
Expand All @@ -174,6 +205,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
resultsPrinter.print(functions.parallelStream().map(Function::getTransformations).filter(Objects::nonNull)
.flatMap(as -> as.parallelStream()).filter(a -> Objects.equals(a, transformation)).count());

// actually perform the refactoring if there are no fatal errors.
if (Boolean.getBoolean(PERFORM_CHANGE_PROPERTY_KEY) && !status.hasFatalError()) {
resultsTimeCollector.start();
Change change = refactoring.createChange(monitor.slice(IProgressMonitor.UNKNOWN));
Expand Down

0 comments on commit 80a4bca

Please sign in to comment.