def generate_records_imported(): """Generate count of records imported """ l = Base.metadata.tables['log'] s = select([func.count('*').label('count')]).select_from(l).\ where(func.lcase(l.c.action).like('import%')) results = DBSession.execute(s) row = results.fetchone() fd = open(settings['reports.dir'] + '/records_imported.json', 'w') fd.write(str(json.dumps({'count':row['count']})))
def generate_uploaded_documents_imported(): """Generate count of uploaded docs imported """ l = Base.metadata.tables['log'] s = select([func.count('*').label('count')]).select_from(l).\ where(and_( func.lcase(l.c.action).like('import%'), l.c.entity_type == 'document', l.c.status == 'success')) result = DBSession.execute(s) row = result.fetchone() fd = open(settings['reports.dir'] + '/uploaded_docs_imported.json', 'w') fd.write(str(json.dumps({'count':row['count']})))
def generate_records_exported_by_type(): l = Base.metadata.tables['log'] s = select([l.c.entity_type, func.count('*').label('count')]).\ select_from(l).\ where(and_( func.lcase(l.c.action).like('export%'), l.c.status == 'failed')).\ group_by(l.c.entity_type) results = DBSession.execute(s) j = [] for row in results: j.append({ 'entity_type':row['entity_type'], 'count':row['count'] }) fd = open(settings['reports.dir'] + '/records_exported_by_type.json', 'w') fd.write(str(json.dumps(j)))