def handle(self, *args, **options):
        print("Importing Khan Academy topic tree from khan_academy_ricecooker_tree.json...")
        filename = os.path.join(data_dir, 'khan_academy_ricecooker_tree.json')
        root_node = json.loads(open(filename).read(), encoding='utf-8')

        source_id = "khan_academy_us"
        topic = "Khan Academy Curriculum"
        country = "USA"
        digitization_method = "data_import"
        draft = True

        ka_user, _created = User.objects.get_or_create(username='******')

        try:
            existing_doc = CurriculumDocument.objects.get(source_id=source_id)
            # this will delete all children and also learning objectives due to cascade delete
            existing_doc.delete()
        except CurriculumDocument.DoesNotExist:
            pass

        ka_judgments = HumanRelevanceJudgment.objects.filter(user=ka_user)
        ka_judgments.delete()

        document = CurriculumDocument.objects.create(
            source_id=source_id,
            title=topic,
            country=country,
            digitization_method=digitization_method,
            is_draft=draft,
        )
        root = StandardNode.add_root(title=topic, identifier='KA-en', kind='channel', document=document)
        for domain in root_node['children']:
            get_node_data_recursive(domain, parent=root, user=ka_user)
Exemplo n.º 2
0
def load_ngss(transformed_tree):
    try:
        document = CurriculumDocument.objects.get(
            source_id=NGSS_DOCUMENT_ATTRIBUTES["source_id"])
        document.delete()
    except CurriculumDocument.DoesNotExist:
        pass
    document = CurriculumDocument.objects.create(**NGSS_DOCUMENT_ATTRIBUTES)

    root = StandardNode.add_root(
        identifier=transformed_tree["identifier"],
        title=transformed_tree["title"],
        kind=transformed_tree["kind"],
        document=document,
    )

    def _add_children_to_parent(parent, children):
        for i, child in enumerate(children):
            sort_order = i + 1
            source_kind = child["kind"]
            if source_kind in NGSS_TO_NODE_KIND_MAPPING:
                kind = NGSS_TO_NODE_KIND_MAPPING[source_kind]
            else:
                kind = source_kind
            node = parent.add_child(
                document=parent.document,
                title=child["title"],
                identifier=child["identifier"],
                sort_order=sort_order,
                kind=kind,
            )
            _add_children_to_parent(node, child["children"])

    _add_children_to_parent(root, transformed_tree["children"])
