# Path: sitegeist/mongo.py
# def connect(db="sitegeist"):
# def create_indexes():


import datetime
import logging
from django.conf import settings
from sitegeist.mongo import db



logger = logging.getLogger(__name__)


class CoordinateCache(object):

    def __init__(self, namespace, snap_radius=None):
        self.namespace = namespace
        self.snap_radius = snap_radius or settings.SITEGEIST['GEO_SNAP_RADIUS']

    def get(self, latlon):

        if not settings.SITEGEIST.get('COORDCACHE', False):
            return

        latlon = [float(p) for p in latlon]

        spec = {
            "namespace": self.namespace,
            "geo": {
                "$maxDistance": self.snap_radius,
                "$near": latlon
            }
        }


# Path: sitegeist/mongo.py
# def connect(db="sitegeist"):
# def create_indexes():


# Path: sitegeist/cache.py
import datetime
import logging
from django.conf import settings
from sitegeist.mongo import db




logger = logging.getLogger(__name__)


class CoordinateCache(object):

    def __init__(self, namespace, snap_radius=None):
        self.namespace = namespace
        self.snap_radius = snap_radius or settings.SITEGEIST['GEO_SNAP_RADIUS']

    def get(self, latlon):

        if not settings.SITEGEIST.get('COORDCACHE', False):
            return

        latlon = [float(p) for p in latlon]

        spec = {
            "namespace": self.namespace,
            "geo": {
                "$maxDistance": self.snap_radius,
                "$near": latlon
            }
        }


        doc = db.coordcache.find_one(spec)