Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
pilot test achievements model
  • Loading branch information
dtraviglia committed Sep 28, 2015
1 parent 75f52c1 commit 1c72fb12f8776182c08905dce5af17912800a589
Showing 6 changed files with 103 additions and 8 deletions.
@@ -41,4 +41,8 @@
url(r'^users/tasks/viewall/(?P<profile>.*)$', views.view_user_tasks, name='view_user_tasks'),
url(r'^experiment/products/$', views.view_experiment_products, name='view_experiment_products'),
url(r'^email/$', views.send_email, name='send_email'),
)
)

# print settings.DEBUG, settings.STATIC_ROOT
if settings.DEBUG:
urlpatterns += url(r'^static/(?P<path>.*)$', vs.serve),
@@ -6,8 +6,6 @@
from products import *
from tasks import *
from email import *
import csv
import pandas

@login_required(login_url='/tasking/login')
def home_page(request):
@@ -0,0 +1,19 @@
from op_tasks.models import UserProfile, \
Product, Dataset, OpTask, TaskListItem, Experiment, \
UserAchievement, Achievement

def checkAchievements(request):
if tasksComplete(request):
user = request.user
userprofile = user.userprofile
userachievement = UserAchievement()
userachievement.userprofile = userprofile
userachievement.achievement = Achievement.objects.get(name='tasksComplete')
userachievement.save()


def tasksComplete(request):
if request.method == 'POST':
user = request.user
userprofile = user.userprofile
return True
@@ -3,21 +3,26 @@
import hashlib
import time, datetime


def _createHash():
hash = hashlib.sha1()
hash.update(str(time.time()))
return hash.hexdigest()[:-10]


# the dataset class stores parameters about the
class Dataset(models.Model):
name = models.CharField(max_length=1000) # name of dataset
version = models.CharField(max_length=10)
is_active = models.BooleanField(default=True)

def __unicode__(self): # Python 3: def __str__(self):
return '%s - %s' % (self.name, self.version)

class Meta:
unique_together = ("name", "version")


class Product(models.Model): # product = tool + dataset
dataset = models.ForeignKey(Dataset, null=True, blank=True) # data for tool
url = models.CharField(max_length=1000, unique=True) # path to product
@@ -26,9 +31,11 @@ class Product(models.Model): # product = tool + dataset
version = models.CharField(max_length=10)
is_active = models.BooleanField(default=True)
instructions = models.CharField(max_length=1000)

def __unicode__(self): # Python 3: def __str__(self):
return '%s:%s:%s:%s' % (self.team, self.name, self.dataset, self.version)


class OpTask(models.Model):
dataset = models.ForeignKey(Dataset, null=True, blank=True)
name = models.CharField(max_length=200)
@@ -40,6 +47,7 @@ class OpTask(models.Model):
def __unicode__(self): # Python 3: def __str__(self):
return '%s-%s' % (self.name, self.dataset)


class Experiment(models.Model):
name = models.CharField(max_length=250) # name of the experiment
task_count = models.IntegerField(default=0)
@@ -59,6 +67,7 @@ class Experiment(models.Model):
def __unicode__(self):
return '%s' % (self.name)


class UserProfile(models.Model):
user = models.OneToOneField(User)
user_hash = models.CharField(max_length=30, default=_createHash, unique=True, editable=False)
@@ -107,3 +116,19 @@ def __unicode__(self): # Python 3: def __str__(self):
class Meta:
ordering = ('userprofile', 'index')
# index = models.IntegerField()


class Achievement(models.Model):
name = models.CharField(max_length=50)
desc = models.CharField(max_length=1000)

def __unicode__(self):
return '%s' % (self.name)


class UserAchievement(models.Model):
userprofile = models.ForeignKey(UserProfile)
achievement = models.ForeignKey(Achievement)

def __unicode__(self):
return '%s - %s' % (self.userprofile.user.username, self.achievement.name)
@@ -1,9 +1,9 @@
from django.core.urlresolvers import resolve
from django.test import TestCase
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password

from op_tasks.models import Dataset, Product, OpTask, UserProfile, TaskListItem, Experiment
from op_tasks.models import Dataset, \
Product, OpTask, UserProfile, TaskListItem, Experiment, Achievement, UserAchievement

# Create your tests here.

@@ -12,6 +12,7 @@
# def test_bad_math(self):
# self.assertEqual(1+1,3)


class ModelTest(TestCase):

def test_user_can_be_assigned_an_experiment(self):
@@ -197,9 +198,15 @@ def test_can_find_users_tasks(self):
testtask2 = OpTask(dataset=testdata, name='task2')
testtask2.save()

test_tli_1 = TaskListItem(userprofile=userprofile1, product=testproduct, op_task=testtask1, index=0)
test_tli_1 = TaskListItem(userprofile=userprofile1,
product=testproduct,
op_task=testtask1,
index=0)
test_tli_1.save()
test_tli_2 = TaskListItem(userprofile=userprofile1, product=testproduct, op_task=testtask2, index=1)
test_tli_2 = TaskListItem(userprofile=userprofile1,
product=testproduct,
op_task=testtask2,
index=1)
test_tli_2.save()

test_tlis = TaskListItem.objects.all()
@@ -212,4 +219,44 @@ def test_can_find_users_tasks(self):
if userprofile.user.username == 'John':
self.assertEqual(matched_task_items.count(),2)
else:
self.assertEqual(matched_task_items.count(),0)
self.assertEqual(matched_task_items.count(),0)

def test_can_assign_user_achievements(self):
# create a bunch of users
user = User(username='John', password=make_password('John'))
user.save()
userprofile = UserProfile(user=user)
userprofile.save()

userTwo = User(username='Paul', password=make_password('Paul'))
userTwo.save()
userprofileTwo = UserProfile(user=userTwo)
userprofileTwo.save()

achievement = Achievement(name='One')
achievement.save()

userachievement = UserAchievement()
userachievement.achievement = achievement
userachievement.userprofile = userprofile
userachievement.save()

userachievementTwo = UserAchievement()
userachievementTwo.userprofile = userprofileTwo
userachievementTwo.achievement = Achievement.objects.get(name='One')
userachievementTwo.save()

saved_achievements = Achievement.objects.all()
self.assertEqual(saved_achievements.count(), 1)

saved_userachievements = UserAchievement.objects.all()
self.assertEqual(saved_userachievements.count(), 2)

for saved_userachievement in saved_userachievements:
if saved_userachievement.userprofile.user.username == 'Paul':
self.assertEqual(saved_userachievement.achievement.name, 'One')





@@ -9,10 +9,12 @@
from django.contrib.auth.models import User
from django.utils import timezone
from elasticsearch import Elasticsearch
from achievements import *

import exp_portal
import datetime


from op_tasks.models import Product, UserProfile, TaskListItem, Experiment


0 comments on commit 1c72fb1

Please sign in to comment.