Skip to content

Commit

Permalink
Merge pull request #1044 from ie3-institute/ms/#981-abstract-commonly…
Browse files Browse the repository at this point in the history
…-used-functionality-from-EntitySource

Abstract commonly used functionality from `EntitySource`.
  • Loading branch information
sebastian-peter authored Jun 24, 2024
2 parents 227ce33 + 756f807 commit 8d312a1
Show file tree
Hide file tree
Showing 42 changed files with 1,481 additions and 1,689 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Improvements to the search for corner points in `IdCoordinateSource` [#1016](https://github.com/ie3-institute/PowerSystemDataModel/issues/1016)
- Refactor `CsvFileConnector` and `CsvDataSource` [#1007](https://github.com/ie3-institute/PowerSystemDataModel/issues/1007)

- Make `EntitySource` completely static [#975](https://github.com/ie3-institute/PowerSystemDataModel/issues/975)
- Abstract commonly used functionality from `EntitySource` [#981](https://github.com/ie3-institute/PowerSystemDataModel/issues/981)

## [5.0.1] - 2024-03-07

Expand Down
159 changes: 140 additions & 19 deletions docs/uml/main/EntitySourceClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,38 @@
note "Assuming all classes to implement \nthe abstract methods of their interfaces\n\n" as generalNotes

abstract class EntitySource {
# DataSource dataSource
# {static} <E extends EntityData, T extends UniqueEntity, R extends E> Try<R, SourceException> enrichEntityData(E, String, Map<UUID, T>, BiFunction<E, T, R>)
# {static} <E extends EntityData, T1 extends UniqueEntity, T2 extends UniqueEntity, R extends E> Try<R, SourceException> enrichEntityData(E, String, Map<UUID, T1>, String, Map<UUID, T2>, TriFunction<E, T1, T2, R>)
# {static} <T extends UniqueEntity> Try<T, SourceException> getLinkedEntity(EntityData, String, Map<UUID, T>)
# {static} <E extends EntityData, T extends UniqueEntity, R extends E> Try<R, SourceException> optionallyEnrichEntityData(E, String, Map<UUID, T>, T, BiFunction<E, T, R>)
# Stream<Try<NodeAssetInputEntityData, SourceException>> buildNodeAssetEntities(Class<T>, Map<UUID, OperatorInput>, Map<UUID, NodeInput>)
# {static} Stream<Try<NodeAssetInputEntityData, SourceException>> nodeAssetInputEntityDataStream(Stream<Try<AssetInputEntityData, SourceException>>, Map<UUID, NodeInput>)
# Stream<Try<AssetInputEntityData, SourceException>> buildAssetInputEntities(Class<? extends AssetInput>, Map<UUID, OperatorInput>)
# {static} Stream<Try<AssetInputEntityData, SourceException>> assetInputEntityDataStream(Stream<Try<EntityData, SourceException>>, Map<UUID, OperatorInput>)
# Stream<Try<EntityData, SourceException>> buildEntityData(Class<? extends UniqueEntity>)
# {static} <S extends UniqueEntity> Map<UUID, S> unpackMap(Stream<Try<S, FactoryException>>, Class<S>) throws SourceException
# {static} <S extends UniqueEntity> Set<S> unpackSet(Stream<Try<S, FactoryException>>, Class<S>) throws SourceException
# {static} <S, E extends Exception> Stream<S> unpackSet(Stream<Try<S, E>>, Class<S>) throws SourceException
+ void validate() throws ValidationException
}

EntitySource <|-- EnergyManagementSource
EntitySource <|-- GraphicSource
EntitySource <|-- IdCoordinateSource
IdCoordinateSource <|-- CsvIdCoordinateSource
IdCoordinateSource <|-- SqlIdCoordinateSource
EntitySource <|-- RawGridSource
EntitySource <|-- ResultEntitySource
EntitySource <|-- SystemParticipantSource
EntitySource <|-- ThermalSource
EntitySource <|-- TimeSeriesMappingSource
TimeSeriesMappingSource <|-- CsvTimeSeriesMappingSource
TimeSeriesMappingSource <|-- SqlTimeSeriesMappingSource
EntitySource <|-- TimeSeriesSource
TimeSeriesSource <|-- CsvTimeSeriesSource
TimeSeriesSource <|-- SqlTimeSeriesSource
EntitySource <|-- TypeSource
EntitySource <|-- WeatherSource
WeatherSource <|-- CouchbaseWeatherSource
WeatherSource <|-- CsvWeatherSource
WeatherSource <|-- InfluxDbWeatherSource
WeatherSource <|-- SqlWeatherSource

class EnergyManagementSource {
- TypeSource typeSource
- EmInputFactory emInputFactory
+ EnergyManagementSource(TypeSource, DataSource)
+ Map<UUID, EmInput> getEmUnits() throws SourceException
+ Map<UUID, EmInput> getEmUnits(Map<UUID, OperatorInput>) throws SourceException
}

class GraphicSource {
- TypeSource typeSource
Expand All @@ -39,6 +50,34 @@ class GraphicSource {
+ Set<LineGraphicInput> getLineGraphicInput(Map<UUID, LineInput>) throws SourceException
}

abstract class IdCoordinateSource {
+ Optional<Set<String>> getSourceFields() throws SourceException
+ Optional<Point> getCoordinate(int)
+ Collection<Point> getCoordinates(int[])
+ Optional<Integer> getId(Point)
+ Collection<Point> getAllCoordinates()
+ List<CoordinateDistance> getNearestCoordinates(Point, int)
+ List<CoordinateDistance> getClosestCoordinates(Point, int, ComparableQuantity<Length>)
+ List<CoordinateDistance> calculateCoordinateDistances(Point, int, Collection<Point>)
+ List<CoordinateDistance> findCornerPoints(Point, ComparableQuantity<Length>)
+ List<CoordinateDistance> findCornerPoints(Point, Collection<CoordinateDistance>)
}

class CsvIdCoordinateSource {
- Map<Integer, Point> idToCoordinate;
- Map<Point, Integer> coordinateToId;
- CsvDataSource dataSource;
- IdCoordinateFactory factory;
+ CsvIdCoordinateSource(IdCoordinateFactory, CsvDataSource) throws SourceException
+ int getCoordinateCount()
}

class SqlIdCoordinateSource {
- SqlDataSource dataSource
- SqlIdCoordinateFactory factory
+ SqlIdCoordinateSource(SqlIdCoordinateFactory, String, SqlDataSource)
}

class RawGridSource {
- TypeSource typeSource
- NodeInputFactory nodeInputFactory
Expand Down Expand Up @@ -70,9 +109,10 @@ class ResultEntitySource {
- SwitchResultFactory switchResultFactory
- NodeResultFactory nodeResultFactory
- ConnectorResultFactory connectorResultFactory
- CongestionResultFactory congestionResultFactory
- FlexOptionsResultFactory flexOptionsResultFactory
+ ResultEntitySource(DataSource)
+ ResultEntitySource(DataSource, String)
+ ResultEntitySource(DataSource, DateTimeFormatter)
+ Set<NodeResult> getNodeResults() throws SourceException
+ Set<SwitchResult> getSwitchResults() throws SourceException
+ Set<LineResult> getLineResults() throws SourceException
Expand All @@ -92,12 +132,14 @@ class ResultEntitySource {
+ Set<CylindricalStorageResult> getCylindricalStorageResult() throws SourceException
+ Set<ThermalHouseResult> getThermalHouseResults() throws SourceException
+ Set<EmResult> getEmResults() throws SourceException
+ Set<CongestionResult> getCongestionResults() throws SourceException
}

class SystemParticipantSource{
- TypeSource typeSource
- RawGridSource rawGridSource
- ThermalSource thermalSource
- EnergyManagementSource energyManagementSource
- BmInputFactory bmInputFactory
- ChpInputFactory chpInputFactory
- EvInputFactory evInputFactory
Expand All @@ -108,7 +150,7 @@ class SystemParticipantSource{
- StorageInputFactory storageInputFactory
- WecInputFactory wecInputFactory
- EvcsInputFactory evcsInputFactory
+ SystemParticipantSource(TypeSource, ThermalSource, RawGridSource, DataSource)
+ SystemParticipantSource(TypeSource, ThermalSource, RawGridSource, EnergyManagementSource, DataSource)
+ SystemParticipants getSystemParticipants() throws SourceException
+ SystemParticipants getSystemParticipants(Map<UUID, OperatorInput>, Map<UUID, NodeInput>) throws SourceException
+ Set<BmInput> getBmPlants() throws SourceException
Expand Down Expand Up @@ -141,20 +183,65 @@ class ThermalSource {
+ ThermalSource(TypeSource, DataSource)
+ Map<UUID, ThermalBusInput> getThermalBuses() throws SourceException
+ Map<UUID, ThermalBusInput> getThermalBuses(Map<UUID, OperatorInput>) throws SourceException
+ Set<ThermalStorageInput> getThermalStorages() throws SourceException
+ Set<ThermalStorageInput> getThermalStorages(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
+ Set<ThermalHouseInput> getThermalHouses() throws SourceException
+ Set<ThermalHouseInput> getThermalHouses(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
+ Map<UUID, ThermalStorageInput> getThermalStorages() throws SourceException
+ Map<UUID, ThermalStorageInput> getThermalStorages(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
+ Map<UUID, ThermalHouseInput> getThermalHouses() throws SourceException
+ Map<UUID, ThermalHouseInput> getThermalHouses(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
+ Set<CylindricalStorageInput> getCylindricStorages() throws SourceException
+ Set<CylindricalStorageInput> getCylindricStorages(Map<UUID, OperatorInput>, Map<UUID, ThermalBusInput>) throws SourceException
}

abstract class TimeSeriesMappingSource {
- TimeSeriesMappingFactory mappingFactory
+ Map<UUID, UUID> getMapping() throws SourceException
+ Optional<UUID> getTimeSeriesUuid(UUID) throws SourceException
+ Stream<Map<String, String>> getMappingSourceData() throws SourceException
+ Optional<Set<String>> getSourceFields() throws SourceException
}

class CsvTimeSeriesMappingSource {
- CsvDataSource dataSource
+ CsvTimeSeriesMappingSource(String, Path, FileNamingStrategy)
}

class SqlTimeSeriesMappingSource {
- EntityPersistenceNamingStrategy entityPersistenceNamingStrategy
- SqlDataSource dataSource
+ SqlTimeSeriesMappingSource(SqlConnector, String, EntityPersistenceNamingStrategy)
}

abstract class TimeSeriesSource {
- Class<V> valueClass
- TimeBasedSimpleValueFactory<V> valueFactory
+ TimeSeriesSource(Class<V>, TimeBasedSimpleValueFactory<V>)
+ IndividualTimeSeries<V> getTimeSeries()
+ IndividualTimeSeries<V> getTimeSeries(ClosedInterval<ZonedDateTime>) throws SourceException
+ Optional<V> getValue(ZonedDateTime) throws SourceException
}

class CsvTimeSeriesSource {
- IndividualTimeSeries<V> timeSeries
- CsvDataSource dataSource
- Path filePath
+ {static} CsvTimeSeriesSource<? extends Value> getSource(String, Path, FileNamingStrategy, CsvIndividualTimeSeriesMetaInformation)
+ CsvTimeSeriesSource(String, Path, FileNamingStrategy, UUID, Path, Class<V>, TimeBasedSimpleValueFactory<V>)
}

class SqlTimeSeriesSource {
- SqlDataSource dataSource
- UUID timeSeriesUuid
+ SqlTimeSeriesSource(SqlDataSource, UUID, Class<V>, TimeBasedSimpleValueFactory<V>)
+ SqlTimeSeriesSource(SqlConnector, String, DatabaseNamingStrategy, UUID, Class<V>, TimeBasedSimpleValueFactory<V>)
+ SqlTimeSeriesSource<? extends Value> createSource(SqlConnector, String, DatabaseNamingStrategy, IndividualTimeSeriesMetaInformation, DateTimeFormatter) throws SourceException
}

class TypeSource {
- OperatorInputFactory operatorInputFactory
- Transformer2WTypeInputFactory transformer2WTypeInputFactory
- LineTypeInputFactory lineTypeInputFactory
- Transformer3WTypeInputFactory transformer3WTypeInputFactory
- SystemParticipantTypeInputFactory systemParticipantTypeInputFactory
- DataSource dataSource
+ TypeSource(DataSource)
+ Map<UUID, Transformer2WTypeInput> getTransformer2WTypes() throws SourceException
+ Map<UUID, Transformer3WTypeInput> getTransformer3WTypes() throws SourceException
Expand All @@ -167,4 +254,38 @@ class TypeSource {
+ Map<UUID, WecTypeInput> getWecTypes() throws SourceException
+ Map<UUID, EvTypeInput> getEvTypes() throws SourceException
}

abstract class WeatherSource {
- TimeBasedWeatherValueFactory weatherFactory
- IdCoordinateSource idCoordinateSource
+ WeatherSource(IdCoordinateSource, TimeBasedWeatherValueFactory)
+ Optional<Set<String>> getSourceFields() throws SourceException
+ Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(ClosedInterval<ZonedDateTime>) throws SourceException
+ Map<Point, IndividualTimeSeries<WeatherValue>> getWeather(ClosedInterval<ZonedDateTime>, Collection<Point>) throws SourceException
+ Optional<TimeBasedValue<WeatherValue>> getWeather(ZonedDateTime, Point) throws SourceException
}

class CouchbaseWeatherSource {
- CouchbaseConnector connector
+ CouchbaseWeatherSource(CouchbaseConnector, IdCoordinateSource, String, TimeBasedWeatherValueFactory, String)
+ CouchbaseWeatherSource(CouchbaseConnector, IdCoordinateSource, String, String, TimeBasedWeatherValueFactory, String)
}

class CsvWeatherSource {
- CsvDataSource dataSource
- Map<Point, IndividualTimeSeries<WeatherValue>> coordinateToTimeSeries
+ CsvWeatherSource(String, Path, FileNamingStrategy, IdCoordinateSource, TimeBasedWeatherValueFactory) throws SourceException
}

class InfluxDbWeatherSource {
- InfluxDbConnector connector
+ InfluxDbWeatherSource(InfluxDbConnector, IdCoordinateSource, TimeBasedWeatherValueFactory)
+ IndividualTimeSeries<WeatherValue> getWeather(ClosedInterval<ZonedDateTime>, Point)
}

class SqlWeatherSource {
- SqlDataSource dataSource
+ SqlWeatherSource(SqlConnector, IdCoordinateSource, String, String, TimeBasedWeatherValueFactory)
}

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class AssetInputEntityFactory<T extends AssetInput, D extends As
private static final String OPERATES_FROM = "operatesFrom";
private static final String OPERATES_UNTIL = "operatesUntil";

@SafeVarargs
protected AssetInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @param <D> Type of data class that is required for entity creation
* @since 19.02.20
*/
abstract class ConnectorInputEntityFactory<
public abstract class ConnectorInputEntityFactory<
T extends ConnectorInput, D extends ConnectorInputEntityData>
extends AssetInputEntityFactory<T, D> {

Expand All @@ -31,6 +31,7 @@ abstract class ConnectorInputEntityFactory<
*/
protected static final String PARALLEL_DEVICES = "parallelDevices";

@SafeVarargs
protected ConnectorInputEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ public Transformer3WInputEntityData(
this.nodeC = nodeC;
}

/**
* Creates a new Transformer3WInputEntityData object based on a given {@link
* ConnectorInputEntityData} object, a given third node as well as a given {@link
* Transformer3WTypeInput}.
*
* @param entityData The TypedConnectorInputEntityData object to enhance
* @param nodeC The third node
* @param type of the transformer
*/
public Transformer3WInputEntityData(
ConnectorInputEntityData entityData, NodeInput nodeC, Transformer3WTypeInput type) {
super(entityData, type);
this.nodeC = nodeC;
}

/**
* Creates a new Transformer3WInputEntityData object based on a given {@link
* TypedConnectorInputEntityData} object and given third node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
* @version 0.1
* @since 11.02.20
*/
abstract class ResultEntityFactory<T extends ResultEntity> extends EntityFactory<T, EntityData> {
public abstract class ResultEntityFactory<T extends ResultEntity>
extends EntityFactory<T, EntityData> {

protected static final String TIME = "time";

protected final TimeUtil timeUtil;

@SafeVarargs
protected ResultEntityFactory(Class<? extends T>... allowedClasses) {
super(allowedClasses);
timeUtil = TimeUtil.withDefaults;
}

@SafeVarargs
protected ResultEntityFactory(
DateTimeFormatter dateTimeFormatter, Class<? extends T>... allowedClasses) {
super(allowedClasses);
Expand Down
Loading

0 comments on commit 8d312a1

Please sign in to comment.