diff globalneighbors/locations.py @ 0:5dba84370182

initial commit; half-working prototype
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Jun 2017 12:03:39 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/globalneighbors/locations.py	Sat Jun 24 12:03:39 2017 -0700
@@ -0,0 +1,27 @@
+"""
+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])
+