In [1]:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'stamped_project.settings'

from django.shortcuts import *
from stamped.models import *

In [2]:
from django.contrib.auth.models import User

In [3]:
from django.contrib.auth.models import Group, Permission

In [12]:
u = User.objects.get(pk=8)
u


Out[12]:
<User: george>

In [64]:
r = Restaurant.objects.get(pk=1)

In [71]:
r = Review.objects.get(pk=1)

In [74]:
r.restaurant.address


Out[74]:
u'848 Washington Street New York'

In [76]:
c = Comment.objects.get(pk=1)

In [ ]:
c.review.restaurant

In [68]:
r.get_category_display()


Out[68]:
u'Seafood'

In [59]:
p = Permission.objects.get(codename='add_restaurant')

In [85]:
u.has_perm(Permission.objects.get(codename='add_restaurant'))


Out[85]:
False

In [91]:
Permission.permission_required


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-91-479b7ea15d7f> in <module>()
----> 1 Permission.permission_required

AttributeError: type object 'Permission' has no attribute 'permission_required'

In [13]:
u.has_perm('stamped.add_restaurant')


Out[13]:
True

In [92]:
u.username


Out[92]:
u'johnson'

In [62]:
u.user_permissions.add(p)

In [14]:
r = Restaurant.objects.get(pk=1)

In [14]:
Restaurant.objects.order_by("date_added")[:5]


Out[14]:
[<Restaurant: Stock_Restaurant>, <Restaurant: Stock_Restaurant>, <Restaurant: Stock_Restaurant>, <Restaurant: Stock_Restaurant>, <Restaurant: Stock_Restaurant>]

In [15]:
get_object_or_404(Restaurant, name=r.name, address=r.address)


Out[15]:
<Restaurant: Mission Chinese Food>

In [5]:
s_count = Restaurant.objects.get(pk=1).stamped_out_count
u_count = User.objects.count()

In [6]:
s_count


Out[6]:
1

In [7]:
u_count


Out[7]:
1

Decay fucntion:


In [ ]:
import random

In [86]:
choices = [[1,91], [0,9]]

In [99]:
def decay_choice(choices, val):
    #for each additional 10,000 users, remove a percentage
    #chance for a single user to get the add_restaurant 
    #privlage stops assigning admins at 1,000,000 users 
    #where app should be self sufficent
    penalty = val // 10000
    #control for values that might exceed 100
    if penalty >= 100:
        penalty = 100
    print penalty
    choices[0][1] -= penalty
    choices[0][1] += penalty
    #get a random number from a uniform distribution
    r = random.uniform(0, 100)
    if r <= choices[0][1]:
        return choices[0][0]
    elif r <= choices[1][1]:
        return choices[1][0]

In [97]:
decay_choice(choices=choices, val=100000)


100
Out[97]:
1

In [67]:



Out[67]:
2

In [38]:
weighted_choice(choices)


Out[38]:
0

In [10]:
user.has_perm('add_resturant')


Out[10]:
True

In [20]:
r = Review.objects.get(pk='1')
r.avg_rating


Out[20]:
5.0

In [22]:
r = Restaurant.objects.get(pk=1)

In [23]:
r.stamped_out_count


Out[23]:
0

Basic Test Cases:


In [2]:
import datetime 
d = datetime.datetime(2013,3,5)
m = {'d': d}

In [3]:
print m


{'d': datetime.datetime(2013, 3, 5, 0, 0)}

In [4]:
import datetime

In [5]:
d = datetime.datetime.now() - datetime.datetime(2008,2,1)

Post Tests


In [8]:
from django.test.client import Client
c = Client()

In [25]:
response = c.post('/results/',{'name': 'Fisssh', 'address': '280 Bleecker St'})


I've been posted. Here are my values
<QueryDict: {u'name': [u'Fisssh'], u'address': [u'280 Bleecker St']}>
Fisssh
280 Bleecker St

In [26]:
response.status_code


Out[26]:
200

Restaurant Results View Rendering:


In [8]:
Restaurant.objects.filter(category=category[0]).order_by('_rating')[:5]


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-0ec9f442c610> in <module>()
----> 1 Restaurant.objects.filter(category=category[0]).order_by('_rating')[:5]

NameError: name 'category' is not defined

In [ ]:
Restaurant.objects.filter(name='Fissh', address='280 Bleecker St')

