-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvJointGridContainerSource.java
68 lines (59 loc) · 2.85 KB
/
CsvJointGridContainerSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* © 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.FileException;
import edu.ie3.datamodel.exceptions.SourceException;
import edu.ie3.datamodel.io.naming.DefaultDirectoryHierarchy;
import edu.ie3.datamodel.io.naming.EntityPersistenceNamingStrategy;
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;
/** Convenience class for cases where all used data comes from CSV sources */
public class CsvJointGridContainerSource {
private CsvJointGridContainerSource() {}
public static JointGridContainer read(
String gridName, String csvSep, String directoryPath, boolean isHierarchic)
throws SourceException, FileException {
/* Parameterization */
FileNamingStrategy namingStrategy;
if (isHierarchic) {
// Hierarchic structure
DefaultDirectoryHierarchy fileHierarchy =
new DefaultDirectoryHierarchy(directoryPath, gridName);
namingStrategy = new FileNamingStrategy(new EntityPersistenceNamingStrategy(), fileHierarchy);
fileHierarchy.validate();
} else {
// Flat structure
namingStrategy = new FileNamingStrategy();
}
CsvDataSource dataSource = new CsvDataSource(csvSep, directoryPath, namingStrategy);
/* Instantiating sources */
TypeSource typeSource = new TypeSource(dataSource);
RawGridSource rawGridSource = new RawGridSource(typeSource, dataSource);
ThermalSource thermalSource = new ThermalSource(typeSource, dataSource);
SystemParticipantSource systemParticipantSource =
new SystemParticipantSource(typeSource, thermalSource, rawGridSource, dataSource);
GraphicSource graphicSource = new GraphicSource(typeSource, rawGridSource, dataSource);
/* 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 =
graphicSource
.getGraphicElements()
.orElseThrow(() -> new SourceException("Error during reading of graphic elements."));
return new JointGridContainer(gridName, rawGridElements, systemParticipants, graphicElements);
}
}