Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metadata records format #1269

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/panoptes/pocs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def should_retry(self):
def status(self) -> dict:
try:
status = {
'from_state': self.state,
'to_state': self.next_state,
'state': self.state,
'next_state': self.next_state,
'system': {
'free_space': str(self._free_space),
},
Expand Down
25 changes: 13 additions & 12 deletions src/panoptes/pocs/utils/cli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
event_handler = FileSystemEventHandler()
firestore_db = firestore.Client()
# Get the unit reference to link metadata to unit.
unit_metadata_ref = firestore_db.collection(f'units/{unit_id}/metadata')
unit_metadata_ref = firestore_db.document(f'units/{unit_id}/metadata')
metadata_records_ref = unit_metadata_ref.collection('records')

Check warning on line 103 in src/panoptes/pocs/utils/cli/network.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/network.py#L102-L103

Added lines #L102 - L103 were not covered by tests

def handleEvent(event):
if event.is_directory:
Expand All @@ -112,23 +113,22 @@

try:
record = json.loads(Path(event.src_path).read_text())
collection = record['type']

# Get the "current" record and collections refs.
metadata_record = unit_metadata_ref.document(collection)
records_ref = metadata_record.collection('records')

# Unpack the envelope.
collection = record['type']

Check warning on line 118 in src/panoptes/pocs/utils/cli/network.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/network.py#L118

Added line #L118 was not covered by tests
data = record['data']
data['date'] = record['date']
data['received_time'] = firestore.SERVER_TIMESTAMP

if verbose:
print(f'Adding {data=}')
print(f'Adding data for {collection=}: {data}')

Check warning on line 124 in src/panoptes/pocs/utils/cli/network.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/network.py#L124

Added line #L124 was not covered by tests

# Update the main "current" record for the unit.
unit_metadata_ref.set({collection: data}, merge=True)

Check warning on line 127 in src/panoptes/pocs/utils/cli/network.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/network.py#L127

Added line #L127 was not covered by tests

# Update the "current" record.
metadata_record.set(data)
# Add a new record.
doc_ts, doc_id = records_ref.add(data)
# Add the record, storing the collection name in the data.
data['collection'] = collection
doc_ts, doc_id = metadata_records_ref.add(data)

Check warning on line 131 in src/panoptes/pocs/utils/cli/network.py

View check run for this annotation

Codecov / codecov/patch

src/panoptes/pocs/utils/cli/network.py#L130-L131

Added lines #L130 - L131 were not covered by tests
if verbose:
print(f'Added data to firestore with {doc_id.id=} at {doc_ts}')
except Exception as e:
Expand All @@ -152,7 +152,8 @@
def upload_image_cmd(file_path: Path, bucket_path: str,
bucket_name: str = 'panoptes-images-incoming',
timeout: float = 180.,
storage_client=None) -> str:
storage_client=None
) -> str:
"""Uploads an image to google storage bucket."""
public_url = upload_image(
file_path, bucket_path,
Expand Down
Loading