Exemplo n.º 3
0
    def handle(self, *args, **options):
        """
        Imports Australian curriculum standards into the alignment prototype database.

        This command expects to find rdf files named "<subject grades>.rdf" (e.g. "Mathematics F-10.rdf") in the
        alignmentpro/importing/data/australia_standards directory. These files can be retrieved from:

        http://rdf.australiancurriculum.edu.au/

        Currently, this function accepts no arguments.
        """
        standards_dir = os.path.join(data_dir, 'australia_standards')
        for afile in glob.glob(os.path.join(standards_dir, '*.rdf')):
            basename = os.path.basename(afile)
            topic = os.path.splitext(basename)[0]
            with open(afile, encoding='utf-8') as doc:
                data = xmltodict.parse(doc.read())
                json_file = os.path.join(standards_dir, basename + ".json")
                f = open(json_file, 'w', encoding='utf-8')
                f.write(json.dumps(data, ensure_ascii=False, indent=2))
                f.close()
                # continue

                source_id = "australia_standards_{}".format(
                    topic.lower().replace(" ", "_"))
                country = "Australia"
                digitization_method = "data_import"
                draft = True

                # For now, clean out old runs so we don't proliferate the db.
                try:
                    existing_doc = CurriculumDocument.objects.get(
                        source_id=source_id)
                    # this will delete all children and also learning objectives due to cascade delete
                    existing_doc.delete()
                except CurriculumDocument.DoesNotExist:
                    pass

                document = CurriculumDocument.objects.create(
                    source_id=source_id,
                    title=topic,
                    country=country,
                    digitization_method=digitization_method,
                    is_draft=draft,
                )

                root = StandardNode.add_root(title=topic,
                                             kind='document',
                                             document=document)
                topic_tree = get_topic_hierarchy(data)
                for subject in topic_tree:
                    add_standard(subject, parent=root)
    def handle(self, *args, **options):
        print("Handling importchunk with options = ", options)
        source_id = options["source_id"]
        digitization_method = options["digitization_method"] or "unknown"
        title = options.get("title", "Unknown title")
        country = options["country"] or "Unknown"
        draft = options["draft"]

        try:
            document = CurriculumDocument.objects.get(source_id=source_id)
            if document.is_draft:
                print("Deleting old draft verison of curriculum document...")
                document.delete()
            else:
                print(
                    'ERROR: document is no longer in draft state so cannot be updated.'
                )
                sys.exit(1)
        except CurriculumDocument.DoesNotExist:
            pass

        document = CurriculumDocument.objects.create(
            source_id=source_id,
            title=title,
            country=country,
            digitization_method=digitization_method,
            is_draft=draft,
        )
        root = StandardNode.add_root(title=title, document=document)

        curriculum_list = load_curriculum_list(options["gsheet_id"],
                                               options["gid"])

        nodes_breadcrumbs = [root, None]
        node_counts = [None, 0]
        cur_level = 1
        for row in curriculum_list:
            assert len(node_counts) == cur_level + 1, 'wrong node_counts'
            assert len(
                nodes_breadcrumbs) == cur_level + 1, 'wrong nodes_breadcrumbs'

            # staying at the same level
            if row["level"] == cur_level:
                pass

            # going deeper (add a child to current leaf)
            elif row["level"] > cur_level:
                if not (row["level"] - 1 == cur_level):
                    print("ERR too many indentnts at \n", list(row.values()))
                    sys.exit(1)
                cur_level = row["level"]
                nodes_breadcrumbs.append(None)
                node_counts.append(0)

            # popping out (add a child to parent at level)
            elif row["level"] < cur_level:
                cur_level = row["level"]
                nodes_breadcrumbs = nodes_breadcrumbs[0:cur_level + 1]
                node_counts = node_counts[0:cur_level + 1]

            # Add the node to the appropriate location
            parent = nodes_breadcrumbs[cur_level - 1]
            node_counts[cur_level] += 1
            node = parent.add_child(
                document=parent.document,
                title=row[TITLE_KEY],
                identifier=row[IDENTIFIER_KEY],
                sort_order=node_counts[cur_level],
                kind=row[KIND_KEY],
                time_units=float(row[TIME_UNITS_KEY])
                if row[TIME_UNITS_KEY] else None,
                notes=row[NOTES_KEY] or '',
            )
            nodes_breadcrumbs[cur_level] = node

        print("Import finished")
        print(get_tree_as_markdown(root, {}))
