# Path: data_model.py
# class StopStat(db.Model):
#     dateAdded   = db.DateTimeProperty(auto_now_add=True)
#     stopID      = db.StringProperty()
#     apiKey      = db.StringProperty()


import logging
import urllib
import urllib2
import webapp2 as webapp
import config
from google.appengine.api import urlfetch
from google.appengine.api.labs.taskqueue import Task
from google.appengine.api import memcache
from data_model import StopStat

  def post(self):
    stat_key = self.request.get('stat_key')
    value = self.request.get('value')

    stathat = StatHat()
    stathat.post_value(config.STATHAT_USER_KEY,stat_key,value,callback=noop)

## end StatValueTaskHandler

class StatFlushHandler(webapp.RequestHandler):

    def get(self):
        stathat = StatHat()

        errors = memcache.get(STATHAT_MEMCACHE_ERROR_COUNT)
        if errors is not None:
            stathat.post_count(config.STATHAT_USER_KEY,config.STATHAT_API_ERROR_STAT_KEY,errors,callback=noop)
            memcache.decr(STATHAT_MEMCACHE_ERROR_COUNT, errors)

        req_count = memcache.get(STATHAT_MEMCACHE_REQ_COUNT)
        if req_count is not None:
            stathat.post_count(config.STATHAT_USER_KEY,config.STATHAT_API_COUNT_STAT_KEY,req_count,callback=noop)
            memcache.decr(STATHAT_MEMCACHE_REQ_COUNT, req_count)

## end StatFlushHandler

class StatStopsCollectHandler(webapp.RequestHandler):

    def post(self):

# Path: data_model.py
# class StopStat(db.Model):
#     dateAdded   = db.DateTimeProperty(auto_now_add=True)
#     stopID      = db.StringProperty()
#     apiKey      = db.StringProperty()


# Path: stats_and_maps/stats/stathat.py
import logging
import urllib
import urllib2
import webapp2 as webapp
import config
from google.appengine.api import urlfetch
from google.appengine.api.labs.taskqueue import Task
from google.appengine.api import memcache
from data_model import StopStat


  def post(self):
    stat_key = self.request.get('stat_key')
    value = self.request.get('value')

    stathat = StatHat()
    stathat.post_value(config.STATHAT_USER_KEY,stat_key,value,callback=noop)

## end StatValueTaskHandler

class StatFlushHandler(webapp.RequestHandler):

    def get(self):
        stathat = StatHat()

        errors = memcache.get(STATHAT_MEMCACHE_ERROR_COUNT)
        if errors is not None:
            stathat.post_count(config.STATHAT_USER_KEY,config.STATHAT_API_ERROR_STAT_KEY,errors,callback=noop)
            memcache.decr(STATHAT_MEMCACHE_ERROR_COUNT, errors)

        req_count = memcache.get(STATHAT_MEMCACHE_REQ_COUNT)
        if req_count is not None:
            stathat.post_count(config.STATHAT_USER_KEY,config.STATHAT_API_COUNT_STAT_KEY,req_count,callback=noop)
            memcache.decr(STATHAT_MEMCACHE_REQ_COUNT, req_count)

## end StatFlushHandler

class StatStopsCollectHandler(webapp.RequestHandler):

    def post(self):

        stat = StopStat()