Skip to content

Commit

Permalink
Add region and year to extra fields and remove additional attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
henhuy committed Oct 6, 2023
1 parent f28a453 commit e539037
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions data_adapter_oemof/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@ class Adapter:
extra_fields = (
Field(name="name", type=str),
Field(name="type", type=str),
Field(name="region", type=str),
Field(name="year", type=int),
)

def __init__(self, struct: dict, mapper: Mapper):
self.facade_dict = self.get_default_parameters(struct, mapper)

def get_default_parameters(self, struct: dict, mapper: Mapper) -> dict:
defaults = {
"type": self.type,
}
defaults = {"type": self.type}
# Add mapped attributes
mapped_values = mapper.get_default_mappings(struct)
defaults.update(mapped_values)
# Add additional attributes
attributes = {
"region": mapper.get("region"),
"year": mapper.get("year"),
}
defaults.update(attributes)

# add name if found in data, else use calculation for name:
if (name := mapper.get("name")) is not None:
Expand All @@ -53,6 +47,7 @@ class DispatchableAdapter(Adapter):
"""
Dispatchable Adapter
"""

type = "dispatchable"
facade = facades.Dispatchable

Expand All @@ -61,6 +56,7 @@ class HeatPumpAdapter(Adapter):
"""
HeatPump Adapter
"""

type = "heat_pump"
facade = facades.HeatPump

Expand All @@ -69,6 +65,7 @@ class LinkAdapter(Adapter):
"""
Link Adapter
"""

type = "link"
facade = facades.Link

Expand All @@ -77,6 +74,7 @@ class ReservoirAdapter(Adapter):
"""
Reservoir Adapter
"""

type = "reservoir"
facade = facades.Reservoir

Expand All @@ -85,6 +83,7 @@ class ExcessAdapter(Adapter):
"""
Excess Adapter
"""

type = "excess"
facade = facades.Excess

Expand All @@ -93,6 +92,7 @@ class BackpressureTurbineAdapter(Adapter):
"""
BackpressureTurbine Adapter
"""

type = "backpressure_turbine"
facade = facades.BackpressureTurbine

Expand All @@ -101,6 +101,7 @@ class CommodityAdapter(Adapter):
"""
CommodityAdapter
"""

type = "commodity"
facade = facades.Commodity

Expand All @@ -110,6 +111,7 @@ class ConversionAdapter(Adapter):
ConversionAdapter
To use Conversion, map the inputs and outputs within the structure to avoid deduction failure.
"""

type = "conversion"
facade = facades.Conversion

Expand All @@ -118,6 +120,7 @@ class LoadAdapter(Adapter):
"""
LoadAdapter
"""

type = "load"
facade = facades.Load

Expand All @@ -126,6 +129,7 @@ class StorageAdapter(Adapter):
"""
StorageAdapter
"""

type = "storage"
facade = facades.Storage

Expand All @@ -134,6 +138,7 @@ class ExtractionTurbineAdapter(Adapter):
"""
ExtractionTurbineAdapter
"""

type = "extraction_turbine"
facade = facades.ExtractionTurbine

Expand All @@ -142,11 +147,14 @@ class VolatileAdapter(Adapter):
"""
VolatileAdapter
"""

type = "volatile"
facade = facades.Volatile


# Create a dictionary of all adapter classes defined in this module
FACADE_ADAPTERS = {
adapter.type: adapter for name, adapter in globals().items() if name.endswith("Adapter")
adapter.type: adapter
for name, adapter in globals().items()
if name.endswith("Adapter")
}

0 comments on commit e539037

Please sign in to comment.