OpenEnergyPlatform / omi

Repository for the Open Metadata Integration (OMI). For metadata definition see metadata repo:
https://github.com/OpenEnergyPlatform/metadata
GNU Affero General Public License v3.0
7 stars 4 forks source link

The structure.py seems not to be compatible with previous OEM versions #47

Closed jh-RLI closed 2 years ago

jh-RLI commented 2 years ago

When updating the structure.py with the latest metadata version (oem v1.5.0 and v1.5.1) I noticed that older versions are no longer supported when the structure is changed. For example in OEM v 1.5.0 the key temporal has been changed. Here the subkey timeseries is now a separate object.

Old until oem v1.4:

 class Temporal(Compilable):
      __compiler_name__ = "temporal"

      def __init__(
          self,
          reference_date: datetime = None,
          start: datetime = None,
          end: datetime = None,
          resolution: str = None,
          ts_orientation: TimestampOrientation = None,
          aggregation: str = None,
      ):  # TODO: This should not be a string... maybe
          # we should use datetime instead?
          self.reference_date = reference_date
          self.ts_start = start
          self.ts_end = end
          self.ts_resolution = resolution
          self.ts_orientation = ts_orientation
          self.aggregation = aggregation

New in oem v1.5:

class Timeseries(Compilable):
    __compiler_name__ = "timeseries"

    def __init__(self, 
        start: datetime = None,
        end: datetime = None,
        resolution: str = None,
        ts_orientation: TimestampOrientation = None,
        aggregation: str = None):
        self.ts_start = start
        self.ts_end = end
        self.ts_resolution = resolution
        self.ts_orientation = ts_orientation
        self.aggregation = aggregation

class Temporal(Compilable):
    __compiler_name__ = "temporal"

    def __init__(
        self,
        reference_date: datetime = None,
        timeseries_collection: Iterable[Timeseries] = None
        # start: datetime = None,
        # end: datetime = None,
        # resolution: str = None,
        # ts_orientation: TimestampOrientation = None,
        # aggregation: str = None,
    ):  # TODO: This should not be a string... maybe
        # we should use datetime instead?
        self.reference_date = reference_date
        self.timeseries_collection = timeseries_collection
        # self.ts_start = start
        # self.ts_end = end
        # self.ts_resolution = resolution
        # self.ts_orientation = ts_orientation
        # self.aggregation = aggregation

Is there a way to keep the structure.py downward compatible without keeping a class for obsolete structure. Or would one structure.py have to be created for each OEM version.

@MGlauer as you implemented this could you help me out with this? Let me know if you understand my issue description.

MGlauer commented 2 years ago

I agree, that there are two ways forward here:

  1. Keep the internal representation (structure.py) and create a second that reflects the newer version and implement translations between those representations.
  2. Update structure.py, but update parsers and compilers to translate older versions into the newer structure.

I think I would prefer the first one, given our use-cases. The intention of OMI is that users can use the present python structures in their code to define metadata objects. If these structures change, it may break the code of these users. But I do not have any definite opinions on this.

jh-RLI commented 2 years ago

@MGlauer I have started to implement this towards the approach described in 1. In the process more questions came up: (have not yet pushed anything)

[1] image

[2] old

class JSONCompiler(Compiler):
    __METADATA_VERSION = "OEP-1.4.0"
.....

new

class JSONCompilerOEMv1_4_0(Compiler):
    __METADATA_VERSION = "OEP-1.4.0"
    ....

class JSONCompilerOEMv1_4_1(Compiler):
    __METADATA_VERSION = "OEP-1.4.1"
    .....

class JSONCompilerOEMv1_5_0(Compiler):
    __METADATA_VERSION = "OEP-1.5.0"
    .....

class JSONCompilerOEMv1_5_1(Compiler):
    __METADATA_VERSION = "OEP-1.5.1"
   .....