Ejemplo n.º 1
0
    def scrub_knowledge_map(knowledge_map, node_cache):
        """
        Some topics in the knowledge map, we don't keep in our topic tree / node cache.
        Eliminate them from the knowledge map here.
        """
        for slug in knowledge_map["topics"].keys():
            nodecache_node = node_cache["Topic"].get(slug)
            topictree_node = topic_tools.get_topic_by_path(
                node_cache["Topic"][slug]["path"], root_node=topictree)

            if not nodecache_node or not topictree_node:
                logging.debug(
                    "Removing unrecognized knowledge_map topic '%s'" % slug)
            elif not topictree_node.get("children"):
                logging.debug(
                    "Removing knowledge_map topic '%s' with no children." %
                    slug)
            elif not "Exercise" in topictree_node.get("contains"):
                logging.debug(
                    "Removing knowledge_map topic '%s' with no exercises." %
                    slug)
            else:
                continue

            del knowledge_map["topics"][slug]
            nodecache_node["in_knowledge_map"] = False
            topictree_node["in_knowledge_map"] = False
Ejemplo n.º 2
0
def validate_data(topictree, node_cache, knowledge_map):

    # Validate related videos
    for exercise in node_cache['Exercise'].values():
        exercise_path = os.path.join(settings.PROJECT_PATH, "static", "js", "khan-exercises", "exercises", "%s.html" % exercise["slug"])
        if not os.path.exists(exercise_path):
            sys.stderr.write("Could not find exercise HTML file: %s\n" % exercise_path)
        for vid in exercise.get("related_video_readable_ids", []):
            if not vid in node_cache["Video"]:
                sys.stderr.write("Could not find related video %s in node_cache (from exercise %s)\n" % (vid, exercise["slug"]))

    # Validate related exercises
    for video in node_cache["Video"].values():
        ex = video["related_exercise"]
        if ex and not ex["slug"] in node_cache["Exercise"]:
            sys.stderr.write("Could not find related exercise %s in node_cache (from video %s)\n" % (ex["slug"], video["slug"]))
            
    # Validate all topics have leaves
    for topic in node_cache["Topic"].values():
        if not topic_tools.get_topic_by_path(topic["path"], root_node=topictree).get("children"):
            sys.stderr.write("Could not find any children for topic %s\n" % (topic["path"]))

    # Validate all topics in knowledge map are in the node cache
    for slug in knowledge_map["topics"]:
        if slug not in node_cache["Topic"]:
            sys.stderr.write("Unknown topic in knowledge map: %s\n" % slug)

        topicdata_path = os.path.join(settings.PROJECT_PATH + "/static/data/", "topicdata", "%s.json" % slug)
        if not os.path.exists(topicdata_path):
            sys.stderr.write("Could not find topic data in topicdata directory: '%s'\n" % slug)

    # Validate all topics in node-cache are in (or out) of knowledge map, as requested.
    for topic in node_cache["Topic"].values():
        if topic["in_knowledge_map"] and not topic["slug"] in knowledge_map["topics"]:
            sys.stderr.write("Topic '%-40s' not in knowledge map, but node_cache says it should be.\n" % topic["slug"])

        elif not topic["in_knowledge_map"] and topic["slug"] in knowledge_map["topics"]:
            sys.stderr.write("Topic '%-40s' in knowledge map, but node_cache says it shouldn't be.\n" % topic["slug"])

        elif topic["in_knowledge_map"] and not topic_tools.get_topic_by_path(topic["path"], root_node=topictree).get("children"):
            sys.stderr.write("Topic '%-40s' in knowledge map, but has no children.\n" % topic["slug"])

        elif topic["in_knowledge_map"] and not topic_tools.get_all_leaves(topic_tools.get_topic_by_path(topic["path"], root_node=topictree), leaf_type="Exercise"):
            sys.stderr.write("Topic '%40s' in knowledge map, but has no exercises.\n" % topic["slug"])
