corva-worker-python 2.3.3__py3-none-any.whl → 2.3.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: corva-worker-python
3
- Version: 2.3.3
3
+ Version: 2.3.7
4
4
  Summary: SDK for interacting with Corva
5
5
  Home-page: https://github.com/corva-ai/corva-worker-python
6
6
  Author: Jordan Ambra <jordan.ambra@corva.ai>, Mohammadreza Kamyab <m.kamyab@corva.ai>
@@ -1,9 +1,21 @@
1
+ testcase/app/__init__.py,sha256=VwSALtTIW4Vfu4dF95Zk046_8GcFeKGVtORwevAb89w,271
2
+ testcase/app/app_constants.py,sha256=7Ih4TisFF3B7prqPVsRpZDRTaOcHxsQwlRlSziwq0qw,937
3
+ testcase/app/app_lambda.py,sha256=GhmXvd241EEF8IzlE3ztN0TZK-ZmUTf0cAGAR8FQ2Qk,830
4
+ testcase/app/app_partial_rerun_merger.py,sha256=zSl6MWrPim6oG9kxe_1-qhrTSVyuu5aQpyrH8_5t9Sc,721
5
+ testcase/app/disable_module.py,sha256=HGK4aGsLrpr4tGIatybqP8e6cPukhOWtv8yOjT2Wxfw,286
6
+ testcase/app/drilling_efficiency_app.py,sha256=AQXbLBN_1pscqYSohWyvVDQOS0Xqw8eWasiKgdZx_m4,254
7
+ testcase/app/surface_mse_module.py,sha256=3dlsAGtr42LQ1KSnXNmeFYpdcqSwX5tya76YG-BIUh0,5390
8
+ testcase/state_testing_app/__init__.py,sha256=KDjBx9wBIwpAc68Z9ztPZ_w4jBe1ZkipK3a5tulb5a4,196
9
+ testcase/state_testing_app/app_constants.py,sha256=qD2nQsOhACr1HWCgVb2iQKWiv2aGe9CqkQiwT-3NARY,360
10
+ testcase/state_testing_app/app_lambda.py,sha256=UDKYAnkRHBcd-HUECGvce23HhJ9ix3ZD7XXcEzqAzcE,579
11
+ testcase/state_testing_app/state_modules.py,sha256=qdp2S2sBx_cZpzhsiK3_iMhyoVE1kYQJcnd5mXFWHDs,2647
12
+ testcase/state_testing_app/state_testing_app.py,sha256=T2YbEyPHXi9pONrIIMuYXUoX3jRwtuw1UbvQ4B_a6sg,339
1
13
  worker/__init__.py,sha256=xw-_4rRcZm65YTohJOUOZY7ZXE7WDGYwhwQxo3ng_t0,58
2
14
  worker/constants.py,sha256=beZCoZk6Tl32EzHCxP6WNtH4QPsG_Tay6sfZSnddYYI,1480
3
15
  worker/exceptions.py,sha256=ABjo2tay2TI40cVFSaKBE4i_ZqIC3IJZCw88qo2iLws,309
4
16
  worker/app/__init__.py,sha256=-PEDBW7xCBbbc3fE6pxA5JBKM_5SJaCaVFqvzS5aNxc,11596
5
17
  worker/app/modules/__init__.py,sha256=wJV7Jo_DSlkgDQqQRcmzplXGBG1SGfJIL9JHFi5hWgo,8871
6
- worker/app/modules/activity_module.py,sha256=ot1zHSBhOP76gu9RV4OWnQY1JNAq-r3nkRLtgpwdmU0,5046
18
+ worker/app/modules/activity_module.py,sha256=2qRpZK5Vej0JLKcS9SjuSu1DfVTzkjCok_Op2cycUPs,5298
7
19
  worker/app/modules/connection_module.py,sha256=qvaDgTBrf3NMA9Q1A-490fhjlhPVh_iskaMvLYK09lc,575
