Skip to content

Abstract commonly used functionality from EntitySource. #1044

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
221d066
Abstract commonly used functionality from `EntitySource`.
staudtMarius Mar 8, 2024
ce8bb07
Abstract more functionality.
staudtMarius Mar 11, 2024
b938a53
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Mar 11, 2024
3d3256f
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Mar 11, 2024
8bd4ee0
Adapting tests.
staudtMarius Mar 12, 2024
8cf9614
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Mar 12, 2024
36fc1e5
Some improvements
staudtMarius Mar 12, 2024
e1f528b
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Apr 3, 2024
d5e86e2
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Apr 9, 2024
192d096
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Apr 15, 2024
0bc7510
Adapting `CHANGELOG`.
staudtMarius Apr 15, 2024
a7bbece
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Apr 17, 2024
11b8a8e
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Apr 23, 2024
3ca3238
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius May 2, 2024
58a295d
Some minor adaption.
staudtMarius May 2, 2024
e52c889
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius May 6, 2024
88a9989
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius May 16, 2024
d459cbf
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius May 23, 2024
270a270
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Jun 4, 2024
9f6533f
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Jun 10, 2024
2fb012e
Merge branch 'refs/heads/dev' into ms/#981-abstract-commonly-used-fun…
sebastian-peter Jun 13, 2024
b537276
Adapting to changes in #1031
sebastian-peter Jun 13, 2024
1ef0d2d
Merge branch 'refs/heads/dev' into ms/#981-abstract-commonly-used-fun…
staudtMarius Jun 14, 2024
e8945d9
Implementing requested changes.
staudtMarius Jun 14, 2024
7589f8a
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
staudtMarius Jun 20, 2024
c44b047
Implementing requested changes.
staudtMarius Jun 24, 2024
b0a9f35
Merge branch 'dev' into ms/#981-abstract-commonly-used-functionality-…
sebastian-peter Jun 24, 2024
756f807
Removing unused import
sebastian-peter Jun 24, 2024
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
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