Exemplo n.º 1
0
def main(request):
	
	response = None
	
	if not request.COOKIES.has_key('has_version'):
		version = random.randint(1, 6)
		response = render_to_response('landingpage-' + str(version)+ '.html')
		response.set_cookie('has_version', version)
		if len(Version.objects.filter(version = version)) == 0:
			newObject = Version(version = version, total = 1, success = 0)
			newObject.save()
		else:
			obj = Version.objects.get(version = version)
			obj.total += 1
			obj.save()
	else:
		version = request.COOKIES['has_version']	
		response = render_to_response('landingpage-' + str(version)+ '.html')
		
	if request.method == 'POST':
		name = request.POST.get('inputName', '')
		surname = request.POST.get('inputSurName', '')
		patronymic = request.POST.get('inputPatronymic', '')
		phone = request.POST.get('inputPhone', '')
		if request.COOKIES.has_key('has_version'):
			version = request.COOKIES['has_version']
			obj = Version.objects.get(version = version)
			obj.success += 1
			obj.save()
	return response
Exemplo n.º 2
0
def main(request):
	
	responseName = ""
	setVersion = -1
	setCompleted = False
	
	if not request.COOKIES.has_key('has_version'):
		version = random.randint(1, 6)
		responseName = 'landingpage-' + str(version)+ '.html'
		setVersion = version
		if len(Version.objects.filter(version = version)) == 0:
			newObject = Version(version = version, total = 1, success = 0)
			newObject.save()
		else:
			obj = Version.objects.get(version = version)
			obj.total += 1
			obj.save()
	else:
		version = request.COOKIES['has_version']	
		responseName = 'landingpage-' + str(version)+ '.html'
		
	if request.method == 'POST':
		name = request.POST.get('inputName', '')
		surname = request.POST.get('inputSurName', '')
		patronymic = request.POST.get('inputPatronymic', '')
		phone = request.POST.get('inputPhone', '')
		email = request.POST.get('inputEmail', '')
		people = Data(name=name, surname=surname, patronymic=patronymic,phone=phone,email=email)
		people.save()
		if request.COOKIES.has_key('has_version'):
			version = request.COOKIES['has_version']
			obj = Version.objects.get(version = version)
			obj.success += 1
			obj.save()
		setCompleted = True
	
	arg = {}
	if setCompleted or request.COOKIES.has_key('completed'):
		arg = {'completed':'YES'}
	else:
		arg = {'completed':None}	
	response = render_to_response(responseName, arg)
	if setVersion != -1:
		response.set_cookie('version', str(setVersion))
	if setCompleted:
		response.set_cookie('completed', 'YES')
	return response
Exemplo n.º 3
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),
    })
Exemplo n.º 4
0
 def insert_version(self, Code_Version, Modele):
     version = Version(Code_Version=Code_Version, Id_Modele=Modele)
     version.save()
     pass