<s> from django_lean . experiments . models import Participant <EOL> from django_lean . experiments . utils import WebUser <EOL> from django_lean . lean_analytics import IdentificationError <EOL> class BaseAnalytics ( object ) : <EOL> def _id_from_session ( self , session ) : <EOL> try : <EOL> return '<STR_LIT>' % session . session_key <EOL> except AttributeError as e : <EOL> raise IdentificationError ( e ) <EOL> def _id_from_user ( self , user ) : <EOL> try : <EOL> return '<STR_LIT>' % user . pk <EOL> except AttributeError as e : <EOL> raise IdentificationError ( e ) <EOL> def _compute_id ( self , experiment_user ) : <EOL> if not experiment_user . is_anonymous ( ) : <EOL> return self . _id_from_user ( experiment_user . user ) <EOL> return self . _id_from_session ( experiment_user . session ) <EOL> def enroll ( self , experiment , experiment_user , group_id ) : <EOL> self . _submit ( name = '<STR_LIT>' , <EOL> properties = { '<STR_LIT>' : unicode ( experiment ) , <EOL> '<STR_LIT>' : dict ( Participant . GROUPS ) [ group_id ] } , <EOL> experiment_user = experiment_user ) <EOL> def record ( self , goal_record , experiment_user ) : <EOL> self . _submit ( name = '<STR_LIT>' , <EOL> properties = { '<STR_LIT>' : unicode ( goal_record . goal_type ) } , <EOL> experiment_user = experiment_user ) <EOL> def event ( self , name , properties , request = None ) : <EOL> if request : <EOL> self . _submit ( name , properties , experiment_user = WebUser ( request ) ) <EOL> def _submit ( self , name , properties , experiment_user = None ) : <EOL> raise NotImplementedError ( ) </s>
