Пример #1
0
def events_summary():
    has_clip = request.args.get("has_clip", type=int)
    has_snapshot = request.args.get("has_snapshot", type=int)

    clauses = []

    if not has_clip is None:
        clauses.append((Event.has_clip == has_clip))

    if not has_snapshot is None:
        clauses.append((Event.has_snapshot == has_snapshot))

    if len(clauses) == 0:
        clauses.append((1 == 1))

    groups = (Event.select(
        Event.camera,
        Event.label,
        fn.strftime("%Y-%m-%d",
                    fn.datetime(Event.start_time, "unixepoch",
                                "localtime")).alias("day"),
        Event.zones,
        fn.COUNT(Event.id).alias("count"),
    ).where(reduce(operator.and_, clauses)).group_by(
        Event.camera,
        Event.label,
        fn.strftime("%Y-%m-%d",
                    fn.datetime(Event.start_time, "unixepoch", "localtime")),
        Event.zones,
    ))

    return jsonify([e for e in groups.dicts()])
Пример #2
0
 def from_timestamp(self, date_field):
     return fn.datetime(date_field, 'unixepoch')