diff --git a/MyApp/settings.py b/MyApp/settings.py index b3a3351..60775b7 100644 --- a/MyApp/settings.py +++ b/MyApp/settings.py @@ -12,7 +12,6 @@ import os - # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -25,8 +24,10 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['127.0.0.1','floating-bastion-32116.herokuapp.com', 'localhost'] - +ALLOWED_HOSTS = [ + '127.0.0.1', 'floating-bastion-32116.herokuapp.com', 'localhost', + 'fairness-two.herokuapp.com' +] # Application definition @@ -93,20 +94,23 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + 'NAME': + 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + 'NAME': + 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + 'NAME': + 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + 'NAME': + 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] - # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ @@ -120,7 +124,6 @@ USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.11/howto/static-files/ PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -130,8 +133,5 @@ STATIC_URL = '/static/' # Extra places for collectstatic to find static files. -STATICFILES_DIRS = ( - os.path.join(PROJECT_ROOT, 'accounts/static/images'), -) +STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static/images'), ) STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' - diff --git a/Procfile b/Procfile index 928dde1..f266119 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ -web: gunicorn MyApp.wsgi --log-file - \ No newline at end of file +release: python manage.py migrate +web: gunicorn MyApp.wsgi --log-file - diff --git a/accounts/algorithms/Game.py b/accounts/algorithms/Game.py index 7324a9f..3f77f96 100644 --- a/accounts/algorithms/Game.py +++ b/accounts/algorithms/Game.py @@ -11,6 +11,7 @@ def getRobot(request, toggle): uservalues = UserValues.objects.get(user=user) robots = Robots.objects.filter(user=user) current_robot = random.choice(robots) + #current_robot=robots if toggle == 1: offeror = current_robot acceptor = uservalues diff --git a/accounts/algorithms/getValues.py b/accounts/algorithms/getValues.py index 0cbdcad..c291e04 100644 --- a/accounts/algorithms/getValues.py +++ b/accounts/algorithms/getValues.py @@ -4,6 +4,7 @@ def getDefaultUserValues(): dict = {} user_comfort = round(random(), 5) user_discretized_comfort = round(user_comfort*4)/4 + #user_discretized_comfort = 0.5 general_loss = user_comfort - user_discretized_comfort offeror_positive_loss_count = offeror_negative_loss_count = acceptor_positive_loss_count = acceptor_negative_loss_count = 0 @@ -17,6 +18,7 @@ def getDefaultUserValues(): offeror_negative_loss = acceptor_negative_loss = abs(general_loss) user_stubbornness = round(random(), 5) + #user_stubbornness = 0.5 dict['comfort'] = user_discretized_comfort dict['stubbornness'] = user_stubbornness diff --git a/accounts/models.py b/accounts/models.py index 8f0eae4..7a148ff 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -5,7 +5,7 @@ from accounts.algorithms import getValues # Create your models here. - +#try to update '''basic profile model for a user''' class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) @@ -17,8 +17,12 @@ class UserProfile(models.Model): class UserValues(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) firstLogin = models.BooleanField(default=True) - comfort = models.FloatField(default=0.0) - stubbornness = models.FloatField(default=0.0) + STUB_NEUR=0.5 + COMFORT_NEU=0.5 + COMFORT_CHOICES=[(COMFORT_NEU,'Neur')] + STUB_CHOICES=[(STUB_NEUR,'Neu')] + comfort = models.FloatField(choices=COMFORT_CHOICES) + stubbornness = models.FloatField(choices=STUB_CHOICES) neighbors = models.TextField(default='') offeror_values = models.TextField(default='') user_offeror_values = models.TextField(default='') @@ -46,10 +50,24 @@ class UserValues(models.Model): last_robot_value = models.FloatField(default=0) '''the robots/bots who will play with the users''' + class Robots(models.Model): + COMFORT_NEU=0.5 + #COMFORT_MAX=1.0 + #OMFORT_CHOICES=((0.5,'Neur')) + STUB_NEUR=0.5 + #STUB_MIN=0.0 + #STUB_CHOICES=((0.5,'Neur')) + COMFORT_CHOICES=[(COMFORT_NEU,'Neur')] + STUB_CHOICES=[(STUB_NEUR,'Neu')] + user = models.ForeignKey(User, on_delete=models.CASCADE) - comfort = models.FloatField(default=0.0) - stubbornness = models.FloatField(default=0.0) + #comfort = models.FloatField(default=0.0) + comfort = models.FloatField(choices=COMFORT_CHOICES, default='Neur') + + #stubbornness = models.FloatField(default=0.0) + stubbornness = models.FloatField(choices=STUB_CHOICES, default='Neu') + neighbors = models.TextField(default='') offeror_values = models.TextField(default='') acceptor_values = models.TextField(default='') @@ -84,9 +102,12 @@ def create_profile(sender, instance, created, **kwargs): lastName = instance.last_name) dict = getValues.getDefaultUserValues() values_profile = UserValues.objects.create(user = instance, comfort = dict['comfort'], - stubbornness = dict['stubbornness'], offeror_values=str(dict['comfort']), - acceptor_values = str(dict['comfort']), user_offeror_values=str(dict['comfort']), - user_acceptor_values = str(dict['comfort']), offeror_positive_loss_count = dict['oplc'], + stubbornness = dict['stubbornness'], + offeror_values=str(dict['comfort']), + acceptor_values = str(dict['comfort']), + user_offeror_values=str(dict['comfort']), + user_acceptor_values = str(dict['comfort']), + offeror_positive_loss_count = dict['oplc'], offeror_negative_loss_count = dict['onlc'], acceptor_positive_loss_count = dict['aplc'], acceptor_negative_loss_count = dict['anlc'], offeror_positive_loss = dict['opl'], offeror_negative_loss = dict['onl'], acceptor_positive_loss = dict['apl'], @@ -94,9 +115,11 @@ def create_profile(sender, instance, created, **kwargs): for i in range (0,10): dict = getValues.getDefaultUserValues() - robot = Robots.objects.create(user = instance, comfort = dict['comfort'], - stubbornness = dict['stubbornness'], offeror_values=str(dict['comfort']), - acceptor_values = str(dict['comfort']),offeror_positive_loss_count = dict['oplc'], + robot = Robots.objects.create(user = instance, comfort = 0.2, #dict['comfort'], + stubbornness = 0.8, #dict['stubbornness'], + offeror_values=str(0.2),#str(dict['comfort']), + acceptor_values =str(0.2), #str(dict['comfort']), + offeror_positive_loss_count = dict['oplc'], offeror_negative_loss_count = dict['onlc'], acceptor_positive_loss_count = dict['aplc'], acceptor_negative_loss_count = dict['anlc'], offeror_positive_loss = dict['opl'], offeror_negative_loss = dict['onl'], acceptor_positive_loss = dict['apl'], diff --git a/accounts/static/images/.1.a1b7bd2da96f.png.icloud b/accounts/static/images/.1.a1b7bd2da96f.png.icloud new file mode 100644 index 0000000..d1bdfa9 Binary files /dev/null and b/accounts/static/images/.1.a1b7bd2da96f.png.icloud differ diff --git a/accounts/static/images/.10.95540c125e71.png.icloud b/accounts/static/images/.10.95540c125e71.png.icloud new file mode 100644 index 0000000..fb9bc97 Binary files /dev/null and b/accounts/static/images/.10.95540c125e71.png.icloud differ diff --git a/accounts/static/images/.10.png.icloud b/accounts/static/images/.10.png.icloud new file mode 100644 index 0000000..0aa4d2c Binary files /dev/null and b/accounts/static/images/.10.png.icloud differ diff --git a/accounts/static/images/.3.ec976afe3115.png.icloud b/accounts/static/images/.3.ec976afe3115.png.icloud new file mode 100644 index 0000000..e79ef35 Binary files /dev/null and b/accounts/static/images/.3.ec976afe3115.png.icloud differ diff --git a/accounts/static/images/.3.png.icloud b/accounts/static/images/.3.png.icloud new file mode 100644 index 0000000..2aafc15 Binary files /dev/null and b/accounts/static/images/.3.png.icloud differ diff --git a/accounts/static/images/1.jpg b/accounts/static/images/1.jpg new file mode 100644 index 0000000..90c4f18 Binary files /dev/null and b/accounts/static/images/1.jpg differ diff --git a/accounts/static/images/1.png b/accounts/static/images/1.png index 05b6f89..10661cf 100644 Binary files a/accounts/static/images/1.png and b/accounts/static/images/1.png differ diff --git a/accounts/static/images/10.png b/accounts/static/images/10.png deleted file mode 100644 index 996f3ca..0000000 Binary files a/accounts/static/images/10.png and /dev/null differ diff --git a/accounts/static/images/11.428564d09c81.jpg b/accounts/static/images/11.428564d09c81.jpg new file mode 100644 index 0000000..4f3b0a7 Binary files /dev/null and b/accounts/static/images/11.428564d09c81.jpg differ diff --git a/accounts/static/images/12.f60c72f44885.jpg b/accounts/static/images/12.f60c72f44885.jpg new file mode 100644 index 0000000..1c94663 Binary files /dev/null and b/accounts/static/images/12.f60c72f44885.jpg differ diff --git a/accounts/static/images/2.497faf6bf03f.png b/accounts/static/images/2.497faf6bf03f.png new file mode 100644 index 0000000..e9a736a Binary files /dev/null and b/accounts/static/images/2.497faf6bf03f.png differ diff --git a/accounts/static/images/3.png b/accounts/static/images/3.png deleted file mode 100644 index c09577e..0000000 Binary files a/accounts/static/images/3.png and /dev/null differ diff --git a/accounts/static/images/4.3f1e188f978c.jpg b/accounts/static/images/4.3f1e188f978c.jpg new file mode 100644 index 0000000..0455134 Binary files /dev/null and b/accounts/static/images/4.3f1e188f978c.jpg differ diff --git a/accounts/static/images/5.78ec7c79cd39.jpg b/accounts/static/images/5.78ec7c79cd39.jpg new file mode 100644 index 0000000..549bea4 Binary files /dev/null and b/accounts/static/images/5.78ec7c79cd39.jpg differ diff --git a/accounts/static/images/6.edca85b9d316.png b/accounts/static/images/6.edca85b9d316.png new file mode 100644 index 0000000..e41650a Binary files /dev/null and b/accounts/static/images/6.edca85b9d316.png differ diff --git a/accounts/static/images/7.e702e2fa260f.png b/accounts/static/images/7.e702e2fa260f.png new file mode 100644 index 0000000..b0c24b2 Binary files /dev/null and b/accounts/static/images/7.e702e2fa260f.png differ diff --git a/accounts/static/images/8.0f491ba34a0c.jpg b/accounts/static/images/8.0f491ba34a0c.jpg new file mode 100644 index 0000000..0c191b4 Binary files /dev/null and b/accounts/static/images/8.0f491ba34a0c.jpg differ diff --git a/accounts/static/images/9.7c1e696606e3.png b/accounts/static/images/9.7c1e696606e3.png new file mode 100644 index 0000000..1cebdc7 Binary files /dev/null and b/accounts/static/images/9.7c1e696606e3.png differ diff --git a/accounts/static/images/best_friends.77c012c844b7.jpg b/accounts/static/images/best_friends.77c012c844b7.jpg new file mode 100644 index 0000000..93bd407 Binary files /dev/null and b/accounts/static/images/best_friends.77c012c844b7.jpg differ diff --git a/accounts/static/images/colleagues.75cd6414dccc.jpg b/accounts/static/images/colleagues.75cd6414dccc.jpg new file mode 100644 index 0000000..6b937f9 Binary files /dev/null and b/accounts/static/images/colleagues.75cd6414dccc.jpg differ diff --git a/accounts/static/images/family.9a0bbc0744bb.jpg b/accounts/static/images/family.9a0bbc0744bb.jpg new file mode 100644 index 0000000..1f29c41 Binary files /dev/null and b/accounts/static/images/family.9a0bbc0744bb.jpg differ diff --git a/accounts/static/images/imageTexts.py b/accounts/static/images/imageTexts.py index fb9561e..e3398cd 100644 --- a/accounts/static/images/imageTexts.py +++ b/accounts/static/images/imageTexts.py @@ -45,7 +45,10 @@ "42796962380": 12, } -names = ['Monica', 'Chandler', 'Joey', 'Phoebe', 'Rachel', 'Ross', 'Eric', 'Sloan', 'Vince', 'Ari', 'Shauna', 'Amanda'] +names = [ + 'Monica', 'Chandler', 'Joey', 'Phoebe', 'Rachel', 'Ross', 'Eric', 'Sloan', + 'Vince', 'Ari', 'Shauna', 'Amanda' +] settings = { 0: 'Private/Only Me', @@ -54,22 +57,29 @@ 0.75: 'Friends of Friends of Friends', 1: 'Public' } + + def getImageTexts(): return texts + def getNames(): return names + def getSettings(): return settings + def getFlickrIds(): return image_ids_flickr + def getExtensions(): return extensions + def getRole(imageId): if imageId % 3 == 1: return "Friends" - elif imageId %3 == 2: return "Best Friends" - else: return "Family members" \ No newline at end of file + elif imageId % 3 == 2: return "Best Friends" + else: return "Family members" diff --git a/accounts/static/images/large_friends.9a7386da7aca.jpg b/accounts/static/images/large_friends.9a7386da7aca.jpg new file mode 100644 index 0000000..4b69f8a Binary files /dev/null and b/accounts/static/images/large_friends.9a7386da7aca.jpg differ diff --git a/accounts/static/images/network.4692317959d1.jpg b/accounts/static/images/network.4692317959d1.jpg new file mode 100644 index 0000000..92bd047 Binary files /dev/null and b/accounts/static/images/network.4692317959d1.jpg differ diff --git a/accounts/templates/accounts/finished.html b/accounts/templates/accounts/finished.html index 01e994d..7962296 100644 --- a/accounts/templates/accounts/finished.html +++ b/accounts/templates/accounts/finished.html @@ -13,8 +13,9 @@ {% block body %} <div class="jumbotron"> <h1 class="display-3">Thank you!</h1> - <p class="lead">We are glad that you took out your precious time to complete the study for us.</p> - <p>You have completed your study!</p> + <p class="lead">We are glad that you took time to complete the study for us.</p> + <p>You have completed your study! Please fill this quick survey <a href="https://pennstate.qualtrics.com/jfe/form/SV_9TbYToErmlqMQHb" target=_blank> survey </a>. At the end of the survey you will be given + a code to put on AMAZON TURK. This is important to be paid and finish the study</p> </div> <div class="container"> <p><h2>Fun fact: During the study, you shared a total of {{ no_images }} posts and {{ failure_count }} were not published!</h2></p><hr> @@ -23,4 +24,4 @@ <h1 class="display-3">Thank you!</h1> <p><h4>You can logout now!</h4></p> <a href="/accounts/logout/" class="btn btn-outline-info" role="button" aria-pressed="true">Logout</a></p> </div> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/accounts/templates/accounts/login.html b/accounts/templates/accounts/login.html index 115641b..93531be 100644 --- a/accounts/templates/accounts/login.html +++ b/accounts/templates/accounts/login.html @@ -15,10 +15,12 @@ {% block body %} <div class="jumbotron"> <h1 class="display-3">Welcome!</h1> - <p class="lead">We are conducting this user study to investigate and explore how a user's data sharing privacy - preference evolve over time.</p> + <p class="lead">We are conducting this research study to investigate users' data sharing privacy + preferences.</p> + <p> Before logging in you must register. You can obtain the password FOR REGISTRATION upon completing this survey following + this <a href="https://pennstate.qualtrics.com/jfe/form/SV_0VxnXmKRSo1MIex" target="_blank"> link </a> <hr> - <p>Thank you for agreeing to take part in our study.</p> + </div> <div class="container"> @@ -37,4 +39,4 @@ <h1 class="display-3">Welcome!</h1> </form> </div> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/accounts/templates/accounts/logout.html b/accounts/templates/accounts/logout.html index 63238a2..963682f 100644 --- a/accounts/templates/accounts/logout.html +++ b/accounts/templates/accounts/logout.html @@ -8,7 +8,7 @@ <h1>Logged Out</h1> </div> <div class="container"> - <p><h2>You have logged out!</h2></p><hr> + <p><h2>You have logged out! Bye!</h2></p><hr> <p><a href="/accounts/login/" class="btn btn-outline-success" role="button" aria-pressed="true">Login Again</a> </div> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/accounts/templates/accounts/model_form_upload.html b/accounts/templates/accounts/model_form_upload.html index 20bd8c8..2489828 100644 --- a/accounts/templates/accounts/model_form_upload.html +++ b/accounts/templates/accounts/model_form_upload.html @@ -1,49 +1,45 @@ {% extends 'base.html' %} {% block head %} <title>Content</title> -````<style> +<style> button { cursor: pointer; } + img { + border-style: none !important; + } </style> - <script> - $( document ).ready(function() { - $('#privacy').hide() - $('#next').hide() - $('#Yes').click(function() { - $('#next').hide() - $('#privacy').show() - }); - $('#No').click(function() { - $('#privacy').hide() - $('#next').show(); - }); - }); - </script> + + {% endblock %} {% block body %} <br><br><br> <div class="container"> -{% if form and not image_id %} - <!--<div class="alert alert-warning" role="alert">--> - <!--<strong>Warning!</strong> Please reload the page if you're not seeing the image after uploading!--> - <!--</div>--> - {% if error %} + + {% if form and not image_id %} + <div class="alert alert-warning" role="alert">--> + <strong>Warning!</strong> Please reload the page if you're not seeing the image after uploading!--> + </div> + {% if error %} <div class="alert alert-danger"> <strong>{{ error|escape }}</strong> </div> {% endif %} - <!--Please select a photo from the Flickr album and copy the link below after opening the photo.</p>--> + +Please select a photo from the Flickr album and copy the link below after opening the photo.</p> --> + <p>Please select a photo you wish to share from the Flickr album and link to it below</p> <p><a target="_blank" href="https://www.flickr.com/photos/166878378@N08/albums/72157701200346045" class="btn btn-info" role="button" aria-pressed="true">Go to album</a></p> <p>Please note that we need you to post the URL or link of the photo; which will appear on the address bar (where you enter the website name) <b>after</b> you've opened the photo by clicking on it.</p> - <p><form method="post" name="photo"> + <p><form method="post" name="photo"> {% csrf_token %} {{ form.as_p }} <button class="btn btn-info" type="submit" role="button" name="change" aria-pressed="true">Upload</button> </form></p> {% endif %} -{% if image_id %} + +{% if image_id %} + <p>You are tagged in this photo with <b>{{ name }}</b> (one of your {{ role }}).</p> <p>According to what you set for your privacy setting, this image will be shared with <b>{{ setting }}</b>.</p> <p>If you wish to select a different setting than the default, @@ -53,9 +49,9 @@ <!-- Modal --> - <div height="200" width="200"> + <div> {% load static %} - <center><img src="{% static imagePath %}" alt="My image" height="100%" width="500" /></center> + <img src="{% static imagePath %}" alt="My image" /> </div><br> <!--<p>Would you like to share this photo?</p>--> @@ -66,10 +62,10 @@ <a href="{% url 'upload' %}" class="btn btn-info">ReUpload</a> </form></p> -{% endif %} +{% endif %} {% if result %} {% if 'pass' in result %} - <p>Yayy! <b>{{ name }}</b> accepted your request for tagging!</p> + <p>Great! <b>{{ name }}</b> accepted your request for tagging!</p> <form method="post"> {% csrf_token %} <b>Let's continue with the study!</b> @@ -149,5 +145,18 @@ <h4 class="modal-title">Privacy Setting</h4> </div> </div> </div> - +<script> + $( document ).ready(function() { + $('#privacy').hide() + $('#next').hide() + $('#Yes').click(function() { + $('#next').hide() + $('#privacy').show() + }); + $('#No').click(function() { + $('#privacy').hide() + $('#next').show(); + }); + }); + </script> {% endblock %} diff --git a/accounts/templates/accounts/pages.html b/accounts/templates/accounts/pages.html index 66edea6..fbc442d 100644 --- a/accounts/templates/accounts/pages.html +++ b/accounts/templates/accounts/pages.html @@ -2,25 +2,15 @@ {% block head %} <title>Content</title> -````<style> + <style> button { cursor: pointer; } + img { + border-style: none !important; + } </style> - <script> - $( document ).ready(function() { - $('#next').hide() - $('#privacy').hide() - $('#Yes').click(function() { - $('#next').hide() - $('#privacy').show() - }); - $('#No').click(function() { - $('#privacy').hide() - $('#next').show(); - }); - }); - </script> + {% endblock %} {% block body %} @@ -31,11 +21,11 @@ <strong>Warning!</strong> Please reload the page if you're not seeing the image! </div> - <b>Please look at the below image and read the associated content. Kindly answer the question - as if it were a real-life situation.</b></div><br><br> - <div height="200" width="200"> + <b>Please look at the below image and its note. Answer the question + as if it were a photo of your choosing or chosen by a friend.</b></div><br><br> + <div> {% load static %} - <center><img src="{% static imagePath %}" alt="My image1" height="100%" width="500" /></center> + <img src="{% static imagePath %}" alt="My image1" /> <!--<center><img src="/static/images/{{ image_id }}.png" alt="My image" height="100%" width="500" /></center>--> </div> @@ -101,5 +91,18 @@ </form> {% endif %} </div> - -{% endblock %} \ No newline at end of file +<script> + $( document ).ready(function() { + $('#next').hide() + $('#privacy').hide() + $('#Yes').click(function() { + $('#next').hide() + $('#privacy').show() + }); + $('#No').click(function() { + $('#privacy').hide() + $('#next').show(); + }); + }); +</script> +{% endblock %} diff --git a/accounts/templates/accounts/profile.html b/accounts/templates/accounts/profile.html index 1e5229c..b8d66d9 100644 --- a/accounts/templates/accounts/profile.html +++ b/accounts/templates/accounts/profile.html @@ -19,10 +19,11 @@ <strong>Warning!</strong> Please reload the page if you're not seeing the images! </div> <div id="network"> - <p style="text-align:justify">You have agreed to take part in a user study. We will show you a series of photos.<br> - After watching each photo, kindly respond if you'd like to share the photo to your network. <br> + <p style="text-align:justify"> Thank you for agreeing to participate in this research study. Assume you are in a social network. + We will show you a series of photos, or you will be asked to choose a photo to upload on your fictitious account.<br> + After watching each photo, you will make a decision on the photo sharing settings. <br> - <b><p>But first, let's meet your network!!</p> + <b><p>But first, let's meet your social network of friends!!</p> <center>Say hello to your colleagues at work!<br><br> <div height="200" width="200"> {% load static %} diff --git a/accounts/templates/base.html b/accounts/templates/base.html index ab7ff54..604d296 100644 --- a/accounts/templates/base.html +++ b/accounts/templates/base.html @@ -3,13 +3,12 @@ <html lang="en"> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> - <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> - <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> - <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> + {% block head%} <meta charset="UTF-8"> <title>Title</title> {% endblock %} + </head> <body> <br> @@ -51,7 +50,9 @@ {% block body %} <h1>Base</h1> {% endblock %} - +<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> +<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script> +<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> </body> </html> \ No newline at end of file diff --git a/static/.10.95540c125e71.png.icloud b/static/.10.95540c125e71.png.icloud new file mode 100644 index 0000000..fb9bc97 Binary files /dev/null and b/static/.10.95540c125e71.png.icloud differ diff --git a/static/.10.png.icloud b/static/.10.png.icloud new file mode 100644 index 0000000..0aa4d2c Binary files /dev/null and b/static/.10.png.icloud differ diff --git a/static/.3.ec976afe3115.png.icloud b/static/.3.ec976afe3115.png.icloud new file mode 100644 index 0000000..e79ef35 Binary files /dev/null and b/static/.3.ec976afe3115.png.icloud differ diff --git a/static/.3.png.icloud b/static/.3.png.icloud new file mode 100644 index 0000000..2aafc15 Binary files /dev/null and b/static/.3.png.icloud differ diff --git a/static/1.a1b7bd2da96f.png b/static/1.a1b7bd2da96f.png deleted file mode 100644 index 05b6f89..0000000 Binary files a/static/1.a1b7bd2da96f.png and /dev/null differ diff --git a/static/1.png b/static/1.png index 05b6f89..10661cf 100644 Binary files a/static/1.png and b/static/1.png differ diff --git a/static/10.95540c125e71.png b/static/10.95540c125e71.png deleted file mode 100644 index 996f3ca..0000000 Binary files a/static/10.95540c125e71.png and /dev/null differ diff --git a/static/10.png b/static/10.png deleted file mode 100644 index 996f3ca..0000000 Binary files a/static/10.png and /dev/null differ diff --git a/static/3.ec976afe3115.png b/static/3.ec976afe3115.png deleted file mode 100644 index c09577e..0000000 Binary files a/static/3.ec976afe3115.png and /dev/null differ diff --git a/static/3.png b/static/3.png deleted file mode 100644 index c09577e..0000000 Binary files a/static/3.png and /dev/null differ diff --git a/static/images/.1.a1b7bd2da96f.png.icloud b/static/images/.1.a1b7bd2da96f.png.icloud new file mode 100644 index 0000000..d1bdfa9 Binary files /dev/null and b/static/images/.1.a1b7bd2da96f.png.icloud differ diff --git a/static/images/.10.95540c125e71.png.icloud b/static/images/.10.95540c125e71.png.icloud new file mode 100644 index 0000000..fb9bc97 Binary files /dev/null and b/static/images/.10.95540c125e71.png.icloud differ diff --git a/static/images/.10.png.icloud b/static/images/.10.png.icloud new file mode 100644 index 0000000..0aa4d2c Binary files /dev/null and b/static/images/.10.png.icloud differ diff --git a/static/images/.3.ec976afe3115.png.icloud b/static/images/.3.ec976afe3115.png.icloud new file mode 100644 index 0000000..e79ef35 Binary files /dev/null and b/static/images/.3.ec976afe3115.png.icloud differ diff --git a/static/images/.3.png.icloud b/static/images/.3.png.icloud new file mode 100644 index 0000000..2aafc15 Binary files /dev/null and b/static/images/.3.png.icloud differ diff --git a/static/images/1.a1b7bd2da96f.png b/static/images/1.a1b7bd2da96f.png deleted file mode 100644 index 05b6f89..0000000 Binary files a/static/images/1.a1b7bd2da96f.png and /dev/null differ diff --git a/static/images/1.jpg b/static/images/1.jpg new file mode 100644 index 0000000..90c4f18 Binary files /dev/null and b/static/images/1.jpg differ diff --git a/static/images/1.png b/static/images/1.png index 05b6f89..10661cf 100644 Binary files a/static/images/1.png and b/static/images/1.png differ diff --git a/static/images/10.95540c125e71.png b/static/images/10.95540c125e71.png deleted file mode 100644 index 996f3ca..0000000 Binary files a/static/images/10.95540c125e71.png and /dev/null differ diff --git a/static/images/10.png b/static/images/10.png deleted file mode 100644 index 996f3ca..0000000 Binary files a/static/images/10.png and /dev/null differ diff --git a/static/images/3.ec976afe3115.png b/static/images/3.ec976afe3115.png deleted file mode 100644 index c09577e..0000000 Binary files a/static/images/3.ec976afe3115.png and /dev/null differ diff --git a/static/images/3.png b/static/images/3.png deleted file mode 100644 index c09577e..0000000 Binary files a/static/images/3.png and /dev/null differ diff --git a/views.py b/views.py new file mode 100644 index 0000000..905ec2c --- /dev/null +++ b/views.py @@ -0,0 +1,267 @@ +'''the views are kinda modularized and I've tried to avoid unconventional practices. +Being the sole developer of this project, and a timeline of 55 days, this is the best I could +do with respect to applying design patterns. In future, I plan to adhere to SRP and modularize this better''' + +'''Note that while rendering HTML, a combination of Jinja 2 and jQuery is used. This can be confusing for the +browsers and bugs can appear if not done properly. I suggest using one WAY for one component +of your application and not mixing them up''' + +from django.contrib import auth +from django.contrib.auth.decorators import login_required +from django.shortcuts import render, redirect, HttpResponse +from accounts.algorithms import Game +from accounts.forms import RegistrationForm, DocumentForm +from accounts.models import UserValues, Robots +from accounts.static.images.imageTexts import getImageTexts, getNames, getSettings, getFlickrIds, getExtensions, getRole + +'''registration of account; mostly handled by Django''' +def register(request): + form = RegistrationForm(request.POST or None) + if request.method == "POST": + if form.is_valid(): + form.save() + return redirect('/accounts/profile') + args = {'form':form} + return render(request, 'accounts/reg_form.html', args) + +'''the survey page; contains logic for user both in the offeror and acceptor case. +the cases appear alternate identified by image id modulo 2.''' +def pages(request): + if request.user.is_authenticated: + imageId = request.session['image_id'] + names = getNames() + imageTexts = getImageTexts() + settings = getSettings() + extensions = getExtensions() + if request.POST: + user = UserValues.objects.get(user=request.user) + + if 'began' in request.POST: + user.firstLogin = False + user.save() + + if 'next' in request.POST: + request.session['image_id'] += 1 + imageId = request.session['image_id'] + no_images = user.offeror_count + user.acceptor_count + failure_count = user.user_offeror_failure + user.user_acceptor_failure + if(imageId > len(getImageTexts())): + return render(request, 'accounts/finished.html', {'imageId':imageId, 'no_images':no_images, + 'failure_count': failure_count},) + + if 'offeror' in request.POST: + offeror_values = list(map(float, user.offeror_values.split())) + del offeror_values[-1] + offeror_values.append(float(request.POST.get('offeror'))) + user.offeror_values = " ".join(map(str, offeror_values)) + user.save() + offeror_val = list(map(float, user.offeror_values.split()))[-1] + imagePath = "images/" + str(imageId) + "." + extensions[imageId] + return render(request, 'accounts/model_form_upload.html', { + 'image_id': imageId, "imagePath": imagePath, "role": getRole(imageId), + 'setting': settings[offeror_val], 'name': names[int(request.session['image_id']) - 1] + }) + + '''if image id is odd, user is an acceptor''' + if imageId % 2 == 1: + preference="" + change = "" + + if 'began' in request.POST or 'next' in request.POST or 'continue' in request.POST: + uservalues, current_robot = Game.getRobot(request, 1) + robot_offeror_value = list(map(float, current_robot.offeror_values.split()))[-1] + request.session['robot_offeror_value'] = robot_offeror_value + request.session['current_robot'] = current_robot.id + + if 'preference' in request.POST: + preference = request.POST.get('preference') + current_robot = Robots.objects.get(id=request.session['current_robot']) + (user, robot) = Game.imagePreference(request, current_robot, 1) + if 'Yes' in preference: + user.user_acceptor_success += 1 + else: + user.user_acceptor_failure += 1 + user_acceptor_values = list(map(float, user.user_acceptor_values.split())) + user_offeror_values = list(map(float, user.user_offeror_values.split())) + user_acceptor_values.append(user_acceptor_values[-1]) + user_offeror_values.append(user_offeror_values[-1]) + user.user_acceptor_values = " ".join(map(str, user_acceptor_values)) + user.user_offeror_values = " ".join(map(str, user_offeror_values)) + user.save() + robot.save() + + if 'change' in request.POST: + change = 'Yes' + user_acceptor_values = list(map(float, user.user_acceptor_values.split())) + del user_acceptor_values[-1] + user_acceptor_values.append(float(request.POST.get('change'))) + user.user_acceptor_values = " ".join(map(str, user_acceptor_values)) + user.save() + + imagePath = "images/" + str(imageId) + "." + extensions[imageId] + args = {'image_id':imageId, 'imagePath': imagePath, 'preference':preference, + 'change':change, 'text':imageTexts[str(imageId)], 'role': getRole(imageId), + 'name': names[int(imageId-1)], 'setting': settings[request.session['robot_offeror_value']]} + + return render(request, 'accounts/pages.html', args) + else: + '''if image id is even, user is an offeror''' + + form = DocumentForm(request.POST or None) + + if 'began' in request.POST or 'next' in request.POST or 'continue' in request.POST: + current_robot, uservalues = Game.getRobot(request, 0) + request.session['current_robot'] = current_robot.id + form = DocumentForm() + offeror_val = list(map(float, uservalues.offeror_values.split()))[-1] + uservalues.save() + current_robot.save() + return render(request, 'accounts/model_form_upload.html', { + 'form': form, + }) + + if "link" in request.POST: + uservalues = UserValues.objects.get(user=request.user) + link = request.POST.get("link") + segemented_link = link.split("/") + image_ids = getFlickrIds() + try: + imageId = int(image_ids[segemented_link[5]]) + except (KeyError, IndexError): + errorMsg = "We're sorry! The link doesn't exist! Are you sure you copied it correct from the album AFTER opening the photo? Please retry!" + form = DocumentForm() + return render(request, 'accounts/model_form_upload.html', { + 'form': form, 'error': errorMsg + }) + offeror_val = list(map(float, uservalues.offeror_values.split()))[-1] + imagePath = "images/" + str(imageId) + "." + extensions[imageId] + return render(request, 'accounts/model_form_upload.html', { + 'image_id': imageId, "imagePath": imagePath, "role": getRole(imageId), + 'form': form, 'setting': settings[offeror_val], 'name':names[int(request.session['image_id'])-1] + }) + + if "shared" in request.POST: + current_robot = Robots.objects.get(id=request.session['current_robot']) + (robot, user) = Game.imagePreference(request, current_robot, 0) + user_acceptor_values = list(map(float, user.user_acceptor_values.split())) + user_offeror_values = list(map(float, user.user_offeror_values.split())) + user_acceptor_values.append(user_acceptor_values[-1]) + user_offeror_values.append(user_offeror_values[-1]) + user.user_acceptor_values = " ".join(map(str, user_acceptor_values)) + user.user_offeror_values = " ".join(map(str, user_offeror_values)) + result = "" + if request.session['success'] == True: + user.user_offeror_success += 1 + result = "pass" + elif request.session['failure'] == True: + user.user_offeror_failure += 1 + result = "fail" + user.save() + robot.save() + return render(request, 'accounts/model_form_upload.html', { + 'result': result, 'name':names[int(request.session['image_id'])-1] + }) + + if 'change' in request.POST: + change = 'Yes' + user = UserValues.objects.get(user=request.user) + user_offeror_values = list(map(float, user.user_offeror_values.split())) + del user_offeror_values[-1] + user_offeror_values.append(float(request.POST.get('change'))) + user.user_offeror_values = " ".join(map(str, user_offeror_values)) + user.save() + return render(request, 'accounts/model_form_upload.html', { + 'change': change, + }) + else: + '''this part is to control the state of the page in case the user presses the refresh button''' + settings = getSettings() + + if(imageId > len(getImageTexts())): + user = UserValues.objects.get(user=request.user) + no_images = user.offeror_count + user.acceptor_count + failure_count = user.user_offeror_failure + user.user_acceptor_failure + return render(request, 'accounts/finished.html', {'imageId':imageId, 'no_images':no_images, + 'failure_count': failure_count},) + if imageId % 2 == 1: + imagePath = "images/" + str(imageId) + ".png" + args = {'image_id':imageId, 'imagePath':imagePath, 'text':getImageTexts()[str(imageId)], 'role': getRole(imageId), + 'name': names[int(imageId-1)], 'setting': settings[request.session['robot_offeror_value']]} + return render(request, 'accounts/pages.html', args) + else: + current_robot, uservalues = Game.getRobot(request, 0) + request.session['current_robot'] = current_robot.id + form = DocumentForm() + offeror_val = list(map(float, uservalues.offeror_values.split()))[-1] + uservalues.save() + current_robot.save() + return render(request, 'accounts/model_form_upload.html', { + 'form': form, 'setting': settings[offeror_val], 'name':names[int(request.session['image_id'])], + }) + else: + return render(request, 'accounts/login.html') + +@login_required() +def profile(request): + if request.user.is_authenticated: + uservalues = UserValues.objects.get(user=request.user) + if 'image_id' not in request.session: + request.session['image_id'] = uservalues.image_id + imageId = request.session['image_id'] + + '''there will be total 12 iterations; finish the study when image id exceeds.''' + if(imageId > len(getImageTexts())): + no_images = uservalues.offeror_count + uservalues.acceptor_count + failure_count = uservalues.user_offeror_failure + uservalues.user_acceptor_failure + return render(request, 'accounts/finished.html', {'imageId':imageId, 'no_images':no_images, + 'failure_count': failure_count},) + + args = {'username': request.user.username, 'user':uservalues, + 'image_id':uservalues.image_id, 'firstLogin':uservalues.firstLogin, + 'offeror':'No', 'acceptor':'No'} + + if imageId % 2 == 0: + args['toggle'] = 'upload' + else: + args['toggle'] = 'pages' + + if 'showQuestions' in request.POST: + request.session['questions'] = 'Yes' + if 'questions' in request.session: + args['questions'] = request.session['questions'] + + if 'offeror' in request.POST: + offeror = request.POST.get('offeror') + uservalues.comfort = float(offeror) + uservalues.offeror_values = offeror + uservalues.user_offeror_values = offeror + request.session['offeror'] = 'Yes' + uservalues.save() + + if 'acceptor' in request.POST: + comfort = request.POST.get('acceptor') + uservalues.comfort = float(comfort) + request.session['acceptor']= 'Yes' + uservalues.acceptor_values = comfort + uservalues.user_acceptor_values = comfort + uservalues.save() + + if 'offeror' in request.session: + args['offeror'] = request.session['offeror'] + if 'acceptor' in request.session: + args['acceptor'] = request.session['acceptor'] + + return render(request, 'accounts/profile.html', args) + + +@login_required() +def logout(request): + uservalues = UserValues.objects.get(user=request.user) + if 'image_id' in request.session: + uservalues.image_id = request.session['image_id'] + if 'robot_offeror_value' in request.session: + uservalues.last_robot_value = request.session['robot_offeror_value'] + uservalues.save() + request.session.flush() + auth.logout(request) + return render(request, "accounts/logout.html") \ No newline at end of file