Compare commits

...

5 Commits

4 changed files with 77 additions and 60 deletions

8
TODO
View File

@@ -1,5 +1,13 @@
###
# get override data into view
# think view_transform might need to be included?
# should start with an empty DB and test - definitely no dirs in storage_sp gives:
# dir_id=dir_arr[0]
# IndexError: list index out of range
# empty directories are sometimes showing "No matches for: 'undefined'" <- should only comes up for search in URL???
# transforms in files_* also fails (old js in *transform uses current)
# also all the add ref img/add override, etc are non-functional - FIX the override* stuff first to get table/naming consistency as that is half the problem
# delete button also uses current? (eid is empty anyway)
###
### major fix - go to everywhere I call GetEntries(), and redo the logic totally...

View File

@@ -62,13 +62,13 @@ class FaceRefimgLink(PA, db.Model):
Attributes:
face_id (int): face id of row in Face table / foreign key - part primary key
refimg_id (int): face id of row in Face table / foreign key - part primary key
face_distance (int): distance value (how similar matched Face was)
face_distance (float): distance value (how similar matched Face was)
"""
__tablename__ = "face_refimg_link"
face_id = db.Column(db.Integer, db.ForeignKey("face.id"), primary_key=True )
refimg_id = db.Column(db.Integer, db.ForeignKey("refimg.id"), primary_key=True )
face_distance = db.Column(db.Integer)
face_distance = db.Column(db.Float)
################################################################################

View File

@@ -183,6 +183,7 @@ class DirSchema(ma.SQLAlchemyAutoSchema):
class FaceFileLinkSchema(ma.SQLAlchemyAutoSchema):
class Meta: model = FaceFileLink
model_used = ma.auto_field()
load_instance = True
class PersonSchema(ma.SQLAlchemyAutoSchema):
@@ -206,6 +207,9 @@ class FaceSchema(ma.SQLAlchemyAutoSchema):
exclude = ('face',)
load_instance = True
refimg = ma.Nested(RefimgSchema,allow_none=True)
# faces have to come with a file connection
facefile_lnk = ma.Nested(FaceFileLinkSchema)
refimg_lnk = ma.Nested(FaceRefimgLinkSchema,allow_none=True)
class FileSchema(ma.SQLAlchemyAutoSchema):
class Meta: model = File
@@ -268,12 +272,14 @@ def process_ids():
stmt = (
select(Entry)
.options(
joinedload(Entry.file_details).joinedload(File.faces),
joinedload(Entry.file_details).joinedload(File.faces).joinedload(Face.refimg).joinedload(Refimg.person)
joinedload(Entry.file_details).joinedload(File.faces).joinedload(Face.refimg).joinedload(Refimg.person),
joinedload(Entry.file_details).joinedload(File.faces).joinedload(Face.refimg_lnk),
joinedload(Entry.file_details).joinedload(File.faces).joinedload(Face.facefile_lnk),
)
.where(Entry.id.in_(ids))
)
# unique as the ORM query returns a Cartesian product for the joins. E.g if file has 3 faces, the result has 3 rows of the same entry and file data, but different face data
data=db.session.execute(stmt).unique().scalars().all()

View File

@@ -87,11 +87,12 @@ function DrawImg()
// if we have faces, the enable the toggles, otherwise disable them
// and reset model select too
if( document.viewing.faces )
if( document.viewing.file_details.faces )
{
$('#faces').attr('disabled', false)
$('#distance').attr('disabled', false)
$('#model').val( Number(document.viewing.face_model) )
// first face is good enough as whole file has to have used same model
$('#model').val( document.viewing.file_details.faces[0].facefile_lnk.model_used )
}
else
{
@@ -102,33 +103,34 @@ function DrawImg()
}
// okay, we want faces drawn so lets do it
if( $('#faces').prop('checked') && document.viewing.faces )
if( $('#faces').prop('checked') && document.viewing.file_details.faces )
{
faces=document.viewing.file_details.faces
// draw rect on each face
for( i=0; i<document.viewing.faces.length; i++ )
for( i=0; i<faces.length; i++ )
{
x = document.viewing.faces[i].x / ( im.width/canvas.width )
y = document.viewing.faces[i].y / ( im.height/canvas.height )
w = document.viewing.faces[i].w / ( im.width/canvas.width )
h = document.viewing.faces[i].h / ( im.height/canvas.height )
x = faces[i].face_left / ( im.width/canvas.width )
y = faces[i].face_top / ( im.height/canvas.height )
w = faces[i].w / ( im.width/canvas.width )
h = faces[i].h / ( im.height/canvas.height )
context.beginPath()
context.rect( x, y, w, h )
context.lineWidth = 2
// this face has an override so diff colour
if( document.viewing.faces[i].override )
if( faces[i].override )
{
context.strokeStyle = 'blue'
DrawLabelOnFace( document.viewing.faces[i].override.who )
DrawLabelOnFace( faces[i].override.who )
}
else
{
context.strokeStyle = 'green'
if( document.viewing.faces[i].who )
if( faces[i].refimg )
{
str=document.viewing.faces[i].who
str=faces[i].refimg.person.tag
if( $('#distance').prop('checked') )
str += "("+document.viewing.faces[i].distance+")"
str += "("+faces[i].refimg_lnk.face_distance.toFixed(2)+")"
DrawLabelOnFace( str )
}
}
@@ -223,32 +225,33 @@ $(document).ready( function()
item_list = { not_a_face: { name: "Not a face", which_face: '-1' } }
for( i=0; i<document.viewing.faces.length; i++ )
faces=document.viewing.file_details.faces
for( i=0; i<faces.length; i++ )
{
fx = document.viewing.faces[i].x / ( im.width/canvas.width )
fy = document.viewing.faces[i].y / ( im.height/canvas.height )
fw = document.viewing.faces[i].w / ( im.width/canvas.width )
fh = document.viewing.faces[i].h / ( im.height/canvas.height )
fx = faces[i].face_left / ( im.width/canvas.width )
fy = faces[i].face_top / ( im.height/canvas.height )
fw = faces[i].w / ( im.width/canvas.width )
fh = faces[i].h / ( im.height/canvas.height )
if( x >= fx && x <= fx+fw && y >= fy && y <= fy+fh )
{
if( document.viewing.faces[i].override )
if( faces[i].override )
{
item_list['remove_force_match_override']={ 'name': 'Remove override for this face', 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['remove_force_match_override']={ 'name': 'Remove override for this face', 'which_face': i, 'id': faces[i].id }
}
else if( document.viewing.faces[i].who )
else if( faces[i].refimg )
{
item_list['match']={ 'name': document.viewing.faces[i].who, 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['match_add_refimg']={ 'name': 'Add this as refimg for ' + document.viewing.faces[i].who,
'person_id': document.viewing.faces[i].pid, 'who': document.viewing.faces[i].who, 'which_face': i, 'id': document.viewing.faces[i].id, }
item_list['wrong_person']={ 'name': 'wrong person', 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['match']={ 'name': faces[i].refimg.person.tag, 'which_face': i, 'id': faces[i].id }
item_list['match_add_refimg']={ 'name': 'Add this as refimg for ' + faces[i].refimg.person.tag,
'person_id': faces[i].refimg.person.id, 'who': faces[i].refimg.person.tag, 'which_face': i, 'id': faces[i].id, }
item_list['wrong_person']={ 'name': 'wrong person', 'which_face': i, 'id': faces[i].id }
}
else
{
item_list['no_match_new_person']={ 'name': 'Add as reference image to NEW person', 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['no_match_new_refimg']={ 'name': 'Add as reference image to EXISTING person', 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['no_match_new_person']={ 'name': 'Add as reference image to NEW person', 'which_face': i, 'id': faces[i].id }
item_list['no_match_new_refimg']={ 'name': 'Add as reference image to EXISTING person', 'which_face': i, 'id': faces[i].id }
for( var el in NMO ) {
item_list['NMO_'+el]={'type_id': NMO[el].type_id, 'name': 'Override: ' + NMO[el].name, 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['NMO_'+el]={'type_id': NMO[el].type_id, 'name': 'Override: ' + NMO[el].name, 'which_face': i, 'id': faces[i].id }
}
}
delete item_list['not_a_face']
@@ -282,11 +285,11 @@ function OverrideForceMatch( person_id, key )
}
ofm='&person_id='+person_id+'&face_id='+item[key].id
$.ajax({ type: 'POST', data: ofm, url: '/add_force_match_override', success: function(data) {
document.viewing.faces[item[key].which_face].override={}
document.viewing.faces[item[key].which_face].override.who=data.person_tag
document.viewing.faces[item[key].which_face].override.distance='N/A'
document.viewing.faces[item[key].which_face].override.type_id=NMO[fm_idx].id
document.viewing.faces[item[key].which_face].override.type_name=NMO[fm_idx].name
document.viewing.file_details.faces[item[key].which_face].override={}
document.viewing.file_details.faces[item[key].which_face].override.who=data.person_tag
document.viewing.file_details.faces[item[key].which_face].override.distance='N/A'
document.viewing.file_details.faces[item[key].which_face].override.type_id=NMO[fm_idx].id
document.viewing.file_details.faces[item[key].which_face].override.type_name=NMO[fm_idx].name
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
@@ -305,8 +308,8 @@ function CreatePersonAndRefimg( key )
+'&refimg_data='+item[key].refimg_data
$.ajax({ type: 'POST', data: d, url: '/match_with_create_person',
success: function(data) {
document.viewing.faces[item[key].which_face].who=data.who
document.viewing.faces[item[key].which_face].distance=data.distance
document.viewing.file_details.faces[item[key].which_face].refimg.person.tag=data.who
document.viewing.file_details.faces[item[key].which_face].facefile_lnk.face_distance=data.distance
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
DrawImg()
@@ -320,8 +323,8 @@ function AddRefimgTo( person_id, key, search )
d='&face_id='+item[key].id+'&person_id='+person_id+'&refimg_data='+item[key].refimg_data+'&search='+search
$.ajax({ type: 'POST', data: d, url: '/add_refimg_to_person',
success: function(data) {
document.viewing.faces[item[key].which_face].who=data.who
document.viewing.faces[item[key].which_face].distance=data.distance
document.viewing.file_details.faces[item[key].which_face].refimg.person.tag=data.who
document.viewing.file_details.faces[item[key].which_face].facefile_lnk.face_distance=data.distance
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
DrawImg()
@@ -369,15 +372,15 @@ function SearchForPerson(content, key, face_id, face_pos, type_id)
function RemoveOverrideForceMatch(face_pos)
{
if( document.viewing.faces[face_pos].override )
who=document.viewing.faces[face_pos].override.who
if( document.viewing.file_details.faces[face_pos].override )
who=document.viewing.file_details.faces[face_pos].override.who
else
who=document.viewing.faces[face_pos].who
who=document.viewing.file_details.faces[face_pos].refimg.person.tag
d='&face_id='+document.viewing.faces[face_pos].id+'&person_tag='+who+'&file_eid='+current
d='&face_id='+document.viewing.file_details.faces[face_pos].id+'&person_tag='+document.viewing.file_details.faces[face_pos].refimg.person.tag+'&file_eid='+document.viewing.id
$.ajax({ type: 'POST', data: d, url: '/remove_force_match_override',
success: function(data) {
delete document.viewing.faces[face_pos].override
delete document.viewing.file_details.faces[face_pos].override
$('#dbox').modal('hide')
DrawImg()
CheckForJobs()
@@ -389,10 +392,10 @@ function RemoveOverrideForceMatch(face_pos)
function RemoveOverrideNoMatch(face_pos, type_id)
{
d='&face_id='+document.viewing.faces[face_pos].id+'&type_id='+type_id
d='&face_id='+document.viewing.file_details.faces[face_pos].id+'&type_id='+type_id
$.ajax({ type: 'POST', data: d, url: '/remove_no_match_override',
success: function(data) {
delete document.viewing.faces[face_pos].override
delete document.viewing.file_details.faces[face_pos].override
$('#dbox').modal('hide')
DrawImg()
CheckForJobs()
@@ -407,11 +410,11 @@ function AddNoMatchOverride(type_id, face_id, face_pos, type_id)
d='&type_id='+type_id+'&face_id='+face_id
$.ajax({ type: 'POST', data: d, url: '/add_no_match_override',
success: function(data) {
document.viewing.faces[face_pos].override={}
document.viewing.faces[face_pos].override.who=NMO[type_id].name
document.viewing.faces[face_pos].override.distance='N/A'
document.viewing.faces[face_pos].override.type_id=type_id
document.viewing.faces[face_pos].override.type_name=NMO[type_id].name
document.viewing.file_details.faces[face_pos].override={}
document.viewing.file_details.faces[face_pos].override.who=NMO[type_id].name
document.viewing.file_details.faces[face_pos].override.distance='N/A'
document.viewing.file_details.faces[face_pos].override.type_id=type_id
document.viewing.file_details.faces[face_pos].override.type_name=NMO[type_id].name
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
DrawImg()
@@ -459,17 +462,17 @@ function FaceDBox(key, item)
div+='</div><div class="col-6">'
if ( key == 'remove_force_match_override' )
{
if( document.viewing.faces[face_pos].override.type_name == 'Manual match to existing person' )
div+='<div class="row col-12">remove this override (force match to: ' + document.viewing.faces[face_pos].override.who + ')</div>'
if( document.viewing.file_details.faces[face_pos].override.type_name == 'Manual match to existing person' )
div+='<div class="row col-12">remove this override (force match to: ' + document.viewing.file_details.faces[face_pos].override.who + ')</div>'
else
div+='<div class="row col-12">remove this override (no match)</div>'
div+='<div class="row">'
div+='<button class="btn btn-outline-info col-6" type="button" onClick="$(\'#dbox\').modal(\'hide\'); return false">Cancel</button>'
div+='<button class="btn btn-outline-danger col-6" type="button" '
if( document.viewing.faces[face_pos].override.type_name == 'Manual match to existing person' )
if( document.viewing.file_details.faces[face_pos].override.type_name == 'Manual match to existing person' )
div+='onClick="RemoveOverrideForceMatch(' +face_pos+ ')">Remove</button>'
else
div+='onClick="RemoveOverrideNoMatch(' +face_pos+','+document.viewing.faces[face_pos].override.type_id+ ')">Remove</button>'
div+='onClick="RemoveOverrideNoMatch(' +face_pos+','+document.viewing.file_details.faces[face_pos].override.type_id+ ')">Remove</button>'
div+='</div>'
}
if ( key == 'no_match_new_person' )
@@ -544,7 +547,7 @@ function FaceDBox(key, item)
// pops results up in a dbox
function JoblogSearch()
{
data="eid="+current
data="eid="+document.viewing.id
$.ajax({ type: 'POST', data: data, url: '/joblog_search', success: function(res) {
data = JSON.parse(res)
div ='<div><table class="table table-striped table-sm sm-txt">'