diff --git a/bin/datastore.py b/bin/datastore.py index 3d0efb8..df4e9dc 100644 --- a/bin/datastore.py +++ b/bin/datastore.py @@ -406,12 +406,12 @@ class Datastore: self.del_hash("*online*", cursor) qry = """ - INSERT INTO raw_lines (sequence, line, remarks, ntbp, incr) - VALUES (%s, %s, '', %s, %s) + INSERT INTO raw_lines (sequence, line, remarks, ntbp, incr, meta) + VALUES (%s, %s, '', %s, %s, %s) ON CONFLICT DO NOTHING; """ - cursor.execute(qry, (fileinfo["sequence"], fileinfo["line"], ntbp, incr)) + cursor.execute(qry, (fileinfo["sequence"], fileinfo["line"], ntbp, incr, json.dumps(fileinfo["meta"]))) qry = """ INSERT INTO raw_lines_files (sequence, hash) @@ -448,12 +448,12 @@ class Datastore: hash = self.add_file(filepath, cursor) qry = """ - INSERT INTO final_lines (sequence, line, remarks) - VALUES (%s, %s, '') + INSERT INTO final_lines (sequence, line, remarks, meta) + VALUES (%s, %s, '', %s) ON CONFLICT DO NOTHING; """ - cursor.execute(qry, (fileinfo["sequence"], fileinfo["line"])) + cursor.execute(qry, (fileinfo["sequence"], fileinfo["line"], json.dumps(fileinfo["meta"]))) qry = """ INSERT INTO final_lines_files (sequence, hash) diff --git a/bin/import_final_p111.py b/bin/import_final_p111.py index 9a45524..b6bf0cf 100755 --- a/bin/import_final_p111.py +++ b/bin/import_final_p111.py @@ -103,6 +103,7 @@ if __name__ == '__main__': continue file_info = dict(zip(pattern["captures"], match.groups())) + file_info["meta"] = {} if pending: print("Skipping / removing final file because marked as PENDING", filepath) @@ -117,6 +118,7 @@ if __name__ == '__main__': print("Saving") p111_records = p111.p111_type("S", p111_data) + file_info["meta"]["lineName"] = p111.line_name(p111_data) db.save_final_p111(p111_records, file_info, filepath, survey["epsg"]) else: diff --git a/bin/import_raw_p111.py b/bin/import_raw_p111.py index 8f15c1a..71991b8 100755 --- a/bin/import_raw_p111.py +++ b/bin/import_raw_p111.py @@ -75,12 +75,14 @@ if __name__ == '__main__': continue file_info = dict(zip(pattern["captures"], match.groups())) + file_info["meta"] = {} p111_data = p111.from_file(filepath) print("Saving") p111_records = p111.p111_type("S", p111_data) + file_info["meta"]["lineName"] = p111.line_name(p111_data) db.save_raw_p111(p111_records, file_info, filepath, survey["epsg"], ntbp=ntbp) else: diff --git a/bin/p111.py b/bin/p111.py index d599f4b..cc36575 100644 --- a/bin/p111.py +++ b/bin/p111.py @@ -153,6 +153,9 @@ def parse_line (string): return None +def line_name(records): + return set([ r['Acquisition Line Name'] for r in p111_type("S", records) ]).pop() + def p111_type(type, records): return [ r for r in records if r["type"] == type ]