Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
test merge into development
  • Loading branch information
dtraviglia committed Jul 30, 2014
2 parents 6afac92 + 018a0fd commit ed22dd3c9e9587591332053d6bece35f94509817
Show file tree
Hide file tree
Showing 24 changed files with 696 additions and 192 deletions.
@@ -7,3 +7,6 @@
*.ogg
*.mp4
*.sqlite3
*.vagrant
*.cer
files/draper-openrc.sh
@@ -1 +1,55 @@
# Documentation for the XDATA Online Experiment
# Documentation for the XDATA Online Experiment

Once this package is cloned, create the database

```bash
$ python manage.py syncdb
```

This will also create a superuser.


# During development, if you want to drop to the database and start over run the following:

```bash
$ python manage.py sqlclear op_tasks | python manage.py dbshell
$ python manage.py syncdb
$ python manage.py populate_db
```

This will keep your super user and drop just the app database which is a lot nicer than deleting the whole database and starting over

This process is also under the `reset_optask` command

```bash
$ python manage.py reset_optask
```


# Getting this working on Vagrant (VirtualBox)

Get a base centos box (this may take awhile)
```bash
vagrant box add centos_6.5 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
```

Start it
```bash
vagrant up virtualbox
```

# Getting this working on Vagrant (OpenStack)

Get a base centos box (this may take awhile)

You need 2 files:

1. The first is the `.pem` (or `.cer`) file which is the KeyPair file you can download from the OpenStack dashboard.

2. The second is a shell script which contains all the environment variables referenced in the Vagrantfile. This is located under API Access under the Security Settings. Once you download this file run `source $file.sh`, and this will ask you for you OpenStack password and load all the required varaibles under your current environment.

Adjust the Vagrantfile to use the appropriate `.pem` file and the appropriate KeyPair name associated with that pem file. Once that is complete you can run:

```bash
vagrant up openstack --provider=openstack
```
@@ -0,0 +1,80 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "virtualbox" do |vbox|
vbox.vm.box = "centos_6.5"
vbox.vm.network "forwarded_port", guest: 80, host: 8080
vbox.vm.network "forwarded_port", guest: 8000, host: 9000

vbox.vm.provision :shell, path: "scripts/install.sh"
vbox.vm.provision :shell, path: "scripts/install_python.sh"
vbox.vm.provision :shell, path: "scripts/start_oe.sh"
end

config.vm.define "openstack", autostart: false do |osConfig|
require 'vagrant-openstack-plugin'

osConfig.ssh.private_key_path = "/Users/dreed/draper/xdata/code/logging_server/vagrant/user-ale-logger-vagrant.cer"

osConfig.vm.box = "dummy"
osConfig.vm.box_url = "https://github.com/cloudbau/vagrant-openstack-plugin/raw/master/dummy.box"

osConfig.vm.provider :openstack do |os|
os.username = "#{ENV['OS_USERNAME']}"
os.api_key = "#{ENV['OS_PASSWORD']}"
os.flavor = /m1.small/ # Regex or String
os.image = /xdata-centos-base/ # Regex or String
os.endpoint = "#{ENV['OS_AUTH_URL']}/tokens"
os.keypair_name = "User-ALE-logger-vagrant" # as stored in Nova
os.ssh_username = "cloud-user" # login for the VM
os.floating_ip = "10.1.93.171"
os.networks = []
os.server_name = "oe_vagrant_test"
end

osConfig.ssh.pty = true

config.vm.provision :shell, path: "scripts/install.sh"
config.vm.provision :shell, path: "scripts/setup_iptables.sh"
config.vm.provision :shell, path: "scripts/install_python.sh"
config.vm.provision :shell, path: "scripts/start_oe.sh"
end

config.vm.define "aws", autostart: false do |aws| #install on ubuntu image
require 'vagrant-aws'

aws.vm.box = "dummy"
aws.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"

aws.ssh.username = "ubuntu"
aws.ssh.private_key_path = "PATH_TO_YOUR_KEY_FILE.pem"

