From f51d6ced71db086160521879eb4214728c12e1d3 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Thu, 11 Jan 2024 14:48:08 +0000 Subject: [PATCH] Add hostname and microscope ID to metadata It's often helpful to tell if images came from the same microscope - this metadata should answer that question. --- .../things/settings_manager.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/openflexure_microscope_server/things/settings_manager.py b/src/openflexure_microscope_server/things/settings_manager.py index 1769b3e4..d69ece9d 100644 --- a/src/openflexure_microscope_server/things/settings_manager.py +++ b/src/openflexure_microscope_server/things/settings_manager.py @@ -6,7 +6,9 @@ for code that currently lives in clients but needs to persist settings on the server. """ from collections.abc import Mapping +from socket import gethostname from typing import Any, MutableMapping, Optional, Sequence +from uuid import UUID, uuid4 from fastapi import HTTPException from labthings_fastapi.dependencies.metadata import GetThingStates from labthings_fastapi.thing import Thing @@ -84,6 +86,13 @@ class SettingsManager(Thing): ) self.thing_settings["external_metadata"] = metadata + @thing_property + def microscope_id(self) -> UUID: + """A unique identifier for this microscope""" + if "microscope_id" not in self.thing_settings: + self.thing_settings["microscope_id"] = uuid4() + return self.thing_settings["microscope_id"] + @thing_action def get_things_state(self, metadata_getter: GetThingStates) -> Mapping: """Metadata summarising the current state of all Things in the server""" @@ -100,7 +109,10 @@ class SettingsManager(Thing): @property def thing_state(self) -> Mapping: - state = {} + state = { + "hostname": gethostname(), + "microscope-uuid": self.microscope_id, + } metadata = self.external_metadata for k in self.external_metadata_in_state: try: