Skip to content

Commit

Permalink
Load old-entity into the dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
psd committed Apr 7, 2022
1 parent 2aebe6e commit be8acf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions digital_land/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ def dataset_create_cmd(self, input_paths, output_path, organisation_path):
for path in input_paths:
package.load_transformed(path)
package.load_entities()

old_entity_path = os.path.join(self.pipeline.path, "old-entity.csv")
if os.path.exists(old_entity_path):
package.load_old_entities(old_entity_path)

package.add_counts()

def dataset_dump_cmd(self, input_path, output_path):
Expand Down
12 changes: 12 additions & 0 deletions digital_land/package/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ def insert_entity(self, facts):
if row:
self.insert("entity", self.entity_fields, row)

def load_old_entities(self, path):
"""load the old-entity table"""

fields = self.specification.schema["old-entity"]["fields"]
logging.info(f"loading old-entity from {path}")
self.connect()
self.create_cursor()
for row in csv.DictReader(open(path, newline="")):
self.insert("old-entity", fields, row)
self.commit()
self.disconnect()

def load_entities(self):
"""load the entity table from the fact table"""
self.connect()
Expand Down

0 comments on commit be8acf8

Please sign in to comment.