# Path: plenario/database.py
# def create_database(bind: Engine, database: str) -> None:
# def drop_database(bind: Engine, database: str) -> None:
# def create_extension(bind: Engine, extension: str) -> None:
# def psql(path: str) -> None:
# def postgres_session_context():
# def redshift_session_context():
# 
# Path: plenario/utils/helpers.py
# def get_size_in_degrees(meters, latitude):
#     earth_circumference = 40041000.0  # meters, average circumference
#     degrees_per_meter = 360.0 / earth_circumference
# 
#     degrees_at_equator = meters * degrees_per_meter
# 
#     latitude_correction = 1.0 / math.cos(latitude * (math.pi / 180.0))
# 
#     degrees_x = degrees_at_equator * latitude_correction
#     degrees_y = degrees_at_equator
# 
#     return degrees_x, degrees_y
# 
# def slugify(text: str, delimiter: str = '_') -> str:
#     return _slugify(text, separator=delimiter)


import json
import sqlalchemy as sa
from collections import namedtuple
from datetime import datetime
from hashlib import md5
from itertools import groupby
from operator import itemgetter
from flask_bcrypt import Bcrypt
from geoalchemy2 import Geometry
from shapely.geometry import shape
from sqlalchemy import Boolean, Column, Date, DateTime, String, Table, Text, func, select
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
from sqlalchemy.exc import ProgrammingError
from plenario.database import postgres_base, postgres_session
from plenario.utils.helpers import get_size_in_degrees, slugify
        # returns [lon, lat]
        return json.loads(result.first()[0])['coordinates']

    def update_date_added(self):
        now = datetime.now()
        if self.date_added is None:
            self.date_added = now
        self.last_update = now

    def make_grid(self, resolution, geom=None, conditions=None, obs_dates={}):
        """
        :param resolution: length of side of grid square in meters
        :type resolution: int
        :param geom: string representation of geojson fragment
        :type geom: str
        :param conditions: conditions on columns to filter on
        :type conditions: list of SQLAlchemy binary operations
                          (e.g. col > value)
        :return: grid: result proxy with all result rows
                 size_x, size_y: the horizontal and vertical size
                                    of the grid squares in degrees
        """
        if conditions is None:
            conditions = []

        # We need to convert resolution (given in meters) to degrees
        # - which is the unit of measure for EPSG 4326 -
        # - in order to generate our grid.
        center = self.get_bbox_center()
        # center[1] is longitude

# Path: plenario/database.py
# def create_database(bind: Engine, database: str) -> None:
# def drop_database(bind: Engine, database: str) -> None:
# def create_extension(bind: Engine, extension: str) -> None:
# def psql(path: str) -> None:
# def postgres_session_context():
# def redshift_session_context():
# 
# Path: plenario/utils/helpers.py
# def get_size_in_degrees(meters, latitude):
#     earth_circumference = 40041000.0  # meters, average circumference
#     degrees_per_meter = 360.0 / earth_circumference
# 
#     degrees_at_equator = meters * degrees_per_meter
# 
#     latitude_correction = 1.0 / math.cos(latitude * (math.pi / 180.0))
# 
#     degrees_x = degrees_at_equator * latitude_correction
#     degrees_y = degrees_at_equator
# 
#     return degrees_x, degrees_y
# 
# def slugify(text: str, delimiter: str = '_') -> str:
#     return _slugify(text, separator=delimiter)


# Path: plenario/models/MetaTable.py
import json
import sqlalchemy as sa
from collections import namedtuple
from datetime import datetime
from hashlib import md5
from itertools import groupby
from operator import itemgetter
from flask_bcrypt import Bcrypt
from geoalchemy2 import Geometry
from shapely.geometry import shape
from sqlalchemy import Boolean, Column, Date, DateTime, String, Table, Text, func, select
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
from sqlalchemy.exc import ProgrammingError
from plenario.database import postgres_base, postgres_session
from plenario.utils.helpers import get_size_in_degrees, slugify

        # returns [lon, lat]
        return json.loads(result.first()[0])['coordinates']

    def update_date_added(self):
        now = datetime.now()
        if self.date_added is None:
            self.date_added = now
        self.last_update = now

    def make_grid(self, resolution, geom=None, conditions=None, obs_dates={}):
        """
        :param resolution: length of side of grid square in meters
        :type resolution: int
        :param geom: string representation of geojson fragment
        :type geom: str
        :param conditions: conditions on columns to filter on
        :type conditions: list of SQLAlchemy binary operations
                          (e.g. col > value)
        :return: grid: result proxy with all result rows
                 size_x, size_y: the horizontal and vertical size
                                    of the grid squares in degrees
        """
        if conditions is None:
            conditions = []

        # We need to convert resolution (given in meters) to degrees
        # - which is the unit of measure for EPSG 4326 -
        # - in order to generate our grid.
        center = self.get_bbox_center()
        # center[1] is longitude

        size_x, size_y = get_size_in_degrees(resolution, center[1])