aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKumar Damani <kumar.damani@mail.utoronto.ca>2019-02-26 05:55:06 +0000
committerKumar Damani <kumar.damani@mail.utoronto.ca>2019-02-26 05:55:06 +0000
commit7586a38438925f89b2979e724e73d4fabeb76111 (patch)
tree32977db762336f3ae0163ca51696f5fecf58df0c
parenta844d93b5dd799b202ef476fa151bea5bd125456 (diff)
generated some mock data to test withmockdata
-rw-r--r--mock_data/README.md14
-rw-r--r--mock_data/out/dumbdata.json1
-rw-r--r--mock_data/raw/dumb_coordinates.csv21
-rw-r--r--mock_data/scripts/gen_geojson.py61
4 files changed, 97 insertions, 0 deletions
diff --git a/mock_data/README.md b/mock_data/README.md
new file mode 100644
index 0000000..edd5445
--- /dev/null
+++ b/mock_data/README.md
@@ -0,0 +1,14 @@
+# This file contains information about how we populated the database with existing points for development and testing purposes.
+
+CSV file generated using https://www.mapdevelopers.com/geocode_tool.php and manually clicking various parts of the city to give us coordinates of those points.
+
+Then the python script `gen_geojson.py` created json objects and pushed it up to the database to populate the `dumbpointscollection`.
+
+Then the scripts also reads this from the database and dumps into a .json file. Cuz why not?
+
+> DO NOT RUN THIS FILE ON ACTUAL DATABASE WITHOUT CREATING A BACKUP FIRST. You can change the db used by un/commenting out the line where the uri is passed into the `MongoClient` on line 6 and 7.
+
+# Requirements to run the python script
+
+1. pymongo
+2. dnspython
diff --git a/mock_data/out/dumbdata.json b/mock_data/out/dumbdata.json
new file mode 100644
index 0000000..01ac9ba
--- /dev/null
+++ b/mock_data/out/dumbdata.json
@@ -0,0 +1 @@
+[{"_id": {"$oid": "5c723c241bc4ab6d80ee05be"}, "type": "Point", "coordinates": [-79.3787224, 43.7179786], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05bf"}, "type": "Point", "coordinates": [-79.3871596, 43.7213548], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c0"}, "type": "Point", "coordinates": [-79.3837533, 43.712758], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c1"}, "type": "Point", "coordinates": [-79.4209714, 43.7037593], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c2"}, "type": "Point", "coordinates": [-79.4505764, 43.6909183], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c3"}, "type": "Point", "coordinates": [-79.4286938, 43.6776278], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c4"}, "type": "Point", "coordinates": [-79.4258082, 43.6628024], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c5"}, "type": "Point", "coordinates": [-79.4166619, 43.6546241], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c6"}, "type": "Point", "coordinates": [-79.391236, 43.647069], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c7"}, "type": "Point", "coordinates": [-79.389838, 43.647169], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c8"}, "type": "Point", "coordinates": [-79.390199, 43.647322], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05c9"}, "type": "Point", "coordinates": [-79.3815339, 43.6486639], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05ca"}, "type": "Point", "coordinates": [-79.3815339, 43.6486639], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05cb"}, "type": "Point", "coordinates": [-79.3815339, 43.6486639], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05cc"}, "type": "Point", "coordinates": [-79.376619, 43.650907], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05cd"}, "type": "Point", "coordinates": [-79.381407, 43.659324], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05ce"}, "type": "Point", "coordinates": [-79.3808212, 43.6614691], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05cf"}, "type": "Point", "coordinates": [-79.38024, 43.663758], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05d0"}, "type": "Point", "coordinates": [-79.4103483, 43.6426436], "another": "random field"}, {"_id": {"$oid": "5c723c241bc4ab6d80ee05d1"}, "type": "Point", "coordinates": [-79.416122, 43.650337], "another": "random field"}] \ No newline at end of file
diff --git a/mock_data/raw/dumb_coordinates.csv b/mock_data/raw/dumb_coordinates.csv
new file mode 100644
index 0000000..4bfad6b
--- /dev/null
+++ b/mock_data/raw/dumb_coordinates.csv
@@ -0,0 +1,21 @@
+lat,lon
+43.7179786, -79.3787224
+43.7213548, -79.3871596
+43.712758, -79.3837533
+43.7037593, -79.4209714
+43.6909183, -79.4505764
+43.6776278, -79.4286938
+43.6628024, -79.4258082
+43.6546241, -79.4166619
+43.647069, -79.391236
+43.647169, -79.389838
+43.647322, -79.390199
+43.6486639, -79.3815339
+43.6486639, -79.3815339
+43.6486639, -79.3815339
+43.650907, -79.376619
+43.659324, -79.381407
+43.6614691, -79.3808212
+43.663758, -79.38024
+43.6426436, -79.4103483
+43.650337, -79.416122
diff --git a/mock_data/scripts/gen_geojson.py b/mock_data/scripts/gen_geojson.py
new file mode 100644
index 0000000..33c5c98
--- /dev/null
+++ b/mock_data/scripts/gen_geojson.py
@@ -0,0 +1,61 @@
+from pymongo import MongoClient
+from bson.json_util import dumps
+import json
+import csv
+
+client = MongoClient('mongodb://localhost:27017/helpthehome')
+#client = MongoClient('mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true')
+db = client.helpthehome
+
+def read_coords_csv():
+ points = []
+ with open("../raw/dumb_coordinates.csv") as csvfile:
+ reader = csv.reader(csvfile, delimiter=",")
+ line_number = 0
+ for row in reader:
+ if line_number == 0:
+ line_number += 1
+ continue
+
+ # build in accordance with geojson www.geojson.org
+ points.append({
+ "type": "Point",
+ "coordinates" : [ float(row[1]), float(row[0]) ],
+ "another": "random field"
+ })
+ line_number += 1
+ return points
+
+# into db
+def insert_data(points):
+ print("WRITING to DB...")
+ for point in points:
+ result = db.dumbpointscollection.insert_one(point)
+
+# from the db - not necessary
+def find_data():
+ print("READING from DB...")
+ points = db.dumbpointscollection.find({})
+ return dumps(points)
+
+# not necessary
+def serialize(data, jfilepath):
+ jdata = find_data()
+ print("WRITING to FILE...")
+ with open("../out/dumbdata.json", "w+") as outfile:
+ outfile.write(jdata)
+
+# load serialized data - not necessary
+def read_data_json(jfilepath):
+ print("READING from FILE...")
+ with open(jfilepath, "r") as infile:
+ jdata = json.load(infile)
+ return jdata
+
+##### Execute functions here #####
+#points = read_coords_csv()
+#insert_data(points)
+jdata = find_data()
+serialize(jdata, '../out/dumbdata.json')
+
+#jdata = read_data_json('../out/dumbdata.json')