<commit_before>from django.shortcuts import render, redirect
from op_tasks.models import UserProfile, Product, Dataset, OpTask, TaskListItem, Experiment
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import JsonResponse
from users import *
from products import *
from tasks import *

@login_required(login_url='/tasking/login')
def home_page(request):
	return render(request, 'experimenthome.html')

def view_status(request):
	experiments = Experiment.objects.all()
	masterList = {}
	for experiment in experiments:
		name = experiment.name
		userprofiles = experiment.userprofile_set.all()
		usp = sorted(userprofiles)
		products = []
		tasks = []
		completedTasks = []
		incompleteTasks = []
		experimentList = {}
		for userprofile in userprofiles:
			tasklistitems = userprofile.tasklistitem_set.all()
			for tasklistitem in tasklistitems:
				products.append(tasklistitem.product)
				tasks.append(tasklistitem.op_task)
				if tasklistitem.task_complete is True:
					completedTasks.append(tasklistitem)
				else:
					incompleteTasks.append(tasklistitem)
		percentageComplete = int((len(completedTasks) / float(len(completedTasks) + len(incompleteTasks))) * 100)
		sortedProd = sorted(set(products))
		sortedTasks = sorted(set(tasks))
		sortedCompletedTasks = sorted(completedTasks)
		sortedIncompleteTasks = sorted(incompleteTasks)
		experimentList["users"] = usp
		experimentList["products"] = sortedProd
		experimentList["tasks"] = sortedTasks
		experimentList["completedTasks"] = sortedCompletedTasks
		experimentList["incompleteTasks"] = sortedIncompleteTasks
		experimentList["percentageComplete"] = percentageComplete
		masterList[name] = experimentList
	return render(request, 'status.html', {'experimentList': masterList})

def manage_exps(request):
	experimentlist = Experiment.objects.all()
	return render(request, 'experiments.html', {'experimentlist': experimentlist})

def view_exp_details(request, exppk):
	experiment = Experiment.objects.get(id=exppk)
	return render(request, 'experiment_details.html', {'experiment':experiment})

def add_exp(request):
	if request.method == 'POST':
		experiment = Experiment()
		experiment.name = request.POST['exp_name']
		experiment.task_count = request.POST['exp_taskcount']
		experiment.task_length = request.POST['exp_tasklength']
		experiment.has_achievements = request.POST.get('exp_achievements', False)
		experiment.has_intake = request.POST.get('exp_intake', False)
		experiment.has_followup = request.POST.get('exp_followup', False)
		experiment.consent = request.POST.get('exp_consent', False)
		experiment.sequential_tasks = request.POST.get('exp_sequentialtasks', False)
		experiment.show_progress = request.POST.get('exp_progress', False)
		experiment.timed = request.POST.get('exp_timed', False)

		experiment.save()
		return redirect('exp_portal:manage_exps')

	return render(request, 'add_experiment.html')

def edit_exp(request, exppk):
	experiment = Experiment.objects.get(id=exppk)
	experiment.name = request.POST['exp_name']
	experiment.task_count = request.POST['exp_taskcount']
	experiment.task_length = request.POST['exp_tasklength']
	experiment.has_achievements = request.POST.get('exp_achievements', False)
	experiment.has_intake = request.POST.get('exp_intake', False)
	experiment.has_followup = request.POST.get('exp_followup', False)
	experiment.consent = request.POST.get('exp_consent', False)
	experiment.sequential_tasks = request.POST.get('exp_sequentialtasks', False)
	experiment.show_progress = request.POST.get('exp_progress', False)
	experiment.timed = request.POST.get('exp_timed', False)

	experiment.save()

	return redirect('exp_portal:manage_exps')

def manage_datasets(request):
	datasets = Dataset.objects.all()
	return render(request, 'datasets.html', {'datasets':datasets})

def view_dataset_details(request, datasetpk):
	dataset = Dataset.objects.get(id=datasetpk)
	return render(request, 'dataset_details.html', {'dataset':dataset})

def add_dataset(request):
	if request.method == 'POST':
		# do update
		dataset = Dataset()
		dataset.name = request.POST['dataset_name']
		dataset.version = request.POST['dataset_version']
		dataset.is_active = request.POST.get('dataset_active', False)

		dataset.save()
		return redirect('exp_portal:manage_datasets')
	# else fall here
	return render(request, 'add_dataset.html')

