Skip to content

Commit f4964d3

Browse files
Merge branch 'SC-1697' into 'develop'
SC-1697: Fix calc trace points filtering See merge request SOLO-band/python-sdk!88
2 parents 7a5d457 + 9a7a5b6 commit f4964d3

File tree

4 files changed

+261
-109
lines changed

4 files changed

+261
-109
lines changed

src/rogii_solo/trace.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,22 @@ def to_dict(self, time_from: str = None, time_to: str = None):
211211

212212
class CalcTracePointRepository(TracePointRepository):
213213
def to_dict(self, time_from: str = None, time_to: str = None):
214-
time_from_dt = get_datetime(time_from if time_from else self.start_date_time_index)
215-
time_to_dt = get_datetime(time_to if time_to else self.last_date_time_index)
214+
time_from_dt = max(
215+
get_datetime(time_from or self.start_date_time_index),
216+
get_datetime(self.start_date_time_index),
217+
)
218+
time_to_dt = min(get_datetime(time_to or self.last_date_time_index), get_datetime(self.last_date_time_index))
216219

217220
points_data = []
218221

219222
for point in self:
220223
point_start_dt = get_datetime(point.start)
221224
point_end_dt = get_datetime(point.end)
222225

223-
if (time_to_dt >= point_start_dt or time_to_dt > point_end_dt) and (
224-
time_from_dt <= point_start_dt or time_from_dt < point_end_dt
226+
if (
227+
(point_start_dt >= time_from_dt and point_end_dt <= time_to_dt)
228+
or (time_from_dt < point_end_dt <= time_to_dt)
229+
or (time_from_dt <= point_start_dt < time_to_dt)
225230
):
226231
points_data.append(point.to_dict())
227232

tests/main/test_solo_client.py

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from rogii_solo.calculations.interpretation import get_last_segment_dip
66
from rogii_solo.exceptions import InvalidProjectException, ProjectNotFoundException
77
from tests.papi_data import (
8-
CALC_TRACE_DATA_RESPONSE,
9-
CALC_TRACE_NAME,
108
EARTH_MODEL_NAME,
119
EI_ABSENT_HORIZONS_LAST_SEGMENT_OUT_ID,
1210
EI_ALL_SEGMENTS_OUT_ID,
@@ -31,8 +29,6 @@
3129
STARRED_TOP_TOP_NAME,
3230
STARRED_TOPSET_NAME,
3331
TARGET_LINE_NAME,
34-
TIME_TRACE_DATA_RESPONSE,
35-
TIME_TRACE_NAME,
3632
TYPEWELL_NAME,
3733
WELL_NAME,
3834
)
@@ -383,98 +379,6 @@ def test_get_mudlog(project):
383379
assert mudlog.logs.to_df().at[0, 'MD'] == mudlog.logs[0].points.to_dict()[0]['md']
384380

385381

386-
def test_get_time_trace(project):
387-
start_datetime = '2020-08-31T12:00:00Z'
388-
end_datetime = '2022-06-10T12:17:43.000Z'
389-
390-
well = project.wells.find_by_name(WELL_NAME)
391-
assert well is not None
392-
393-
time_traces = well.time_traces
394-
assert time_traces is not None
395-
396-
traces_data = time_traces.to_dict()
397-
traces_df = time_traces.to_df()
398-
assert traces_data
399-
assert not traces_df.empty
400-
401-
time_trace = time_traces.find_by_name(TIME_TRACE_NAME)
402-
assert time_trace is not None
403-
404-
trace_points = time_trace.points
405-
assert trace_points is not None
406-
407-
trace_points_data = trace_points.to_dict()
408-
assert trace_points_data
409-
assert len(trace_points_data) == len(trace_points)
410-
411-
trace_points_data = trace_points.to_dict(time_from=start_datetime, time_to=end_datetime)
412-
trace_points_df = trace_points.to_df(time_from=start_datetime, time_to=end_datetime)
413-
414-
assert trace_points_data
415-
assert not trace_points_df.empty
416-
417-
point_index = 2
418-
point = TIME_TRACE_DATA_RESPONSE['content'][point_index]
419-
420-
assert trace_points_data[point_index]['value'] == point['value']
421-
assert trace_points_data[point_index]['index'] == point['index']
422-
423-
assert trace_points_df.at[point_index, 'value'] == point['value']
424-
assert trace_points_df.at[point_index, 'index'] == point['index']
425-
426-
427-
def test_get_calc_trace(project):
428-
start_datetime = '2022-06-10T12:00:00Z'
429-
end_datetime = '2022-06-10T13:50:00Z'
430-
431-
well = project.wells.find_by_name(WELL_NAME)
432-
assert well is not None
433-
434-
calc_traces = well.calc_traces
435-
assert calc_traces is not None
436-
437-
traces_data = calc_traces.to_dict()
438-
traces_df = calc_traces.to_df()
439-
assert traces_data
440-
assert not traces_df.empty
441-
442-
calc_trace = calc_traces.find_by_name(CALC_TRACE_NAME)
443-
assert calc_trace is not None
444-
445-
rac_codes = calc_trace.rac_codes
446-
assert rac_codes
447-
448-
rac_codes_data = rac_codes.to_dict()
449-
rac_codes_df = rac_codes.to_df()
450-
assert rac_codes_data
451-
assert not rac_codes_df.empty
452-
453-
trace_points = calc_trace.points
454-
assert trace_points is not None
455-
456-
trace_points_data = trace_points.to_dict()
457-
assert trace_points_data
458-
assert len(trace_points_data) == len(trace_points)
459-
460-
trace_points_data = trace_points.to_dict(time_from=start_datetime, time_to=end_datetime)
461-
trace_points_df = trace_points.to_df(time_from=start_datetime, time_to=end_datetime)
462-
463-
assert trace_points_data
464-
assert not trace_points_df.empty
465-
466-
point_index = 2
467-
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
468-
469-
assert trace_points_data[point_index]['start'] == point['start']
470-
assert trace_points_data[point_index]['end'] == point['end']
471-
assert trace_points_data[point_index]['value'] == point['value']
472-
473-
assert trace_points_df.at[point_index, 'start'] == point['start']
474-
assert trace_points_df.at[point_index, 'end'] == point['end']
475-
assert trace_points_df.at[point_index, 'value'] == point['value']
476-
477-
478382
def test_get_well_linked_typewells(project):
479383
well = project.wells.find_by_name(WELL_NAME)
480384
typewell = project.typewells.find_by_name(TYPEWELL_NAME)

tests/main/test_traces.py

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
from tests.papi_data import (
2+
CALC_TRACE_DATA_RESPONSE,
3+
CALC_TRACE_NAME,
4+
TIME_TRACE_DATA_RESPONSE,
5+
TIME_TRACE_NAME,
6+
WELL_NAME,
7+
)
8+
9+
10+
def test_get_time_trace(project):
11+
start_datetime = '2020-08-31T12:00:00Z'
12+
end_datetime = '2022-06-10T12:17:43.000Z'
13+
14+
well = project.wells.find_by_name(WELL_NAME)
15+
assert well is not None
16+
17+
time_traces = well.time_traces
18+
assert time_traces is not None
19+
20+
traces_data = time_traces.to_dict()
21+
traces_df = time_traces.to_df()
22+
assert traces_data
23+
assert not traces_df.empty
24+
25+
time_trace = time_traces.find_by_name(TIME_TRACE_NAME)
26+
assert time_trace is not None
27+
28+
trace_points = time_trace.points
29+
assert trace_points is not None
30+
31+
trace_points_data = trace_points.to_dict()
32+
assert trace_points_data
33+
assert len(trace_points_data) == len(trace_points)
34+
35+
trace_points_data = trace_points.to_dict(time_from=start_datetime, time_to=end_datetime)
36+
trace_points_df = trace_points.to_df(time_from=start_datetime, time_to=end_datetime)
37+
38+
assert trace_points_data
39+
assert not trace_points_df.empty
40+
41+
point_index = 2
42+
point = TIME_TRACE_DATA_RESPONSE['content'][point_index]
43+
44+
assert trace_points_data[point_index]['value'] == point['value']
45+
assert trace_points_data[point_index]['index'] == point['index']
46+
47+
assert trace_points_df.at[point_index, 'value'] == point['value']
48+
assert trace_points_df.at[point_index, 'index'] == point['index']
49+
50+
51+
def test_get_calc_trace(project):
52+
well = project.wells.find_by_name(WELL_NAME)
53+
assert well is not None
54+
55+
calc_traces = well.calc_traces
56+
assert calc_traces is not None
57+
58+
traces_data = calc_traces.to_dict()
59+
traces_df = calc_traces.to_df()
60+
assert traces_data
61+
assert not traces_df.empty
62+
63+
calc_trace = calc_traces.find_by_name(CALC_TRACE_NAME)
64+
assert calc_trace is not None
65+
66+
rac_codes = calc_trace.rac_codes
67+
assert rac_codes
68+
69+
rac_codes_data = rac_codes.to_dict()
70+
rac_codes_df = rac_codes.to_df()
71+
assert rac_codes_data
72+
assert not rac_codes_df.empty
73+
74+
trace_points = calc_trace.points
75+
assert trace_points is not None
76+
77+
trace_points_data = trace_points.to_dict()
78+
trace_points_df = trace_points.to_df()
79+
assert trace_points_data
80+
assert not trace_points_df.empty
81+
assert len(trace_points_data) == len(trace_points_df) == len(CALC_TRACE_DATA_RESPONSE['content'])
82+
83+
84+
def test_calc_trace_before_interval(project):
85+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
86+
assert calc_trace is not None
87+
88+
trace_points = calc_trace.points
89+
assert trace_points is not None
90+
91+
time_from = '2020-08-01T10:00:00Z'
92+
time_to = '2020-09-01T10:00:00Z'
93+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
94+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
95+
assert not trace_points_data
96+
assert trace_points_df.empty
97+
98+
99+
def test_calc_trace_after_interval(project):
100+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
101+
assert calc_trace is not None
102+
103+
trace_points = calc_trace.points
104+
assert trace_points is not None
105+
106+
time_from = '2020-09-13T10:53:19Z'
107+
time_to = '2020-10-13T10:53:19Z'
108+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
109+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
110+
assert not trace_points_data
111+
assert trace_points_df.empty
112+
113+
114+
def test_calc_trace_interval_boundaries(project):
115+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
116+
assert calc_trace is not None
117+
118+
trace_points = calc_trace.points
119+
assert trace_points is not None
120+
121+
point_index = 0
122+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
123+
time_from = point['start']
124+
time_to = point['end']
125+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
126+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
127+
assert len(trace_points_data) == len(trace_points_df) == 1
128+
129+
assert trace_points_data[point_index]['start'] == point['start']
130+
assert trace_points_data[point_index]['end'] == point['end']
131+
assert trace_points_data[point_index]['value'] == point['value']
132+
133+
point_index = -1
134+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
135+
time_from = point['start']
136+
time_to = point['end']
137+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
138+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
139+
assert len(trace_points_data) == len(trace_points_df) == 1
140+
141+
assert trace_points_data[point_index]['start'] == point['start']
142+
assert trace_points_data[point_index]['end'] == point['end']
143+
assert trace_points_data[point_index]['value'] == point['value']
144+
145+
146+
def test_calc_trace_interval_middle(project):
147+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
148+
assert calc_trace is not None
149+
150+
trace_points = calc_trace.points
151+
assert trace_points is not None
152+
153+
time_from = '2020-09-03T11:53:09Z'
154+
time_to = '2020-09-04T06:11:37Z'
155+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
156+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
157+
assert len(trace_points_data) == len(trace_points_df) == 2
158+
159+
for point_index in [1, 2]:
160+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
161+
assert trace_points_data[point_index - 1]['start'] == point['start']
162+
assert trace_points_data[point_index - 1]['end'] == point['end']
163+
assert trace_points_data[point_index - 1]['value'] == point['value']
164+
165+
166+
def test_calc_trace_after_interval_start(project):
167+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
168+
assert calc_trace is not None
169+
170+
trace_points = calc_trace.points
171+
assert trace_points is not None
172+
173+
time_from = '2020-09-01T10:00:00Z'
174+
time_to = '2020-09-01T10:00:01Z'
175+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
176+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
177+
assert len(trace_points_data) == len(trace_points_df) == 1
178+
179+
point_index = 0
180+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
181+
assert trace_points_data[point_index]['start'] == point['start']
182+
assert trace_points_data[point_index]['end'] == point['end']
183+
assert trace_points_data[point_index]['value'] == point['value']
184+
185+
186+
def test_calc_trace_after_interval_start_no_time_from(project):
187+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
188+
assert calc_trace is not None
189+
190+
trace_points = calc_trace.points
191+
assert trace_points is not None
192+
193+
time_from = None
194+
time_to = '2020-09-01T10:00:01Z'
195+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
196+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
197+
assert len(trace_points_data) == len(trace_points_df) == 1
198+
199+
point_index = 0
200+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
201+
assert trace_points_data[point_index]['start'] == point['start']
202+
assert trace_points_data[point_index]['end'] == point['end']
203+
assert trace_points_data[point_index]['value'] == point['value']
204+
205+
206+
def test_calc_trace_before_interval_end(project):
207+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
208+
assert calc_trace is not None
209+
210+
trace_points = calc_trace.points
211+
assert trace_points is not None
212+
213+
time_from = '2020-09-13T10:53:18Z'
214+
time_to = '2020-10-13T10:53:19Z'
215+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
216+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
217+
assert len(trace_points_data) == len(trace_points_df) == 1
218+
219+
point_index = -1
220+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
221+
assert trace_points_data[point_index]['start'] == point['start']
222+
assert trace_points_data[point_index]['end'] == point['end']
223+
assert trace_points_data[point_index]['value'] == point['value']
224+
225+
226+
def test_calc_trace_before_interval_end_no_time_to(project):
227+
calc_trace = project.wells.find_by_name(WELL_NAME).calc_traces.find_by_name(CALC_TRACE_NAME)
228+
assert calc_trace is not None
229+
230+
trace_points = calc_trace.points
231+
assert trace_points is not None
232+
233+
time_from = '2020-09-13T10:53:18Z'
234+
time_to = None
235+
trace_points_data = trace_points.to_dict(time_from=time_from, time_to=time_to)
236+
trace_points_df = trace_points.to_df(time_from=time_from, time_to=time_to)
237+
assert len(trace_points_data) == len(trace_points_df) == 1
238+
239+
point_index = -1
240+
point = CALC_TRACE_DATA_RESPONSE['content'][point_index]
241+
assert trace_points_data[point_index]['start'] == point['start']
242+
assert trace_points_data[point_index]['end'] == point['end']
243+
assert trace_points_data[point_index]['value'] == point['value']

0 commit comments

Comments
 (0)