Пример #1
0
 def check(self):
     DEBUG = get_logger().getEffectiveLevel() == logging.DEBUG
     base_path, filename = os.path.split(self.hash_filename)
     invalids = []
     with codecs.open(self.hash_filename, encoding='utf-8') as sfv:
         for line in sfv:
             orig_hash, path = line.split()
             full_path = os.path.join(base_path, path)
             curr_hash = self.get_from_file(full_path)
             if DEBUG:
                 get_logger().debug("Current hash: '{}', orig hash: '{}'.".format(curr_hash, orig_hash))
             if curr_hash != orig_hash:
                 get_logger().warning("File hash invalid. "
                                      "Filename: '{}' file hash: '{}', "
                                      "check hash: '{}'".format(
                     full_path.encode(encoding='utf-8'),
                     curr_hash,
                     orig_hash))
                 invalids.append({
                     'curr_hash': curr_hash,
                     'orig_hash': orig_hash,
                     'filename': full_path
                 })
     return invalids
Пример #2
0
 def timed(*args, **kw):
     ts = time.time()
     result = method(*args, **kw)
     te = time.time()
     get_logger().debug('%r (%r, %r) %2.2f sec' % (method.__name__, args, kw, te-ts))
     return result
Пример #3
0
from datetime import datetime
import json
import sqlalchemy
from sqlalchemy.orm import sessionmaker, relationship

from conf import POSTGRES_DB, POSTGRES_HOST, POSTGRES_PASSWORD, POSTGRES_PORT, POSTGRES_USER
from conf import get_logger
from db_utils import connect, get_id, check_student_at_course_session
from rmq_utils import get_channel

logger = get_logger('checker')
""" Create a session with the Postgre database """
con, db_meta = connect(user=POSTGRES_USER,
                       password=POSTGRES_PASSWORD,
                       database_name=POSTGRES_DB,
                       host=POSTGRES_HOST,
                       port=POSTGRES_PORT)

Session = sessionmaker(bind=con)
session = Session()
""" Create a channel to RabbitMQ """
channel = get_channel()
""" Message handler """


def message_handler(ch, method, properties, body):
    msg = json.loads(body)
    task = msg.get('task')
    if task == 'best_labels':
        """Save the best labels into the attendance table"""
        labels: list = msg.get('labels')
Пример #4
0
from collections import Counter
from conf import get_logger

logger = get_logger("face_groups")


class Face:
    def __init__(self, id, label, bounding_box):
        self.id = id
        self.label = label
        self.bounding_box = bounding_box

    def __repr__(self):
        return f'Face: ID: {self.id}, label: {self.label}, bounding_box: {self.bounding_box}'


class Group:
    def __init__(self):
        self.labels = Counter()
        self.bboxes = []
        self.main_bb = None

    def __repr__(self):
        return f'Main Box: {self.main_bb}, labels: {self.labels}'

    def add_face(self, face: Face):
        self.labels.update([face.label])
        self.bboxes.append(face.bounding_box)
        self.main_bb = face.bounding_box

    def get_best_label(self):
Пример #5
0
#-*- coding:utf-8 -*-
import sys

import bottle
from bottle import route

from conf import CFG, DB, get_logger

LOG=get_logger(__file__)


html='''<html><title></title><body>%s</body></html>'''

@route('/')
def hello():

    LOG.info('in the hello method')

    table = '<table>'
    for k in CFG:
        table +='<tr><td>%s</td><td>%s</td></tr>' % (k, CFG[k])
    table +='<tr><td>DB</td><td>%s</td></tr>' %  DB
    table += '</table>'
    LOG.error('I am going to out of hello method')
    return html % table


application = bottle.default_app()

if __name__ == '__main__':
    
Пример #6
0
import pika
from conf import RMQ_HOST, RMQ_PORT, RMQ_USER, RMQ_PASSWORD
from conf import get_logger

logger = get_logger("rmq_utils")

params = pika.ConnectionParameters(
    host=RMQ_HOST,
    port=int(RMQ_PORT),
    credentials=pika.credentials.PlainCredentials(RMQ_USER, RMQ_PASSWORD),
    # heartbeat_interval=int(rmq_heartbeat),
)


def get_channel(params=params, prefetch_count: int = 1):
    """ Connect to RabbitMQ and return a channel """
    connection = pika.BlockingConnection(parameters=params)
    channel = connection.channel()
    channel.basic_qos(prefetch_count=prefetch_count)

    return channel

    # channel.basic_consume(on_message_callback=message_handler, queue='face_preds', auto_ack=False)
    # channel.start_consuming()
Пример #7
0
import datetime
import sqlalchemy
from enum import Enum
from datetime import datetime
from conf import get_logger

logger = get_logger('db_utils')


def connect(user, password, database_name, host='localhost', port=5432):
    """Returns a connection and a metadata object"""
    url = 'postgresql://{}:{}@{}:{}/{}'
    url = url.format(user, password, host, port, database_name)
    con = sqlalchemy.create_engine(url, client_encoding='utf8')
    meta = sqlalchemy.MetaData(bind=con, reflect=True)
    return con, meta


def get_id(session, label: str):
    """ Get id of a person by a label """
    id = None
    query = f"""SELECT stud_id FROM label_to_id WHERE label='{label}' LIMIT 1;"""
    result = session.execute(query)
    session.close()
    for row in result:
        id: int = row[0]
        break
    return id


def get_course_id_by_name(session, course_name):