Esempio n. 1
0
def update_common_core_map(cc_file):
    logging.info("Deferred job <update_common_core_map> started")
    reader = csv.reader(cc_file, delimiter='\t')
    _ = reader.next()
    cc_list = []
    cc_standards = {}
    for line in reader:
        cc_standard = line[0]
        cc_cluster = line[1]
        try:
            cc_description = line[2].encode('utf-8')
        except Exception:
            cc_description = cc_cluster
        exercise_name = line[3]
        video_youtube_id = line[4]

        if len(cc_standard) == 0:
            continue

        if cc_standard in cc_standards:
            cc = cc_standards[cc_standard]
        else:
            cc = CommonCoreMap.all().filter('standard = ', cc_standard).get()
            if cc is None:
                cc = CommonCoreMap()

            cc_standards[cc_standard] = cc
            cc_list.append(cc)

        cc.update_standard(cc_standard, cc_cluster, cc_description)

        if len(exercise_name) > 0:
            cc.update_exercise(exercise_name)

        if len(video_youtube_id) > 0:
            cc.update_video(video_youtube_id)

        if len(cc_list) > 500:
            db.put(cc_list)
            cc_list = []
            cc_standards = {}

    db.put(cc_list)

    return
Esempio n. 2
0
def update_common_core_map(cc_file):
    logging.info("Deferred job <update_common_core_map> started")
    reader = csv.reader(cc_file, delimiter='\t')
    _ = reader.next()
    cc_list = []
    cc_standards = {}
    for line in reader:
        cc_standard = line[0]
        cc_cluster = line[1]
        try:
            cc_description = line[2].encode('utf-8')
        except Exception:
            cc_description = cc_cluster
        exercise_name = line[3]
        video_youtube_id = line[4]

        if len(cc_standard) == 0:
            continue

        if cc_standard in cc_standards:
            cc = cc_standards[cc_standard]
        else:
            cc = CommonCoreMap.all().filter('standard = ', cc_standard).get()
            if cc is None:
                cc = CommonCoreMap()

            cc_standards[cc_standard] = cc
            cc_list.append(cc)

        cc.update_standard(cc_standard, cc_cluster, cc_description)

        if len(exercise_name) > 0:
            cc.update_exercise(exercise_name)

        if len(video_youtube_id) > 0:
            cc.update_video(video_youtube_id)

        if len(cc_list) > 500:
            db.put(cc_list)
            cc_list = []
            cc_standards = {}

    db.put(cc_list)

    return
Esempio n. 3
0
        logging.info("Clearing %s Common Core Maps", len(maps))
        db.delete(maps)

    cc_list = []
    for standard, data in cc_standards.iteritems():
        changed = False
        videos, exercises = data.pop("videos"), data.pop("exercises")
        cc = CommonCoreMap.all().filter("standard = ", standard).get()
        if not cc:
            cc = CommonCoreMap(**data)
            changed = True

        for ex in exercises:
            changed |= bool(cc.update_exercise(ex))
        for ex in videos:
            changed |= bool(cc.update_video(ex))

        if changed:
            cc_list.append(cc)

    logging.info("Updating %s Common Core Maps", len(cc_list))
    db.put(cc_list)

    logging.info("Busting caches")
    CommonCoreMap.get_all_structured(lightweight=True, bust_cache=True)
    CommonCoreMap.get_all_structured(lightweight=False, bust_cache=True)
    logging.info("Done with CommonCore.")

class ManageCommonCore(request_handler.RequestHandler):

    @user_util.developer_only