aws.vm.provider :aws do |ec2, override|
ec2.access_key_id = "YOUR_ACCESS_KEY"
ec2.secret_access_key = "YOUR_SECRET"
ec2.keypair_name = "KEYPAIR_NAME"
ec2.instance_type = "m1.medium"
ec2.region = "us-east-1"
ec2.security_groups = ["neon-vagrant"]
ec2.tags = {
'project' => 'neon'
}
ec2.block_device_mapping = [{ :DeviceName => "/dev/sda1", 'Ebs.VolumeSize' => 20, 'Ebs.DeleteOnTermination' => true }]
ec2.ami = "ami-d805f4b0" #"ami-018c9568" #the ami for the image to install
override.ssh.pty = true
end

aws.vm.synced_folder ".", "/vagrant", disabled: true

aws.vm.synced_folder "./puppet/", "/puppet"

aws.vm.provision "shell",
inline: "echo \"Applying puppet\" && puppet apply /puppet/ubuntu.pp"

aws.vm.network "forwarded_port", host: 4567, guest: 8080
end
end
@@ -0,0 +1,14 @@

# Draper Online Experiment
<VirtualHost *:80>
#ServerName www.example.com
WSGIScriptAlias / /var/www/op_task/xdata/wsgi.py
#Alias /media /opt/django/site1/media/statics
#Alias /admin_media /home/myuser/Django-1.1/django/contrib/admin/media

<Directory /var/www/op_task/xdata>
<Files wsgi.py>
Allow from all
</Files>
</Directory>
</VirtualHost>
@@ -36,7 +36,8 @@ class OpTaskAdmin(admin.ModelAdmin):

# Defines how the sequences are viewed
class SequenceAdmin(admin.ModelAdmin):
list_display = ['user', 'op_task', 'index', 'ot_complete', 'exit_complete']
search_fields = ['user__email']
list_display = ['user', 'op_task', 'index', 'ot_complete', 'exit_complete']


# admin.site.unregister(User)
@@ -66,8 +66,11 @@ def save(self, commit=True):
# assign it to the user
setattr(user, 'product', product)

# if commit:
user.save()
# if commit:
# user.save()

print 'USER: ', commit, user, user.pk, user.id

# cycle through the operational tasks and assign to an index
for ot_index, ot in enumerate(operational_tasks[0:3]):
@@ -83,7 +86,7 @@ def save(self, commit=True):

