From 7586a38438925f89b2979e724e73d4fabeb76111 Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Mon, 25 Feb 2019 22:55:06 -0700 Subject: generated some mock data to test with --- mock_data/scripts/gen_geojson.py | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 mock_data/scripts/gen_geojson.py (limited to 'mock_data/scripts/gen_geojson.py') 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') -- cgit v1.2.3