8
20
  worker/app/modules/depth_activity_module.py,sha256=0enhx_fhDiLRaPwVh4BDcu2KkWPzG_9Bkqt1p7RzHbQ,572
9
21
  worker/app/modules/scheduler.py,sha256=oZVLQH2p7aEQJUFXi4zL-QsGcfXGF859grI31TIt7bc,1448
@@ -11,7 +23,7 @@ worker/app/modules/time_activity_module.py,sha256=_M3UhF3FNdjUHMJX1SMFx_weqCT087
11
23
  worker/app/modules/trigger.py,sha256=OYRJCcK9wGxjvi0EcL9ZQSLZOMYR11RGLT_vynK5nF8,1438
12
24
  worker/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
25
  worker/data/alert.py,sha256=1sxY2pQMnirmAV9mNNw8MW0dllebprlHK-XgfSfAKKc,3074
14
- worker/data/api.py,sha256=rXuMv9ceo7XmtpxsXqpjEJwIrKQkuBNXN7AH1qn1hG8,4860
26
+ worker/data/api.py,sha256=quNOzm0jKsn8PsmeVovWNAF9MsawiOlwC4GCKOE1X5o,5121
15
27
  worker/data/enums.py,sha256=Owe3Kp7UrALRdl7_C829S6ULhBK_IRWUXcw_gA_2PT8,3876
16
28
  worker/data/json_encoder.py,sha256=jJcpNymA8370bgVIi_cz-EcUHjn4clC_I_t_2bK8Dqk,549
17
29
  worker/data/math.py,sha256=TSDwWZD-gY6oikhPSmpt97dcxhIFEV5wZgiZcs3FcxE,2952
@@ -40,13 +52,14 @@ worker/state/state.py,sha256=KEiw2-sB6xxyrweNE34JZ-iOD6C61sxXn3tsJvV6vLk,1267
40
52
  worker/test/__init__.py,sha256=WCh2zc6JHZuiK8lPB41_aytnSqVcpAsNj5Tio4BARAA,82
41
53
  worker/test/lambda_function_test_run.py,sha256=nbS6owG9deaHNYllxOs8klHHLR0_iSYy_jn1ZE1aB_I,6406
42
54
  worker/test/utils.py,sha256=Z7tgC_lUk2bRMlR-3tY9i5d836AdYlIY4i9WFFplheg,1479
55
+ worker/test/local_testing/README.md,sha256=dzgCrIyf3gnRI-O3nlYnLwxAmVpDHUr91W9-igni-Bg,1307
43
56
  worker/test/local_testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
57
  worker/test/local_testing/to_local_transfer.py,sha256=QYLGtT9fgDKsSK3x2QsaNDCMOpPZ5rpOsSnSl5s--WI,12343
45
58
  worker/wellbore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
- worker/wellbore/factory.py,sha256=fpvwkTxRI3uASKFMxI76nR3iuYlW6_JdUAZ-3y7uTOY,20095
59
+ worker/wellbore/factory.py,sha256=RyH6AB3GybCUVPpfISexvvPou_6TydYClrRI7h3RC48,20298
47
60
  worker/wellbore/measured_depth_finder.py,sha256=I5FmkELT0_k1ajlraeBx2Q-G3noqNTAw1wEPKyUAQOw,367
48
61
  worker/wellbore/sections_mixin.py,sha256=JNeEKm_fRxMBBD7SUx7LM8lRDJjKIeIcVvcSOKt4DTY,1873
49
- worker/wellbore/wellbore.py,sha256=syvYszkbN40BhzxCQ8m6VmSBGPp2wQR9sJ6TcSu7WO8,11907
62
+ worker/wellbore/wellbore.py,sha256=eyJtf2csKOXVE7YkffBx0jn2hnIWKRQiL_eRoLoYqmM,12195
50
63
  worker/wellbore/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
64
  worker/wellbore/model/ann.py,sha256=4xf-YQqyuWbMXDbH8XV0ohuga5r8SVO9lJVMgdxS-7c,3483
