Exemplo n.º 1
0
 def insert_version(self, Code_Version, Modele):
     version = Version(Code_Version = Code_Version, Id_Modele= Modele)
     version.save()
     pass
Exemplo n.º 2
0
def editor_save_run(message):

    room = get_room_or_error(message["room"], message.user)
    code = message["code"]

    # run the code with test cases of the exercise
    result = compile_code(code, room.exercise)

    # result2 = compile_code2(code,room.exercise)
    #
    # print(str(result))

    if result["overall_success"] == True:

        # print("all pass")

        overall_success = True
    else:
        overall_success = False
        # print("failed")

    room.code = message["code"]
    room.save()

    result_json = json.dumps(result)

    version = Version()
    try:
        version_tree = analyser(code)
        version_tree_json = json.dumps(version_tree)
        version.version_tree = version_tree_json

    except Exception as e:
        # version tree cannot be generated
        version.version_tree = ""

    version.code = message["code"]
    version.room = room
    version.exercise = room.exercise
    version.result = result_json
    version.overall_success = overall_success
    version.save()

    # when it is a success submission

    if overall_success:

        student = Student.objects.get(user=message.user)

        # add complete student to exercise
        room.exercise.complete_student.add(student)
        room.exercise.save()

        data_matrix = []
        version_list = Version.objects.filter(exercise=room.exercise,
                                              overall_success=True)

        student = Student.objects.get(user=message.user)
        profile_tree = json.loads(student.profile_tree)

        # reduce to 0 and 1
        reduce_version_tree = reduce_tree(version_tree)

        # udpate profile tree
        new_profile_tree = add_tree(profile_tree, reduce_version_tree)

        student.profile_tree = json.dumps(new_profile_tree)

        student.save()

        # will only run when the number of success submission is >= limit
        if len(version_list) >= CONST_MIN_VERSION:

            # remove all old clusters

            Cluster.objects.filter(exercise=room.exercise).delete()

            cluster_result = clustering(version_list)

            print(cluster_result)

            cluster_list = cluster_result["cluster_list"]
            label = cluster_result["label"]
            common_skill = cluster_result["common_skill"]

            cluster_object_list = []

            # create new cluster
            for cluster in cluster_list:
                new_cluster = Cluster()
                new_cluster.exercise = room.exercise
                # print(cluster["necessary_skill"])
                new_cluster.necessary_skill = json.dumps(
                    cluster["necessary_skill"])
                new_cluster.redundant_skill = json.dumps(
                    cluster["redundant_skill"])
                new_cluster.center = ','.join(
                    map(str, cluster["center"].tolist()))
                new_cluster.data_count = cluster["data_count"]
                new_cluster.character_skill = json.dumps(
                    cluster["character_skill"])
                new_cluster.other_skill = json.dumps(cluster["other_skill"])
                new_cluster.save()
                cluster_object_list.append(new_cluster)

            for i in range(0, len(label)):
                cluster = cluster_object_list[label[i]]
                version_list[i].cluster = cluster
                version_list[i].save()

            room.exercise.common_skill = json.dumps(common_skill)
            room.exercise.save()

    #
    message.reply_channel.send({
        "text": json.dumps(result),
    })