Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public SortedSet<CharacteristicPoint<A, O>> getPoints() {
*
* @return the characteristic as de-serialized string
*/
public String deSerialize() {
public String deSerialize() { // Auslesen ohne dezimal Kürzung double to String
return characteristicPrefix
+ ":{"
+ points.stream()
Expand All @@ -131,9 +131,14 @@ public String deSerialize() {
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CharacteristicInput<?, ?> that)) return false;

points.iterator();
Copy link
Contributor

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 ]


return decimalPlaces == that.decimalPlaces
&& characteristicPrefix.equals(that.characteristicPrefix)
&& points.equals(that.points);
&& points.equals(
that.points); // hier Streams erstellen mit zip und dann equals With Tolerence für jeden
// Punkt aufrufen --> Ergebnis Stream von booleans
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package edu.ie3.datamodel.models.input.system.characteristic;

import edu.ie3.datamodel.exceptions.ParsingException;
import edu.ie3.util.quantities.QuantityUtil;
import java.io.Serializable;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -103,6 +104,8 @@ public ComparableQuantity<O> getY() {
*/
public String deSerialize(int decimalPlaces) {
String formattingString = String.format("(%%.%sf,%%.%sf)", decimalPlaces, decimalPlaces);
// warum %Sf?? es sollen doch die decimal places als Anzahl für die Float Nachkommastellen
// eingesetzt werden? --> %%.%if ??
return String.format(
Locale.ENGLISH, formattingString, x.getValue().doubleValue(), y.getValue().doubleValue());
}
Expand All @@ -114,6 +117,12 @@ public boolean equals(Object o) {
return Objects.equals(x, that.x) && Objects.equals(y, that.y);
}

public boolean equalsWithTolerance(CharacteristicPoint<A, O> p, int decimalPlaces) {
double tolerance = Math.pow(10, -decimalPlaces);
return QuantityUtil.isEquivalentAbs(this.x, p.x, tolerance)
&& QuantityUtil.isEquivalentAbs(this.y, p.y, tolerance);
}

@Override
public int hashCode() {
return Objects.hash(x, y);
Expand Down
173 changes: 173 additions & 0 deletions src/test/groovy/edu/ie3/datamodel/io/GridIoIT.groovy
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')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ trait CsvTestDataMeta {
static String coordinatesCosmoFolderPath = getResourceAbs("_coordinates/cosmo")
static String weatherCosmoFolderPath = getResourceAbs("_weather/cosmo")
static String weatherIconFolderPath = getResourceAbs("_weather/icon")
static String jointGridFolderPath = getResourceAbs("_joint_grid")

static String gridDefaultFolderPath = getResourceAbs("_grid/default")
static String gridMalformedFolderPath = getResourceAbs("_grid/malformed")
Expand Down