view globalneighbors/locations.py @ 25:991bce6b6881 default tip

[knn] placeholder for planning session
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Sep 2017 14:35:50 -0700
parents 5dba84370182
children
line wrap: on
line source

"""
location data transformations
"""

from .schema import primary_key
from .schema import name
from collections import OrderedDict


def locations(rows, key=primary_key):
    """
    filter out just the location
    returns a data structure like
    {key: (lat, lon)
    ...}
    """

    return {row[key]: (row['latitude'], row['longitude'])
            for row in rows}


def city_dict(rows, name=name):
    """return an ordered dict of cities"""

    return OrderedDict([(row[name], row)
                        for row in rows])