52
65
  worker/wellbore/model/annulus.py,sha256=U2JHQtJp6KPVlcAZMlO2MvrQf0I-cM2GlM969RBn8fg,3805
@@ -57,7 +70,7 @@ worker/wellbore/model/enums.py,sha256=DZm-o9ZCM1hSRHw_CcOK4Oy2Q_bmpDM7Gx3GlKQ_bv
57
70
  worker/wellbore/model/hole.py,sha256=LYikxOMJfxhc2yoKZN12pDBIl6W8apJcAGtGR3ZuvhM,10046
58
71
  worker/wellbore/model/hole_section.py,sha256=4sfP19xiY--wV1Ve2MtRoNqpya-FdPhNNmTgxLb90uk,1630
59
72
  worker/wellbore/model/riser.py,sha256=ElxvQMfdFTGGpJ1Jba_DNVue3zGAsm-05zDl1HBXwDk,824
60
- corva_worker_python-2.3.3.dist-info/METADATA,sha256=1L6_hZTla6BsYxUwHLZXj98GyI2a_f9zX5OD2rH5cHg,1020
61
- corva_worker_python-2.3.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
62
- corva_worker_python-2.3.3.dist-info/top_level.txt,sha256=KrP-SOC-I1V0U33nVzMgkHR8wO-reJYASIvWVyLyFIY,7
63
- corva_worker_python-2.3.3.dist-info/RECORD,,
73
+ corva_worker_python-2.3.7.dist-info/METADATA,sha256=rR4rsGuF4FuiGGvBswyMNEwjxr7FejdPV2IYYREHkW4,1020
74
+ corva_worker_python-2.3.7.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
75
+ corva_worker_python-2.3.7.dist-info/top_level.txt,sha256=cEiwDUvsc9ITDXhHwrvdLLLBwQNLerUOUhh1q5DZL6g,16
76
+ corva_worker_python-2.3.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ testcase
2
+ worker
@@ -0,0 +1,7 @@
1
+ """
2
+ The purpose of this simple test app is to compute Surface MSE
3
+ every 30 seconds of wits stream records. Note that this parameter
4
+ is only generated when the state is Drilling (either Rotary or Slide).
5
+ """
6
+
7
+ from testcase.app.app_constants import constants # noqa: F401
@@ -0,0 +1,24 @@
1
+ from worker import constants
2
+
3
+ constants.update(
4
+ {
5
+ "global": {
6
+ "app-name": "WorkerTest-DrillingEfficiency",
7
+ "app-key": "drilling-efficiency",
8
+ "event-type": "scheduler",
9
+ "query-limit": 3600,
10
+ "wits_query_fields": "_id, timestamp, collection, asset_id, company_id, app, metadata, data.state, "
11
+ "data.weight_on_bit, data.rotary_rpm, data.rotary_torque, data.rop",
12
+ },
13
+ "drilling-efficiency": {
14
+ "mse": {
15
+ "lookback-duration": 30,
16
+ "export-duration": 30, # update and export results every 30 seconds
17
+ "drilling-activity": ["Rotary Drilling", "Slide Drilling"],
18
+ "required-channels": ["weight_on_bit", "rotary_rpm", "rotary_torque", "rop"],
19
+ "running-string": ["drillstring"],
20
+ "reset-config": ["drillstring"],
21
+ }
22
+ },
23
+ }
24
+ )
@@ -0,0 +1,26 @@
1
+ from testcase.app.app_partial_rerun_merger import AppPartialRerunMerger
2
+ from testcase.app.drilling_efficiency_app import DrillingEfficiency
3
+ from worker.data.api import API
4
+ from worker.event.event_handler import EventHandler
5
+ from worker.mixins.logging import Logger
6
+ from worker.state import RedisHandler
7
+
8
+ REDIS_CONNECTION = None
9
+
10
+
11
+ def lambda_handler(event, context):
12
+ """
13
+ This function is the main entry point of the AWS Lambda function
14
+ :param event: a scheduler or kafka event
15
+ :param context: AWS Context
16
+ :return:
17
+ """
18
+ global REDIS_CONNECTION
19
+ REDIS_CONNECTION = RedisHandler.setup_existing_connection(REDIS_CONNECTION)
20
+
21
+ app = DrillingEfficiency()
22
+
23
+ merger = AppPartialRerunMerger(app, API(), Logger.get_logger())
24
+
25
+ event_handler = EventHandler(app, merger)
26
+ event_handler.process(event)
@@ -0,0 +1,19 @@
1
+ from worker.partial_rerun_merge.merge import PartialRerunMerge
2
+ from worker.partial_rerun_merge.models import CollectionMergingModel, MergingSchemaModel
3
+
4
+ collections = [{"collection_name": "drilling-efficiency.mse"}]
5
+
6
+ collections = [CollectionMergingModel(**collection) for collection in collections]
7
+
8
+
9
+ SCHEMA = MergingSchemaModel(collections=collections, modules=None)
10
+
11
+
12
+ class AppPartialRerunMerger(PartialRerunMerge):
13
+ def __init__(self, app, api, logger):
14
+ # adding the required modules to the schema
15
+ schema = SCHEMA
16
+ # app itself has a cache so it needs to be added to the schema as well
17
+ schema.modules = [app] + app.get_active_modules()
18
+
19
+ super().__init__(schema, api, logger)
@@ -0,0 +1,11 @@
1
+ from worker.app import TimeActivityModule
2
+
3
+
4
+ class DisableModule(TimeActivityModule):
5
+ """
6
+ The purpose of this module is to check the disable functionality
7
+ by turing it off from the testing section.
8
+ """
9
+
10
+ module_key = "mse"
11
+ collection = "another-module.collection"
@@ -0,0 +1,9 @@
1
+ from testcase.app.disable_module import DisableModule
2
+ from testcase.app.surface_mse_module import SurfaceMSE
3
+ from worker.app import App
4
+
5
+
6
+ class DrillingEfficiency(App):
7
+ # override
8
+ def get_modules(self):
9
+ return [SurfaceMSE, DisableModule]
@@ -0,0 +1,156 @@
1
+ from typing import List
2
+
3
+ import numpy as np
4
+
5
+ from testcase.app.app_constants import constants
6
+ from worker import API
7
+ from worker.app import TimeActivityModule
8
+ from worker.data.operations import nanround
9
+ from worker.exceptions import Misconfigured
10
+
11
+
12
+ class SurfaceMSE(TimeActivityModule):
13
+ module_key = "mse"
14
+ collection = "drilling-efficiency.mse"
15
+
16
+ module_state_fields = {
17
+ "last_processed_timestamp": int,
18
+ "last_exported_timestamp": int,
19
+ "last_exported_depth": float,
20
+ "active_string_type": str,
21
+ "active_string_id": str,
22
+ "drillstring_number": float,
23
+ }
24
+
25
+ # override
26
+ def run_module(self, event, beginning_results):
27
+ self.results = beginning_results
28
+
29
+ valid_activities = constants.get(f"drilling-efficiency.{self.module_key}.drilling-activity")
30
+ last_exported_timestamp = self.state.get("last_exported_timestamp", -1)
31
+
32
+ valid_records = [
33
+ r
34
+ for r in event
35
+ if r.get("data", {}).get("state", "") in valid_activities and r["timestamp"] > last_exported_timestamp
36
+ ]
37
+ if not valid_records:
38
+ return self.results
39
+
40
+ valid_timestamps = [r["timestamp"] for r in valid_records]
41
+
42
+ drillstring = get_external_data(wits=valid_records[-1])
43
+ bit_size = extract_bit_size(drillstring)
44
+
45
+ updating_frequency_duration = constants.get(f"drilling-efficiency.{self.module_key}.export-duration")
46
+
47
+ if last_exported_timestamp <= 0:
48
+ last_exported_timestamp = min(valid_timestamps) - updating_frequency_duration
49
+
50
+ max_timestamp = max(valid_timestamps)
51
+
52
+ time_check = last_exported_timestamp
53
+ while (time_check + updating_frequency_duration) <= max_timestamp:
54
+ start = time_check # start of the interval
55
+ end = start + updating_frequency_duration # end of the interval
56
+
57
+ segment_data = [r for r in valid_records if start <= r.get("timestamp", 0) <= end]
58
+ if not segment_data:
59
+ continue
60
+
61
+ mse = self.compute_average_mse(segment_data, bit_size)
62
+
63
+ segment_last_hole_depth = segment_data[-1].get("data", {}).get("hole_depth")
64
+ output = self.build_empty_output(segment_data[-1])
65
+ output["data"] = {
66
+ "surface_mse": nanround(mse, decimal_places=1), # in psi
67
+ "depth": segment_last_hole_depth,
68
+ }
69
+
70
+ self.results.append(output)
71
+
72
+ self.set_state("last_exported_timestamp", time_check)
73
+ self.set_state("last_exported_depth", segment_last_hole_depth)
74
+ time_check = end
75
+
76
+ self.debug(self.global_state.get("asset_id"), self.results)
77
+ return self.results
78
+
79
+ def compute_average_mse(self, wits_records: List[dict], bit_size: float) -> float:
80
+ """
81
+ Compute MSE for a list of drilling wits records
82
+ :param wits_records: WITS records
83
+ :param bit_size: bit size in INCH
84
+ :return: MSE in PSI
85
+ """
86
+ channels = ["weight_on_bit", "rotary_rpm", "rotary_torque", "rop"]
87
+ data = {k: [] for k in channels}
88
+ for wits in wits_records:
89
+ wits_data = wits.get("data", {})
90
+ for ch in channels:
91
+ data[ch].append(wits_data.get(ch))
92
+ ave_data = {k: np.nanmean(data[k]) for k in channels}
93
+
94
+ mse = compute_mse(
95
+ bit_size,
96
+ rop=ave_data["rop"],
97
+ rpm=ave_data["rotary_rpm"],
98
+ wob=ave_data["weight_on_bit"],
99
+ torque=ave_data["rotary_torque"],
100
+ )
101
+
102
+ return mse
103
+
104
+
105
+ def get_external_data(wits: dict) -> dict:
106
+ """
107
+ TODO
108
+ :param wits:
109
+ :return:
110
+ """
111
+ drillstring__id = wits.get("metadata", {}).get("drillstring", None)
112
+ if drillstring__id is None:
113
+ raise Misconfigured(f"Wrong drillstring _id ({drillstring__id})!")
114
+
115
+ worker = API()
116
+ drillstring = worker.get_by_id(
117
+ path="/v1/data/corva/", **{"collection": "data.drillstring", "id": drillstring__id}
118
+ ).data # dict
119
+ return drillstring
120
+
121
+
122
+ def extract_bit_size(drillstring: dict) -> float:
123
+ """
124
+ Get the bit size from a drillstring.
125
+ :param drillstring: the dictionary holding the drillstring info
126
+ :return: bit size
127
+ """
128
+ components = drillstring.get("data", {}).get("components", [])
129
+ bit = list(filter(lambda x: x["family"] == "bit", components))
130
+ if not bit:
131
+ raise Misconfigured(f"No bit in the drillstring: {drillstring}")
132
+ return bit[0].get("size", None)
133
+
134
+
135
+ def compute_mse(bit_size, rop, rpm, wob, torque, factor=0.35):
136
+ """
137
+ Compute the MSE
138
+ :param bit_size: bit size in INCH
139
+ :param rop: WITS ROP in FOOT/HOUR
140
+ :param rpm: WITS Rotary RPM in RPM
141
+ :param wob: WITS Weight on Bit in KIPS
142
+ :param torque: WITS Rotary Torque in K-FT-LBF
143
+ :param factor: Based on the recommendation of Dupriest et. al. paper
144
+ (Dupriest, Fred E., and William L. Koederitz. "Maximizing drill rates
145
+ with real-time surveillance of mechanical specific energy."
146
+ SPE/IADC Drilling Conference. Society of Petroleum Engineers, 2005.)
147
+ a factor of <b>0.35</b> is applied for surface MSE.
148
+ :return: MSE in PSI
149
+ """
150
+ bit_area = np.pi / 4 * bit_size**2
151
+
152
+ if rop < 0:
153
+ return None
154
+
155
+ mse = factor * ((wob / bit_area) + (120 * np.pi * rpm * 1000 * torque) / (bit_area * rop))
156
+ return mse
@@ -0,0 +1,6 @@
1
+ """
2
+ The purpose of this App is to test the RedisMixin functionality
3
+ This app tests saving/loading, deleting of states on Redis:
4
+ """
5
+
6
+ from testcase.app.app_constants import constants # noqa: F401
@@ -0,0 +1,15 @@
1
+ from worker import constants # noqa: #402
2
+
3
+ constants.update(
4
+ {
5
+ "global": {
6
+ "app-name": "WorkerTest.RedisMixin",
7
+ "app-key": "worker_test-state_mixin",
8
+ "event-type": "wits_stream",
9
+ "query-limit": 3600,
10
+ },
11
+ "worker_test-state_mixin": {
12
+ "redis-tester": {},
13
+ },
14
+ }
15
+ )
@@ -0,0 +1,20 @@
1
+ from testcase.state_testing_app.state_testing_app import TestingApp
2
+
3
+
4
+ def lambda_handler(event, context):
5
+ """
6
+ This function is the main entry point of the AWS Lambda function
7
+ :param event: a scheduler or kafka event
8
+ :param context: AWS Context
9
+ :return:
10
+ """
11
+ app = TestingApp()
12
+ app.load(None, event)
13
+ app.asset_id = event[0].get("asset_id")
14
+ app.state = app.load_state()
15
+
16
+ app.state["last_processed_timestamp"] = 0
17
+ app.state["message"] = "This is the app state on Redis"
18
+ app.event = event
19
+ app.run_modules()
20
+ app.save_state()
@@ -0,0 +1,77 @@
1
+ import time
2
+
3
+ from worker.app.modules import Module
4
+
5
+
6
+ class TestRedis(Module):
7
+ module_key = "redis-tester"
8
+ collection = "None"
9
+
10
+ module_state_fields = {
11
+ "message": str,
12
+ }
13
+
14
+ # override
15
+ def run_module(self, event, beginning_results):
16
+ start_timer = time.time()
17
+
18
+ self.reset_states()
19
+ self.test_save_load()
20
+ self.test_delete_states()
21
+ self.state = {"message": f"This state is auto saved for {self.module_key}"}
22
+ print(f"Redis tests completed in {int(time.time() - start_timer)} seconds.\n")
23
+
24
+ def run(self, wits_stream: list):
25
+ self.run_module(wits_stream, [])
26
+
27
+ def reset_states(self):
28
+ # Initialize and reset states
29
+ print("Initialize test")
30
+ asset_id = self.global_state["asset_id"]
31
+ state_key = self.get_formatted_state_key(asset_id, self.app_key, self.module_key)
32
+ self.delete_states(state_key)
33
+ self.get_state()
34
+
35
+ def test_save_load(self):
36
+ # Save/load tests
37
+ print("Save/load test")
38
+ self.state = {"message": "This state is and example state"}
39
+ self.save_state()
40
+ state = self.get_state()
41
+ assert self.state == state
42
+ print("Save/load test completed")
43
+
44
+ def test_delete_states(self):
45
+ # Deletion Tests
46
+ asset_id = self.global_state["asset_id"]
47
+
48
+ modules = []
49
+ for i in range(5):
50
+ _module_key = f"delete.test{i}"
51
+ module = TestRedis(self.global_state)
52
+ module.module_key = _module_key
53
+ state_key = module.get_formatted_state_key(asset_id, module.app_key, _module_key)
54
+ state = {"message": f"Redis state with {state_key=}"}
55
+ print(f"Set the {state=}")
56
+ module.state = state
57
+ module.save_state()
58
+ modules.append(module)
59
+ time.sleep(0.1) # back-off to prevent blocking by redis
60
+
61
+ # Delete Multiple
62
+ state_keys = [self.get_formatted_state_key(asset_id, module.app_key, module.module_key) for module in modules]
63
+
64
+ multiple_state_keys = state_keys[0:4]
65
+ print(f"Deleting following {multiple_state_keys=}")
66
+ self.delete_states(multiple_state_keys)
67
+ for i in range(4):
68
+ _module_key = f"delete.test{i}"
69
+ current_state = modules[i].get_state()
70
+ assert current_state == {"message": None}
71
+
72
+ # Delete Single
73
+ single_state_key = state_keys[4]
74
+ print(f"Deleting following single {single_state_key=}")
75
+ self.delete_states(single_state_key)
76
+ current_state = modules[4].get_state()
77
+ assert current_state == {"message": None}
@@ -0,0 +1,14 @@
1
+ from testcase.state_testing_app.state_modules import TestRedis
2
+ from worker.app import App
3
+
4
+
5
+ class TestingApp(App):
6
+ # override
7
+ def get_modules(self):
8
+ return [
9
+ TestRedis, # Redis testing module
10
+ ]
11
+
12
+ def load(self, event_type, event):
13
+ # Do not want to run the super().load method
14
+ return
@@ -65,7 +65,10 @@ class ActivityModule(Module):
65
65
  :return:
