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 return True
elif path == '/sessions/' and user == None: elif path == '/sessions/' and user == None:
return True 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 return True
if request.data: if request.data:

View File

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

View File

@ -953,6 +953,23 @@ class StatsViewSet(viewsets.ViewSet, List):
return Response(200) 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): class MemberCountViewSet(Base, List):
pagination_class = None 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 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; const show_signup = stats?.at_protospace;
return ( return (
@ -357,6 +359,10 @@ export function Home(props) {
} trigger={<a>[more]</a>} /> } trigger={<a>[more]</a>} />
</p> </p>
<p>ORD2 printer: {printer3dStat('ord2')}</p>
<p>ORD3 printer: {printer3dStat('ord3')}</p>
{user && <p>Alarm status: {alarmStat()}{doorOpenStat()}</p>} {user && <p>Alarm status: {alarmStat()}{doorOpenStat()}</p>}
{user && <p>Hosting status: {closedStat()}</p>} {user && <p>Hosting status: {closedStat()}</p>}