-
Notifications
You must be signed in to change notification settings - Fork 19
/
EntsoeFileName.java
79 lines (63 loc) · 2.63 KB
/
EntsoeFileName.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
69
70
71
72
73
74
75
76
77
78
79
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package eu.itesla_project.entsoe.util;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class EntsoeFileName {
private static final Pattern DATE_REGEX = Pattern.compile(".*(\\d{4})[- /._]?(\\d{2})[- /._]?(\\d{2})[- /._]?(\\d{2})[- /._]?(\\d{2}).*");
private final DateTime date;
private final int forecastDistance;
private final EntsoeGeographicalCode geographicalCode;
public static EntsoeFileName parse(String str) {
DateTime date = DateTime.now();
int forecastDistance = 0;
EntsoeGeographicalCode geographicalCode = null;
Matcher m = DATE_REGEX.matcher(str);
if (m.matches()) {
// time zone is Europe/Paris
int year = Integer.parseInt(m.group(1));
int month = Integer.parseInt(m.group(2));
int dayOfMonth = Integer.parseInt(m.group(3));
int hourOfDay = Integer.parseInt(m.group(4));
int minute = Integer.parseInt(m.group(5));
date = new DateTime(year, month, dayOfMonth, hourOfDay, minute, DateTimeZone.forID("Europe/Paris"));
// extract horizon and forecast distance
if (str.contains("FO")) {
forecastDistance = 60 * (6 + hourOfDay) + minute; // DACF generated at 18:00 one day ahead7
} else if (str.contains("SN")) {
forecastDistance = 0;
}
}
if (str.length() >= 19) {
geographicalCode = EntsoeGeographicalCode.valueOf(str.substring(18, 20));
}
return new EntsoeFileName(date, forecastDistance, geographicalCode);
}
private EntsoeFileName(DateTime date, int forecastDistance, EntsoeGeographicalCode geographicalCode) {
this.date = date;
this.forecastDistance = forecastDistance;
this.geographicalCode = geographicalCode;
}
public DateTime getDate() {
return date;
}
public int getForecastDistance() {
return forecastDistance;
}
public EntsoeGeographicalCode getGeographicalCode() {
return geographicalCode;
}
public String getCountry() {
return geographicalCode != null ? geographicalCode.getCountry().toString() : null;
}
}