66
66
  """
67
67
 
68
- previous_string = self.state.get("active_string_id", "")
68
+ # State.get returns the default for a stored None, and older state may hold "", so treat any falsy stored
69
+ # value as "no active string". Otherwise no string compares unequal to no string and every run looks like a
70
+ # change.
71
+ previous_string = self.state.get("active_string_id") or None
69
72
  running_string = constants.get("{}.{}.running-string".format(self.app_key, self.module_key))
70
73
  reset_config = constants.get("{}.{}.reset-config".format(self.app_key, self.module_key))
71
74
 
worker/data/api.py CHANGED
@@ -12,6 +12,8 @@ class API(object):
12
12
  options = {"api_url": "API_ROOT_URL", "api_key": "API_KEY", "app_name": "APP_NAME"}
13
13
 
14
14
  def __init__(self, *args, **kwargs):
15
+ # X-Corva-App must carry the app key (provider.app-name), not the display name in APP_NAME
16
+ self.app_key = kwargs.pop("app_key", None) or os.getenv("APP_KEY")
15
17
  self.configure(self.options, kwargs)
16
18
 
17
19
  def configure(self, options, values):
@@ -44,7 +46,7 @@ class API(object):
44
46
  headers = {
45
47
  "Authorization": "API {0}".format(self.api_key),
46
48
  "Content-Type": content_type,
47
- "X-Corva-App": self.app_name,
49
+ "X-Corva-App": self.app_key or self.app_name,
48
50
  }
49
51
 
50
52
  method = method.lower()
@@ -153,4 +155,9 @@ def convert_python_sdk_api_to_worker_api(python_sdk_api) -> API:
153
155
  Returns:
154
156
  API: Worker API object
155
157
  """
