def clean_learning_record(email):
    result = []

    records = load_user_records(email)
    if records:
        records_to_clean = [
            Statement(actor=email,
                      verb='void',
                      statement_obj=Statement.create_reference_obj(
                          record['statementId'])).to_json()
            for record in records
        ]

        result = _post(records_to_clean)

    return json.dumps(result)
Exemple #2
0
def _create_learning_plan_view_model(plan, email):
    planned_items = []

    for item in load_learning_plan_items(plan['object']['id']):
        records = load_learning_plan_item_learning_records(
            email, item['statementId'])

        verb_name = item['verb']['display']['en']

        info_lines = []
        resource_type = Statement.get_resource_type(
            item.get('object').get('definition').get('type'))
        if resource_type:
            resource_type = resource_type.get('name', '')
            info_lines.append(resource_type)

        duration = item.get('result', {}).get('duration')
        if duration:
            duration = 'Average time: ' + mls_dates.convert_duration(duration)
            info_lines.append(duration)

        actions = [{
            'title':
            verb_name.capitalize() + (' again' if records else ' now'),
            'url':
            item['object']['id']
        }]

        # taking the last one to display, done like this as who knows what they are going to come up with
        # all records may be required later
        if records:
            records = [records[-1]]

        planned_item = {
            'statementId':
            item['statementId'],
            'records':
            records,
            'title':
            '%s %s' % (verb_name.capitalize(),
                       item['object']['definition']['name']['en']),
            'required':
            item.get('result', {}).get('completion', False),
            'descriptionLines': [],
            'infoLines':
            info_lines,
            'actions':
            actions
        }
        planned_items.append(planned_item)

    return {
        'statementId': plan['statementId'],
        'title': plan['object']['definition']['name']['en'],
        'addedBy': 'diagnostic',
        'descriptionLines': [],
        'sections': [],
        'items': planned_items
    }
def load_course_learning_records(email, course_uri):
    verb = Statement.create_verb('complete')
    query_response = _query([
        {'$match': {
            'statement.actor.mbox': 'mailto:%s' % email,
            'statement.object.id': '%s' % url_parse.quote(course_uri),
            'statement.verb.id': '%s' % verb['id'],
            'voided': False
        }},
        PROJECTIONS['learning_record'],
        {'$sort': {'when': -1}}
    ])
    return _get_lrs_result_from(query_response)
Exemple #4
0
def assign_learning_plan():

    post_data = json.loads(request.data.decode('utf-8'))

    # this is only for current user for now
    learner_email = current_user.email
    learning_plan = Statement.create_plan(plan_name='Actions from diagnostic', learner_actor=learner_email)

    for resource in post_data:
        tincan_data = resource.get('tincan', dict())
        verb = tincan_data.get('verb') or 'read'
        statement_obj = tincan_data.get('object') or Statement.create_activity_obj(
            uri=resource.get('url'),
            name=resource.get('title'))
        
        tincan_result = tincan_data.get('result', dict())
        required = tincan_result.get('completion', resource.get('required'))
        duration = tincan_result.get('duration', resource.get('duration'))

        planned_item = Statement(
            verb=verb,
            statement_obj=statement_obj,
            required=required,
            duration=duration)

        learning_plan.add_planned_item(planned_item)

    current_app.logger.info(learning_plan.to_json())

    lrs_result = lrs_service.save_statement(learning_plan.to_json())

    resp = jsonify({
        'postData': post_data,
        'plan': learning_plan.to_json(),
        'lrsResult': lrs_result
    })
    resp.status_code = lrs_result.get('status', lrs_result.get('code', 200)) if type(lrs_result) is dict else 200
    return resp
def assign_learning_plan():

    post_data = json.loads(request.data.decode('utf-8'))

    # this is only for current user for now
    learner_email = current_user.email
    learning_plan = Statement.create_plan(plan_name='Actions from diagnostic', learner_actor=learner_email)

    for resource in post_data:
        tincan_data = resource.get('tincan', dict())
        verb = tincan_data.get('verb') or 'read'
        statement_obj = tincan_data.get('object') or Statement.create_activity_obj(
            uri=resource.get('url'),
            name=resource.get('title'))
        
        tincan_result = tincan_data.get('result', dict())
        required = tincan_result.get('completion', resource.get('required'))
        duration = tincan_result.get('duration', resource.get('duration'))

        planned_item = Statement(
            verb=verb,
            statement_obj=statement_obj,
            required=required,
            duration=duration)

        learning_plan.add_planned_item(planned_item)

    lrs_result = lrs_service.save_learning_plan(learning_plan)

    resp = jsonify({
        'postData': post_data,
        'plan': learning_plan.to_json(),
        'lrsResult': lrs_result
    })
    resp.status_code = lrs_result.get('code', 200) if type(lrs_result) is dict else 200
    return resp
Exemple #6
0
def load_course_learning_records(email, course_uri):
    verb = Statement.create_verb('complete')
    query_response = _query([{
        '$match': {
            'statement.actor.mbox': 'mailto:%s' % email,
            'statement.object.id': '%s' % url_parse.quote(course_uri),
            'statement.verb.id': '%s' % verb['id'],
            'voided': False
        }
    }, PROJECTIONS['learning_record'], {
        '$sort': {
            'when': -1
        }
    }])
    return _get_lrs_result_from(query_response)
def _create_learning_plan_view_model(plan, email):
    planned_items = []
    
    for item in load_learning_plan_items(plan['object']['id']):
        records = load_learning_plan_item_learning_records(email, item['statementId'])

        verb_name = item['verb']['display']['en']
        
        info_lines = []
        resource_type = Statement.get_resource_type(item.get('object').get('definition').get('type'))
        if resource_type:
            resource_type = resource_type.get('name', '')
            info_lines.append(resource_type)
        
        duration = item.get('result', {}).get('duration')
        if duration:
            duration = 'Average time: ' + mls_dates.convert_duration(duration)
            info_lines.append(duration)

        actions = [{
            'title': verb_name.capitalize() + (' again' if records else ' now'),
            'url': item['object']['id']
        }]

        # taking the last one to display, done like this as who knows what they are going to come up with
        # all records may be required later
        if records:
            records = [records[-1]]

        planned_item = {
            'statementId': item['statementId'],
            'records': records,
            'title': '%s %s' % (verb_name.capitalize(), item['object']['definition']['name']['en']),
            'required': item.get('result', {}).get('completion', False),
            'descriptionLines': [],
            'infoLines': info_lines,
            'actions': actions
        }
        planned_items.append(planned_item)

    return {
        'statementId': plan['statementId'],
        'title': plan['object']['definition']['name']['en'],
        'addedBy': 'diagnostic',
        'descriptionLines': [],
        'sections': [],
        'items': planned_items
    }
def load_course_learning_records(email, course_uri):
    verb = Statement.create_verb('complete')
    query = {
        'query': {
            'bool': {
                'must': [{
                    'nested': {
                        'path': 'actor',
                        'query': {
                            'match_phrase': {
                                'actor.mbox': 'mailto:%s' % email
                            }
                        }
                    }
                }, {
                    'nested': {
                        'path': 'verb',
                        'query': {
                            'match_phrase': {
                                'verb.id': verb['id']
                            }
                        }
                    }
                }, {
                    'nested': {
                        'path': 'object',
                        'query': {
                            'match_phrase': {
                                'object.id': course_uri
                            }
                        }
                    }
                }]
            }
        }
    }

    return _get_lrs_result_from(_execute_query(query))