mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:47:08 +00:00
Add DB functions to save raw and final data from P1/11
This commit is contained in:
@@ -3,6 +3,7 @@ import json
|
||||
import psycopg2
|
||||
import configuration
|
||||
import preplots
|
||||
import p111
|
||||
|
||||
"""
|
||||
Interface to the PostgreSQL database.
|
||||
@@ -334,6 +335,88 @@ class Datastore:
|
||||
|
||||
self.maybe_commit()
|
||||
|
||||
def save_raw_p111 (self, records, fileinfo, filepath, epsg = 0, filedata = None):
|
||||
|
||||
with self.conn.cursor() as cursor:
|
||||
hash = self.add_file(filepath, cursor)
|
||||
incr = p111.point_number(records[0]) <= p111.point_number(records[-1])
|
||||
|
||||
qry = """
|
||||
INSERT INTO raw_lines (sequence, line, remarks, ntbp, incr)
|
||||
VALUES (%s, %s, '', %s, %s)
|
||||
ON CONFLICT DO NOTHING;
|
||||
"""
|
||||
|
||||
cursor.execute(qry, (fileinfo["sequence"], fileinfo["line"], False, incr))
|
||||
|
||||
qry = """
|
||||
INSERT INTO raw_lines_files (sequence, hash)
|
||||
VALUES (%s, %s)
|
||||
ON CONFLICT DO NOTHING;
|
||||
"""
|
||||
|
||||
cursor.execute(qry, (fileinfo["sequence"], hash))
|
||||
|
||||
|
||||
shots = [ (fileinfo["sequence"], p111.line(r), p111.point_number(r), r["Object Ref. Number"], r["tstamp"], hash, p111.easting(r), p111.northing(r), epsg) for r in records ]
|
||||
|
||||
qry = """
|
||||
INSERT INTO raw_shots (sequence, line, point, objref, tstamp, hash, geometry)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, ST_SetSRID(ST_MakePoint(%s, %s), %s))
|
||||
ON CONFLICT (sequence, point) DO UPDATE
|
||||
SET
|
||||
objref = EXCLUDED.objref, tstamp = EXCLUDED.tstamp,
|
||||
hash = EXCLUDED.hash, geometry = EXCLUDED.geometry;
|
||||
"""
|
||||
|
||||
cursor.executemany(qry, shots)
|
||||
|
||||
if filedata is not None:
|
||||
self.save_file_data(filepath, json.dumps(filedata), cursor)
|
||||
|
||||
self.maybe_commit()
|
||||
|
||||
def save_final_p111 (self, records, fileinfo, filepath, epsg = 0, filedata = None):
|
||||
|
||||
with self.conn.cursor() as cursor:
|
||||
hash = self.add_file(filepath, cursor)
|
||||
|
||||
qry = """
|
||||
INSERT INTO final_lines (sequence, line, remarks)
|
||||
VALUES (%s, %s, '')
|
||||
ON CONFLICT DO NOTHING;
|
||||
"""
|
||||
|
||||
cursor.execute(qry, (fileinfo["sequence"], fileinfo["line"]))
|
||||
|
||||
qry = """
|
||||
INSERT INTO final_lines_files (sequence, hash)
|
||||
VALUES (%s, %s)
|
||||
ON CONFLICT DO NOTHING;
|
||||
"""
|
||||
|
||||
cursor.execute(qry, (fileinfo["sequence"], hash))
|
||||
|
||||
|
||||
shots = [ (fileinfo["sequence"], p111.line(r), p111.point_number(r), r["Object Ref. Number"], r["tstamp"], hash, p111.easting(r), p111.northing(r), epsg) for r in records ]
|
||||
|
||||
qry = """
|
||||
INSERT INTO final_shots (sequence, line, point, objref, tstamp, hash, geometry)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, ST_SetSRID(ST_MakePoint(%s, %s), %s))
|
||||
ON CONFLICT (sequence, point) DO UPDATE
|
||||
SET
|
||||
objref = EXCLUDED.objref, tstamp = EXCLUDED.tstamp,
|
||||
hash = EXCLUDED.hash, geometry = EXCLUDED.geometry;
|
||||
"""
|
||||
|
||||
cursor.executemany(qry, shots)
|
||||
|
||||
if filedata is not None:
|
||||
self.save_file_data(filepath, json.dumps(filedata), cursor)
|
||||
|
||||
self.maybe_commit()
|
||||
|
||||
|
||||
def save_file_data(self, path, filedata, cursor = None):
|
||||
"""
|
||||
Save arbitrary data associated with a file.
|
||||
|
||||
Reference in New Issue
Block a user