156
- return API(api_url=python_sdk_api.api_url, api_key=python_sdk_api.api_key, app_name=python_sdk_api.app_key)
158
+ return API(
159
+ api_url=python_sdk_api.api_url,
160
+ api_key=python_sdk_api.api_key,
161
+ app_name=python_sdk_api.app_key,
162
+ app_key=python_sdk_api.app_key,
163
+ )
@@ -0,0 +1,28 @@
1
+ # Local Testing
2
+
3
+ The purpose of this project is to copy the data from Corva API to local system,
4
+ to give you an isolated environment for testing, utilizing the local API and Redis.
5
+
6
+ The first step through this process is to get/download all the required data for
7
+ a specific timeframe from qa/staging/production API and store them to local API. In
8
+ order to achieve this we need to follow a few steps to set up local api and redis.
9
+
10
+ ## Steps to Setup the Local API and Redis
11
+
12
+ Follow these steps:
13
+
14
+ - Clone Corva API repository from [this link](https://github.com/corva-ai/corva-api)
15
+ - Create a copy of the `.env.sample` and name if `.env`
16
+ - Follow the the "Getting Started" section instructions in the api repo readme.
17
+ - Go to http://localhost/admin and login with the following credentials: <br>
18
+ - Username: `superadmin@corva.ai` <br>
19
+ - Password: `ResetMeN@w0`
20
+ - Create an API key with read-write access under "People/Api Keys" menu
21
+ - Copy `.env.sample` file as `.env` and update or add the environment variables of
22
+ QA, STAGING and PRODUCTION environments.
23
+
24
+
25
+ ### Interacting with Local API Docker Container after Setup
26
+ - Run `make up` to start local api, database, and redis containers.
27
+ - After pulling the latest code from API, run `make build`.
28
+ - To stop and delete all local data run `make down`.
@@ -393,12 +393,6 @@ def add_open_holes(
393
393
  # the previous bottom depth may need to be modified.
394
394
  previous_hole_section = hole.get_last_hole_section()
395
395
 
396
- top_depth = hole.get_bottom_depth()
397
- bottom_depth = top_depth + 0.0001
398
- current_hole_section = HoleSection(
399
- top_depth=top_depth, bottom_depth=bottom_depth, inner_diameter=bit_size, hole_type=HoleType.OPEN_HOLE
400
- )
401
-
402
396
  if previous_hole_section:
403
397
  # The casing bottom depth can't be modified if the difference is more than 300 ft
404
398
  cased_hole_condition = (
@@ -409,8 +403,16 @@ def add_open_holes(
409
403
  previous_hole_section.set_bottom_depth(start_depth)
410
404
  previous_hole_section.set_length()
411
405
 
412
- if current_hole_section.eq_without_length(previous_hole_section):
413
- continue
406
+ # The new section starts at the (possibly adjusted) bottom of the previous section;
407
+ # computing it before the adjustment leaves the section inverted (bottom above top).
408
+ top_depth = hole.get_bottom_depth()
409
+ bottom_depth = top_depth + 0.0001
410
+ current_hole_section = HoleSection(
411
+ top_depth=top_depth, bottom_depth=bottom_depth, inner_diameter=bit_size, hole_type=HoleType.OPEN_HOLE
412
+ )
413
+
414
+ if previous_hole_section and current_hole_section.eq_without_length(previous_hole_section):
415
+ continue
414
416
 
415
417
  current_hole_section.set_length()
416
418
  hole.add_section(current_hole_section)
@@ -114,6 +114,13 @@ class Wellbore:
114
114
  self.under_reamer.top_depth + 0.0001
115
115
  )
116
116
 
117
+ if current_hole is None:
118
+ Logger.warn(
119
+ f"Under-reamer top depth {self.under_reamer.top_depth} is below the hole bottom depth "
120
+ f"{self.actual_hole.get_bottom_depth()}; skipping under-reamer enlargement"
121
+ )
122
+ return
123
+
117
124
  # Determine a valid start of reaming depth: either casing shoe or open hole top depth.
118
125
  if current_hole.hole_type == HoleType.CASED_HOLE:
119
126
  start_reaming_depth = current_hole.bottom_depth
@@ -1 +0,0 @@
1
- worker