-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #142
- Loading branch information
Showing
6 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from .model import * | ||
|
||
from sqlalchemy_utils import ArrowType | ||
|
||
class BadScan(Base): | ||
__tablename__ = 'badscans' | ||
|
||
id = Column(Integer, primary_key=True, nullable=False) | ||
timestamp = Column(ArrowType, nullable=False, default=datetime.datetime.utcnow) | ||
badscan = Column(String(255), nullable=False) | ||
|
||
def __init__(self, scan): | ||
self.badscan = scan | ||
|
||
@classmethod | ||
def from_id(cls, id): | ||
return DBSession.query(cls).filter(cls.id == id).one() | ||
|
||
@classmethod | ||
def all(cls): | ||
return DBSession.query(cls)\ | ||
.order_by(cls.timestamp).all() | ||
|
||
@classmethod | ||
def get_scans_with_counts(cls): | ||
out = [] | ||
badscans = DBSession.query(cls.badscan, func.count(cls.badscan).label('count'))\ | ||
.group_by(cls.badscan)\ | ||
.all() | ||
for badscan in badscans: | ||
most_recent = DBSession.query(cls)\ | ||
.filter(cls.badscan==badscan.badscan)\ | ||
.order_by(cls.timestamp.desc())\ | ||
.first() | ||
out.append({ | ||
'badscan': badscan.badscan, | ||
'count': badscan.count, | ||
'timestamp': most_recent.timestamp | ||
}) | ||
|
||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends "base.jinja2" %} | ||
{% set active_page = 'badscans' %} | ||
{% block title %}Bad Scans{% endblock %} | ||
|
||
{% block top %} | ||
<h1 class="page-header">Barcode Scans that Errored</h1> | ||
{% endblock %} | ||
|
||
{% block contentwide %} | ||
|
||
<table class="table table-condensed table-striped sticky sortable" id="events_table"> | ||
<thead> | ||
<tr> | ||
<th>Scan</th> | ||
<th>Count</th> | ||
<th>Timestamp</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for badscan in badscans %} | ||
<tr> | ||
<td>{{ badscan.badscan }}</td> | ||
<td>{{ badscan.count }}</td> | ||
<td>{{ badscan.timestamp|pretty_date|safe }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters