Heroku - Cloud API¶
API End Point https://dcapyapi.herokuapp.com/ Documentation https://dcapyapi.herokuapp.com/docs
By taking advantage of the use of Pydantic (Library to make validations) a Web API has been implemented with FastAPI (A web framework for building APIs) and hosted on Heroku. This API, so far, allows the users to save, edit and delete the models configurations on the cloud.
By using the API, a user can work on any Schedule Model (Period
, Scenario
, Well
,WellsGroup
), save the model to the cloud host, then on any other time the user can continue working on it, update the cloud model or delete it
dcapy
has a wrapper for the API that allows you to make those processes in an integrated way.
from dcapy.schedule import Period
from dcapy.dca import Arps
from dcapy.auth import Credential
from datetime import date
Authentication¶
To start using the cloud API service you have to create an account on https://dcapyapi.herokuapp.com/admin/create with an username and password. Underneath the API uses a Oauth2 methodology to authenticate every time you'll make some request.
First Create a Credential
instance with a token given when the user log in on https://dcapyapi.herokuapp.com/admin/login
token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImIyZDQ5NjMyLWM0MzEtNDAzYi04OTEyLTJiZGIyOTA3NTMxNCIsIm5hbWUiOiJTYW50aWFnbyIsImxhc3RfbmFtZSI6IkN1ZXJ2byIsInVzZXJuYW1lIjoic2N1ZXJ2bzkxIiwiZXhwIjoxNjI2OTgyMTg1fQ.VQNueiQHD0cdBlhiNP0UoroLI8KjU55JhDScal0fkCg'
cred = Credential(token = token)
Now let's create a simple Period
model
dec_model = Arps(
ti = date(2021,1,1),
di = 0.3,
freq_di = 'A',
qi = [80,100],
b = 0,
fluid_rate = 250
)
p1 = Period(
name = 'Period-1908',
dca = dec_model,
start = date(2021,1,1),
end = date(2021,6,1),
freq_output='M'
)
Check the object created
print(type(p1))
print(p1.json(exclude_none=True,indent=2))
<class 'dcapy.schedule.schedule.Period'> { "name": "Period-1908", "iter": 1, "dca": { "qi": [ 80.0, 100.0 ], "di": 0.3, "b": 0.0, "ti": "2021-01-01", "freq_di": "A", "fluid_rate": 250.0 }, "start": "2021-01-01", "end": "2021-06-01", "freq_input": "D", "freq_output": "M", "type": "period" }
p1.to_file('Period1')
p1.to_file('Period2')
p1.json(exclude_unset=True)
'{"name": "Period-1908", "dca": {"qi": [80.0, 100.0], "di": 0.3, "b": 0.0, "ti": "2021-01-01", "freq_di": "A", "fluid_rate": 250.0}, "start": "2021-01-01", "end": "2021-06-01", "freq_output": "M"}'
By calling a the method insert_db
and providing the crededentials and a description the user can save the model on the cloud. It is highly recommended to write some description of the models to later identify them. If the operation is sucessfully, it returns an unique key that identify the model.
p1.insert_db(cred, description='Test_Tutorial_Period')
'c331945f-b1ea-4fb2-bb79-57d40a345427'
You don't have to memorize the key, it is saved on the attribute id
of the model
p1.id
'c331945f-b1ea-4fb2-bb79-57d40a345427'
Check the user models¶
If you want to check the user models saved on the cloud, call the credential method get_models_info
cred.get_models_info()
id | created_at | modified_at | type | description | |
---|---|---|---|---|---|
0 | 87f1fe6a-1aa7-4d7f-a130-80ec0bf78fa0 | 2021-07-01 22:46:58.411024+00:00 | 2021-07-01 22:46:58.411071+00:00 | period | Period-Cash tutorial |
1 | f1191ba8-9082-4104-9079-9c3c5747e96c | 2021-07-01 22:55:51.386600+00:00 | 2021-07-01 22:55:51.386648+00:00 | scenario | Scenario-Cash tutorial |
2 | eee95d1f-dee3-40e0-a1a7-800f83e3d7a1 | 2021-07-02 00:09:54.352606+00:00 | 2021-07-02 00:09:54.352675+00:00 | well | well-Cash tutorial |
3 | f066f385-c108-4c7b-8e79-2a55c9301d72 | 2021-07-02 00:14:51.151289+00:00 | 2021-07-02 00:14:51.151313+00:00 | wellsgroup | Tutorial-Wellsgroup |
4 | c6e698a3-cc55-4805-ad38-1027f4001951 | 2021-07-21 02:23:24.856509+00:00 | 2021-07-21 02:23:24.856551+00:00 | well | well-Cash tutorial_update |
5 | 65f4790e-a515-4a14-bb12-9109010ed5e9 | 2021-07-22 03:34:15.472286+00:00 | 2021-07-22 03:34:15.472329+00:00 | period | Period-Cash tutorial1 |
6 | 01de434e-d393-4f3e-8ecf-98e86b4dd39c | 2021-07-22 03:37:42.568885+00:00 | 2021-07-22 03:37:42.568928+00:00 | scenario | Scenario-Cash tutorial |
7 | 1b1ecf58-e252-4ea0-9ac3-66bee10cc050 | 2021-07-22 03:41:04.218514+00:00 | 2021-07-22 03:41:04.218567+00:00 | well | well-Cash tutorial_update1 |
8 | 5f625d24-517d-4890-8067-f8e4da41f779 | 2021-07-22 03:44:05.168659+00:00 | 2021-07-22 03:44:05.168703+00:00 | wellsgroup | Tutorial-Wellsgroup |
9 | c331945f-b1ea-4fb2-bb79-57d40a345427 | 2021-07-22 04:32:42.161613+00:00 | 2021-07-22 04:32:42.161652+00:00 | period | Test_Tutorial_Period |
The row #9 containst the information of the model that was just created.
You can also get only the Periods
Model
cred.get_models_info(schema='period')
id | created_at | modified_at | type | description | |
---|---|---|---|---|---|
0 | 87f1fe6a-1aa7-4d7f-a130-80ec0bf78fa0 | 2021-07-01 22:46:58.411024+00:00 | 2021-07-01 22:46:58.411071+00:00 | period | Period-Cash tutorial |
1 | 65f4790e-a515-4a14-bb12-9109010ed5e9 | 2021-07-22 03:34:15.472286+00:00 | 2021-07-22 03:34:15.472329+00:00 | period | Period-Cash tutorial1 |
2 | c331945f-b1ea-4fb2-bb79-57d40a345427 | 2021-07-22 04:32:42.161613+00:00 | 2021-07-22 04:32:42.161652+00:00 | period | Test_Tutorial_Period |
Load a Model¶
By having the id of the model you can load a model in your python environment by calling the method .get_db
p_load = Period()
p_load.get_db('c331945f-b1ea-4fb2-bb79-57d40a345427',cred)
print(type(p_load))
print(p_load.json(exclude_unset=True,indent=2))
<class 'dcapy.schedule.schedule.Period'> { "name": "Period-1908", "id": "c331945f-b1ea-4fb2-bb79-57d40a345427", "dca": { "qi": [ 80.0, 100.0 ], "di": 0.3, "b": 0.0, "ti": "2021-01-01", "freq_di": "A", "fluid_rate": 250.0 }, "start": "2021-01-01", "end": "2021-06-01", "freq_output": "M" }
Generate Forecast¶
p_load.generate_forecast()
/home/scuervo/Documents/dev/apps/dcapy/dcapy/dca/arps.py:68: RuntimeWarning: divide by zero encountered in true_divide return qi/np.power(1+b*di*time_array,1/b) /home/scuervo/Documents/dev/apps/dcapy/dcapy/dca/arps.py:85: RuntimeWarning: divide by zero encountered in true_divide g = np.power(b*di*time_array+1,(b-1)/b) /home/scuervo/Documents/dev/apps/dcapy/dcapy/dca/arps.py:86: RuntimeWarning: divide by zero encountered in true_divide h = np.power(b*di*ti+1,(b-1)/b)
oil_rate | oil_cum | iteration | oil_volume | fluid_rate | water_rate | bsw | wor | water_cum | fluid_cum | water_volume | fluid_volume | period | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date | |||||||||||||
2021-01 | 80.000000 | 0.000000 | 0 | 2448.672116 | 250.0 | 170.000000 | 0.680000 | 2.125000 | 0.000000 | 0.0 | 5332.390824 | 7750.0 | Period-1908 |
2021-02 | 77.987393 | 2448.672116 | 0 | 2303.691934 | 250.0 | 172.012607 | 0.688050 | 2.205646 | 5332.390824 | 7750.0 | 5099.211884 | 7375.0 | Period-1908 |
2021-03 | 76.213109 | 4607.383867 | 0 | 2245.736596 | 250.0 | 173.786891 | 0.695148 | 2.280276 | 10198.423768 | 14750.0 | 5156.432022 | 7375.0 | Period-1908 |
2021-04 | 74.295771 | 6940.145308 | 0 | 2267.189892 | 250.0 | 175.704229 | 0.702817 | 2.364929 | 15645.254867 | 22500.0 | 5386.122225 | 7625.0 | Period-1908 |
2021-05 | 72.486222 | 9141.763651 | 0 | 2210.152858 | 250.0 | 177.513778 | 0.710055 | 2.448931 | 20970.668217 | 30000.0 | 5442.435709 | 7625.0 | Period-1908 |
2021-06 | 70.662643 | 11360.451023 | 0 | 2218.687372 | 250.0 | 179.337357 | 0.717349 | 2.537937 | 26530.126285 | 37750.0 | 5559.458067 | 7750.0 | Period-1908 |
2021-01 | 100.000000 | 0.000000 | 1 | 3060.840145 | 250.0 | 150.000000 | 0.600000 | 1.500000 | 0.000000 | 0.0 | 4727.988530 | 7750.0 | Period-1908 |
2021-02 | 97.484241 | 3060.840145 | 1 | 2879.614917 | 250.0 | 152.515759 | 0.610063 | 1.564517 | 4727.988530 | 7750.0 | 4530.264855 | 7375.0 | Period-1908 |
2021-03 | 95.266386 | 5759.229834 | 1 | 2807.170745 | 250.0 | 154.733614 | 0.618934 | 1.624220 | 9060.529709 | 14750.0 | 4601.790027 | 7375.0 | Period-1908 |
2021-04 | 92.869714 | 8675.181635 | 1 | 2833.987365 | 250.0 | 157.130286 | 0.628521 | 1.691943 | 13931.568584 | 22500.0 | 4826.402781 | 7625.0 | Period-1908 |
2021-05 | 90.607777 | 11427.204563 | 1 | 2762.691072 | 250.0 | 159.392223 | 0.637569 | 1.759145 | 18713.335272 | 30000.0 | 4896.794636 | 7625.0 | Period-1908 |
2021-06 | 88.328304 | 14200.563778 | 1 | 2773.359215 | 250.0 | 161.671696 | 0.646687 | 1.830350 | 23725.157856 | 37750.0 | 5011.822584 | 7750.0 | Period-1908 |