-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvWindowedTimeSeriesSourceTest.groovy
154 lines (129 loc) · 4.98 KB
/
CsvWindowedTimeSeriesSourceTest.groovy
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* © 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.source.csv
import edu.ie3.datamodel.io.factory.timeseries.TimeBasedSimpleValueFactory
import edu.ie3.datamodel.io.naming.FileNamingStrategy
import edu.ie3.datamodel.models.StandardUnits
import edu.ie3.datamodel.models.value.EnergyPriceValue
import edu.ie3.util.interval.ClosedInterval
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities
import java.time.Duration
import java.time.ZoneId
import java.time.ZonedDateTime
class CsvWindowedTimeSeriesSourceTest extends Specification implements CsvTestDataMeta {
def "The windowed time series source is able to query an instance in time"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def source = new CsvWindowedTimeSeriesSource(
";",
timeSeriesFolderPath,
"its_c_2fcb3e53-b94a-4b96-bea4-c469e499f1a1",
new FileNamingStrategy(),
Duration.ofHours(2L),
EnergyPriceValue,
factory)
def expected = new EnergyPriceValue(Quantities.getQuantity(125.0, StandardUnits.ENERGY_PRICE))
when:
def actual = source.getValue(ZonedDateTime.of(2020, 1, 1, 0, 15, 0, 0, ZoneId.of("UTC")))
then:
actual.isPresent()
actual.get() == expected
source.close()
}
def "The windowed time series source is able to query multiple instances in time"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def source = new CsvWindowedTimeSeriesSource(
";",
timeSeriesFolderPath,
"its_c_2fcb3e53-b94a-4b96-bea4-c469e499f1a1",
new FileNamingStrategy(),
Duration.ofHours(2L),
EnergyPriceValue,
factory)
when:
source.getValue(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")))
source.getValue(ZonedDateTime.of(2020, 1, 1, 0, 15, 0, 0, ZoneId.of("UTC")))
then:
noExceptionThrown()
source.close()
}
def "The windowed time series source throws an exception, if the queried time is before the currently covered interval"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def source = new CsvWindowedTimeSeriesSource(
";",
timeSeriesFolderPath,
"its_c_2fcb3e53-b94a-4b96-bea4-c469e499f1a1",
new FileNamingStrategy(),
Duration.ofHours(2L),
EnergyPriceValue,
factory)
when:
source.getValue(ZonedDateTime.of(2020, 1, 1, 0, 15, 0, 0, ZoneId.of("UTC")))
source.getValue(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")))
then:
def thrown = thrown(RuntimeException)
thrown.message == "The buffer window already passed your desired time instance '2020-01-01T00:00Z[UTC]'."
source.close()
}
def "The windowed time series source throws an exception, if the queried time frame starts before the currently covered interval"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def source = new CsvWindowedTimeSeriesSource(
";",
timeSeriesFolderPath,
"its_c_2fcb3e53-b94a-4b96-bea4-c469e499f1a1",
new FileNamingStrategy(),
Duration.ofHours(2L),
EnergyPriceValue,
factory)
def start = ZonedDateTime.of(2020, 1, 1, 0, 00, 0, 0, ZoneId.of("UTC"))
when:
source.getValue(ZonedDateTime.of(2020, 1, 1, 0, 0, 15, 0, ZoneId.of("UTC")))
source.getTimeSeries(new ClosedInterval<ZonedDateTime>(start, start.plusHours(2L)))
then:
def thrown = thrown(RuntimeException)
thrown.message == "The buffer window already passed the start '2020-01-01T00:00Z[UTC]' of your desired time frame."
source.close()
}
def "The windowed time series source is able to load a time series for a given interval"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def source = new CsvWindowedTimeSeriesSource(
";",
timeSeriesFolderPath,
"its_c_2fcb3e53-b94a-4b96-bea4-c469e499f1a1",
new FileNamingStrategy(),
Duration.ofHours(2L),
EnergyPriceValue,
factory)
def start = ZonedDateTime.of(2020, 1, 1, 0, 00, 0, 0, ZoneId.of("UTC"))
def end = ZonedDateTime.of(2020, 1, 1, 0, 15, 0, 0, ZoneId.of("UTC"))
when:
def actual = source.getTimeSeries(new ClosedInterval<ZonedDateTime>(start, end))
then:
actual.entries.size() == 2
source.close()
}
def "The windowed time series source is able to determine all available time steps"() {
given:
def factory = new TimeBasedSimpleValueFactory(EnergyPriceValue)
def source = new CsvWindowedTimeSeriesSource(
";",
timeSeriesFolderPath,
"its_c_2fcb3e53-b94a-4b96-bea4-c469e499f1a1",
new FileNamingStrategy(),
Duration.ofHours(2L),
EnergyPriceValue,
factory)
when:
def actual = source.availableTimeSteps
then:
actual.size() == 2
}
}