In [ ]:
restaurant = get_object_or_404(Restaurant, name='Fish', address='280 Bleecker St')

In [ ]:
restaurant

In [ ]:
restaur

In [ ]:
restaurant.name

In [ ]:
restaurant.profile_picture.url

In [ ]:
restaurant.address

In [ ]:
restaurant.date_added

In [ ]:
r = restaurant.review_set.all()

In [ ]:
r = r[0]

In [ ]:
r.content

In [ ]:
r.user.get_full_name()

In [ ]:
r.date_added

In [ ]:
r.user.user_meta.profile_picture.url

In [ ]:
r.rating #could make rating a custom tag as well

In [ ]:
c = r.comment_set.all()

In [ ]:
c = c[0]

In [ ]:
c.user.get_full_name()

In [ ]:
c.content

In [ ]:
c.date_added

Dashboard Tests;


In [ ]:
Restaurant.objects.order_by("date_added")

In [ ]:
Review.objects.order_by("date_added")

In [5]:
from django.contrib.auth import authenticate, login

In [6]:
username = 'agconti'
password = 'password'

In [7]:
user = authenticate(username=username, password=password)
Review.objects.filter(user=user).order_by("date_added")


Out[7]:
[<Review: Review of Fish by agconti on 2013-08-22 14:01:00.875655+00:00>, <Review: Review of Waffels and Dinges by agconti on 2013-08-22 14:01:28.994745+00:00>, <Review: Review of Stock_Restaurant by agconti on 2013-08-22 14:01:44.734459+00:00>, <Review: Review of Stock_Bar_Restaurant by agconti on 2013-08-22 14:01:58.169098+00:00>, <Review: Review of Stock_sandwich by agconti on 2013-08-22 14:02:16.600981+00:00>, <Review: Review of Stock_sushi by agconti on 2013-08-22 14:02:25.797847+00:00>, <Review: Review of Stock_Bar_Restaurant by agconti on 2013-08-22 14:02:39.011105+00:00>, <Review: Review of Stock_Restaurant by agconti on 2013-08-22 14:02:58.612601+00:00>]

In [ ]:
#^will give reviews and resturants choiceset #addd categories with @

In [2]:
import random

In [3]:
category_choices = [
					('asian', 'Asian'),
					('american', 'American'),
					('bar_food', 'Bar Food'),
					('seafood', 'Seafood'),
					('sandwiches', 'Sandwiches'),
					('french', 'French'),
					('comfortfood', 'Comfort Food'),
					('suhi', 'Sushi Bar'),
					('unknown_cat', 'To cool to be defined')	
				]

In [4]:
category_choices


Out[4]:
[('asian', 'Asian'),
 ('american', 'American'),
 ('bar_food', 'Bar Food'),
 ('seafood', 'Seafood'),
 ('sandwiches', 'Sandwiches'),
 ('french', 'French'),
 ('comfortfood', 'Comfort Food'),
 ('suhi', 'Sushi Bar'),
 ('unknown_cat', 'To cool to be defined')]

In [5]:
category = random.choice(category_choices)
top_5 = Restaurant.objects.filter(category=category[0]).order_by('rating')[:5]
print category


('bar_food', 'Bar Food')

In [4]:


In [5]:



Out[5]:
1

In [17]:


In [18]:
_._rating


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-e40c17eb3611> in <module>()
----> 1 _._rating

AttributeError: 'float' object has no attribute '_rating'

In [ ]:
## forgot asian resturants!!!

In [ ]:
r = top_5[0]

In [ ]:
str(r.category)

Calculated Model Tests:


In [ ]:
u = User.objects.get(pk=1)

In [ ]:
u_r = Review.objects.filter(user=u).aggregate(Avg('rating'))

In [ ]:
from django.db.models import Avg
u_r

In [ ]:
u_r

In [ ]:
Review.objects.filter(user=u)

In [ ]:
r = Restaurant.objects.get(pk=1)

In [ ]:
Review.objects.filter(restaurant=r).aggregate(Avg('rating'))['rating__avg']

Get Histogram


In [ ]:
Review.objects.filter(user=u).values_list('rating', flat=True).order_by('_rating')

In [ ]:
hist = np.histogram(a, normed=1)

In [ ]:
hist

In [ ]:
plt.scatter(hist[0], hist[1])

In [ ]:
plt.scatter(a, arange(len(a)))

In [ ]: