Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Feature: add timestamp information to text UIs (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
luguina authored Jun 2, 2020
1 parent f8c092d commit 44d9b84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
30 changes: 17 additions & 13 deletions src/com/sheepit/client/standalone/GuiText.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.sheepit.client.Client;
import com.sheepit.client.Gui;
import com.sheepit.client.Job;
import com.sheepit.client.Log;
import com.sheepit.client.Stats;
import com.sheepit.client.standalone.text.CLIInputActionHandler;
Expand All @@ -30,20 +29,25 @@
import sun.misc.Signal;
import sun.misc.SignalHandler;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GuiText implements Gui {
public static final String type = "text";

private int framesRendered;

private int sigIntCount = 0;

private Log log;
private DateFormat df;

private Client client;

public GuiText() {
this.framesRendered = 0;
this.log = Log.getInstance(null);
this.df = new SimpleDateFormat("MMM dd HH:mm:ss");
}

@Override public void start() {
Expand Down Expand Up @@ -98,55 +102,55 @@ else if (client.isRunning() && client.isSuspended() == false) {

if (client != null && client.isSuspended()) {
if (overwriteSuspendedMsg) {
System.out.println(msg_);
System.out.println(String.format("%s %s", this.df.format(new Date()), msg_));
}
}
else {
System.out.println(msg_);
System.out.println(String.format("%s %s", this.df.format(new Date()), msg_));
}
}

@Override public void error(String err_) {
System.out.println("Error " + err_);
System.out.println(String.format("ERROR: %s %s", this.df.format(new Date()), err_));
log.error("Error " + err_);
}

@Override public void AddFrameRendered() {
this.framesRendered += 1;
System.out.println("Frames rendered: " + this.framesRendered);
System.out.println(String.format("%s Frames rendered: %d", this.df.format(new Date()), this.framesRendered));
}

@Override public void displayStats(Stats stats) {
System.out.println("Frames remaining: " + stats.getRemainingFrame());
System.out.println("Credits earned: " + stats.getCreditsEarnedDuringSession());
System.out.println(String.format("%s Frames remaining: %d", this.df.format(new Date()), stats.getRemainingFrame()));
System.out.println(String.format("%s Credits earned: %d", this.df.format(new Date()), stats.getCreditsEarnedDuringSession()));
}

@Override public void displayUploadQueueStats(int queueSize, long queueVolume) {
// No need to check if the queue is not empty to show the volume bc this line is always shown at the end
// of the render process in text GUI (unless an error occurred, where the file is uploaded synchronously)
System.out.println(String.format("Queued uploads: %d (%.2fMB)", queueSize, (queueVolume / 1024.0 / 1024.0)));
System.out.println(String.format("%s Queued uploads: %d (%.2fMB)", this.df.format(new Date()), queueSize, (queueVolume / 1024.0 / 1024.0)));
}

@Override public void setRenderingProjectName(String name_) {
if (name_ != null && name_.isEmpty() == false) {
System.out.println("Rendering project \"" + name_ + "\"");
System.out.println(String.format("%s Rendering project \"%s\"", this.df.format(new Date()), name_));
}
}

@Override public void setRemainingTime(String time_) {
System.out.println("Rendering (remaining " + time_ + ")");
System.out.println(String.format("%s Rendering (remaining %s)", this.df.format(new Date()), time_));
}

@Override public void setRenderingTime(String time_) {
System.out.println("Rendering " + time_);
System.out.println(String.format("%s Rendering %s", this.df.format(new Date()), time_));
}

@Override public void setClient(Client cli) {
client = cli;
}

@Override public void setComputeMethod(String computeMethod) {
System.out.println("Compute method: " + computeMethod);
System.out.println(String.format("%s Compute method: %s", this.df.format(new Date()), computeMethod));
}

@Override public Client getClient() {
Expand Down
14 changes: 10 additions & 4 deletions src/com/sheepit/client/standalone/GuiTextOneLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

import com.sheepit.client.Client;
import com.sheepit.client.Gui;
import com.sheepit.client.Job;
import com.sheepit.client.Stats;
import com.sheepit.client.standalone.text.CLIInputActionHandler;
import com.sheepit.client.standalone.text.CLIInputObserver;

import sun.misc.Signal;
import sun.misc.SignalHandler;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GuiTextOneLine implements Gui {
public static final String type = "oneLine";

Expand All @@ -37,6 +40,7 @@ public class GuiTextOneLine implements Gui {
private int remaining;
private String creditsEarned;
private int sigIntCount = 0;
private DateFormat df;

private String computeMethod;
private String status;
Expand All @@ -59,6 +63,7 @@ public GuiTextOneLine() {
line = "";
uploadQueueSize = 0;
uploadQueueVolume = 0;
df = new SimpleDateFormat("MMM dd HH:mm:ss");
}

@Override public void start() {
Expand Down Expand Up @@ -179,9 +184,10 @@ private void updateLine() {

System.out.print("\r");

line = String.format("Frames: %d Points: %s | Queued uploads: %d%s | %s %s %s", rendered, creditsEarned != null ? creditsEarned : "unknown",
this.uploadQueueSize, (this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""), project,
computeMethod, status + (exiting ? " (Exiting after all frames are uploaded)" : ""));
line = String.format("%s Frames: %d Points: %s | Queued uploads: %d%s | %s %s %s", df.format(new Date()), rendered,
creditsEarned != null ? creditsEarned : "unknown", this.uploadQueueSize,
(this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""), project, computeMethod,
status + (exiting ? " (Exiting after all frames are uploaded)" : ""));

System.out.print(line);
for (int i = line.length(); i <= charToRemove; i++) {
Expand Down

0 comments on commit 44d9b84

Please sign in to comment.