def edit_dataset(request, datasetpk):
	dataset = Dataset.objects.get(id=datasetpk)
	dataset.name = request.POST['dataset_name']
	dataset.version = request.POST['dataset_version']
	dataset.is_active = request.POST.get('dataset_active', False)

	dataset.save()

	return redirect('exp_portal:manage_datasets')

def view_experiment_products(request):
	experiments = Experiment.objects.all()
	masterList = {}
	for experiment in experiments:
		name = experiment.name
		userprofiles = experiment.userprofile_set.all()
		usp = sorted(userprofiles)
		products = []
		tasks = []
		completedTasks = []
		incompleteTasks = []
		experimentList = {}
		for userprofile in userprofiles:
			tasklistitems = userprofile.tasklistitem_set.all()
			for tasklistitem in tasklistitems:
				products.append(tasklistitem.product)
				tasks.append(tasklistitem.op_task)
				if tasklistitem.task_complete is True:
					completedTasks.append(tasklistitem)
				else:
					incompleteTasks.append(tasklistitem)
		percentageComplete = int((len(completedTasks) / float(len(completedTasks) + len(incompleteTasks))) * 100)
		sortedProd = sorted(set(products))
		sortedTasks = sorted(set(tasks))
		sortedCompletedTasks = sorted(completedTasks)
		sortedIncompleteTasks = sorted(incompleteTasks)
		experimentList["users"] = usp
		experimentList["products"] = sortedProd
		experimentList["tasks"] = sortedTasks
		experimentList["completedTasks"] = sortedCompletedTasks
		experimentList["incompleteTasks"] = sortedIncompleteTasks
		experimentList["percentageComplete"] = percentageComplete
		masterList[name] = experimentList
	response = JsonResponse({'experimentInfo': str(masterList)})
	return response
<commit_msg>Started working on filtering CSV master answer sheet.<commit_after>from django.shortcuts import render, redirect
from op_tasks.models import UserProfile, Product, Dataset, OpTask, TaskListItem, Experiment
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.http import JsonResponse
from users import *
from products import *
from tasks import *
import csv

@login_required(login_url='/tasking/login')
def home_page(request):
	return render(request, 'experimenthome.html')

def view_status(request):
	experiments = Experiment.objects.all()
	masterList = {}
	for experiment in experiments:
		name = experiment.name
		userprofiles = experiment.userprofile_set.all()
		usp = sorted(userprofiles)
		products = []
		tasks = []
		completedTasks = []
		incompleteTasks = []
		experimentList = {}
		for userprofile in userprofiles:
			tasklistitems = userprofile.tasklistitem_set.all()
			for tasklistitem in tasklistitems:
				products.append(tasklistitem.product)
				tasks.append(tasklistitem.op_task)
				if tasklistitem.task_complete is True:
					completedTasks.append(tasklistitem)
				else:
					incompleteTasks.append(tasklistitem)
		percentageComplete = int((len(completedTasks) / float(len(completedTasks) + len(incompleteTasks))) * 100)
		sortedProd = sorted(set(products))
		sortedTasks = sorted(set(tasks))
		sortedCompletedTasks = sorted(completedTasks)
		sortedIncompleteTasks = sorted(incompleteTasks)
		experimentList["users"] = usp
		experimentList["products"] = sortedProd
		experimentList["tasks"] = sortedTasks
		experimentList["completedTasks"] = sortedCompletedTasks
		experimentList["incompleteTasks"] = sortedIncompleteTasks
		experimentList["percentageComplete"] = percentageComplete
		masterList[name] = experimentList 
	return render(request, 'status.html', {'experimentList': masterList})

def manage_exps(request):
	experimentlist = Experiment.objects.all()
	return render(request, 'experiments.html', {'experimentlist': experimentlist})

def view_exp_details(request, exppk):
	experiment = Experiment.objects.get(id=exppk)
	return render(request, 'experiment_details.html', {'experiment':experiment})

