Add 3D printer status to stats

This commit is contained in:
Tanner Collin 2023-03-18 23:42:09 +00:00
parent e00bea9faa
commit a460211809
4 changed files with 25 additions and 1 deletions

View File

@ -24,7 +24,7 @@ class LoggingThrottle(throttling.BaseThrottle):
return True
elif path == '/sessions/' and user == None:
return True
elif path in ['/pinball/high_scores/', '/protocoin/printer_balance/', '/hosting/high_scores/']:
elif path in ['/pinball/high_scores/', '/protocoin/printer_balance/', '/hosting/high_scores/', '/stats/ord2/printer3d/', '/stats/ord3/printer3d/']:
return True
if request.data:

View File

@ -30,6 +30,7 @@ DEFAULTS = {
'autoscan': '',
'last_scan': {},
'closing': {},
'printer3d': {},
}
if secrets.MUMBLE:

View File

@ -953,6 +953,23 @@ class StatsViewSet(viewsets.ViewSet, List):
return Response(200)
@action(detail=True, methods=['post'])
def printer3d(self, request, pk=None):
printer3d = cache.get('printer3d', {})
devicename = pk
status = request.data['result']['status']
printer3d[devicename] = dict(
progress=int(status['display_status']['progress'] * 100),
#filename=status['print_stats']['filename'],
state=status['idle_timeout']['state'],
)
cache.set('printer3d', printer3d)
return Response(200)
class MemberCountViewSet(Base, List):
pagination_class = None

View File

@ -244,6 +244,8 @@ export function Home(props) {
const closedStat = (x) => stats && stats.closing ? moment().unix() > stats.closing['time'] ? 'Closed' : 'Open until ' + stats.closing['time_str'] : 'Unknown';
const printer3dStat = (x) => stats && stats.printer3d[x] ? stats.printer3d[x].state === 'Printing' ? 'Printing (' + stats.printer3d[x].progress + '%)' : stats.printer3d[x].state : 'Unknown';
const show_signup = stats?.at_protospace;
return (
@ -357,6 +359,10 @@ export function Home(props) {
} trigger={<a>[more]</a>} />
</p>
<p>ORD2 printer: {printer3dStat('ord2')}</p>
<p>ORD3 printer: {printer3dStat('ord3')}</p>
{user && <p>Alarm status: {alarmStat()}{doorOpenStat()}</p>}
{user && <p>Hosting status: {closedStat()}</p>}