Skip to content

Production

Production is the most frequently updated data category. The database accept daily production data and hourly production data as long as the date follows the format YYYY-MM-DD hh:mm.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from typing import Optional, Dict
import os
import requests

ACCESS_TOKEN = os.environ["WHITSON_API_TOKEN"]
CLIENT_NAME = os.environ["CLIENT_NAME"]


def get_well(
    project_id: Optional[int] = None,
    name: Optional[str] = None,
    uwi_api: Optional[str] = None,
):
    """
    Get a list of wells.
    """
    base_url = f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells"
    response = requests.get(
        base_url,
        headers={
            "content-type": "application/json",
            "Authorization": f"Bearer {ACCESS_TOKEN}",
        },
        params={"project_id": project_id, "name": name, "uwi_api": uwi_api},
    )
    res = response.json()
    if not res:
        raise Exception("no existing wells")
    return res


def upload_production_to_well(well_id: int, payload: Dict[str, list]):
    """
    Upload production to well.
    """
    response = requests.post(
        f"http://{CLIENT_NAME}.whitson.com/api-external/v1/wells/{well_id}/production_data",
        headers={
            "content-type": "application/json",
            "Authorization": f"Bearer {ACCESS_TOKEN}",
        },
        json=payload,
    )
    if response.status_code >= 200 and response.status_code < 300:
        print(f"success on well_id {well_id}")
    else:
        print(response.text)


if __name__ == "__main__":
    well_json = get_well(
        project_id=1, name="SPE-DATA-REPOSITORY-DATASET-1-WELL-1-OSPREY"
    )[0]
    well_id = well_json["id"]
    well_name = well_json["name"]
    print("uploading production to well: ", well_id, ", well name", well_name)

    payload = {
        "production_data": [
            {
                "date": "2015-01-01 00:00",
                "p_wf_measured": 5050,
                "p_casing": 2065,
                "p_tubing": 15,
                "qg_sc": 145.0,
                "qw_sc": 718,
                "qo_sc": 504.39,
            },
            {
                "date": "2015-01-02 00:00",
                "p_wf_measured": 5010,
                "p_casing": 1990,
                "p_tubing": 15,
                "qg_sc": 186.0,
                "qw_sc": 922,
                "qo_sc": 564.76,
            },
        ]
    }
    upload_production_to_well(well_id, payload)