Helpful Scripts
Compendium of popular requests and use cases for the external API.
All the files import whitson_connect.py provided here to use a helper class WhitsonConnection which abstracts some of the API endpoint requests to use simple python functions in python script to manipulate, query data stored in our database for you.
1. Which wells are using 'Custom BHP' instead of a correlation for all calculations?
Objective: Fetch all the wells and scenarios in a list of projects and fetch their BHP input to see which wells are using the 'Custom BHP'. Generate an Excel file containing a list of these wells/scenarios and their owners.
Use Case: You can use external API to upload new production data daily, calculate bottomhole pressures fpr all the wells using the correlations but if the well uses "Custom BHP" (user-defined BHP) for all calculations, the added BHP data does not reflect in other plots because the custom BHP does not get extended to include the new BHP data automatically. Hence, we need to see which wells are using "Custom BHP" so this list of wells can directly be updated on the front end without having to check every well manually.
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 | import whitson_connect
# To fill
CLIENT = "your_domain_here" #This is the company suffix in your whitson urls ex. 'courses' in courses.whitson.com
CLIENT_ID = "your_client_id_here" # Available on request
CLIENT_SECRET = "your_client_secret" # Available on request
PROJECT_ID = "your_project_id_here" # This is the int numeric value of the project, available from the URL like '638' in https://courses.whitson.com/fields/5/projects/638/
whitson_connection = whitson_connect.WhitsonConnection(
CLIENT, CLIENT_ID, CLIENT_SECRET
)
whitson_connection.access_token = whitson_connection.get_access_token_smart()
project_ids = [638, 255, 80, 82] #Input list of project IDs to check, like Project '638' according to this URL https://courses.whitson.com/fields/5/projects/638/
#Fetching all wells and scenarios
all_wells, all_scenarios = whitson_connection.get_wells_and_scenarios_from_projects(project_ids = project_ids, page_size = 200)
#Combining wells and scenarios into one iterable
all_wells.extend(all_scenarios)
#Fetching BHP input data for all wells and scenarios
all_bhp_configs = [whitson_connection.get_well_deviation_and_perf_interval(well["id"]) for well in all_wells]
## For all wells, check if they use custom BHP and if they do,
# If they do, add to the results table of columns - Project ID, Well Name, Well ID, BHP in use, Scenario Name, Scenario owner
data = []
for i, well in enumerate(all_wells):
if all_bhp_configs[i]["bhp_for_sim"]=="custom":
scenario_well = well.get("owner")
if not scenario_well:
new_row = {"Project ID":well["project_id"], "Well Name": well["name"], "Well ID":well["id"], "BHP in use":all_bhp_configs[i]["bhp_for_sim"],
"Scenario Name": "Main", "Scenario Owner":"Default"}
else: #It is a scenario well
new_row = {"Project ID":well["project_id"], "Well Name": well["name"], "Well ID":well["id"], "BHP in use":all_bhp_configs[i]["bhp_for_sim"],
"Scenario Name": well["scenario_name"], "Scenario Owner":well["owner"]}
data.append(new_row)
#Writing to a dataframe
df = pd.DataFrame(data)
#Generating an excel output file to view/share results (in the same folder as this script)
df.to_excel(CLIENT+" - Wells Using Custom BHP.xlsx")
##Done!
|