Ejemplo n.º 3
0
    def scrub_knowledge_map(knowledge_map, node_cache):
        """
        Some topics in the knowledge map, we don't keep in our topic tree / node cache.
        Eliminate them from the knowledge map here.
        """
        for slug in knowledge_map["topics"].keys():
            nodecache_node = node_cache["Topic"].get(slug)
            topictree_node = topic_tools.get_topic_by_path(node_cache["Topic"][slug]["path"], root_node=topictree)

            if not nodecache_node or not topictree_node:
                logging.debug("Removing unrecognized knowledge_map topic '%s'" % slug)
            elif not topictree_node.get("children"):
                logging.debug("Removing knowledge_map topic '%s' with no children." % slug)
            elif not "Exercise" in topictree_node.get("contains"):
                logging.debug("Removing knowledge_map topic '%s' with no exercises." % slug)
            else:
                continue

            del knowledge_map["topics"][slug]
            nodecache_node["in_knowledge_map"] = False
            topictree_node["in_knowledge_map"] = False
Ejemplo n.º 4
0
def validate_data(topictree, node_cache, knowledge_map):

    # Validate related videos
    for exercise in node_cache['Exercise'].values():
        for vid in exercise.get("related_video_readable_ids", []):
            if not vid in node_cache["Video"]:
                sys.stderr.write(
                    "Could not find related video %s in node_cache (from exercise %s)\n"
                    % (vid, exercise["slug"]))

    # Validate related exercises
    for video in node_cache["Video"].values():
        ex = video["related_exercise"]
        if ex and not ex["slug"] in node_cache["Exercise"]:
            sys.stderr.write(
                "Could not find related exercise %s in node_cache (from video %s)\n"
                % (ex["slug"], video["slug"]))

    # Validate all topics have leaves
    for topic in node_cache["Topic"].values():
        if not topic_tools.get_topic_by_path(
                topic["path"], root_node=topictree).get("children"):
            sys.stderr.write("Could not find any children for topic %s\n" %
                             (topic["path"]))

    # Validate all topics in knowledge map are in the node cache
    for slug in knowledge_map["topics"]:
        if slug not in node_cache["Topic"]:
            sys.stderr.write("Unknown topic in knowledge map: %s\n" % slug)

        topicdata_path = os.path.join(settings.PROJECT_PATH + "/static/data/",
                                      "topicdata", "%s.json" % slug)
        if not os.path.exists(topicdata_path):
            sys.stderr.write(
                "Could not find topic data in topicdata directory: '%s'\n" %
                slug)

    # Validate all topics in node-cache are in (or out) of knowledge map, as requested.
    for topic in node_cache["Topic"].values():
        if topic["in_knowledge_map"] and not topic["slug"] in knowledge_map[
                "topics"]:
            sys.stderr.write(
                "Topic '%-40s' not in knowledge map, but node_cache says it should be.\n"
                % topic["slug"])

        elif not topic["in_knowledge_map"] and topic["slug"] in knowledge_map[
                "topics"]:
            sys.stderr.write(
                "Topic '%-40s' in knowledge map, but node_cache says it shouldn't be.\n"
                % topic["slug"])

        elif topic["in_knowledge_map"] and not topic_tools.get_topic_by_path(
                topic["path"], root_node=topictree).get("children"):
            sys.stderr.write(
                "Topic '%-40s' in knowledge map, but has no children.\n" %
                topic["slug"])

        elif topic["in_knowledge_map"] and not topic_tools.get_all_leaves(
                topic_tools.get_topic_by_path(topic["path"],
                                              root_node=topictree),
                leaf_type="Exercise"):
            sys.stderr.write(
                "Topic '%40s' in knowledge map, but has no exercises.\n" %
                topic["slug"])
Ejemplo n.º 5
0
def get_topic_tree(request, topic_path):
    return JsonResponse(convert_topic_tree_for_dynatree(get_topic_by_path(topic_path)));
Ejemplo n.º 6
0
def get_topic_tree(request, topic_path):
    return JsonResponse(
        convert_topic_tree_for_dynatree(get_topic_by_path(topic_path)))