Skip to content
__init__.py 3.15 KiB
Newer Older
#!/usr/bin/python
# -*- coding: UTF-8 -*-

from _collections import defaultdict
from flask import Blueprint
import config
from const import pfsp
from utils.decorator import login_required
from utils.template import my_render_template

from MDmisc.RecursiveDefaultDict import edefaultdict, defDict

trainer_view = Blueprint( "trainer", __name__, template_folder = "templates" )

@trainer_view.route( "/trainer/search" )
@login_required
def search():
    """
        Provide the search page.
    """
            files.id,
            files.uuid,
            mark_info.pfsp,
            mark_info.detection_technic,
            mark_info.surface,
            submissions.uuid AS submission_uuid,
        FROM files
        LEFT JOIN mark_info ON mark_info.uuid = files.uuid
        LEFT JOIN submissions ON files.folder = submissions.id
        LEFT JOIN users ON submissions.donor_id = users.id
        WHERE ( files.type = 3 OR files.type = 4 )
        ORDER BY files.id ASC
    """
    marks = config.db.query_fetchall( sql )
    
    sql = """
        SELECT
            submissions.uuid AS submissions_uuid,
            segments_locations.fpc,
            segments_locations.tenprint_id
        
        FROM segments_locations
        INNER JOIN files ON segments_locations.tenprint_id = files.uuid
        LEFT JOIN submissions ON files.folder = submissions.id
        ORDER BY fpc
    """
    ref_list = config.db.query_fetchall( sql )
    refs = defDict()
    for ref in ref_list:
        refs[ ref[ "submissions_uuid" ] ][ ref[ "fpc" ] ] = ref[ "tenprint_id" ]
    
    all_detection_technics = config.db.query_fetchall( "SELECT * FROM detection_technics ORDER BY name ASC" )
    surfaces = config.db.query_fetchall( "SELECT * FROM surfaces ORDER BY name ASC" )
    
    for _, v in enumerate( marks ):
        for col in [ "detection_technic", "surface", "note" ]:
            for old, new in [ ( "{", "" ), ( "}", "" ), ( "\n", "; " ) ]:
                    v[ col ] = v[ col ].replace( old, new )
        
        v[ "username" ] = v[ "username" ].replace( "_", " " )
    # PFSP zones to fpc
    pfsp2fpc = defaultdict( list )
    for pfc in xrange( 1, 11 ):
        for loc in [ "tip", "distal" ]:
            pfsp2fpc[ "F{}-{}".format( pfc, loc ) ].append( pfc )

    pfsp2fpc[ "F1-tip" ].append( 11 )
    pfsp2fpc[ "F1-distal" ].append( 11 )
    pfsp2fpc[ "F6-tip" ].append( 12 )
    pfsp2fpc[ "F6-distal" ].append( 12 )

    for side, fpc in [ ( "Right", 25 ), ( "Left", 27 ) ]:
        for z in [ "grasp", "carpal_delta_area", "wrist_bracelet", "thenar", "hypothenar", "interdigital", "writer_palm" ]:
            pfsp2fpc[ "{}-{}".format( side, z ) ].append( fpc )

    pfsp2fpc[ "Right-writer_palm" ].append( 22 )
    pfsp2fpc[ "Left-writer_palm" ].append( 24 )
    
    #
    return my_render_template( 
        "trainer/search.html",
        marks = marks,
        refs = refs,
        pfsp2fpc = pfsp2fpc,
        all_detection_technics = all_detection_technics,
        surfaces = surfaces,
        all_pfsp = pfsp.zones