def setUp(self): self.mock_ssh, self.mock_sftp = build_mock_connections(self) self.client = Client() for user in self.users: new_user = get_user_model().objects.create_user( user["username"], user["email"], user["new_password1"]) new_user.save() user = get_user_model().objects.all()[0] profile = user test_path = os.path.join(settings.MEDIA_ROOT, "tests") with open(os.path.join(test_path, "id_rsa.pub"), 'r') as f: profile.public_key = f.read() with open(os.path.join(test_path, "id_rsa"), 'r') as f: profile.private_key = f.read() profile.save() cluster = Cluster(name=self.cluster["name"], hostname=self.cluster["hostname"], port=self.cluster["port"]) cluster.save() self.cluster = cluster credential = Credential(user=user, cluster=cluster, username=self.credential["username"], password='', use_password=False) credential.save() self.credential = credential credential2 = Credential(user=user, cluster=cluster, username=self.credential.username, password="******", use_password=True) credential2.save() self.credential2 = credential2
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), })