Permalink
Browse files

shifting model, fleshing out cron tasks

  • Loading branch information...
1 parent b9f0926 commit ee4c205463c441e4f2b7719304cc198783cc3a0a @schuyler1d committed Sep 17, 2011
Showing with 70 additions and 21 deletions.
  1. +6 −0 main/foursquare.py
  2. +22 −18 main/models.py
  3. +42 −3 main/tasks.py
View
@@ -0,0 +1,6 @@
+
+def grid_target(point,sq_radius,q_radius=100):
+ """creates TargetVenueCategories across a grid to cover an
+ area deeply, one q_radius(m) circle at a time
+ """
+ pass
View
@@ -1,31 +1,35 @@
from django.db import models
+GENDER = {
+ 'male':-1,
+ 'female':1,
+ 'none':0,
+ -1:'male',
+ 1:'female',
+ 0:'none',
+}
+
# Create your models here.
class Rover(models.Model):
- foursq_id = models.CharField(max_length=24)
+ foursq_id = models.CharField(primary_key=True,max_length=24)
#probably too long
oauth_token = models.CharField(blank=True,null=True,max_length=96)
gender = models.SmallIntegerField(blank=True,null=True,default=None)
class Stereotype(models.Model):
title = models.CharField(max_length=64)
category = models.CharField(max_length=96)
- time = models.TimeField()
- timedelta = models.SmallIntegerField()
+ starttime = models.TimeField()
+ endtime = models.TimeField()
color = models.SmallIntegerField(blank=True,null=True)
weekend = models.BooleanField()
-class Venue(models.Model):
- venue_id = models.CharField(max_length=24)
- #if venue is a source for a stereotype
- # not necessarily exclusive
- sourced = models.ForeignKey(Stereotype)
- #e.g. 40.740088,-73.992577
- lat = models.FloatField()
- lon = models.FloatField()
+class VenueStereotype(models.Model):
+ venue = models.CharField(max_length=24)
+ stereotype = models.ForeignKey(Stereotype)
class VenuePing(models.Model):
- venue_id = models.CharField(max_length=24)
+ venue = models.CharField(max_length=24)
count = models.SmallIntegerField(blank=True,null=True,default=None)
gender_ratio = models.FloatField(blank=True,null=True,default=None)
@@ -35,8 +39,8 @@ class TargetVenueCategory(models.Model):
query = models.CharField(blank=True,null=True,max_length=96)
category = models.CharField(blank=True,null=True,max_length=96)
ll = models.CharField(blank=True,null=True,max_length=96)
- time = models.TimeField(blank=True,null=True)
- timedelta = models.SmallIntegerField(blank=True,null=True)
+ starttime = models.TimeField(blank=True,null=True)
+ endtime = models.TimeField(blank=True,null=True)
class Labeling(models.Model):
rover = models.ForeignKey(Rover)
@@ -45,18 +49,18 @@ class Labeling(models.Model):
class Checkin(models.Model):
time = models.TimeField(auto_now_add=True)
date = models.DateField(auto_now_add=True)
- venue = models.ForeignKey(Venue)
+ venue = models.CharField(max_length=24)
gender = models.SmallIntegerField(blank=True,null=True,default=None)
rover = models.ForeignKey(Rover)
lat = models.FloatField()
- lon = models.FloatField()
+ lng = models.FloatField()
class Rediscovered(models.Model):
rover = models.ForeignKey(Rover)
stereotype = models.ForeignKey(Stereotype)
lat = models.FloatField()
- lon = models.FloatField()
- venue = models.ForeignKey(Venue)
+ lng = models.FloatField()
+ venue = models.CharField(max_length=24)
time = models.TimeField(auto_now_add=True)
date = models.DateField(auto_now_add=True)
View
@@ -1,11 +1,50 @@
-from models import Venue
+from models import Venue,Stereotype,VenuePing
+import datetime
def find_venues(category):
'query trending venues in category'
#store in Venue
pass
-def hour_task():
+def hour_task_findstereotyped():
#for all stereotypes that fit this hour,
- # query venues
+ # query all venues for its category
+ # and create
+ # 1. venueping
+ # 2. labeling for each user
+ # 3. checkin for each user
+ now = datetime.datetime.now()
+ is_weekend = (now.weekday() > 4) #5,6=sat,sun
+ sters = Stereotype.objects.filter(weekend=is_weekend,
+ starttime__gte=datetime.time(now.hour),
+ endtime__lte=datetime.time(now.hour),
+ ).values('id')
+ vens = {}
+ for v in VenueStereotype.objects.filter(stereotype__in=sters):
+ vens.setdefault(v.venue,[]).append(v.stereotype_id)
+ #can optimize with multi query
+ for v,st in vens.items():
+ venue_data = foursq.venues(v).get('response',{}).get('venue',None)
+ herenow = venue_data['hereNow']
+ genders = {'male':0,'female':0,'none':0}
+ for rover in herenow['groups']['others']['items']:
+ genders[rover['user']['gender']] += 1
+ Checkin.objects.create(time,
+ date,
+ venue=v,
+ gender=GENDER[rover['user']['gender']],
+ lat=venue_data['location']['lat'],
+ lng=venue_data['location']['lng'],
+ )
+
+
+ VenuePing.objects.create(venue=v,count=herenow['count'])
+
+
+
+def hour_task_findtrendingvenues():
+ #for each source category
+ # query all trending venues and create
+ # 1. venue if not already existing
+ # .create_or_update(VenueStereotype)
pass

0 comments on commit ee4c205

Please sign in to comment.