Skip to content

Commit f871e81

Browse files
committed
Adaption to recent changes.
1 parent c9fc47d commit f871e81

File tree

4 files changed

+86
-121
lines changed

4 files changed

+86
-121
lines changed

docs/readthedocs/gettingstarted.md

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,75 @@
1-
# Getting started
2-
Welcome, dear fellow of bottom up power system modelling!
3-
This section is meant to give you some help getting hands on our project.
4-
If you feel, something is missing, please contact us!
5-
6-
7-
## Requirements
8-
9-
Java > v 17
10-
11-
## Where to get
12-
13-
Checkout latest from [GitHub](https://github.com/ie3-institute/PowerSystemDataModel) or use maven for dependency
14-
management:
15-
16-
### Stable releases
17-
18-
On [Maven central](https://search.maven.org/artifact/com.github.ie3-institute/PowerSystemDataModel):
19-
20-
```xml
21-
<dependency>
22-
<groupId>com.github.ie3-institute</groupId>
23-
<artifactId>PowerSystemDataModel</artifactId>
24-
<version>2.1.0</version>
25-
</dependency>
26-
```
27-
28-
29-
### Snapshot releases
30-
31-
Available on [OSS Sonatype](https://s01.oss.sonatype.org/).
32-
Add the correct repository:
33-
34-
```xml
35-
<repositories>
36-
<repository>https://s01.oss.sonatype.org/content/repositories/snapshots</repository>
37-
</repositories>
38-
```
39-
40-
and add the dependency:
41-
42-
```xml
43-
<dependency>
44-
<groupId>com.github.ie3-institute</groupId>
45-
<artifactId>PowerSystemDataModel</artifactId>
46-
<version>3.0-SNAPSHOT</version>
47-
</dependency>
48-
```
49-
50-
## Important changes
51-
52-
With the release of `PowerSystemDataModel` version `5.0` the support for the old csv file format will be fully removed.
53-
It was already marked as `deprecated` back in version `1.1.0`. For those who are still using a model in the old csv format
54-
the following guide will provide a fast and easy way to convert old format into the new one.
55-
56-
- Since the support is removed in version `5.0`, the `PowerSystemDataModel` version `3.x` or `4.x` must be
57-
used to read the old format. The `PSDM` will automatically write the output model in the new csv format.
58-
59-
60-
``` java
61-
/* Parameterization */
62-
String gridName = "gridWithOldFormat";
63-
String csvSep = ",";
64-
Path folderPath = Path.of("PATH_TO_THE_FOLDER");
65-
boolean isHierarchic = false;
66-
Path output = Path.of("PATH_OF_THE_OUTPUT_FOLDER");
67-
FileNamingStrategy namingStrategy = new FileNamingStrategy();
68-
69-
/* Reading the old format */
70-
JointGridContainer container = CsvJointGridContainerSource.read(gridName, csvSep, folderPath, isHierarchic);
71-
72-
/* Writing in the new format */
73-
CsvFileSink sink = new CsvFileSink(output, namingStrategy, csvSep);
74-
sink.persistJointGrid(container);
75-
```
76-
77-
1+
# Getting started
2+
Welcome, dear fellow of bottom up power system modelling!
3+
This section is meant to give you some help getting hands on our project.
4+
If you feel, something is missing, please contact us!
5+
6+
## Requirements
7+
8+
Java > v 17
9+
10+
## Where to get
11+
12+
Checkout latest from [GitHub](https://github.com/ie3-institute/PowerSystemDataModel) or use maven for dependency
13+
management:
14+
15+
### Stable releases
16+
17+
On [Maven central](https://search.maven.org/artifact/com.github.ie3-institute/PowerSystemDataModel):
18+
19+
```xml
20+
<dependency>
21+
<groupId>com.github.ie3-institute</groupId>
22+
<artifactId>PowerSystemDataModel</artifactId>
23+
<version>2.1.0</version>
24+
</dependency>
25+
```
26+
27+
### Snapshot releases
28+
29+
Available on [OSS Sonatype](https://s01.oss.sonatype.org/).
30+
Add the correct repository:
31+
32+
```xml
33+
<repositories>
34+
<repository>https://s01.oss.sonatype.org/content/repositories/snapshots</repository>
35+
</repositories>
36+
```
37+
38+
and add the dependency:
39+
40+
```xml
41+
<dependency>
42+
<groupId>com.github.ie3-institute</groupId>
43+
<artifactId>PowerSystemDataModel</artifactId>
44+
<version>3.0-SNAPSHOT</version>
45+
</dependency>
46+
```
47+
48+
## Important changes
49+
50+
With the release of `PowerSystemDataModel` version `5.0` the support for the old csv file format will be fully removed.
51+
It was already marked as `deprecated` back in version `1.1.0`. For those who are still using a model in the old csv format
52+
the following guide will provide a fast and easy way to convert old format into the new one.
53+
54+
- Since the support is removed in version `5.0`, the `PowerSystemDataModel` version `3.x` or `4.x` must be
55+
used to read the old format. The `PSDM` will automatically write the output model in the new csv format.
56+
57+
58+
``` java
59+
/* Parameterization */
60+
String gridName = "gridWithOldFormat";
61+
String csvSep = ",";
62+
Path folderPath = Path.of("PATH_TO_THE_FOLDER");
63+
boolean isHierarchic = false;
64+
Path output = Path.of("PATH_OF_THE_OUTPUT_FOLDER");
65+
FileNamingStrategy namingStrategy = new FileNamingStrategy();
66+
67+
/* Reading the old format */
68+
JointGridContainer container = CsvJointGridContainerSource.read(gridName, csvSep, folderPath, isHierarchic);
69+
70+
/* Writing in the new format */
71+
CsvFileSink sink = new CsvFileSink(output, namingStrategy, csvSep);
72+
sink.persistJointGrid(container);
73+
```
74+
75+

src/main/java/edu/ie3/datamodel/io/source/csv/CsvDataSource.java

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
import edu.ie3.datamodel.io.source.DataSource;
1212
import edu.ie3.datamodel.models.Entity;
1313
import edu.ie3.datamodel.utils.Try;
14-
import edu.ie3.datamodel.utils.Try.*;
14+
import edu.ie3.datamodel.utils.Try.Failure;
15+
import edu.ie3.datamodel.utils.Try.Success;
1516
import edu.ie3.util.StringUtils;
1617
import java.io.BufferedReader;
1718
import java.io.FileNotFoundException;
1819
import java.io.IOException;
1920
import java.nio.file.Path;
2021
import java.util.*;
21-
import java.util.concurrent.atomic.AtomicInteger;
22-
import java.util.regex.Matcher;
23-
import java.util.regex.Pattern;
2422
import java.util.stream.Collectors;
2523
import java.util.stream.IntStream;
2624
import java.util.stream.Stream;
@@ -44,13 +42,6 @@ public class CsvDataSource implements DataSource {
4442

4543
private final FileNamingStrategy fileNamingStrategy;
4644

47-
/**
48-
* @deprecated ensures downward compatibility with old csv data format. Can be removed when
49-
* support for old csv format is removed. *
50-
*/
51-
@Deprecated(since = "1.1.0", forRemoval = true)
52-
private boolean notYetLoggedWarning = true;
53-
5445
public CsvDataSource(String csvSep, Path folderPath, FileNamingStrategy fileNamingStrategy) {
5546
this.csvSep = csvSep;
5647
this.connector = new CsvFileConnector(folderPath, fileNamingStrategy);
@@ -90,6 +81,11 @@ public Stream<Map<String, String>> getSourceData(Class<? extends Entity> entityC
9081

9182
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
9283

84+
/** Returns the set {@link FileNamingStrategy}. */
85+
public FileNamingStrategy getNamingStrategy() {
86+
return fileNamingStrategy;
87+
}
88+
9389
/**
9490
* Takes a row string of a .csv file and a string array of the csv file headline, tries to split
9591
* the csv row string based and zip it together with the headline. This method does not contain
@@ -108,13 +104,13 @@ protected Map<String, String> buildFieldsToAttributes(
108104
new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
109105

110106
try {
111-
String[] finalFieldVals = parseCsvRow(csvRow, csvSep);
107+
String[] fieldVals = parseCsvRow(csvRow, csvSep);
112108
insensitiveFieldsToAttributes.putAll(
113-
IntStream.range(0, finalFieldVals.length)
109+
IntStream.range(0, fieldVals.length)
114110
.boxed()
115111
.collect(
116112
Collectors.toMap(
117-
k -> StringUtils.snakeCaseToCamelCase(headline[k]), v -> finalFieldVals[v])));
113+
k -> StringUtils.snakeCaseToCamelCase(headline[k]), v -> fieldVals[v])));
118114

119115
if (insensitiveFieldsToAttributes.size() != headline.length) {
120116
Set<String> fieldsToAttributesKeySet = insensitiveFieldsToAttributes.keySet();
@@ -157,30 +153,6 @@ protected String[] parseCsvRow(String csvRow, String csvSep) {
157153
.toArray(String[]::new);
158154
}
159155

160-
/**
161-
* Extracts all strings from the provided csvRow matching the provided regexString and returns a
162-
* list of strings in the order of their appearance in the csvRow string
163-
*
164-
* @param regexString regex string that should be searched for
165-
* @param csvRow csv row string that should be searched in for the regex string
166-
* @return a list of strings matching the provided regex in the order of their appearance in the
167-
* provided csv row string
168-
*/
169-
private List<String> extractMatchingStrings(String regexString, String csvRow) {
170-
Pattern pattern = Pattern.compile(regexString);
171-
Matcher matcher = pattern.matcher(csvRow);
172-
173-
ArrayList<String> matchingList = new ArrayList<>();
174-
while (matcher.find()) {
175-
matchingList.add(matcher.group());
176-
}
177-
return matchingList;
178-
}
179-
180-
public FileNamingStrategy getNamingStrategy() {
181-
return fileNamingStrategy;
182-
}
183-
184156
/**
185157
* Tries to open a file reader based on the provided entity class and hands it over for further
186158
* processing.

src/test/groovy/edu/ie3/datamodel/io/source/csv/CsvDataSourceTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ class CsvDataSourceTest extends Specification implements CsvTestDataMeta {
3333
String csvRow, String csvSep) {
3434
return super.parseCsvRow(csvRow, csvSep)
3535
}
36-
37-
String[] oldFieldVals(
38-
String csvSep, String csvRow) {
39-
return super.oldFieldVals(csvSep, csvRow)
40-
}
4136
}
4237

4338
@Shared
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
uuid,id,operator,operates_from,operates_until,node,q_characteristics,cos_phi_rated,type,charging_points,location_type,v2g_support,em
2-
798028b5-caff-4da7-bcd9-1750fdd8742c,test_csInput,8f9682df-0744-4b58-a122-f0dc730f6510,2020-03-24T15:11:31Z[UTC],2020-03-25T15:11:31Z[UTC],4ca90220-74c2-4369-9afa-a18bf068840d,cosPhiFixed:{(0.0,0.95)},0.95,hhs,4,HOME,false,977157f4-25e5-4c72-bf34-440edc778792
2+
798028b5-caff-4da7-bcd9-1750fdd8742c,test_csInput,8f9682df-0744-4b58-a122-f0dc730f6510,2020-03-24T15:11:31Z[UTC],2020-03-25T15:11:31Z[UTC],4ca90220-74c2-4369-9afa-a18bf068840d,"cosPhiFixed:{(0.00,0.95)}",0.95,hhs,4,HOME,false,977157f4-25e5-4c72-bf34-440edc778792

0 commit comments

Comments
 (0)