-
Notifications
You must be signed in to change notification settings - Fork 7
Restructuring SQL sources and introducing TimeSeriesTypeSource #546
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5fed853
Restructuring SQL sources and introducing TimeSeriesTypeSource
sebastian-peter a5bdeb8
Fixing/creating missing tests, introducing TimeSeriesUtils.isSchemeAc…
sebastian-peter fdc6647
Fixing code smells
sebastian-peter 381b36a
More fixing of code smells
sebastian-peter ff0fe86
Adapting changelog
sebastian-peter f5aeb3f
Merge branch 'dev' into sp/#515-restructure-sql-sources
t-ober e2c1c5b
Merge branch 'dev' into sp/#515-restructure-sql-sources
sebastian-peter 655162c
Fixing codacy issues
sebastian-peter 513b470
Improving TypeEntry#equals
sebastian-peter 3fe07ed
Merge branch 'dev' into sp/#515-restructure-sql-sources
t-ober 5dfe351
Improving test a tiny bit
sebastian-peter c4997d7
Explicitly creating timeseries-id/time index
sebastian-peter a377704
Addressing reviewer's comments
sebastian-peter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/edu/ie3/datamodel/io/factory/timeseries/TimeSeriesTypeFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * © 2021. TU Dortmund University, | ||
| * Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
| * Research group Distribution grid planning and operation | ||
| */ | ||
| package edu.ie3.datamodel.io.factory.timeseries; | ||
|
|
||
| import edu.ie3.datamodel.io.factory.EntityFactory; | ||
| import edu.ie3.datamodel.io.factory.SimpleEntityData; | ||
| import edu.ie3.datamodel.io.naming.timeseries.ColumnScheme; | ||
| import edu.ie3.datamodel.io.source.TimeSeriesTypeSource; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| /** | ||
| * Factory that creates {@link TimeSeriesTypeSource.TypeEntry} entities from source field mappings | ||
| */ | ||
| public class TimeSeriesTypeFactory | ||
| extends EntityFactory<TimeSeriesTypeSource.TypeEntry, SimpleEntityData> { | ||
| private static final String TIME_SERIES = "timeSeries"; | ||
| private static final String COLUMN_SCHEME = "columnScheme"; | ||
|
|
||
| public TimeSeriesTypeFactory() { | ||
| super(TimeSeriesTypeSource.TypeEntry.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected List<Set<String>> getFields(SimpleEntityData data) { | ||
| return Collections.singletonList( | ||
| Stream.of(TIME_SERIES, COLUMN_SCHEME).collect(Collectors.toSet())); | ||
| } | ||
|
|
||
| @Override | ||
| protected TimeSeriesTypeSource.TypeEntry buildModel(SimpleEntityData data) { | ||
| UUID timeSeries = data.getUUID(TIME_SERIES); | ||
| ColumnScheme columnScheme = ColumnScheme.parse(data.getField(COLUMN_SCHEME)).orElseThrow(); | ||
| return new TimeSeriesTypeSource.TypeEntry(timeSeries, columnScheme); | ||
| } | ||
| } | ||
sebastian-peter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
33 changes: 33 additions & 0 deletions
33
src/main/java/edu/ie3/datamodel/io/naming/DatabaseNamingStrategy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * © 2022. TU Dortmund University, | ||
| * Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
| * Research group Distribution grid planning and operation | ||
| */ | ||
| package edu.ie3.datamodel.io.naming; | ||
|
|
||
| import edu.ie3.datamodel.io.naming.timeseries.ColumnScheme; | ||
|
|
||
| /** A naming strategy for database entities */ | ||
| public class DatabaseNamingStrategy { | ||
|
|
||
| private static final String TIME_SERIES_PREFIX = "time_series_"; | ||
|
|
||
| /** | ||
| * Provides the String that all time series tables are prefixed with | ||
| * | ||
| * @return the time series prefix | ||
| */ | ||
| public String getTimeSeriesPrefix() { | ||
| return TIME_SERIES_PREFIX; | ||
| } | ||
|
|
||
| /** | ||
| * Provides the name of a time series table given a column scheme | ||
| * | ||
| * @param columnScheme the column scheme of the source data | ||
| * @return the table name | ||
| */ | ||
| public String getTimeSeriesEntityName(ColumnScheme columnScheme) { | ||
| return TIME_SERIES_PREFIX + columnScheme.getScheme(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/edu/ie3/datamodel/io/source/TimeSeriesTypeSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * © 2022. TU Dortmund University, | ||
| * Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
| * Research group Distribution grid planning and operation | ||
| */ | ||
| package edu.ie3.datamodel.io.source; | ||
|
|
||
| import edu.ie3.datamodel.io.naming.timeseries.ColumnScheme; | ||
| import edu.ie3.datamodel.io.naming.timeseries.IndividualTimeSeriesMetaInformation; | ||
| import edu.ie3.datamodel.models.input.InputEntity; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.UUID; | ||
|
|
||
| /** Source for all available time series with their {@link UUID} and {@link ColumnScheme} */ | ||
| public interface TimeSeriesTypeSource extends DataSource { | ||
|
|
||
| /** | ||
| * Get a mapping from time series {@link UUID} to its meta information {@link | ||
| * IndividualTimeSeriesMetaInformation} | ||
| * | ||
| * @return that mapping | ||
| */ | ||
| Map<UUID, ? extends IndividualTimeSeriesMetaInformation> getTimeSeriesMetaInformation(); | ||
|
|
||
| /** Class to represent one entry within the participant to time series mapping */ | ||
| class TypeEntry extends InputEntity { | ||
| private final ColumnScheme columnScheme; | ||
|
|
||
| public TypeEntry(UUID timeSeries, ColumnScheme columnScheme) { | ||
| super(timeSeries); | ||
| this.columnScheme = columnScheme; | ||
| } | ||
|
|
||
| public UUID getTimeSeries() { | ||
| return getUuid(); | ||
| } | ||
|
|
||
| public ColumnScheme getColumnScheme() { | ||
| return columnScheme; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
sebastian-peter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (this == o) return true; | ||
| if (!(o instanceof TypeEntry that)) return false; | ||
| if (!super.equals(o)) return false; | ||
| return columnScheme == that.columnScheme; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(super.hashCode(), columnScheme); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "TypeEntry{" + "uuid=" + getUuid() + ", columnScheme=" + columnScheme + '}'; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/edu/ie3/datamodel/io/source/csv/CsvTimeSeriesTypeSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * © 2022. TU Dortmund University, | ||
| * Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
| * Research group Distribution grid planning and operation | ||
| */ | ||
| package edu.ie3.datamodel.io.source.csv; | ||
|
|
||
| import edu.ie3.datamodel.io.naming.FileNamingStrategy; | ||
| import edu.ie3.datamodel.io.naming.timeseries.IndividualTimeSeriesMetaInformation; | ||
| import edu.ie3.datamodel.io.source.TimeSeriesTypeSource; | ||
| import edu.ie3.datamodel.utils.TimeSeriesUtils; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * CSV implementation for retrieving {@link TimeSeriesTypeSource} from input directory structures | ||
| */ | ||
| public class CsvTimeSeriesTypeSource extends CsvDataSource implements TimeSeriesTypeSource { | ||
|
|
||
| /** | ||
| * Creates a time series type source | ||
| * | ||
| * @param csvSep the CSV separator | ||
| * @param folderPath path that time series reside in | ||
| * @param fileNamingStrategy the file naming strategy | ||
| */ | ||
| public CsvTimeSeriesTypeSource( | ||
| String csvSep, String folderPath, FileNamingStrategy fileNamingStrategy) { | ||
| super(csvSep, folderPath, fileNamingStrategy); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<UUID, ? extends IndividualTimeSeriesMetaInformation> getTimeSeriesMetaInformation() { | ||
| return connector.getIndividualTimeSeriesMetaInformation().entrySet().stream() | ||
| .filter(entry -> TimeSeriesUtils.isSchemeAccepted(entry.getValue().getColumnScheme())) | ||
| .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.