Skip to content

Commit

Permalink
Merge pull request #19 from marcelmauel:feature/timeline-extractor
Browse files Browse the repository at this point in the history
new method to extract and print the timeline
  • Loading branch information
66-m authored Dec 5, 2023
2 parents b11b952 + 68a6f11 commit c4cd155
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
28 changes: 20 additions & 8 deletions src/main/java/io/github/compilerstuck/Control/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.compilerstuck.Sound.Sound;
import io.github.compilerstuck.Visual.Bars;
import io.github.compilerstuck.Visual.Gradient.ColorGradient;
import javafx.util.Pair;
import io.github.compilerstuck.Visual.Visualization;
import processing.core.PApplet;

Expand All @@ -30,6 +31,7 @@ public class MainController extends PApplet {
private final ArrayList<String> swaps = new ArrayList<>();
private final ArrayList<String> writesMain = new ArrayList<>();
private final ArrayList<String> writesAux = new ArrayList<>();
private final ArrayList<Integer> timestamps = new ArrayList<>();

private static boolean start = false;
private static boolean running = false;
Expand Down Expand Up @@ -147,6 +149,9 @@ public void draw() {
settings.setProgressBar(100);
settings.setEnableInputs(true);
settings.setEnableCancelButton(false);

printTimestampsToConsole();

} else if (running) {
visualization.update();
arrayController.update();
Expand Down Expand Up @@ -175,21 +180,18 @@ public void draw() {

private void startAlgorithmThread() {
new Thread(() -> {

int startTime = (int) (System.currentTimeMillis() / 1000L);

for (SortingAlgorithm algorithm : algorithms) {
if (!SortingAlgorithm.isRun()) {
break;
}
// if (alg.alternativeSize != arrayController.getLength()) {
// sound.mute(true);
// colorGradient.updateGradient(alg.alternativeSize);
// arrayController.resize(alg.alternativeSize);
//
// delay(1000);
// sound.mute(false);
// }

sound.mute(true);
sound.mute(false);

timestamps.add((int) (System.currentTimeMillis() / 1000L) - startTime);

arrayController.shuffle();
if (!SortingAlgorithm.isRun()) {
Expand Down Expand Up @@ -238,6 +240,16 @@ public static void shutdown(){
processing.exit();
}

public void printTimestampsToConsole() {
System.out.println("\nTimestamps:");
for (int i = 0; i < algorithms.size(); i++) {
int minutes = timestamps.get(i) / 60;
int seconds = timestamps.get(i) % 60;
String time = String.format("%02d:%02d", minutes, seconds);
System.out.println(time + " " + algorithms.get(i).getName());
}
}

private void printResults() {
textSize((int) (20. / 1280 * width));
background(15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class GravitySort extends SortingAlgorithm {

public GravitySort(ArrayController arrayController) {
super(arrayController);
this.name = "Gravity (Bead) Sort";
this.name = "Gravity Sort";
alternativeSize = arrayController.getLength();
delayTime = 2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class QuickSortMiddlePivot extends SortingAlgorithm {

public QuickSortMiddlePivot(ArrayController arrayController) {
super(arrayController);
this.name = "Quick Sort (Pivot Middle)";
this.name = "Quick Sort (Middle Pivot)";
alternativeSize = arrayController.getLength();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public class RadixLSDSortBase10 extends SortingAlgorithm {

public RadixLSDSortBase10(ArrayController arrayController) {
super(arrayController);
this.name = "Radix (LSD) Sort (Base " + RADIX + ")";
this.name = "Radix Sort (LSD) (Base " + RADIX + ")";
alternativeSize = arrayController.getLength();
}

public RadixLSDSortBase10(ArrayController arrayController, int radix_base) {
super(arrayController);
RADIX = radix_base;
this.name = "Radix (LSD) Sort (Base " + RADIX + ")";
this.name = "Radix Sort (LSD) (Base " + RADIX + ")";
}


Expand Down

0 comments on commit c4cd155

Please sign in to comment.