class ParticipantChangeForm(forms.ModelForm):
email = forms.EmailField(label=_("Email"),
help_text=_("Required. dreed@test.com"),
help_text=_("Required. test@test.com"),
error_messages={
'invalid': _("Please enter a valid email address.")})
password = ReadOnlyPasswordHashField(label=_("Password"),
@@ -1,40 +1,77 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.hashers import make_password
from op_tasks.models import *
from django.conf import settings
from django.conf.urls.static import static

# this pre-populates the database prior to any user interaction.
# any changes here likely won't be seen unless the database is rebuilt
# any changes here won't be seen unless the database is rebuilt

# name of operational task, link to task, and link to exit survey
kiva_ots = [
('Kiva-OT1','https://www.surveymonkey.com/jsEmbed.aspx?sm=sxPflNw3jozCzZypcqWRQw_3d_3d',
'https://www.research.net/jsEmbed.aspx?sm=tYJM5iagWbyhqTn4_2fiY9Vg_3d_3d'),
('Kiva-OT2','https://www.surveymonkey.com/jsEmbed.aspx?sm=IpK_2f4QEuQ4gHlzXW23Jwmw_3d_3d',
'https://www.research.net/jsEmbed.aspx?sm=ENjFjhorB6q_2fS_2f7XTBG8gA_3d_3d'),
('Kiva-OT3','https://www.surveymonkey.com/jsEmbed.aspx?sm=aYs37Ot_2fVlOBNcbfMH1yUg_3d_3d',
'https://www.research.net/jsEmbed.aspx?sm=ny3fOPYFSUODDGx5w8guYA_3d_3d')
test_ot = [
{
'name': 'Test-OT1',
'ot_survey_url': 'https://www.surveymonkey.com/s/LR37HZG',
'ot_exit_url': 'https://www.surveymonkey.com/s/VD8NQZT'
},
{
'name': 'Test-OT2',
'ot_survey_url': 'https://www.surveymonkey.com/s/LR37HZG',
'ot_exit_url': 'https://www.surveymonkey.com/s/VD8NQZT'
}
]

class Command(BaseCommand):
help = 'our help string comes here'

def _create_participants(self):
participant = Participant(email="test@test.com", password=make_password("test"))

product = Product.objects.filter(is_active=True).order_by('?')[0]
dataset = product.dataset

# get random sequence of operational tasks
operational_tasks = dataset.optask_set.filter(is_active=True).order_by('?')

# assign it to the user
setattr(participant, 'product', product)
participant.save()

for ot_index, ot in enumerate(operational_tasks[0:3]):
if ot_index==0:
ot_active=True
else:
ot_active=False
exit_active=False
Sequence(
user=participant,
op_task=ot,
index=ot_index,
ot_active=ot_active,
exit_active=exit_active
).save()

def _create_data(self):
kiva = Dataset(name='Kiva', version='v0.1')
kiva.save()
# print kiva_ots[0][0]
test = Dataset(name='Test-DS', version='v0.1')
test.save()

influent = Product(
dataset=kiva,
url='xd-viz-ws3:8080/kiva/',
team='Oculus',
name='Influent',
version='v0.1').save()

for ot in kiva_ots:
Product(
dataset=test,
url='/static/testing/index.html',
instructions=settings.STATIC_URL + 'testing/instructions.html',
team='test-team',
name='test-product',
version='v0.1'
).save()

for ot in test_ot:
ot1 = OpTask(
dataset=kiva,
name=ot[0],
survey_url=ot[1],
exit_url=ot[2]).save()
dataset=test,
name=ot['name'],
survey_url=ot['ot_survey_url'],
exit_url=ot['ot_exit_url']
).save()

def handle(self, *args, **options):
self._create_data()
self._create_data()
self._create_participants()
@@ -0,0 +1,15 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.hashers import make_password
from op_tasks.models import *
import os

class Command(BaseCommand):
help = 'our help string comes here'

def _reset(self):
os.system('python manage.py sqlclear op_tasks | python manage.py dbshell')
os.system('python manage.py syncdb')
os.system('python manage.py populate_db')

def handle(self, *args, **options):
self._reset()
@@ -34,9 +34,9 @@ def __unicode__(self): # Python 3: def __str__(self):
class OpTask(models.Model):
dataset = models.ForeignKey(Dataset, null=True, blank=True)
name = models.CharField(max_length=200)
survey_url = models.CharField(max_length=1000, unique=True)
survey_url = models.CharField(max_length=1000, unique=False)
is_active = models.BooleanField(default=True)
exit_url = models.CharField(max_length=1000, unique=True)
exit_url = models.CharField(max_length=1000, unique=False)
instructions = models.CharField(max_length=1000)

def __unicode__(self): # Python 3: def __str__(self):
@@ -102,9 +102,6 @@ def get_full_name(self):
def get_short_name(self):
"Returns the short name for the user."
return self.first_name

def get_user_hash(self):
return self.user_hash

# sends an email to this user
def email_user(self, subject, message, from_email=None, **kwargs):
@@ -129,8 +126,15 @@ class Sequence(models.Model):
exit_active = models.BooleanField(default=False)
exit_complete = models.BooleanField(default=False)

def _both_complete(self):
"returns whether both task and survey are complete"
return self.exit_complete and self.ot_complete

both_complete = property(_both_complete)

def __unicode__(self): # Python 3: def __str__(self):
return '%s, %s, %s, %s, %s, %s' % (self.pk, self.user, self.op_task, self.index, self.ot_complete, self.user.user_hash)
return '%s, %s, %s' % (self.user, self.op_task, self.index)

class Meta:
ordering = ('user', 'index')
# index = models.IntegerField()

0 comments on commit ed22dd3

Please sign in to comment.