From 44d9b84b7dc7621347b19f0db28ad49a313b2bbe Mon Sep 17 00:00:00 2001 From: Luis Uguina Date: Wed, 3 Jun 2020 01:10:14 +1000 Subject: [PATCH] Feature: add timestamp information to text UIs (#241) --- .../sheepit/client/standalone/GuiText.java | 30 +++++++++++-------- .../client/standalone/GuiTextOneLine.java | 14 ++++++--- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/com/sheepit/client/standalone/GuiText.java b/src/com/sheepit/client/standalone/GuiText.java index 7873b1d4..a4e11837 100644 --- a/src/com/sheepit/client/standalone/GuiText.java +++ b/src/com/sheepit/client/standalone/GuiText.java @@ -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; @@ -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() { @@ -98,47 +102,47 @@ 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) { @@ -146,7 +150,7 @@ else if (client.isRunning() && client.isSuspended() == false) { } @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() { diff --git a/src/com/sheepit/client/standalone/GuiTextOneLine.java b/src/com/sheepit/client/standalone/GuiTextOneLine.java index 5854b26f..43e2a20c 100644 --- a/src/com/sheepit/client/standalone/GuiTextOneLine.java +++ b/src/com/sheepit/client/standalone/GuiTextOneLine.java @@ -21,7 +21,6 @@ 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; @@ -29,6 +28,10 @@ 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"; @@ -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; @@ -59,6 +63,7 @@ public GuiTextOneLine() { line = ""; uploadQueueSize = 0; uploadQueueVolume = 0; + df = new SimpleDateFormat("MMM dd HH:mm:ss"); } @Override public void start() { @@ -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++) {