-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructuring SQL sources and introducing TimeSeriesTypeSource (#546)
* Restructuring SQL sources and introducing TimeSeriesTypeSource * Fixing/creating missing tests, introducing TimeSeriesUtils.isSchemeAccepted * Fixing code smells * More fixing of code smells * Adapting changelog * Fixing codacy issues * Improving TypeEntry#equals * Improving test a tiny bit * Explicitly creating timeseries-id/time index * Addressing reviewer's comments Co-authored-by: t-ober <63147366+t-ober@users.noreply.github.com>
- Loading branch information
1 parent
1935566
commit a10a543
Showing
35 changed files
with
708 additions
and
363 deletions.
There are no files selected for viewing
This file contains 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 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 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 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); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/edu/ie3/datamodel/io/naming/DatabaseNamingStrategy.java
This file contains 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 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 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 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) { | ||
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 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 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 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.