Fix types that are used in webUI

This commit is contained in:
Nick Mowen 2023-04-29 13:07:36 -06:00
parent dd304b162e
commit cefac89d6a
4 changed files with 27 additions and 15 deletions

View File

@ -44,7 +44,6 @@ from frigate.util import (
restart_frigate, restart_frigate,
vainfo_hwaccel, vainfo_hwaccel,
get_tz_modifiers, get_tz_modifiers,
to_relative_box,
) )
from frigate.storage import StorageMaintainer from frigate.storage import StorageMaintainer
from frigate.version import VERSION from frigate.version import VERSION
@ -196,7 +195,7 @@ def send_to_plus(id):
return make_response(jsonify({"success": False, "message": message}), 404) return make_response(jsonify({"success": False, "message": message}), 404)
# events from before the conversion to relative dimensions cant include annotations # events from before the conversion to relative dimensions cant include annotations
if any(d > 1 for d in event.box): if any(d > 1 for d in event.data["box"]):
include_annotation = None include_annotation = None
if event.end_time is None: if event.end_time is None:
@ -252,8 +251,8 @@ def send_to_plus(id):
event.save() event.save()
if not include_annotation is None: if not include_annotation is None:
region = event.region region = event.data["region"]
box = event.box box = event.data["box"]
try: try:
current_app.plus_api.add_annotation( current_app.plus_api.add_annotation(
@ -294,7 +293,7 @@ def false_positive(id):
return make_response(jsonify({"success": False, "message": message}), 404) return make_response(jsonify({"success": False, "message": message}), 404)
# events from before the conversion to relative dimensions cant include annotations # events from before the conversion to relative dimensions cant include annotations
if any(d > 1 for d in event.box): if any(d > 1 for d in event.data["box"]):
message = f"Events prior to 0.13 cannot be submitted as false positives" message = f"Events prior to 0.13 cannot be submitted as false positives"
logger.error(message) logger.error(message)
return make_response(jsonify({"success": False, "message": message}), 400) return make_response(jsonify({"success": False, "message": message}), 400)
@ -311,11 +310,15 @@ def false_positive(id):
# need to refetch the event now that it has a plus_id # need to refetch the event now that it has a plus_id
event = Event.get(Event.id == id) event = Event.get(Event.id == id)
region = event.region region = event.data["region"]
box = event.box box = event.data["box"]
# provide top score if score is unavailable # provide top score if score is unavailable
score = event.top_score if event.score is None else event.score score = (
(event.data["top_score"] if event.data["top_score"] else event.top_score)
if event.data["score"] is None
else event.data["score"]
)
try: try:
current_app.plus_api.add_false_positive( current_app.plus_api.add_false_positive(
@ -756,6 +759,7 @@ def events():
Event.top_score, Event.top_score,
Event.false_positive, Event.false_positive,
Event.box, Event.box,
Event.data,
] ]
if camera != "all": if camera != "all":

View File

@ -41,7 +41,7 @@ def migrate(migrator, database, fake=False, **kwargs):
) )
migrator.add_fields( migrator.add_fields(
Event, Event,
data=pw_pext.JSONField(), data=JSONField(default={}),
) )

View File

@ -163,7 +163,9 @@ export function EventCard({ camera, event }) {
<div className="text-xs md:text-normal text-gray-300">Start: {format(start, 'HH:mm:ss')}</div> <div className="text-xs md:text-normal text-gray-300">Start: {format(start, 'HH:mm:ss')}</div>
<div className="text-xs md:text-normal text-gray-300">Duration: {duration}</div> <div className="text-xs md:text-normal text-gray-300">Duration: {duration}</div>
</div> </div>
<div className="text-lg text-white text-right leading-tight">{(event.top_score * 100).toFixed(1)}%</div> <div className="text-lg text-white text-right leading-tight">
{((event?.data?.top_score || event.top_score) * 100).toFixed(1)}%
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -206,7 +206,7 @@ export default function Events({ path, ...props }) {
e.stopPropagation(); e.stopPropagation();
setDownloadEvent((_prev) => ({ setDownloadEvent((_prev) => ({
id: event.id, id: event.id,
box: event.box, box: event?.data?.box || event.box,
label: event.label, label: event.label,
has_clip: event.has_clip, has_clip: event.has_clip,
has_snapshot: event.has_snapshot, has_snapshot: event.has_snapshot,
@ -599,7 +599,7 @@ export default function Events({ path, ...props }) {
{event.sub_label {event.sub_label
? `${event.label.replaceAll('_', ' ')}: ${event.sub_label.replaceAll('_', ' ')}` ? `${event.label.replaceAll('_', ' ')}: ${event.sub_label.replaceAll('_', ' ')}`
: event.label.replaceAll('_', ' ')} : event.label.replaceAll('_', ' ')}
({(event.top_score * 100).toFixed(0)}%) ({((event?.data?.top_score || event.top_score) * 100).toFixed(0)}%)
</div> </div>
<div className="text-sm flex"> <div className="text-sm flex">
<Clock className="h-5 w-5 mr-2 inline" /> <Clock className="h-5 w-5 mr-2 inline" />
@ -638,7 +638,9 @@ export default function Events({ path, ...props }) {
<Button <Button
color="gray" color="gray"
disabled={uploading.includes(event.id)} disabled={uploading.includes(event.id)}
onClick={(e) => showSubmitToPlus(event.id, event.label, event.box, e)} onClick={(e) =>
showSubmitToPlus(event.id, event.label, event?.data?.box || event.box, e)
}
> >
{uploading.includes(event.id) ? 'Uploading...' : 'Send to Frigate+'} {uploading.includes(event.id) ? 'Uploading...' : 'Send to Frigate+'}
</Button> </Button>
@ -680,7 +682,9 @@ export default function Events({ path, ...props }) {
<div> <div>
<TimelineSummary <TimelineSummary
event={event} event={event}
onFrameSelected={(frame, seekSeconds) => onEventFrameSelected(event, frame, seekSeconds)} onFrameSelected={(frame, seekSeconds) =>
onEventFrameSelected(event, frame, seekSeconds)
}
/> />
<div> <div>
<VideoPlayer <VideoPlayer
@ -738,7 +742,9 @@ export default function Events({ path, ...props }) {
? `${apiHost}/api/events/${event.id}/snapshot.jpg` ? `${apiHost}/api/events/${event.id}/snapshot.jpg`
: `${apiHost}/api/events/${event.id}/thumbnail.jpg` : `${apiHost}/api/events/${event.id}/thumbnail.jpg`
} }
alt={`${event.label} at ${(event.top_score * 100).toFixed(0)}% confidence`} alt={`${event.label} at ${((event?.data?.top_score || event.top_score) * 100).toFixed(
0
)}% confidence`}
/> />
</div> </div>
) : null} ) : null}