def add_exp(request):
	if request.method == 'POST':
		experiment = Experiment()
		experiment.name = request.POST['exp_name']
		experiment.task_count = request.POST['exp_taskcount']
		experiment.task_length = request.POST['exp_tasklength']
		experiment.has_achievements = request.POST.get('exp_achievements', False)
		experiment.has_intake = request.POST.get('exp_intake', False)
		experiment.has_followup = request.POST.get('exp_followup', False)
		experiment.consent = request.POST.get('exp_consent', False)
		experiment.sequential_tasks = request.POST.get('exp_sequentialtasks', False)
		experiment.show_progress = request.POST.get('exp_progress', False)
		experiment.timed = request.POST.get('exp_timed', False)

		experiment.save()
		return redirect('exp_portal:manage_exps')

	return render(request, 'add_experiment.html')

def edit_exp(request, exppk):
	experiment = Experiment.objects.get(id=exppk)
	experiment.name = request.POST['exp_name']
	experiment.task_count = request.POST['exp_taskcount']
	experiment.task_length = request.POST['exp_tasklength']
	experiment.has_achievements = request.POST.get('exp_achievements', False)
	experiment.has_intake = request.POST.get('exp_intake', False)
	experiment.has_followup = request.POST.get('exp_followup', False)
	experiment.consent = request.POST.get('exp_consent', False)
	experiment.sequential_tasks = request.POST.get('exp_sequentialtasks', False)
	experiment.show_progress = request.POST.get('exp_progress', False)
	experiment.timed = request.POST.get('exp_timed', False)

	experiment.save()

	return redirect('exp_portal:manage_exps')

def manage_datasets(request):
	datasets = Dataset.objects.all()
	return render(request, 'datasets.html', {'datasets':datasets})

def view_dataset_details(request, datasetpk):
	dataset = Dataset.objects.get(id=datasetpk)
	return render(request, 'dataset_details.html', {'dataset':dataset})

def add_dataset(request):
	if request.method == 'POST':
		# do update
		dataset = Dataset()
		dataset.name = request.POST['dataset_name']
		dataset.version = request.POST['dataset_version']
		dataset.is_active = request.POST.get('dataset_active', False)

		dataset.save()
		return redirect('exp_portal:manage_datasets')
	# else fall here
	return render(request, 'add_dataset.html')

def edit_dataset(request, datasetpk):
	dataset = Dataset.objects.get(id=datasetpk)
	dataset.name = request.POST['dataset_name']
	dataset.version = request.POST['dataset_version']
	dataset.is_active = request.POST.get('dataset_active', False)

	dataset.save()

	return redirect('exp_portal:manage_datasets')

def view_experiment_products(request):
	experiments = Experiment.objects.all()
	masterList = {}
	for experiment in experiments:
		name = experiment.name
		userprofiles = experiment.userprofile_set.all()
		usp = sorted(userprofiles)
		products = []
		tasks = []
		completedTasks = []
		incompleteTasks = []
		experimentList = {}
		for userprofile in userprofiles:
			tasklistitems = userprofile.tasklistitem_set.all()
			for tasklistitem in tasklistitems:
				products.append(tasklistitem.product)
				tasks.append(tasklistitem.op_task)
				if tasklistitem.task_complete is True:
					completedTasks.append(tasklistitem)
				else:
					incompleteTasks.append(tasklistitem)
		percentageComplete = int((len(completedTasks) / float(len(completedTasks) + len(incompleteTasks))) * 100)
		sortedProd = sorted(set(products))
		sortedTasks = sorted(set(tasks))
		sortedCompletedTasks = sorted(completedTasks)
		sortedIncompleteTasks = sorted(incompleteTasks)
		experimentList["users"] = usp
		experimentList["products"] = sortedProd
		experimentList["tasks"] = sortedTasks
		experimentList["completedTasks"] = sortedCompletedTasks
		experimentList["incompleteTasks"] = sortedIncompleteTasks
		experimentList["percentageComplete"] = percentageComplete
		masterList[name] = experimentList
	response = JsonResponse({'experimentInfo': str(masterList)})
	return response

{'fraction_non_alphanumeric': 0.11493027071369975, 'fraction_numerical': 0.0009844134536505333, 'mean_word_length': 6.361714975845411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2086695', 'n_tokens_mistral': 3994, 'n_tokens_neox': 3697, 'n_words': 675}