Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ uv.lock
.venv/

# Jupyter checkpoints
**/.ipynb_checkpoints/
**/.ipynb_checkpoints/

/resourcecode/__pycache__
/resourcecode/*/__pycache__
*/__pycache__
/build
/doc
/.doctrees
/resourcecode.egg-info
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ See the following example:
... """)

>>> data
fp hs
2017-01-01 00:00:00 0.412 0.246
2017-01-01 01:00:00 0.410 0.212
2017-01-01 02:00:00 0.414 0.172
2017-01-01 03:00:00 0.437 0.138
2017-01-01 04:00:00 0.464 0.102
... ... ...
2017-03-19 02:00:00 0.088 0.056
2017-03-19 03:00:00 0.088 0.066
2017-03-19 04:00:00 0.089 0.078
2017-03-19 05:00:00 0.090 0.084
2017-03-19 06:00:00 0.732 0.086
fp hs
2017-01-01 00:00:00+00:00 0.412 0.246
2017-01-01 01:00:00+00:00 0.410 0.212
2017-01-01 02:00:00+00:00 0.414 0.172
2017-01-01 03:00:00+00:00 0.437 0.138
2017-01-01 04:00:00+00:00 0.464 0.102
... ... ...
2017-03-19 02:00:00+00:00 0.088 0.056
2017-03-19 03:00:00+00:00 0.088 0.066
2017-03-19 04:00:00+00:00 0.089 0.078
2017-03-19 05:00:00+00:00 0.090 0.084
2017-03-19 06:00:00+00:00 0.732 0.086
<BLANKLINE>
[1855 rows x 2 columns]

Expand Down
2 changes: 1 addition & 1 deletion resourcecode/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def get_dataframe_from_criteria(self, criteria: Union[str, dict]) -> pd.DataFram
return pd.DataFrame(
result_array[:, 1:],
columns=parsed_criteria["parameter"],
index=pd.to_datetime(index_array.astype(np.int64), unit="ms"),
index=pd.to_datetime(index_array.astype(np.int64), unit="ms", utc=True),
)

def _get_rawdata_from_criteria(self, single_parameter_criteria):
Expand Down
13 changes: 7 additions & 6 deletions resourcecode/opsplanning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def oplen_calc(critsubs, oplen, critical_operation=False, date=1, monstrt=True):
Nominal length of the operation (if no downtime), in hours
critical_operation : BOOLEAN
- False for non-critical operations:
With this flag to False, it is assumed that the operation can be
halted for the duration of weather downtime and started again
With this flag to False, it is assumed that the operation can be
halted for the duration of weather downtime and started again
- True is for continuous window search:
In this case operations can't be halted and if stopped due to
weather downtime have to restart from the beginning once the
conditions allow
In this case operations can't be halted and if stopped due to
weather downtime have to restart from the beginning once the
conditions allow

The default is non critical operation.
date : INT,DATETIME optional
Expand Down Expand Up @@ -207,6 +207,7 @@ def oplen_calc(critsubs, oplen, critical_operation=False, date=1, monstrt=True):
start=dt.datetime(yerng[0], morng[0], 1),
end=dt.datetime(yerng[1], morng[1], 1),
freq="MS",
tz="utc",
)
daterng = daterng.shift(dayval - 1, freq="D")
oplendetect = pd.Series(np.zeros(daterng.shape[0], dtype="timedelta64[s]"), index=daterng)
Expand All @@ -215,7 +216,7 @@ def oplen_calc(critsubs, oplen, critical_operation=False, date=1, monstrt=True):
daterng = pd.date_range(start=date, end=date)
oplendetect = pd.Series(np.zeros(daterng.shape[0], dtype="timedelta64[s]"), index=daterng)
else:
msg = "Variable date in single result calculation should be" " a datetime object"
msg = "Variable date in single result calculation should be a datetime object"
raise NameError(msg)
else:
raise NameError("Input option monstrt should be boolean")
Expand Down
18 changes: 9 additions & 9 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def test_get_criteria_single_parameter(client):

assert len(data) == 744
assert (data.columns == ["fp"]).all()
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00")
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00")
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00", utc=True)
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00", utc=True)
assert data.fp[0] == pytest.approx(0.074)
assert data.fp[-1] == pytest.approx(0.097)

Expand All @@ -169,8 +169,8 @@ def test_get_criteria_single_tp_parameter(client):

assert len(data) == 744
assert (data.columns == ["tp"]).all()
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00")
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00")
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00", utc=True)
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00", utc=True)
assert data.tp[0] == pytest.approx(13.51351)
assert data.tp[-1] == pytest.approx(10.30928)

Expand All @@ -180,8 +180,8 @@ def test_get_criteria_multiple_parameters(client):

assert len(data) == 744
assert (data.columns == ["fp", "hs"]).all()
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00")
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00")
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00", utc=True)
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00", utc=True)
assert data.fp[0] == pytest.approx(0.074)
assert data.fp[-1] == pytest.approx(0.097)
assert data.hs[0] == pytest.approx(0.296)
Expand All @@ -200,7 +200,7 @@ def test_get_criteria_multiple_parameters_and_none_values(client):
assert pd.isnull(data.uust[0])

# the third value is not null.
assert data.index[2] == pd.to_datetime("2017-01-01 02:00:00")
assert data.index[2] == pd.to_datetime("2017-01-01 02:00:00", utc=True)
assert data.uust[2] == pytest.approx(0.1699999962)

data = client.get_dataframe_from_criteria('{"parameter": ["uust", "fp"]}')
Expand All @@ -210,8 +210,8 @@ def test_get_criteria_multiple_parameters_and_none_values(client):

# in that case, we have two variables. The second one, fp, is not null,
# therefore the index can be completed despite that uust is null.
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00")
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00")
assert data.index[0] == pd.to_datetime("2017-01-01 00:00:00", utc=True)
assert data.index[-1] == pd.to_datetime("2017-01-31 23:00:00", utc=True)

assert data.fp[0] == pytest.approx(0.074)
assert data.fp[-1] == pytest.approx(0.097)
Expand Down
1 change: 1 addition & 0 deletions tests/test_opsplanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def data():
parse_dates=True,
dayfirst=True,
)
df = df.tz_localize("UTC")
return df


Expand Down
Loading