Exemplo n.º 5
0
    def handle(self, *args, **options):
        print("Handling importchunk with options = ", options)
        source_id = options["source_id"]
        digitization_method = options["digitization_method"] or "unknown"
        title = options.get("title", "Unknown title")
        country = options["country"] or "Unknown"
        draft = options["draft"]

        document, created = CurriculumDocument.objects.get_or_create(
            source_id=source_id,
            title=title,
            country=country,
            digitization_method=digitization_method,
            is_draft=draft,
        )
        if created:
            root = StandardNode.add_root(title=title, document=document)
        else:
            root = document.root

        curriculum_list = load_curriculum_list(options["gsheet_id"],
                                               options["gid"])

        nodes_breadcrumbs = [root]
        node_counts = [0]
        cur_level = 0
        for row in curriculum_list:
            print(
                "Porcessing row",
                "  " * row["level"] + "-",
                row[IDENTIFIER_KEY],
                row[TITLE_KEY],
            )

            # staying (add a child to current parent)
            if row["level"] == cur_level:
                node_counts[cur_level] += 1
                parent = nodes_breadcrumbs[cur_level - 1]
                node = _add_row_to_parent(parent,
                                          row,
                                          sort_order=node_counts[cur_level])
                if row[LEARNING_OBJECTIVES_KEY]:
                    _add_learning_objectives(node,
                                             row[LEARNING_OBJECTIVES_KEY])
                nodes_breadcrumbs[cur_level] = node

            # going deeper (add a child to current leaf)
            elif row["level"] > cur_level:
                parent = nodes_breadcrumbs[cur_level]
                node = _add_row_to_parent(parent,
                                          row,
                                          sort_order=node_counts[cur_level])
                if row[LEARNING_OBJECTIVES_KEY]:
                    _add_learning_objectives(node,
                                             row[LEARNING_OBJECTIVES_KEY])
                nodes_breadcrumbs.append(node)
                node_counts.append(1)
                cur_level += 1

            # popping out (add a child to parent at level)
            elif row["level"] < cur_level:
                new_level = row["level"]
                parent = nodes_breadcrumbs[new_level - 1]
                node_counts[new_level] += 1
                node = _add_row_to_parent(parent,
                                          row,
                                          sort_order=node_counts[new_level])
                if row[LEARNING_OBJECTIVES_KEY]:
                    _add_learning_objectives(node,
                                             row[LEARNING_OBJECTIVES_KEY])
                nodes_breadcrumbs = nodes_breadcrumbs[0:new_level] + [node]
                node_counts = node_counts[0:new_level + 1]
                cur_level = new_level

        print("Import finished")
Exemplo n.º 6
0
def import_california():
    j = Jurisdictions.objects.get(id=CALIFORNIA_JURISDICTION_ID)
    root_tuples = CALIFORNIA_VOCATIONAL_ROOTS
    tree = join_standards(
        root_tuples,
        identifier="CTE",
        title="California Career Technical Education",
    )

    transformed_tree = transform_subtree(tree)

    # drop empty folders
    transformed_tree = drop_titles(transformed_tree, ['Academics'])

    # set subjects
    for child in transformed_tree['children']:
        child['title'] = child['extra_fields']['subject']

    # set some identifiers
    def _set_identifier_from_listId(subtree):
        if subtree['identifier'] == 'no identifier' and 'listId' in subtree[
                'extra_fields']:
            subtree['identifier'] = subtree['extra_fields']['listId']
        for child in subtree['children']:
            _set_identifier_from_listId(child)

    _set_identifier_from_listId(transformed_tree)

    # hoist non-useful headings
    hoist_unnecessary_tree_nodes(
        transformed_tree, hoist_titles=CALIFORNIA_VOCATIONAL_HOIST_TITLES)

    # set kinds
    for subject in transformed_tree['children']:
        if subject['kind'] == 'no statementLabel':
            subject['kind'] = 'subject'
        for topic in subject['children']:
            if topic['kind'] == 'no statementLabel':
                topic['kind'] = 'topic'

    print_commonstandards_tree(transformed_tree, display_len_limit=90)
    # return transformed_tree

    try:
        document = CurriculumDocument.objects.get(
            source_id=CALIFORNIA_VOCATIONAL_DOCUMENT_ATTRIBUTES["source_id"])
        document.delete()
    except CurriculumDocument.DoesNotExist:
        pass
    document = CurriculumDocument.objects.create(
        **CALIFORNIA_VOCATIONAL_DOCUMENT_ATTRIBUTES)

    root = StandardNode.add_root(
        identifier=transformed_tree["identifier"],
        title=transformed_tree["title"],
        kind=transformed_tree["kind"],
        document=document,
    )

    def _add_children_to_parent(parent, children):
        for i, child in enumerate(children):
            sort_order = i + 1
            node = parent.add_child(
                document=parent.document,
                title=child["title"],
                identifier=child["identifier"],
                sort_order=sort_order,
                kind=child["kind"],
            )
            _add_children_to_parent(node, child["children"])

    _add_children_to_parent(root, transformed_tree["children"])
    print("Finished importing California vocational standards")