Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add elapsed time and finish time to Printer Status #510

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: [push, pull_request]

jobs:
setup-venv:
runs-on: ubuntu-latest
runs-on: debian-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
Expand All @@ -24,7 +24,7 @@ jobs:
if: steps.setup-venv.outputs.cache-hit != 'true'

backend-build:
runs-on: ubuntu-latest
runs-on: debian-latest
needs: setup-venv
strategy:
matrix:
Expand All @@ -48,7 +48,7 @@ jobs:
path: backend-coverage.xml

frontend-build:
runs-on: ubuntu-latest
runs-on: debian-latest
defaults:
run:
working-directory: frontend
Expand All @@ -68,7 +68,7 @@ jobs:
path: frontend-coverage.json

codecov:
runs-on: ubuntu-latest
runs-on: debian-latest
needs: [backend-build, frontend-build]
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: debian-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/components/PrintStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class PrintStatus extends React.Component<
layerCount: response.layer_count,
printTimeSecs: response.print_time_secs,
timeLeftSecs: response.time_left_secs,
elapsedSecs: response.elapsed_seconds,
finishTime: response.finish_time,
},
});
}
Expand Down Expand Up @@ -256,6 +258,18 @@ class PrintStatus extends React.Component<

<div className={classes.gridRoot}>
<Grid container spacing={3}>
<Grid item xs={6}>
<Typography variant="h5" color="textPrimary" display="inline">
{renderTime(nullthrows(elapsedSecs))}&nbsp;
</Typography>
<Typography
variant="body1"
color="textSecondary"
display="inline"
>
done
</Typography>
</Grid>
<Grid item xs={6}>
<Typography variant="h5" color="textPrimary" display="inline">
{renderTime(nullthrows(timeLeftSecs))}&nbsp;
Expand All @@ -268,6 +282,18 @@ class PrintStatus extends React.Component<
left
</Typography>
</Grid>
<Grid item xs={6}>
<Typography variant="h5" color="textPrimary" display="inline">
{finishTime}&nbsp;
</Typography>
<Typography
variant="body1"
color="textSecondary"
display="inline"
>
finish time
</Typography>
</Grid>
<Grid item xs={6}>
<Typography variant="h5" color="textPrimary" display="inline">
{currentLayer}
Expand Down
7 changes: 6 additions & 1 deletion mariner/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Match, Optional, Type

import serial
import time

from mariner import config
from mariner.exceptions import UnexpectedPrinterResponse
Expand Down Expand Up @@ -139,7 +140,11 @@ def start_printing(self, filename: str) -> None:
timeout_secs=2.0,
)
if "ok" not in response:
raise UnexpectedPrinterResponse(response)
raise UnexpectedPrinterResponse(response)
timestamp_file = config.get_cache_directory() + '/timestamp.txt'
f = open(timestamp_file,"w")
f.write(str(int(time.time())))
f.close()
Comment on lines +144 to +147
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit hacky 😅 You are basically doing this so you can later on figure out when the printing was started, right?

Here's some thoughts I have on the current implementation:

  1. We will run into issues with prints which were started from other sources (e.g. from the printer itself).
  2. This is doing a write to the filesystem from mariner.printer, which is meant really to just interface with the printer. The removal of the state file is happening from mariner.server.api - so it seems like we're mixing the roles of each module.
  3. This will create all sorts of bugs with things like: if we start a print from the UI and then never come back to it, the state file won't get deleted. If we start a print from the printer and open the UI, we won't have a state file.

I feel like if we want to build this functionality correctly, we should create some sort of internal in-memory state for the server. Probably a second thread which is responsible for doing all communication with the printer and also responsible for polling the printer for its status - so that if a print is started from the printer we will get to know about it. This is something which I have been interested in for a while but haven't had the time to build: see #75 if you're interested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very valid points.

BTW, congrats on getting it back to a building state - I have no idea what you did, but I would like to know.

I need to have a chat with you privately about this and a few other things I have in mind, however I have no way of getting in touch with you. Could you please drop me an email on [email protected]


def pause_printing(self) -> None:
response = self._send_and_read(b"M25")
Expand Down
26 changes: 23 additions & 3 deletions mariner/server/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import traceback
import time
import datetime from datetime
from enum import Enum
from typing import Any, Dict, Optional, Tuple

Expand Down Expand Up @@ -62,9 +64,13 @@ def print_status() -> str:
num_retries=3,
)

timestamp_file = config.get_cache_directory() + '/timestamp.txt'

if print_status.state == PrinterState.IDLE:
progress = 0.0
print_details = {}
if os.path.exists(timestamp_file) and os.path.isfile(timestamp_file):
os.remove(timestamp_file)
else:
sliced_model_file = read_cached_sliced_model_file(
config.get_files_directory() / selected_file
Expand All @@ -86,13 +92,27 @@ def print_status() -> str:
/ none_throws(sliced_model_file.layer_count)
)

time_left_secs = round(sliced_model_file.print_time_secs * (100.0 - progress) / 100.0)
elapsed_secs = 0
finish_time = "00:00"
if os.path.exists(timestamp_file) and os.path.isfile(timestamp_file) and current_layer > 1:
f = open(timestamp_file, 'r')
start_time = int(f.readline().rstrip())
f.close()

now_time = int(time.time())
elapsed_secs = now_time - start_time
time_left_secs = round ((elapsed_secs / current_layer) * (sliced_model_file.layer_count - current_layer))
finish_time_full = datetime.fromtimestamp(now_time + time_left_secs)
finish_time = finish_time_full.strftime("%H:%M")

print_details = {
"current_layer": current_layer,
"layer_count": sliced_model_file.layer_count,
"print_time_secs": sliced_model_file.print_time_secs,
"time_left_secs": round(
sliced_model_file.print_time_secs * (100.0 - progress) / 100.0
),
"time_left_secs": time_left_secs,
"elapsed_secs": elapsed_secs,
"finish_time": finish_time,
}

return jsonify(
Expand Down