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 _create_actor(): """Create xAPI actor""" student_id = "https://www.lip6.fr/mocah/invalidURI/student-number:" + student_hash partner_id = "https://www.lip6.fr/mocah/invalidURI/partner-number:" + partner_hash StudentAgent = Agent(openid=student_id, name="student") PartnerAgent = Agent(openid=partner_id, name="partner") AgentGroup = Group(member=[StudentAgent, PartnerAgent], name=student_hash + "||" + partner_hash) # print(student_hash, partner_hash) return AgentGroup
def setUp(self): self.endpoint = lrs_properties.endpoint self.version = lrs_properties.version self.username = lrs_properties.username self.password = lrs_properties.password self.lrs = RemoteLRS( version=self.version, endpoint=self.endpoint, username=self.username, password=self.password, ) self.agent = Agent(mbox="mailto:[email protected]") self.agent2 = Agent(mbox="mailto:[email protected]") self.verb = Verb(id="http://adlnet.gov/expapi/verbs/experienced", display=LanguageMap({"en-US": "experienced"})) self.group = Group(member=[self.agent, self.agent2]) self.activity = Activity( id="http://tincanapi.com/TinCanPython/Test/Unit/0", definition=ActivityDefinition()) self.activity.definition.type = "http://id.tincanapi.com/activitytype/unit-test" self.activity.definition.name = LanguageMap({"en-US": "Python Tests"}) self.activity.definition.description = LanguageMap( {"en-US": "Unit test in the test suite for the Python library"}) self.activity.object_type = 'Activity' self.parent = Activity(id="http://tincanapi.com/TinCanPython/Test", definition=ActivityDefinition()) self.parent.definition.type = "http://id.tincanapi.com/activitytype/unit-test-suite" self.parent.definition.name = LanguageMap({"en-US": "Python Tests"}) self.parent.definition.description = LanguageMap( {"en-US": "Unit test in the test suite for the Python library"}) self.parent.object_type = 'Activity' self.statement_ref = StatementRef(id=uuid.uuid4()) self.context = Context(registration=uuid.uuid4(), statement=self.statement_ref) # self.context.context_activities = ContextActivities(parent=[self.parent]) self.score = Score(raw=97, scaled=0.97, max=100, min=0) self.result = Result(score=self.score, success=True, completion=True, duration="PT120S") self.substatement = SubStatement( actor=self.agent, verb=self.verb, object=self.activity, )
def test_InitAll(self): ctx = Context( registration=uuid.uuid4(), instructor=Group(member=[Agent(name='instructorGroupMember')]), team=Group(member=[Agent(name='teamGroupMember')]), context_activities=ContextActivities(category=Activity( id='contextActivityCategory')), revision='revision', platform='platform', language='en-US', statement=StatementRef(id='016699c6-d600-48a7-96ab-86187498f16f'), extensions=Extensions({'extensions': 'extend!'})) self.ctxVerificationHelper(ctx)
def generate_actor(cls, user): actor = Agent(name=user.fullname) if current_app.config.get( 'LRS_ACTOR_ACCOUNT_USE_GLOBAL_UNIQUE_IDENTIFIER'): account = cls._generate_global_unique_identifier_account(user) if account: actor.account = account # set account to compair account by default if not actor.account: actor.account = cls._generate_compair_account(user) return actor
def generate_actor(cls, user): actor = Agent( name=user.fullname ) if current_app.config.get('LRS_ACTOR_ACCOUNT_USE_GLOBAL_UNIQUE_IDENTIFIER'): account = cls._generate_global_unique_identifier_account(user) if account: actor.account = account # set account to compair account by default if not actor.account: actor.account = cls._generate_compair_account(user) return actor
def test_FromJSONOpenId(self): agent = Agent.from_json('{"name":"test", "mbox":"mailto:[email protected]", "mbox_sha1sum":"test", "openid":"test"}') 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')
def getStatements(self, name): # connect LRS lrs = self.LRS # specify user as agent actor = Agent( name=name, mbox='mailto:' + name + '@id.lrs', ) # optional specify verb verb = Verb( id=self.verbs.get("experienced"), display=LanguageMap({'en-US': 'experienced'}), ) query = { "agent": actor, #"verb": verb, "limit": 1000 #change limit if needed } # query LRS for statements response = lrs.query_statements(query) # check response if not response: raise ValueError("statements could not be queried") # return queried statements return response
def test_FromJSONMboxSha1(self): agent = Agent.from_json( '{"name":"test", "mbox":"mailto:[email protected]", "mbox_sha1sum":"test"}' ) self.assertEqual(agent.object_type, "Agent") self.assertEqual(agent.name, 'test') self.assertEqual(agent.mbox, 'mailto:[email protected]') self.assertEqual(agent.mbox_sha1sum, 'test')
def get_actor(self, username, email): """ Get actor for the statement. """ return Agent( name=username, mbox='mailto:{email}'.format(email=email), )
def test_FromJSONobject_type(self): agent = Agent.from_json('''{"name":"test", "mbox":"mailto:[email protected]", "mbox_sha1sum":"test", "openid":"test", "account":{"name":"test", "home_page":"test.com"}, "object_type":"Test"}''') 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 test_InitMboxSha1(self): agent = Agent(name='test', mbox='mailto:[email protected]', mbox_sha1sum='test') self.assertEqual(agent.object_type, "Agent") self.assertEqual(agent.name, 'test') self.assertEqual(agent.mbox, 'mailto:[email protected]') self.assertEqual(agent.mbox_sha1sum, 'test')
def test_InitExceptionUnpackEmptymbox_sha1sum(self): obj = { "name": "test", "mbox": "mailto:[email protected]", "mbox_sha1sum": "" } with self.assertRaises(ValueError): Agent(**obj)
def generate_actor(cls, user): actor = Agent(name=user.fullname) if current_app.config.get('LRS_ACTOR_ACCOUNT_USE_CAS'): from compair.models import ThirdPartyType cas_user = user.third_party_auths \ .filter_by(third_party_type=ThirdPartyType.cas) \ .first() if cas_user: actor.account = cls._generate_cas_account(cas_user) # set account to compair account by default if not actor.account: actor.account = cls._generate_compair_account(user) return actor
def test_InitAnonGroupActor(self): statement = Statement(actor={'member': [Agent(name='test')], 'object_type': 'Group'}) self.assertIsNone(statement.id) self.assertIsNone(statement.verb) self.assertIsNone(statement.object) self.assertIsNone(statement.timestamp) self.assertIsNone(statement.stored) self.assertIsNone(statement.authority) self.groupVerificationHelper(statement.actor)
def test_InitGroupActor(self): statement = Statement(actor=Group(member=[Agent(name='test')])) self.assertIsNone(statement.id) self.assertIsNone(statement.verb) self.assertIsNone(statement.object) self.assertIsNone(statement.timestamp) self.assertIsNone(statement.stored) self.assertIsNone(statement.authority) self.groupVerificationHelper(statement.actor)
def test_InitAuthority(self): statement = Statement(authority=Agent(name='test')) self.assertIsNone(statement.id) self.assertIsNone(statement.verb) self.assertIsNone(statement.object) self.assertIsNone(statement.timestamp) self.assertIsNone(statement.stored) self.assertIsNone(statement.actor) self.agentVerificationHelper(statement.authority)
def setUp(self): self.agent = Agent(mbox="mailto:[email protected]") self.activity = Activity( id="http://tincanapi.com/TinCanPython/Test/Unit/0", definition=ActivityDefinition()) self.activity.definition.type = "http://id.tincanapi.com/activitytype/unit-test" self.activity.definition.name = LanguageMap({"en-US": "Python Tests"}) self.activity.definition.description = LanguageMap( {"en-US": "Unit test in the test suite for the Python library"})
def test_FromJSONAccount(self): agent = Agent.from_json( '''{"name":"test", "mbox":"mailto:[email protected]", "mbox_sha1sum":"test", "openid":"test", "account":{"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 get_actor(self, user, user_social_auth): """ Get actor for the statement. """ social_auth_uid = user_social_auth.uid if user_social_auth else '' sso_id = social_auth_uid.split(':')[-1] name = sso_id if sso_id else user.email return Agent( name=name, mbox=u'mailto:{email}'.format(email=user.email), )
def test_ToJSON(self): substatement = SubStatement(object_type='SubStatement', actor=Agent(name='test'), verb=Verb(id='test'), object=Activity(id='test')) self.assertEqual( json.loads(substatement.to_json()), json.loads( '{"verb": {"id": "test"}, "object": {"id": "test", "objectType": "Activity"}, ' '"actor": {"name": "test", "objectType": "Agent"}, "objectType": "SubStatement"}' ))
def generate_actor(cls, user): actor = Agent( name=user.fullname ) if current_app.config.get('LRS_ACTOR_ACCOUNT_USE_CAS'): from compair.models import ThirdPartyType cas_user = user.third_party_auths \ .filter_by(third_party_type=ThirdPartyType.cas) \ .first() if cas_user: actor.account = cls._generate_cas_account(cas_user) # set account to compair account by default if not actor.account: actor.account = cls._generate_compair_account(user) return actor
def get_actor(self, user, user_social_auth): """ Returns the actor component of the Enterprise xAPI statement. Arguments: user (User): User. user_social_auth (UserSocialAuth): UserSocialAuth. """ name = self._get_actor_name(user, user_social_auth) return Agent( name=name, mbox=u'mailto:{email}'.format(email=user.email), )
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 test_InitEmptyAccount(self): agent = Agent(name='test', mbox='mailto:[email protected]', mbox_sha1sum='test', openid='test', account={}) 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.assertIsInstance(agent.account, AgentAccount)
def get_actor(self): """ Return `Agent` object for the event. Returns: `Agent` """ user_uuid = get_anonymous_user_id(self.extract_username_or_userid()) return Agent( account={"homePage": settings.LMS_ROOT_URL, "name": user_uuid} )
def sendstatement_session_ended(self): aname = 'sysadmin' actor = Agent( name=aname, mbox='mailto:' + aname + '@iltserver.com', ) verb = Verb( id='http://adlnet.gov/expapi/verbs/terminated', display=LanguageMap({'en-US': 'terminated'}), ) statement = Statement(actor=actor, verb=verb, object=self._session_object) self._send_to_LRS(statement)
def sendstatement_session_started(self): aname = 'sysadmin' actor = Agent( name=aname, mbox='mailto:' + aname + '@iltserver.com', ) verb = Verb( id='http://activitystrea.ms/schema/1.0/start', display=LanguageMap({'en-US': 'started'}), ) statement = Statement(actor=actor, verb=verb, object=self._session_object) self._send_to_LRS(statement)
def get_actor(self, event): """Get Actor for the statement.""" 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 return Agent( name=edx_user_info['fullname'], mbox='mailto:{}'.format(edx_user_info['email']), )
def test_InitUnpack(self): obj = { "name": "test", "mbox": "mailto:[email protected]", "mbox_sha1sum": "test", "openid": "test", "account": { 'name': 'test', 'home_page': 'test.com' } } agent = Agent(**obj) 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 create_statement(arbtt_csv_entry): """Creates a Tincan statement from arbtt csv input""" arbtt_record = ArbttRecord(arbtt_csv_entry) app = arbtt_record.application duration = arbtt_record.duration # XXX: Look for a cleaner way to get user details user = os.environ['LOGNAME'] email_address = "*****@*****.**" % (user, ) actor = Agent( name=user, mbox='mailto:' + email_address, ) verb = Verb( id='http://adlnet.gov/expapi/verbs/interacted', display=LanguageMap({'en-US': 'interacted'}), ) # Get activity from config or set the activity as 'unknown' activity_from_map = activity_map.get(app, "unknown") object = Activity( id=os.path.join(lrs['activities_uri'], activity_from_map), definition=ActivityDefinition( name=LanguageMap({'en-US': activity_from_map}), extensions=Extensions( {'http://id.tincanapi.com/extension/duration': duration}, ), ), ) context = Context(platform=app) # Construct the statement return Statement( actor=actor, verb=verb, object=object, context=context, )
def handle(self, *args, **options): # make sure file option is present if options['extract_event_number'] is None: extract_event_number = 100 else: extract_event_number = int(options['extract_event_number']) evt_list = TrackingLog.objects \ .filter(tincan_error='WRONG_VERB_OBJECT') \ .order_by('dtcreated')[:extract_event_number] for evt in evt_list: statement_json = json.loads(evt.statement) statement = { 'actor': Agent.from_json(json.dumps(statement_json['actor'])), 'verb': Verb.from_json(json.dumps(statement_json['verb'])), 'object': Activity.from_json(json.dumps(statement_json['object'])), 'timestamp': statement_json['timestamp'], 'context': Context.from_json(json.dumps(statement_json['context'])), } evt.statement = json.dumps(statement) evt.tincan_error = "CONVERTED" evt.save()
def test_FromJSONName(self): agent = Agent.from_json('{"name":"test"}') self.assertEqual(agent.object_type, "Agent") self.assertEqual(agent.name, 'test')
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', 'Bookmark': 'http://activitystrea.ms/schema/1.0/bookmark'} 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
def test_FromJSONMboxMailto(self): agent = Agent.from_json('{"name":"test", "mbox":"mailto:[email protected]"}') self.assertEqual(agent.object_type, "Agent") self.assertEqual(agent.name, 'test') self.assertEqual(agent.mbox, 'mailto:[email protected]')
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://www.w3.org/ns/activitystreams#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", "added": "http://www.w3.org/ns/activitystreams#Add", "updated": "http://adlnet.gov/expapi/verbs/updated", "removed": "http://adlnet.gov/expapi/verbs/removed", "deleted": "http://www.w3.org/ns/activitystreams#Delete", "opened": "http://activitystrea.ms/schema/1.0/open", "closed": "http://activitystrea.ms/schema/1.0/close", } 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", "Bookmark": "http://activitystrea.ms/schema/1.0/bookmark", #'Collection': 'http://activitystrea.ms/schema/1.0/collection', "File": "http://activitystrea.ms/schema/1.0/file", "Task": "http://activitystrea.ms/specs/json/schema/activity-schema.html#task", "checklist": "http://id.tincanapi.com/activitytype/checklist", "checklist-item": "http://id.tincanapi.com/activitytype/checklist-item", } 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) # if otherObjTypeName is not None: # otherObject = Activity( # id=object_id, # object_type=object_type, # definition=ActivityDefinition( # name=LanguageMap({'en-US': otherObjTypeName}), # type=objectmapper[object_type] # ), # ) # taglist.append(otherObject) # if object_type == 'File': # otherObject = Activity( # id=grand_parent, # object_type=object_type # ) # taglist.append(otherObject) parentlist = [] if verb in ["liked", "shared", "commented", "rated"]: parentobject = Activity(id=parent_id, object_type=parent_object_type) parentlist.append(parentobject) elif platform == "GitHub": 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
def test_AddMember(self): group = Group() group.addmember(Agent(name='test')) self.assertIsInstance(group.member[0], Agent)
def test_InitMember(self): group = Group(member=[Agent(name='test')]) self.assertIsInstance(group.member[0], Agent)
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 test_FromJSONEmpty(self): with self.assertRaises(ValueError): Agent.from_json('')