from wtforms import SubmitField, StringField, HiddenField, validators, Form from flask_wtf import FlaskForm from flask import request, render_template, redirect from main import db, app, ma from sqlalchemy import Sequence from sqlalchemy.exc import SQLAlchemyError from status import st, Status from files import Entry, File from person import Refimg, Person, PersonRefimgLink from flask_login import login_required, current_user from job import Job, JobExtra, Joblog, NewJob from face import Face, FaceFileLink, FaceRefimgLink # pylint: disable=no-member ################################################################################ # /aistats -> placholder for some sort of stats ################################################################################ @app.route("/aistats", methods=["GET", "POST"]) @login_required def aistats(): stats = db.session.execute( "select p.tag, count(f.id) from person p, face f, face_file_link ffl, face_refimg_link frl, person_refimg_link prl where p.id = prl.person_id and prl.refimg_id = frl.refimg_id and frl.face_id = ffl.face_id and ffl.face_id = f.id group by p.tag" ) fstats={} fstats['files_with_a_face'] = db.session.execute( "select count(distinct file_eid) as count from face_file_link" ).first()[0] fstats['files_with_a_match'] = db.session.execute( "select count(distinct ffl.file_eid) as count from face_file_link ffl, face_refimg_link frl where frl.face_id = ffl.face_id" ).first()[0] fstats['files_with_missing_matches'] = db.session.execute( "select count(distinct ffl.file_eid) from face f left join face_refimg_link frl on f.id = frl.face_id join face_file_link ffl on f.id = ffl.face_id where frl.refimg_id is null" ).first()[0] # files_with_no_matches? fstats['all_faces'] = db.session.execute( "select count(distinct face_id) as count from face_file_link" ).first()[0] fstats['all_matched_faces'] = db.session.execute( "select count(distinct face_id) as count from face_refimg_link" ).first()[0] fstats['all_unmatched_faces'] = db.session.execute( "select count(f.id) from face f left join face_refimg_link frl on f.id = frl.face_id where frl.refimg_id is null" ).first()[0] return render_template("aistats.html", page_title='AI Statistics', stats=stats, fstats=fstats ) ################################################################################ # /run_ai_on -> CAM: needs more thought (what actual params, e.g list of file - # tick, but which face or faces? are we forcing a re-finding of unknown faces # or just looking for matches? (maybe in the long run there are different # routes, not params - stuff we will work out as we go) ################################################################################ @app.route("/run_ai_on", methods=["POST"]) @login_required def run_ai_on(): jex=[] for el in request.form: jex.append( JobExtra( name=f"{el}", value=request.form[el] ) ) print( f"would create new job with extras={jex}" ) job=NewJob( "run_ai_on", 0, None, jex ) st.SetAlert("success") st.SetMessage( f"Created Job #{job.id} to Look for face(s) in selected file(s)") return render_template("base.html")