Commit 05d184c3 authored by Doriane's avatar Doriane 💬
Browse files

ploting the coordinates to look at them

parent 4f4631da
import json
import matplotlib.pyplot as plt
import sqlite3
from sqlite3 import Error
db_file = 'potelets.db'
# --- sqlite request ---
def create_connection(db_file):
""" create a database connection to a database that resides
in the memory
"""
conn = None;
try:
conn = sqlite3.connect(db_file)
conn.row_factory = sqlite3.Row
return conn
except Error as e:
print(e)
def get_potelets(conn):
""" return the last ??? potelet cases and format them for templating
"""
# sql = ''' SELECT * FROM potelets ORDER BY id DESC LIMIT 50'''
sql = ''' SELECT * FROM potelets ORDER BY id'''
# sql = ''' SELECT potelet_id FROM history WHERE type='INCIDENT_ASKED_REOPENING '''
cur = conn.cursor()
cur.execute(sql)
# convert from a list of sqlite3.Row objects to real dict objects
potelets = [dict(potelet) for potelet in cur.fetchall()]
# in the db most data are strings, we may want to loads them as python objects,
# or reformat the string, before inserting them in the jinja template.
for potelet in potelets:
# loads the dumped json
potelet["coordinates"] = json.loads(potelet["coordinates"])
return potelets
# def gen_geojson(potelets):
# --- Main ---
if __name__ == '__main__':
print('___ Ploting potelets coordinates ___')
print('1. Establishing db connection')
conn = create_connection(db_file)
print('2. Making the sqlite request')
potelets = get_potelets(conn)
x = []
y = []
colors = []
for potelet in potelets:
x.append(potelet["coordinates"]["x"])
y.append(potelet["coordinates"]["y"])
if(potelet["subcat"]=="missing"):
colors.append('tab:blue')
elif(potelet["subcat"]=="damaged"):
colors.append('tab:green')
else:
colors.append('tab:red')
# feed two list for ploting: one with all the x and another with all the y
# plt.scatter(x, y, s=area, c=colors, alpha=0.5)
fig, ax = plt.subplots()
ax.set_aspect('equal')
plt.scatter(x, y, s=2, c=colors)
plt.grid(True)
plt.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment