Skip to content

Commit 915ba35

Browse files
committed
Merge branch 'SC-1221' into 'develop'
SC-1221: Add meta table for TimeTraces object See merge request SOLO-band/python-sdk!66
2 parents a35683f + ca34f4b commit 915ba35

File tree

7 files changed

+38
-78
lines changed

7 files changed

+38
-78
lines changed

src/rogii_solo/papi/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ def fetch_well_mapped_traces(self,
958958
def fetch_well_time_trace(self,
959959
well_id: str,
960960
trace_id: str,
961-
time_from: str,
961+
time_from: Optional[str] = None,
962962
time_to: Optional[str] = None,
963963
trace_hash: Optional[str] = None,
964964
headers: Optional[Dict] = None

src/rogii_solo/papi/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,10 @@ def get_well_mapped_time_traces_data(self, well_id: str, **kwargs) -> PapiDataLi
283283
def get_well_time_trace_data(self,
284284
well_id: str,
285285
trace_id: str,
286-
time_from: str,
287286
**kwargs) -> PapiDataList:
288287
return self.fetch_well_time_trace(
289288
well_id=well_id,
290289
trace_id=trace_id,
291-
time_from=time_from,
292290
**kwargs
293291
)
294292

src/rogii_solo/trace.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Dict
22

33
from pandas import DataFrame
44

@@ -17,7 +17,7 @@ def __init__(self, papi_client: PapiClient, **kwargs):
1717

1818
self.__dict__.update(kwargs)
1919

20-
def to_dict(self, *args, **kwargs) -> Dict[str, Any]:
20+
def to_dict(self, *args, **kwargs) -> Dict:
2121
return self._get_data()
2222

2323
def to_df(self, *args, **kwargs) -> TraceType:
@@ -47,26 +47,36 @@ def __init__(self, papi_client: PapiClient, well: 'rogii_solo.well.Well', **kwar
4747
self.well = well
4848
self.hash = None
4949
self.unit = None
50+
self.start_date_time_index = None
51+
self.last_date_time_index = None
5052

5153
self.__dict__.update(kwargs)
5254

53-
def to_dict(self, time_from: str, time_to: str) -> Dict[str, Any]:
55+
def to_dict(self, time_from: str = None, time_to: str = None) -> Dict:
5456
return self._get_data(time_from=time_from, time_to=time_to)
5557

56-
def to_df(self, time_from: str, time_to: str) -> TraceType:
58+
def to_df(self, time_from: str = None, time_to: str = None) -> TraceType:
5759
data = self._get_data(time_from=time_from, time_to=time_to)
5860

5961
return {
6062
'meta': DataFrame([data['meta']]),
6163
'points': DataFrame(data['points']),
6264
}
6365

64-
def _get_data(self, time_from: str, time_to: str):
66+
def _get_data(self, time_from: str = None, time_to: str = None):
67+
if time_from is None:
68+
time_from = self.start_date_time_index
69+
70+
if time_to is None:
71+
time_to = self.last_date_time_index
72+
6573
meta = {
6674
'uuid': self.uuid,
6775
'name': self.name,
6876
'hash': self.hash,
69-
'unit': self.unit
77+
'unit': self.unit,
78+
'start_date_time_index': self.start_date_time_index,
79+
'last_date_time_index': self.last_date_time_index
7080
}
7181
points = self._get_points(time_from=time_from, time_to=time_to)
7282

@@ -76,9 +86,6 @@ def _get_data(self, time_from: str, time_to: str):
7686
}
7787

7888
def _get_points(self, time_from: str, time_to: str):
79-
if time_from is None or time_to is None:
80-
return []
81-
8289
return self._papi_client.get_well_time_trace_data(
8390
well_id=self.well.uuid,
8491
trace_id=self.uuid,

src/rogii_solo/well.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import rogii_solo.project
66
from rogii_solo.base import ComplexObject, ObjectRepository
77
from rogii_solo.calculations.enums import ELogMeasureUnits
8-
from rogii_solo.exceptions import TraceNotFoundException
98
from rogii_solo.interpretation import Interpretation
109
from rogii_solo.log import Log
1110
from rogii_solo.mudlog import Mudlog
@@ -303,36 +302,16 @@ def _get_mudlogs_data(self) -> DataList:
303302
def time_traces(self) -> ObjectRepository[TimeTrace]:
304303
if self._time_traces is None:
305304
mapped_traces = self._get_time_traces_data()
306-
named_traces = []
307-
308-
for mapped_trace in mapped_traces:
309-
try:
310-
name = self._get_trace_name(mapped_trace['uuid'])
311-
except TraceNotFoundException:
312-
name = 'Unknown trace'
313-
named_traces.append({
314-
**mapped_trace,
315-
'name': name
316-
})
317305

318306
self._time_traces = ObjectRepository(
319307
objects=[
320308
TimeTrace(papi_client=self._papi_client, well=self, **item)
321-
for item in named_traces
309+
for item in mapped_traces
322310
]
323311
)
324312

325313
return self._time_traces
326314

327-
def _get_trace_name(self, trace_id: str):
328-
traces = self._papi_client.get_traces()
329-
330-
for trace in traces:
331-
if trace['uuid'] == trace_id:
332-
return trace['name']
333-
334-
raise TraceNotFoundException(f'Trace with id={trace_id} not found.')
335-
336315
def _get_time_traces_data(self) -> DataList:
337316
if self._time_traces_data is None:
338317
self._time_traces_data = self._papi_client.get_well_mapped_time_traces_data(self.uuid)

tests/papi_data.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,58 +2698,35 @@
26982698
'content': [
26992699
{
27002700
'uuid': '793b06f6-d494-45e0-9ed8-b5e8e916a2a8',
2701+
'name': 'Bit depth',
27012702
'hash': 'bd9863171705c3a0bf3e334cdcfcb85d',
2702-
'unit': ''
2703+
'unit': '',
2704+
'start_date_time_index': '2020-09-01T10:00:00Z',
2705+
'last_date_time_index': '2020-09-13T10:53:19Z'
27032706
},
27042707
{
27052708
'uuid': '11b379f9-184b-465a-beb8-7307c7b4b1d9',
2709+
'name': 'Hole Depth',
27062710
'hash': 'bdf8d4fbfc4a9238a0a77077fc8c7e89',
2707-
'unit': 'm'
2711+
'unit': 'm',
2712+
'start_date_time_index': '2020-09-01T10:00:00Z',
2713+
'last_date_time_index': '2020-09-13T10:53:19Z'
27082714
},
27092715
{
27102716
'uuid': '491c2160-c65b-4ca0-afa9-7514fc6f7c56',
2717+
'name': 'Block position',
27112718
'hash': '1afd16706047b52fae650a4c90c5e212',
2712-
'unit': 'm'
2719+
'unit': 'm',
2720+
'start_date_time_index': '2020-09-01T10:00:00Z',
2721+
'last_date_time_index': '2020-09-13T10:53:19Z'
27132722
},
27142723
{
27152724
'uuid': '8752123d-d270-4eb6-b132-ba0f3e0d83b8',
2725+
'name': 'Hookload',
27162726
'hash': '68e05d9c28dc1440d606cd2ea421e822',
2717-
'unit': ''
2718-
},
2719-
{
2720-
'uuid': '8752123d-d270-4eb6-b132-ba0f3e0d83b8',
2721-
'hash': 'f057732b91f6c397cfe98f4233f882fd',
2722-
'unit': ''
2723-
},
2724-
{
2725-
'uuid': 'c908bc68-0e9b-4368-a2be-97b48cbd5440',
2726-
'hash': '62c94c73d18fa1dab139a63fadd6cda2',
2727-
'unit': ''
2728-
},
2729-
{
2730-
'uuid': '2b2ad244-f208-4bb9-9b7c-6bbde9483635',
2731-
'hash': '9ffabe39ac818d9a5452710039cd0044',
2732-
'unit': ''
2733-
},
2734-
{
2735-
'uuid': '77c1bd4d-0fc1-470f-a24c-e28a5dd4c5fc',
2736-
'hash': '10d2ef4b350e8321309310af6aaab08c',
2737-
'unit': ''
2738-
},
2739-
{
2740-
'uuid': '0a745541-0a23-45be-870d-9fdd8a1849c6',
2741-
'hash': '8046e97e52a04a93f3401c5afcd06340',
2742-
'unit': ''
2743-
},
2744-
{
2745-
'uuid': '9f7ed05c-66cd-441c-855d-a4aec51b33e2',
2746-
'hash': 'd0419aeed61716dda7a784e237fa0323',
2747-
'unit': ''
2748-
},
2749-
{
2750-
'uuid': '98bce1cd-fda0-41dd-8d04-e6020dd6e3e1',
2751-
'hash': '7fd89649a07b54b842712965799b7d99',
2752-
'unit': ''
2727+
'unit': '',
2728+
'start_date_time_index': '2020-09-01T10:00:00Z',
2729+
'last_date_time_index': '2020-09-13T10:53:19Z'
27532730
}
27542731
]
27552732
}

tests/test_solo_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ def convert_to_datetime_tz(time_string: str):
399399

400400
start_datetime_tz = convert_to_datetime_tz(START_DATETIME)
401401
end_datetime_tz = convert_to_datetime_tz(END_DATETIME)
402-
time_trace_data = time_trace.to_dict(start_datetime_tz, end_datetime_tz)
403-
time_trace_df = time_trace.to_df(start_datetime_tz, end_datetime_tz)
402+
time_trace_data = time_trace.to_dict(time_from=start_datetime_tz, time_to=end_datetime_tz)
403+
time_trace_df = time_trace.to_df(time_from=start_datetime_tz, time_to=end_datetime_tz)
404404

405405
assert time_trace_data['meta']['name'] == TRACE_NAME
406406

tests/test_solo_client_papi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import datetime
22
from math import fabs
3-
import random
43
import pytest
54
import random
65
from typing import Any
@@ -660,8 +659,8 @@ def convert_to_datetime_tz(time_string: str):
660659

661660
start_datetime_tz = convert_to_datetime_tz(START_DATETIME)
662661
end_datetime_tz = convert_to_datetime_tz(END_DATETIME)
663-
time_trace_data = time_trace.to_dict(start_datetime_tz, end_datetime_tz)
664-
time_trace_df = time_trace.to_df(start_datetime_tz, end_datetime_tz)
662+
time_trace_data = time_trace.to_dict(time_from=start_datetime_tz, time_to=end_datetime_tz)
663+
time_trace_df = time_trace.to_df(time_from=start_datetime_tz, time_to=end_datetime_tz)
665664

666665
assert time_trace_data['meta']['name'] == TRACE_NAME
667666

0 commit comments

Comments
 (0)