# 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
            # try to figure out if we have a stoplocation for each id
            stop = db.GqlQuery("SELECT * FROM StopLocation where stopID = :1", key).get()
            if stop is None:
                stops_stats.append({'stopID':key,
                                    'count':value,
                                  })
        template_values = {'stops':stops_stats,
                           }
        
        # create a page that provides a form for sending an SMS message
        path = os.path.join(os.path.dirname(__file__), 'stops.html')
        self.response.out.write(template.render(path,template_values))
                
## end DisplayStops

class FixStopForm(webapp.RequestHandler):
    def get(self):
        template_values = {'stopID':self.request.get('stopID')}
        # create a page that provides a form for sending an SMS message
        path = os.path.join(os.path.dirname(__file__), 'fixstop.html')
        self.response.out.write(template.render(path,template_values))
        
## end FixStop

class FixStop(webapp.RequestHandler):
    def post(self):
        stopID = self.request.get('stopID')
        lat = self.request.get('lat')
        lon = self.request.get('lon')


# 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

            # try to figure out if we have a stoplocation for each id
            stop = db.GqlQuery("SELECT * FROM StopLocation where stopID = :1", key).get()
            if stop is None:
                stops_stats.append({'stopID':key,
                                    'count':value,
                                  })
        template_values = {'stops':stops_stats,
                           }
        
        # create a page that provides a form for sending an SMS message
        path = os.path.join(os.path.dirname(__file__), 'stops.html')
        self.response.out.write(template.render(path,template_values))
                
## end DisplayStops

class FixStopForm(webapp.RequestHandler):
    def get(self):
        template_values = {'stopID':self.request.get('stopID')}
        # create a page that provides a form for sending an SMS message
        path = os.path.join(os.path.dirname(__file__), 'fixstop.html')
        self.response.out.write(template.render(path,template_values))
        
## end FixStop

class FixStop(webapp.RequestHandler):
    def post(self):
        stopID = self.request.get('stopID')
        lat = self.request.get('lat')
        lon = self.request.get('lon')


        stop = StopLocation()