# Path: data_model.py
# class StopLocation(GeoModel):
# class StopLocationLoader(db.Model):
# class RouteListing(db.Model):
# class RouteListingLoader(db.Model):
# class DestinationListing(db.Model):
# class DeveloperKeys(db.Model):
# class DeveloperRequest(db.Model):
# class ParseErrors(db.Model):
# class BusStopAggregation(db.Model):
# class StopStat(db.Model):
# 
# Path: data_model.py
# class StopLocation(GeoModel):
#     stopID       = db.StringProperty()
#     intersection = db.StringProperty()
#     direction    = db.StringProperty()
#     description  = db.StringProperty(multiline=True)
# 
# Path: data_model.py
# class RouteListing(db.Model):
#     route        = db.StringProperty()
#     routeCode    = db.StringProperty()
#     direction    = db.StringProperty()
#     stopID       = db.StringProperty()
#     stopCode     = db.StringProperty()
#     scheduleURL  = db.StringProperty(indexed=False)
#     stopLocation = db.ReferenceProperty(StopLocation,collection_name="stops")


import os
import wsgiref.handlers
import logging
from operator import itemgetter
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.db import GeoPt
from google.appengine.ext.webapp import template
from google.appengine.api.labs.taskqueue import Task
from google.appengine.runtime import apiproxy_errors
from data_model import PhoneLog
from data_model import StopLocation
from data_model import RouteListing
          if cursor:
              q.with_cursor(cursor)

          # Perform the query to get results.
          locationQuery = q.fetch(1000)
          cursor = q.cursor()
          if len(locationQuery) > 0:
            logging.debug('just read in another chunk of stop locations...')
            for l in locationQuery:
                location = l.location
                stopKey = l.stopID + ':loc'
                if l.stopID in validStops and stopKey not in stopLocs:
                    logging.debug('adding location %s for stopID %s' % (location,l.stopID))
                    stopLocs[stopKey] = location
          else:
              logging.debug('No more stop locations left in the query!')
              break
          
      memcache.set_multi(stopLocs)
      return
    
## end CollectorHandler

# @todo memcache this list
# @todo create a task that periodically refreshes this list
def getRequestedStops():
      # do some analysis on the request history...
      reqs = dict()
      cursor = None
      # Start a query for all Person entities.

# Path: data_model.py
# class StopLocation(GeoModel):
# class StopLocationLoader(db.Model):
# class RouteListing(db.Model):
# class RouteListingLoader(db.Model):
# class DestinationListing(db.Model):
# class DeveloperKeys(db.Model):
# class DeveloperRequest(db.Model):
# class ParseErrors(db.Model):
# class BusStopAggregation(db.Model):
# class StopStat(db.Model):
# 
# Path: data_model.py
# class StopLocation(GeoModel):
#     stopID       = db.StringProperty()
#     intersection = db.StringProperty()
#     direction    = db.StringProperty()
#     description  = db.StringProperty(multiline=True)
# 
# Path: data_model.py
# class RouteListing(db.Model):
#     route        = db.StringProperty()
#     routeCode    = db.StringProperty()
#     direction    = db.StringProperty()
#     stopID       = db.StringProperty()
#     stopCode     = db.StringProperty()
#     scheduleURL  = db.StringProperty(indexed=False)
#     stopLocation = db.ReferenceProperty(StopLocation,collection_name="stops")


# Path: labs/mapit.py
import os
import wsgiref.handlers
import logging
from operator import itemgetter
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.db import GeoPt
from google.appengine.ext.webapp import template
from google.appengine.api.labs.taskqueue import Task
from google.appengine.runtime import apiproxy_errors
from data_model import PhoneLog
from data_model import StopLocation
from data_model import RouteListing

          if cursor:
              q.with_cursor(cursor)

          # Perform the query to get results.
          locationQuery = q.fetch(1000)
          cursor = q.cursor()
          if len(locationQuery) > 0:
            logging.debug('just read in another chunk of stop locations...')
            for l in locationQuery:
                location = l.location
                stopKey = l.stopID + ':loc'
                if l.stopID in validStops and stopKey not in stopLocs:
                    logging.debug('adding location %s for stopID %s' % (location,l.stopID))
                    stopLocs[stopKey] = location
          else:
              logging.debug('No more stop locations left in the query!')
              break
          
      memcache.set_multi(stopLocs)
      return
    
## end CollectorHandler

# @todo memcache this list
# @todo create a task that periodically refreshes this list
def getRequestedStops():
      # do some analysis on the request history...
      reqs = dict()
      cursor = None
      # Start a query for all Person entities.

      q = PhoneLog.all()