38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
import json
|
||
|
import sqlite3
|
||
|
|
||
|
def db_to_js(db_name: str):
|
||
|
conn = sqlite3.connect(db_name)
|
||
|
c = conn.cursor()
|
||
|
c.execute("SELECT wayid, name, length, start_ele, end_ele, slope_correct, slope_confidence, centroid_lat, centroid_lon FROM rivers")
|
||
|
|
||
|
rows = c.fetchall()
|
||
|
ret = []
|
||
|
for river in rows:
|
||
|
sc = river[5]
|
||
|
if sc == 1:
|
||
|
#print(f"OK: {river}")
|
||
|
continue
|
||
|
r = {
|
||
|
'wayid': river[0],
|
||
|
'name': river[1],
|
||
|
'length': river[2],
|
||
|
'start_ele': river[3],
|
||
|
'end_ele': river[4],
|
||
|
'slope_correct': river[5],
|
||
|
'slope_confidence': river[6],
|
||
|
'centroid_lat': river[7],
|
||
|
'centroid_lon': river[8]
|
||
|
}
|
||
|
if r['slope_confidence'] > 0.4:
|
||
|
print(f"KO: {r}")
|
||
|
if r['start_ele'] + 20 < r['end_ele']:
|
||
|
print(f"KO: {r}")
|
||
|
ret.append(r)
|
||
|
return ret
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
rivers = db_to_js('db.sqlite')
|
||
|
with open('public/rivers.json', 'w') as f:
|
||
|
f.write(json.dumps(rivers, indent=1))
|