예제 #1
0
def all_get(learnerId):  # noqa: E501
    """Get all activities

    Returns all activities. # noqa: E501

    :param learnerId: Id of the learner to get a recommendation for
    :type learnerId: str

    :rtype: Recommendation
    """
    print("INFO: Received request for all activities recommendation for learner with id {}".format(learnerId))
    query_cacher = QueryCacher()
    learner, etag = query_cacher.get_learner(mongo_id_from_url(learnerId))
    if learner is None:
        return {"error_msg": "Learner cannot be found"}, 404
    print("INFO: Detected goals for learner with id {}. Goals={}".format(learnerId, learner.goals))
    cass_graph = load_or_instantiate('recommenderserver.resources', CassGraph, '603d5ac2-fa9e-43c3-9c50-87ff65804ccd')

    recommendation = Recommender(learner=learner,
                                 etag=etag,
                                 query_cacher=query_cacher,
                                 elo_row_strategy_classes=[],
                                 activity_row_strategy_classes=[AllActivities],
                                 not_enough_content_elo_row_strategy_classes=[],
                                 not_enough_content_activity_row_strategy_classes=[],
                                 min_content_threshold=-1,
                                 cass_graph=cass_graph,
                                 filter_locked=False).get_recommendation()

    print(
        'INFO: All activities recommendation made for learner with id {}. Recommendation: {}'.format(learnerId,
                                                                                               recommendation.to_dict()))
    return recommendation
예제 #2
0
def generate_associations():  # noqa: E501
    """Generates mapping from TLOs/ELOs to activities and token types to activities

    Generates a list of all activities mapped to their corresponding TLOs/ELOs and a list of all activities mapped to their corresponding token types # noqa: E501


    :rtype: None
    """

    db.activity_associations.remove({})
    db.token_associations.remove({})
    activityCursor = db.learning_activities.find({})
    cass_graph = load_or_instantiate('recommenderserver.resources', CassGraph,
                                     '59e884bb-510b-4f36-8443-8c3842336e28')

    # Generate activity associations
    while 0 == 0:
        try:
            activityDict = activityCursor.next()
        except StopIteration:
            break
        if 'educationalAlignment' in activityDict:
            for alignment in activityDict['educationalAlignment']:
                if 'additionalType' in alignment and (alignment['additionalType'] == 'TLOAlignment' \
                    or alignment['additionalType'] == 'ELOAlignment'):
                    db.activity_associations.update({'competency': alignment['targetUrl']}, \
                        {'$addToSet': {'activities': str(activityDict['_id'])}}, upsert = True)

    # Generate token associations
    activityAssociationsCursor = db.activity_associations.find({}, {'_id': 0})
    while 0 == 0:
        try:
            activityAssociationsDict = activityAssociationsCursor.next()
        except StopIteration:
            break
        if activityAssociationsDict[
                'competency'] in cass_graph.competency_objs:
            competencyNode = cass_graph.competency_objs[
                activityAssociationsDict['competency']]
            if competencyNode is not None and competencyNode.ceasncoded_notation is not None:
                tokenType = competencyNode.ceasncoded_notation
                if '.' in competencyNode.ceasncoded_notation:
                    tokenType = competencyNode.ceasncoded_notation[:
                                                                   competencyNode
                                                                   .
                                                                   ceasncoded_notation
                                                                   .rfind('.')]
                for activity in activityAssociationsDict['activities']:
                    db.token_associations.update({'tokenType': tokenType}, \
                        {'$addToSet': {'activities': activity}}, upsert = True)

    return 'Activity associations generated'
예제 #3
0
def upcoming_get(learnerId):  # noqa: E501
    """Get upcoming activities

    Returns an overview of what the learner will be working on (and reflected in upcoming recommendations). It should include current ELO in the sequence that the learner has not yet mastered that they will continue learning. It will also include any ELOs that the learner has forgotten that will be reviewed. # noqa: E501

    :param learnerId: Id of the learner to get a recommendation for
    :type learnerId: str

    :rtype: Recommendation
    """
    print(
        "INFO: Received request for upcoming recommendation for learner with id {}"
        .format(learnerId))
    query_cacher = QueryCacher()
    learner, etag = query_cacher.get_learner(mongo_id_from_url(learnerId))
    if learner is None:
        return {"error_msg": "Learner cannot be found"}, 404
    print("INFO: Detected goals for learner with id {}. Goals={}".format(
        learnerId, learner.goals))
    cass_graph = load_or_instantiate('recommenderserver.resources', CassGraph,
                                     '603d5ac2-fa9e-43c3-9c50-87ff65804ccd')

    recommendation = Recommender(
        learner=learner,
        etag=etag,
        query_cacher=query_cacher,
        elo_row_strategy_classes=RowStrategyConfig.
        UPCOMING_COMPETENCY_ROW_STRATEGIES,
        activity_row_strategy_classes=[],
        not_enough_content_elo_row_strategy_classes=RowStrategyConfig.
        NOT_ENOUGH_CONTENT_ELO_ROW_STRATEGIES,
        not_enough_content_activity_row_strategy_classes=[],
        cass_graph=cass_graph,
        min_content_threshold=-1,
        filter_locked=RowStrategyConfig.FILTER_LOCKED_ACTIVITIES,
        use_prerequisties=False).get_recommendation()
    print_with_time(
        'INFO: Upcoming recommendation made for learner with id {}.'.format(
            learnerId))
    return recommendation
예제 #4
0
    learner, etag = query_cacher.get_learner(learner_id)

    if UPDATE_LEARNER:
        print("About to clear data for learner '{}', with ID {}.".format(
            learner.name, learner.identifier))
        confirmation = input("Proceed (yes/no)? ")
    else:
        print(
            "Will print out what call payloads would be. Note: NO UPDATING IS HAPPENING."
        )
        confirmation = "yes"

    if confirmation == "yes":
        clear_learner_patch(learner)
        cass_graph = load_or_instantiate(
            'recommenderserver.resources', CassGraph,
            '59e884bb-510b-4f36-8443-8c3842336e28')  # type: CassGraph

        if UPDATE_THROUGH_TLO:
            last_mastered_tlo = master_up_through_tlo("3", cass_graph, learner)

            if SET_GOAL:
                # Assuming that the UI is setting this goal. Is this accurate?
                set_goal_to_next_elo(last_mastered_tlo, learner)

        if UPDATE_THROUGH_ELO:
            last_mastered_elo = master_up_through_elo('3.1', cass_graph,
                                                      learner)

    else:
        print("Aborted.")
예제 #5
0
def recommendation_get(learnerId: str, focusedCompetencies=None):  # noqa: E501
    """Get a new recommendation

     # noqa: E501

    :param learnerId: Id of the learner to get a recommendation for
    :type learnerId: str

    :rtype: Recommendation
    """
    print("INFO: Received request for recommendation for learner with id {}".format(learnerId))
    if focusedCompetencies != None:
        print("INFO: Getting recommendations with focused competencies: {}".format(focusedCompetencies))
    else:
        focusedCompetencies = False

    query_cacher = QueryCacher()
    learner, etag = query_cacher.get_learner(mongo_id_from_url(learnerId))
    if learner is None:
        return {"error_msg": "Learner cannot be found"}, 404
    print("INFO: Detected goals for learner with id {}. Goals={}".format(learnerId, learner.goals))
    cass_graph = load_or_instantiate('recommenderserver.resources', CassGraph, '603d5ac2-fa9e-43c3-9c50-87ff65804ccd')

    if MandatoryAssignmentMakerConfig.USE_MANDATORY_ASSIGNMENTS:
        mandatory_assignment_maker = MandatoryAssignmentMaker(learner, etag, query_cacher, cass_graph)
        assignment = mandatory_assignment_maker.get_mandatory_assignment()

        if assignment is not None:
            print(
                'INFO: Mandatory Assignment Recommendation made for learner with id {}. Recommendation: {}'.format(
                    learnerId, assignment.to_dict()))

            assigned_activity = query_cacher.get_activity(assignment.assignment.activity_id)
            aligned_tlo = get_aligned_tlo(assigned_activity)
            # TODO - figure out how to encode user's information into this xAPI statement. Likely either in context or result.
            log_statement = XApiStatement(agent_name="Recommender",
                                          agent_url_id=Config.RECOMMENDER_URL,
                                          verb_id="https://w3id.org/xapi/dod-isd/verbs/assigned",
                                          activity_id=aligned_tlo)

            xapi_sender = XAPISender(base_url='http://'+LoggingLRSConfig.BASE_URL,
                                     x_experience_version=LoggingLRSConfig.X_EXPERIENCE_VERSION,
                                     basic_auth_user=LoggingLRSConfig.CLIENT_USR,
                                     basic_auth_pwd=LoggingLRSConfig.CLIENT_PWD)
            if False:
                xapi_sender.statements_post([log_statement])

            return assignment

    recommendation = Recommender(learner=learner,
                                 etag=etag,
                                 query_cacher=query_cacher,
                                 elo_row_strategy_classes=RowStrategyConfig.PRIORITY_COMPETENCY_ROW_STRATEGIES,
                                 activity_row_strategy_classes=RowStrategyConfig.PRIORITY_ACTIVITY_ROW_STRATEGIES,
                                 not_enough_content_elo_row_strategy_classes=RowStrategyConfig.NOT_ENOUGH_CONTENT_ELO_ROW_STRATEGIES,
                                 not_enough_content_activity_row_strategy_classes=[],
                                 cass_graph=cass_graph,
                                 min_content_threshold=-1,
                                 filter_locked=RowStrategyConfig.FILTER_LOCKED_ACTIVITIES,
                                 use_prerequisties=True,
                                 focus_competencies=focusedCompetencies).get_recommendation()

    print_with_time(
        'INFO: Recommendation made for learner with id {}.'.format(learnerId))
    return recommendation