forked from QuantCrimAtLeeds/PredictCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreds.py
More file actions
66 lines (52 loc) · 1.79 KB
/
Copy pathpreds.py
File metadata and controls
66 lines (52 loc) · 1.79 KB
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
"""
preds.py
~~~~~~~~
Wrappers around each prediction algorithm, and some utilities.
We import all of :mod:`open_cp.evaluation` and reuse the
:class:`StandardPredictionProvider` and subclasses thereof.
"""
from ..evaluation import *
import logging as _logging
import math as _math
_logger = _logging.getLogger(__name__)
class TimeRange():
"""A simple class to define an interface for time ranges. This class just
supports a series of equally sized, contiguous intervals, but the interface
is general.
Encapsulates a list of intervals
- `[first, first + duration)`
- `[first + duration, first + 2 * duration)`
- ...
Stops before `stop_before`.
:param first: Start of the first inverval.
:param stop_before: The final interval will not include this time point.
:param duration: Length of each interval.
"""
def __init__(self, first, stop_before, duration):
self._first = first
self._stop_before = stop_before
self._duration = duration
def __iter__(self):
st = self._first
en = st + self._duration
while en <= self._stop_before:
yield st, en
st = en
en = st + self._duration
def __len__(self):
return _math.floor((self._stop_before - self._first) / self._duration)
def __repr__(self):
return "TimeRange({} -> {}, length={})".format(self._first,
self._stop_before, self._duration)
@property
def first(self):
"""Start of the time range."""
return self._first
@property
def stop_before(self):
"""End (not inclusive) of the time range."""
return self._stop_before
@property
def duration(self):
"""Gap between each entry."""
return self._duration