-
Notifications
You must be signed in to change notification settings - Fork 7
Generalize CSV->File #1450
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
Open
PhilippSchmelter
wants to merge
13
commits into
dev
Choose a base branch
from
ps/#1445-CsvToFile
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Generalize CSV->File #1450
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a63ded9
abstract
PhilippSchmelter 180f3ee
spotless
PhilippSchmelter b898816
fix
PhilippSchmelter 60252c0
fix
PhilippSchmelter 910590b
Merge branch 'dev' into ps/#1445-CsvToFile
PhilippSchmelter 19a9134
some more fittings and FileType enum
PhilippSchmelter cfb255d
Merge branch 'dev' into ps/#1445-CsvToFile
PhilippSchmelter 1dfab2a
spotless
PhilippSchmelter 5c45532
Merge remote-tracking branch 'origin/ps/#1445-CsvToFile' into ps/#144…
PhilippSchmelter a3860e9
tests
PhilippSchmelter 0d8d35d
spotless
PhilippSchmelter fa0ab94
little fix in FileType enum
PhilippSchmelter 60b092f
CHANGELOG.md
PhilippSchmelter 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
60 changes: 60 additions & 0 deletions
60
src/main/java/edu/ie3/datamodel/io/connectors/FileConnector.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,60 @@ | ||
/* | ||
* © 2025. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io.connectors; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.util.function.Function; | ||
|
||
/** Base connector for file-based sources and sinks. */ | ||
public abstract class FileConnector implements DataConnector { | ||
|
||
protected final Path baseDirectory; | ||
private final Function<String, InputStream> inputStreamBuilder; | ||
|
||
protected FileConnector(Path baseDirectory) { | ||
this(baseDirectory, null); | ||
} | ||
|
||
protected FileConnector(Path baseDirectory, Function<String, InputStream> inputStreamBuilder) { | ||
this.baseDirectory = baseDirectory; | ||
this.inputStreamBuilder = inputStreamBuilder; | ||
} | ||
|
||
/** Returns the base directory backing this connector. */ | ||
public Path getBaseDirectory() { | ||
return baseDirectory; | ||
} | ||
|
||
/** | ||
* Open an {@link InputStream} to the given file path (without file ending) relative to the base | ||
* directory. | ||
*/ | ||
protected InputStream openInputStream(Path filePath) throws FileNotFoundException { | ||
Path fullPath = resolveFilePath(filePath); | ||
if (inputStreamBuilder != null) { | ||
return inputStreamBuilder.apply(fullPath.toString()); | ||
} | ||
return new FileInputStream(fullPath.toFile()); | ||
} | ||
|
||
/** Resolve the path including the file ending relative to the base directory. */ | ||
protected Path resolveFilePath(Path filePath) { | ||
String relativePath = filePath.toString(); | ||
if (!relativePath.endsWith(getFileEnding())) { | ||
relativePath = relativePath + getFileEnding(); | ||
} | ||
return baseDirectory.resolve(relativePath); | ||
} | ||
|
||
/** Returns the file ending (including the dot) handled by this connector. */ | ||
protected abstract String getFileEnding(); | ||
|
||
@Override | ||
public void shutdown() {} | ||
} |
55 changes: 0 additions & 55 deletions
55
src/main/java/edu/ie3/datamodel/io/csv/CsvLoadProfileMetaInformation.java
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* © 2025. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.io.file; | ||
|
||
import edu.ie3.datamodel.exceptions.ParsingException; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
public enum FileType { | ||
CSV(".csv"); | ||
|
||
public final String fileEnding; | ||
|
||
FileType(String fileEnding) { | ||
this.fileEnding = fileEnding; | ||
} | ||
|
||
public static FileType getFileType(String fileName) throws ParsingException { | ||
FileType[] fileTypes = FileType.values(); | ||
return Arrays.stream(fileTypes) | ||
.filter(f -> fileName.endsWith(f.fileEnding)) | ||
.findFirst() | ||
.orElseThrow( | ||
() -> | ||
new ParsingException( | ||
"No file ending found for file '" | ||
+ fileName | ||
+ "'. Only supports file types: " | ||
+ Arrays.stream(fileTypes) | ||
.map(t -> t.fileEnding) | ||
.collect(Collectors.joining(", ")))); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/edu/ie3/datamodel/io/naming/timeseries/FileLoadProfileMetaInformation.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,53 @@ | ||
/* | ||
* © 2024. 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.timeseries; | ||
|
||
import edu.ie3.datamodel.io.file.FileType; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
|
||
public class FileLoadProfileMetaInformation extends LoadProfileMetaInformation { | ||
private final Path fullFilePath; | ||
private final FileType fileType; | ||
|
||
public FileLoadProfileMetaInformation(String profile, Path fullFilePath, FileType fileType) { | ||
super(profile); | ||
this.fullFilePath = fullFilePath; | ||
this.fileType = fileType; | ||
} | ||
|
||
public Path getFullFilePath() { | ||
return fullFilePath; | ||
} | ||
|
||
public FileType getFileType() { | ||
return fileType; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (!super.equals(o)) return false; | ||
FileLoadProfileMetaInformation that = (FileLoadProfileMetaInformation) o; | ||
return Objects.equals(fullFilePath, that.fullFilePath) && fileType == that.fileType; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), fullFilePath, fileType); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FileLoadProfileMetaInformation{" | ||
+ ", fullFilePath='" | ||
+ fullFilePath | ||
+ '\'' | ||
+ ", fileType=" | ||
+ fileType | ||
+ '}'; | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an empty line below?