def get_actor(self, event): """Get Actor for the statement.""" try: edx_user_info = self._get_edx_user_info(event['event']['username']) except: if event['username'] == 'anonymous': edx_user_info = self._get_edx_user_info( event['context']['module']['username']) else: edx_user_info = self._get_edx_user_info(event['username']) # this can happen in case a user was just deleted, or # in cases a user is automatically logged out while # they are interacting with courseware (e.g., a video is playing), # due to an LMS restart or other circumstance, in which # case an event with no username can be sent to the tracking # logs. In this case don't send a Statement if not edx_user_info['email']: return None if settings.UNTI_XAPI and edx_user_info['unti_id']: return Agent( name=edx_user_info['fullname'], account=AgentAccount(name=edx_user_info['unti_id'], home_page='https://my.2035.university'), ) else: return Agent( name=edx_user_info['fullname'], mbox='mailto:{}'.format(edx_user_info['email']), )
def _generate_global_unique_identifier_account(cls, user): name = user.global_unique_identifier homepage = current_app.config.get( 'LRS_ACTOR_ACCOUNT_GLOBAL_UNIQUE_IDENTIFIER_HOMEPAGE') if not (name and homepage): return None return AgentAccount(name=name, home_page=homepage)
def test_InitAccount(self): agent = Agent(name='test', mbox='mailto:[email protected]', mbox_sha1sum='test', openid='test', account=AgentAccount(name="test", home_page="test.com")) self.assertEqual(agent.object_type, "Agent") self.assertEqual(agent.name, 'test') self.assertEqual(agent.mbox, 'mailto:[email protected]') self.assertEqual(agent.mbox_sha1sum, 'test') self.assertEqual(agent.openid, 'test') self.accountVerificationHelper(agent.account)
def _generate_cas_account(cls, cas_user): identifier = current_app.config.get('LRS_ACTOR_ACCOUNT_CAS_IDENTIFIER') homepage = current_app.config.get('LRS_ACTOR_ACCOUNT_CAS_HOMEPAGE') name = None if not identifier: name = cas_user.unique_identifier elif cas_user.params: name = cas_user.params.get(identifier, None) if not (name and homepage): return None return AgentAccount(name=name, home_page=homepage)
def socialmedia_builder(statement_id, verb, platform, account_name, account_homepage, object_type, object_id, message, tags=[], parent_object_type=None, parent_id=None, rating=None, instructor_name=None, instructor_email=None, team_name=None, unit=None, account_email=None, user_name=None, timestamp=None, other_contexts=[]): agentaccount = AgentAccount(name=account_name, home_page=account_homepage) actor = Agent(account=agentaccount) # XAPI statements can only have one of: AgentAccount, mbox, mboxsha1 or Openid #if (account_email is not None): # actor.mbox = account_email #if (user_name is not None): # actor.name = user_name verb_obj = Verb(id=xapi_settings.get_verb_iri(verb), display=LanguageMap({'en-US': verb})) #message = message.decode('utf-8').encode('ascii', 'ignore') #message.decode('utf-8').replace(u"\u2018", "'").replace(u"\u2019", "'").replace(u"\u2013", "-").replace(u"\ud83d", " ").replace(u"\ude09", " ").replace(u"\u00a0l", " ").replace(u"\ud83d", " ").replace(u"\u2026", " ").replace(u"\ude09", " ").replace(u"\u00a0"," ") object = Activity( id=object_id, object_type=object_type, definition=ActivityDefinition( name=LanguageMap({'en-US': message}), type=xapi_settings.get_object_iri(object_type)), ) taglist = [] for tag in tags: tagobject = Activity( id='http://id.tincanapi.com/activity/tags/tincan', object_type='Activity', definition=ActivityDefinition( name=LanguageMap({'en-US': tag}), type=xapi_settings.get_object_iri('Tag')), ) taglist.append(tagobject) # Add "other" in contextActivities other_contexts_list = [] for other in other_contexts: other_context_obj = Activity( id=other['obj_id'], object_type=other['obj_type'], definition=ActivityDefinition(name=LanguageMap( {'en-US': other['definition']['name']}), type=other['definition']['type']), ) other_contexts_list.append(other_context_obj) taglist.extend(other_contexts_list) parentlist = [] if (verb in ['liked', 'shared', 'commented', 'rated']): #recipe specific config parentobject = Activity( id=parent_id, object_type=parent_object_type, ) parentlist.append(parentobject) elif (platform == 'GitHub' or platform.lower() == 'trello'): parentobject = Activity( id=parent_id, object_type=parent_object_type, ) parentlist.append(parentobject) courselist = [] if unit is not None: courseobject = Activity( id="http://adlnet.gov/expapi/activities/course", object_type='Course', definition=ActivityDefinition( name=LanguageMap({'en-US': unit.code}), description=LanguageMap({ 'en-US': "A course/unit of learning hosted on the CLAToolkit" }))) courselist.append(courseobject) instructor = None if (instructor_name is not None): instructor = Agent(name=instructor_name, mbox=instructor_email) team = None if (team_name is not None): team = Group(Agent(name=team_name), object_type='Group') result = None if (rating is not None): rating_as_float = float(rating) result = Result(score=Score(raw=rating_as_float)) context = Context(registration=uuid.uuid4(), platform=platform, instructor=instructor, team=team, context_activities=ContextActivities( other=ActivityList(taglist), parent=ActivityList(parentlist), grouping=ActivityList(courselist))) # Xapi spec requires that the learning provider SHOULD provide the authority # Authority is a group with Agent as oauth consumer app where name is token url and homepage is consumer_key account = AgentAccount(name=unit.get_lrs_key(), home_page=unit.get_lrs_access_token_url()) authority = Group(Agent(account=account)) statement = statement_builder(statement_id, actor, verb_obj, object, context, result, authority, timestamp) return statement
def _generate_compair_account(cls, user): return AgentAccount(name=user.uuid, home_page=XAPIResourceIRI.actor_homepage())
def _get_actor_from_user(user: AbstractUser) -> Optional[Agent]: """Generate a XAPI Agent object from a Ashley User object""" if user.lti_remote_user_id and user.lti_consumer.url: return Agent(account=AgentAccount(name=user.lti_remote_user_id, home_page=user.lti_consumer.url)) return None
def socialmedia_builder(verb, platform, account_name, account_homepage, object_type, object_id, message, tags=[], parent_object_type=None, parent_id=None, rating=None, instructor_name=None, instructor_email=None, team_name=None, course_code=None, account_email=None, user_name=None, timestamp=None): verbmapper = {'created': 'http://activitystrea.ms/schema/1.0/create', 'shared': 'http://activitystrea.ms/schema/1.0/share', 'liked': 'http://activitystrea.ms/schema/1.0/like', 'rated': 'http://id.tincanapi.com/verb/rated', 'commented': 'http://adlnet.gov/expapi/verbs/commented'} objectmapper = {'Note': 'http://activitystrea.ms/schema/1.0/note', 'Tag': 'http://id.tincanapi.com/activitytype/tag', 'Article': 'http://activitystrea.ms/schema/1.0/article', 'Video': 'http://activitystrea.ms/schema/1.0/video'} agentaccount = AgentAccount(name=account_name, home_page=account_homepage) actor = Agent(account=agentaccount) if (account_email is not None): actor.mbox = account_email if (user_name is not None): actor.name = user_name verb_obj = Verb(id=verbmapper[verb],display=LanguageMap({'en-US': verb})) #message = message.decode('utf-8').encode('ascii', 'ignore') #message.decode('utf-8').replace(u"\u2018", "'").replace(u"\u2019", "'").replace(u"\u2013", "-").replace(u"\ud83d", " ").replace(u"\ude09", " ").replace(u"\u00a0l", " ").replace(u"\ud83d", " ").replace(u"\u2026", " ").replace(u"\ude09", " ").replace(u"\u00a0"," ") object = Activity( id=object_id, object_type=object_type, definition=ActivityDefinition( name=LanguageMap({'en-US': message}), type=objectmapper[object_type] ), ) taglist = [] for tag in tags: tagobject = Activity( id='http://id.tincanapi.com/activity/tags/tincan', object_type='Activity', definition=ActivityDefinition( name=LanguageMap({'en-US': tag}), type=objectmapper['Tag'] ), ) taglist.append(tagobject) parentlist = [] if (verb in ['liked','shared','commented','rated']): parentobject = Activity( id=parent_id, object_type=parent_object_type, ) parentlist.append(parentobject) courselist = [] if (course_code is not None): courseobject = Activity( id=course_code, object_type='Course', definition=ActivityDefinition(type="http://adlnet.gov/expapi/activities/course") ) courselist.append(courseobject) instructor = None if (instructor_name is not None): instructor=Agent(name=instructor_name,mbox=instructor_email) team = None if (team_name is not None): team = Group(Agent(name=team_name), object_type='Group') result = None if (rating is not None): rating_as_float = float(rating) result = Result(score=Score(raw=rating_as_float)) context = Context( registration=uuid.uuid4(), platform=platform, instructor=instructor, team=team, context_activities=ContextActivities(other=ActivityList(taglist),parent=ActivityList(parentlist),grouping=ActivityList(courselist)) ) statement = statement_builder(actor, verb_obj, object, context, result, timestamp) return statement