-
Notifications
You must be signed in to change notification settings - Fork 7
Lr/#586 grid io it #643
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
Lr/#586 grid io it #643
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa0c1e1
avoid shortening wec input doubles while reading
lararou 3939bbd
Merge branch 'dev' into lr/#586-grid-io-it
lararou 1a683fb
Merge branch 'dev' into lr/#586-grid-io-it
lararou 74354ce
fmt
lararou 29e8919
finalising and deleting comments
lararou d03dbf1
Merge branch 'dev' into lr/#586-grid-io-it
lararou 37b6e79
committing joint grid csv files
lararou 9d712fd
create temporary output directory
lararou 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
60 changes: 60 additions & 0 deletions
60
src/main/java/edu/ie3/datamodel/io/source/csv/CsvJointGridContainerSource.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 @@ | ||
| /* | ||
| * © 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.exceptions.SourceException; | ||
| import edu.ie3.datamodel.io.naming.FileNamingStrategy; | ||
| import edu.ie3.datamodel.io.source.*; | ||
| import edu.ie3.datamodel.models.input.container.GraphicElements; | ||
| import edu.ie3.datamodel.models.input.container.JointGridContainer; | ||
| import edu.ie3.datamodel.models.input.container.RawGridElements; | ||
| import edu.ie3.datamodel.models.input.container.SystemParticipants; | ||
|
|
||
| public class CsvJointGridContainerSource { | ||
| private CsvJointGridContainerSource() { | ||
| // vllt mit Exception werfen | ||
| // bei utils Klassen suchen (ohne INstanziierung) | ||
| } | ||
|
|
||
| public static JointGridContainer read(String gridName, String csvSep, String directoryPath) | ||
| throws SourceException { | ||
|
|
||
| /* Parameterization */ | ||
|
|
||
| FileNamingStrategy namingStrategy = new FileNamingStrategy(); // Default naming strategy | ||
|
|
||
| /* Instantiating sources */ | ||
| TypeSource typeSource = new CsvTypeSource(csvSep, directoryPath, namingStrategy); | ||
| RawGridSource rawGridSource = | ||
| new CsvRawGridSource(csvSep, directoryPath, namingStrategy, typeSource); | ||
| ThermalSource thermalSource = | ||
| new CsvThermalSource(csvSep, directoryPath, namingStrategy, typeSource); | ||
| SystemParticipantSource systemParticipantSource = | ||
| new CsvSystemParticipantSource( | ||
| csvSep, directoryPath, namingStrategy, typeSource, thermalSource, rawGridSource); | ||
| GraphicSource graphicsSource = | ||
| new CsvGraphicSource(csvSep, directoryPath, namingStrategy, typeSource, rawGridSource); | ||
|
|
||
| /* Loading models */ | ||
| RawGridElements rawGridElements = | ||
| rawGridSource | ||
| .getGridData() | ||
| .orElseThrow(() -> new SourceException("Error during reading of raw grid data.")); | ||
| SystemParticipants systemParticipants = | ||
| systemParticipantSource | ||
| .getSystemParticipants() | ||
| .orElseThrow( | ||
| () -> new SourceException("Error during reading of system participant data.")); | ||
| GraphicElements graphicElements = | ||
| graphicsSource | ||
| .getGraphicElements() | ||
| .orElseThrow(() -> new SourceException("Error during reading of graphic elements.")); | ||
| JointGridContainer fullGrid = | ||
| new JointGridContainer(gridName, rawGridElements, systemParticipants, graphicElements); | ||
|
|
||
| return fullGrid; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /* | ||
| * © 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 | ||
|
|
||
| import edu.ie3.datamodel.io.sink.CsvFileSink | ||
| import edu.ie3.datamodel.io.source.csv.CsvGraphicSource | ||
| import edu.ie3.datamodel.io.source.csv.CsvGraphicSourceTest | ||
| import edu.ie3.datamodel.io.source.csv.CsvJointGridContainerSource | ||
| import edu.ie3.datamodel.io.source.csv.CsvRawGridSource | ||
| import edu.ie3.datamodel.io.source.csv.CsvTestDataMeta | ||
| import edu.ie3.datamodel.io.source.csv.CsvTypeSource | ||
| import edu.ie3.datamodel.models.input.NodeInput | ||
| import edu.ie3.datamodel.models.input.OperatorInput | ||
| import spock.lang.Specification | ||
|
|
||
| import java.nio.file.Path | ||
| import java.security.MessageDigest | ||
| import org.apache.commons.io.FileUtils | ||
|
|
||
| class GridIoIT extends Specification implements CsvTestDataMeta { | ||
|
|
||
| def setup(){ | ||
| println "setup in progress..." | ||
| } | ||
|
|
||
| def cleanup(){ | ||
| println "cleanup in progress..." | ||
| } | ||
|
|
||
| def "Input Files equal Output Files." (){ | ||
|
|
||
| given: | ||
| // create joint grid container | ||
| def gridname = new String("vn_simona") | ||
| def seperator = new String(",") | ||
| def folderpath = new String(jointGridFolderPath) | ||
| def firstgridContainer = CsvJointGridContainerSource.read(gridname, seperator, folderpath) | ||
| def secondgridContainer = CsvJointGridContainerSource.read(gridname, seperator, folderpath) | ||
|
|
||
| // input | ||
| def inDirectory = new File(folderpath) | ||
| def inHashCodes = [:] | ||
|
|
||
| // output | ||
| def outFolderpath = new String("./exampleGridOut") | ||
| def sink = new CsvFileSink(outFolderpath) | ||
| def outDirectory = new File(outFolderpath) | ||
| def outHashCodes = [:] | ||
|
|
||
| // list and number of filenames | ||
| def filenames = [] | ||
| def filesCount = 0 | ||
| def checkUpCount = 0 | ||
|
|
||
| when: | ||
| // Read original grid from input directory and generate hashcodes | ||
| inDirectory.eachFile { | ||
| inHashCodes.putAt(it.name, csvreader(it)) | ||
| } | ||
| //println(inHashCodes) | ||
|
|
||
| // write files in output directory | ||
| sink.persistJointGrid(firstgridContainer) | ||
|
|
||
| // read files from output folder and generate hashcodes | ||
| outDirectory.eachFile { | ||
| outHashCodes.putAt(it.name, csvreader(it)) | ||
| filenames.add(it.name) | ||
| filesCount++ // geht auch über filenames | ||
| } | ||
|
|
||
| // delete files in output directory | ||
| outDirectory.eachFile { | ||
| it.deleteOnExit() | ||
| } | ||
|
|
||
| then: | ||
| inHashCodes.keySet().each{assert inHashCodes.get(it) == outHashCodes.get(it)} | ||
|
|
||
| //firstgridContainer.getSystemParticipants().equals(second) | ||
| println firstgridContainer.hashCode() | ||
| println secondgridContainer.hashCode() | ||
| //SPA, RawGrid eleemnts, ... | ||
| } | ||
|
|
||
| def "Input JointGridContainer equals Output JointGridContainer."(){ | ||
|
|
||
| given: | ||
| // create joint grid container | ||
| def gridname = new String("vn_simona") | ||
| def seperator = new String(",") | ||
| def folderpath = new String(jointGridFolderPath) | ||
| def firstGridContainer = CsvJointGridContainerSource.read(gridname, seperator, folderpath) | ||
|
|
||
| // output | ||
| def outFolderpath = new String("./exampleGridOut") | ||
| def sink = new CsvFileSink(outFolderpath) | ||
| def outDirectory = new File(outFolderpath) | ||
|
|
||
| when: | ||
| // write files in output directory | ||
| sink.persistJointGrid(firstGridContainer) | ||
| // an welcher Stelle wird cp type gekürzt? | ||
| // sonst doubles mit toleranz vergleichen | ||
|
|
||
| // create second grid container | ||
| def secondGridContainer = CsvJointGridContainerSource.read(gridname, seperator, outFolderpath) | ||
|
|
||
| // delete files in output directory | ||
| /*outDirectory.eachFile { | ||
| it.deleteOnExit() | ||
| }*/ | ||
|
|
||
| then: | ||
| /* | ||
| println firstGridContainer.getSystemParticipants().hashCode() | ||
| println secondGridContainer.getSystemParticipants().hashCode() | ||
| println firstGridContainer.getRawGrid().hashCode() | ||
| println secondGridContainer.getRawGrid().hashCode() | ||
| */ | ||
| println("Grid Name: " + firstGridContainer.getGridName().equals(secondGridContainer.getGridName())) | ||
| println("RawGrid: " + firstGridContainer.getRawGrid().equals(secondGridContainer.getRawGrid())) | ||
| println("System Participants: " + firstGridContainer.getSystemParticipants().equals(secondGridContainer.getSystemParticipants())) | ||
| println("Graphics: " + firstGridContainer.getGraphics().equals(secondGridContainer.getGraphics())) | ||
|
|
||
| println("System Participants - Fixed Feed Ins: " + firstGridContainer.getSystemParticipants().getFixedFeedIns().equals(secondGridContainer.getSystemParticipants().getFixedFeedIns())) | ||
| println("System Participants - BM Plants: " + firstGridContainer.getSystemParticipants().getBmPlants().equals(secondGridContainer.getSystemParticipants().getBmPlants())) | ||
| println("System Participants - PV Plants: " + firstGridContainer.getSystemParticipants().getPvPlants().equals(secondGridContainer.getSystemParticipants().getPvPlants())) | ||
| println("System Participants - Loads: " + firstGridContainer.getSystemParticipants().getLoads().equals(secondGridContainer.getSystemParticipants().getLoads())) | ||
| println("System Participants - EvCS: " + firstGridContainer.getSystemParticipants().getEvCS().equals(secondGridContainer.getSystemParticipants().getEvCS())) | ||
| println("System Participants - Storages: " + firstGridContainer.getSystemParticipants().getStorages().equals(secondGridContainer.getSystemParticipants().getStorages())) | ||
|
|
||
| println("System Participants - wec Plants: " + firstGridContainer.getSystemParticipants().getWecPlants().equals(secondGridContainer.getSystemParticipants().getWecPlants())) | ||
| //println("System Participants - Properties: " + firstGridContainer.getSystemParticipants().getProperties().equals(secondGridContainer.getSystemParticipants().getProperties())) | ||
| //println("System Participants - Meta Property Values: " + firstGridContainer.getSystemParticipants().getMetaPropertyValues().equals(secondGridContainer.getSystemParticipants().getMetaPropertyValues())) | ||
| } | ||
|
|
||
|
|
||
| def csvreader(final file) { | ||
| List<String> hashcodes = new ArrayList<String>() | ||
| BufferedReader br = new BufferedReader(new FileReader(file)) | ||
| String line | ||
| println("br setup") | ||
|
|
||
| while ((line = br.readLine()) != null) { | ||
| String values = line.split(",") | ||
| hashcodes.add(values.hashCode()) | ||
| } | ||
| println("br loop done") | ||
|
|
||
| return hashcodes; | ||
| } | ||
|
|
||
| def generateMD5(final file) { | ||
| //StringBuilder strb = new StringBuilder() | ||
| //strb.append() | ||
| MessageDigest digest = MessageDigest.getInstance("MD5") | ||
| file.withInputStream() { is -> | ||
| byte[] buffer = new byte[8192] | ||
| int read = 0 | ||
| while( (read = is.read(buffer)) > 0) { | ||
| digest.update(buffer, 0, read); | ||
| } | ||
| } | ||
| byte[] md5sum = digest.digest() | ||
| BigInteger bigInt = new BigInteger(1, md5sum) | ||
|
|
||
| return bigInt.toString(16).padLeft(32, '0') | ||
| } | ||
| } |
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
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.
ReturnValueIgnored: Return value of 'iterator' must be used
Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]