Skip to content

Commit

Permalink
Fix and suppress issues from Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
SamCarlberg committed Jul 10, 2016
1 parent b71d79a commit 493560f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/edu/wpi/grip/core/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ protected final void runPerformIfPossible() {
* InputSocket#getValue()} are not empty. If one input is invalid then the perform method will not
* run and all output sockets will be assigned to their default values.
*
* @param inBenchmark if this step is being benchmarked. The operation's perform method will be
* called if every input is valid regardless of 'dirtiness' if it's being
* benchmarked.
* @param benchmarking if this step is being benchmarked. The operation's perform method will be
* called if every input is valid regardless of 'dirtiness' if it's being
* benchmarked.
*/
protected final void runPerform(boolean inBenchmark) {
protected final void runPerform(boolean benchmarking) {
boolean anyDirty = false; // Keeps track of if there are sockets that are dirty

for (InputSocket<?> inputSocket : inputSockets) {
Expand All @@ -125,7 +125,7 @@ protected final void runPerform(boolean inBenchmark) {
// If one value is true then this will stay true
anyDirty |= inputSocket.dirtied();
}
if (!inBenchmark && !anyDirty) {
if (!benchmarking && !anyDirty) {
// If there aren't any dirty inputs don't clear the exceptions, just return
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* An event posted before and after a pipeline is benchmarked.
*/
public class BenchmarkEvent {
public final class BenchmarkEvent {

private final boolean isStart;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.wpi.grip.core.metrics;

import edu.wpi.grip.core.Pipeline;
import edu.wpi.grip.core.events.BenchmarkEvent;
import edu.wpi.grip.core.events.BenchmarkRunEvent;
import edu.wpi.grip.core.events.RunStartedEvent;
Expand All @@ -26,8 +25,6 @@ public class BenchmarkRunner {

@Inject
private EventBus eventBus;
@Inject
private Pipeline pipeline;

private AtomicBoolean isBenchmarking = new AtomicBoolean(false);
private AtomicInteger runsRemaining = new AtomicInteger(0);
Expand All @@ -46,6 +43,7 @@ public void run(int numRuns) {
}

@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onRunStart(@Nullable RunStartedEvent event) {
if (!isBenchmarking.get()) {
return;
Expand All @@ -54,6 +52,7 @@ private void onRunStart(@Nullable RunStartedEvent event) {
}

@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onRunStop(@Nullable RunStoppedEvent event) {
if (!isBenchmarking.get()) {
return;
Expand All @@ -66,7 +65,12 @@ private void onRunStop(@Nullable RunStoppedEvent event) {
}
}

/**
* Resets the runner if a "finished" benchmark event is posted while a benchmark is being run.
* This is used to kill the runner if the analysis window is closed or the application is exited.
*/
@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onBenchmarkEvent(BenchmarkEvent event) {
if (isBenchmarking.get() && !event.isStart()) {
isBenchmarking.set(false);
Expand Down
4 changes: 2 additions & 2 deletions ui/src/main/java/edu/wpi/grip/ui/MainWindowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ private void updateElapsedTimeLabel(long elapsed) {
}

@FXML
@SuppressWarnings({"PMD.UnusedPrivateMethod"})
private void showAnalysis() {
Stage analysisStage = new Stage();
try {
Expand All @@ -304,7 +305,7 @@ private void showAnalysis() {
controller.setBenchmarker(benchmarkRunner);
eventBus.register(controller);
} catch (IOException e) {
throw new RuntimeException(e);
throw new AssertionError("Analysis window FXML is not present or readable", e);
}
analysisStage.initModality(Modality.WINDOW_MODAL);
analysisStage.initOwner(root.getScene().getWindow());
Expand All @@ -314,6 +315,5 @@ private void showAnalysis() {
eventBus.post(BenchmarkEvent.finished());
});
analysisStage.showAndWait();
System.out.println("User finished analysis");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void initialize() {
table.setItems(tableItems);

benchmarkRunsField.textProperty().addListener((observable, oldValue, newValue) -> {
if ((oldValue.isEmpty() && newValue.equals("0")) || !newValue.matches("[\\d]*")) {
if ((oldValue.isEmpty() && "0".equals(newValue)) || !newValue.matches("[\\d]*")) {
benchmarkRunsField.setText(oldValue);
return;
}
Expand All @@ -90,6 +90,7 @@ public void initialize() {
}

@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onRun(TimerEvent<?> event) {
if (event.getSource() instanceof Step) {
Step source = (Step) event.getSource();
Expand All @@ -99,6 +100,7 @@ private void onRun(TimerEvent<?> event) {
}

@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onStepRemoved(StepRemovedEvent event) {
stepData.stream()
.filter(p -> p.getLeft() == event.getStep()) // Want reference equality
Expand All @@ -108,6 +110,7 @@ private void onStepRemoved(StepRemovedEvent event) {
}

@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onPipelineFinish(@Nullable RunStoppedEvent event) {
// Update the table after the pipeline finishes
tableItems.clear();
Expand All @@ -119,6 +122,7 @@ private void onPipelineFinish(@Nullable RunStoppedEvent event) {
}

@Subscribe
@SuppressWarnings({"PMD.UnusedPrivateMethod", "PMD.UnusedFormalParameter"})
private void onBenchmark(BenchmarkEvent event) {
benchmarkButton.setDisable(event.isStart());
benchmarkRunsField.setDisable(event.isStart());
Expand All @@ -129,6 +133,7 @@ public void setBenchmarker(BenchmarkRunner benchmarker) {
}

@FXML
@SuppressWarnings("PMD.UnusedPrivateMethod")
private void runBenchmark() {
if (benchmarkRunsField.getText().length() > 0) {
benchmarker.run(Integer.parseInt(benchmarkRunsField.getText()));
Expand All @@ -143,16 +148,14 @@ private static class TimeView extends HBox {
private final ProgressBar progressBar = new ProgressBar();

TimeView(double time, double relativeAmount, double hotness) {
super();
text.setText(String.format("%.1fms", time / 1e3));
progressBar.setProgress(relativeAmount);
progressBar.setPrefWidth(BAR_LENGTH);
progressBar.setPadding(new Insets(0, 10, 0, 5));
if (hotness > 0) {
final double max = 3; // highest value before being clamped
if (hotness > max) {
hotness = max; // clamp
}
double h = ((max - hotness) * 270 / max) - 45;
double h = ((max - Math.min(hotness, max)) * 270 / max) - 45;
final String formatStyle = "-fx-accent: hsb(%.2f, 100%%, 100%%);";
progressBar.setStyle(String.format(formatStyle, h));
}
Expand Down

0 comments on commit 493560f

Please sign in to comment.