<s> """<STR_LIT>""" <EOL> import re <EOL> import logging <EOL> from dateutil . parser import parse as parse_date <EOL> from modularodm import Q <EOL> from modularodm . exceptions import ModularOdmException <EOL> from website . models import User , Node , NodeLog <EOL> logging . basicConfig ( level = logging . INFO ) <EOL> logger = logging . getLogger ( __name__ ) <EOL> def find_by_email ( email ) : <EOL> try : <EOL> return User . find_one ( Q ( '<STR_LIT:username>' , '<STR_LIT>' , email ) ) <EOL> except ModularOdmException : <EOL> return None <EOL> def find_by_name ( name ) : <EOL> try : <EOL> parts = re . split ( r'<STR_LIT>' , name . strip ( ) ) <EOL> except : <EOL> return None <EOL> if len ( parts ) < <NUM_LIT:2> : <EOL> return None <EOL> users = User . find ( <EOL> reduce ( <EOL> lambda acc , value : acc & value , <EOL> [ <EOL> Q ( '<STR_LIT>' , '<STR_LIT>' , part . decode ( '<STR_LIT:utf-8>' , '<STR_LIT:ignore>' ) ) <EOL> for part in parts <EOL> ] <EOL> ) <EOL> ) . sort ( '<STR_LIT>' ) <EOL> if not users : <EOL> return None <EOL> if len ( users ) > <NUM_LIT:1> : <EOL> logger . warn ( '<STR_LIT>' . format ( name ) ) <EOL> return users [ <NUM_LIT:0> ] <EOL> def logs_since ( user , date ) : <EOL> return NodeLog . find ( <EOL> Q ( '<STR_LIT:user>' , '<STR_LIT>' , user . _id ) & <EOL> Q ( '<STR_LIT:date>' , '<STR_LIT>' , date ) <EOL> ) <EOL> def nodes_since ( user , date ) : <EOL> return Node . find ( <EOL> Q ( '<STR_LIT>' , '<STR_LIT>' , user . _id ) & <EOL> Q ( '<STR_LIT>' , '<STR_LIT>' , date ) <EOL> ) <EOL> def process ( frame ) : <EOL> frame = frame . copy ( ) <EOL> frame [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> frame [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> frame [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> frame [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> for idx , row in frame . iterrows ( ) : <EOL> user = ( <EOL> find_by_email ( row [ '<STR_LIT>' ] . strip ( ) ) or <EOL> find_by_name ( row [ '<STR_LIT:Name>' ] ) <EOL> ) <EOL> if user : <EOL> date = parse_date ( row [ '<STR_LIT>' ] ) <EOL> frame . loc [ idx , '<STR_LIT>' ] = user . _id <EOL> logs = logs_since ( user , date ) <EOL> frame . loc [ idx , '<STR_LIT>' ] = logs . count ( ) <EOL> frame . loc [ idx , '<STR_LIT>' ] = nodes_since ( user , date ) . count ( ) <EOL> if logs : <EOL> frame . loc [ idx , '<STR_LIT>' ] = logs . sort ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . date . strftime ( '<STR_LIT>' ) <EOL> return frame </s>
