Spaces:
Runtime error
Runtime error
AmrGharieb
commited on
Commit
•
7a3bca6
1
Parent(s):
bb86b4f
Upload app.py
Browse files
app.py
CHANGED
@@ -1,142 +1,145 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
from datetime import datetime
|
4 |
-
from streamlit_ext import download_button as down_btn
|
5 |
-
|
6 |
-
|
7 |
-
def generate_perforations(df,plug_df):
|
8 |
-
content = "UNITS METRIC\n\n"
|
9 |
-
|
10 |
-
# Iterate through unique well names
|
11 |
-
for well_name in df['well'].unique():
|
12 |
-
content += f'WELLNAME "{well_name}"\n'
|
13 |
-
|
14 |
-
# Filter the dataframe for the current well
|
15 |
-
well_df = df[df['well'] == well_name]
|
16 |
-
|
17 |
-
# Iterate through rows of the filtered dataframe
|
18 |
-
for index, row in well_df.iterrows():
|
19 |
-
if row['type'] == 'p':
|
20 |
-
date = row['date'].strftime('%d/%m/%Y')
|
21 |
-
top = row['top']
|
22 |
-
btm = row['btm']
|
23 |
-
# Write the perforation line to the content
|
24 |
-
content += f'{date} perforation {top} {btm} 0.1905 0 0 0\n'
|
25 |
-
|
26 |
-
if row['type'] == 's':
|
27 |
-
date = row['date'].strftime('%d/%m/%Y')
|
28 |
-
top = row['top']
|
29 |
-
btm = row['btm']
|
30 |
-
# Write the shut-in line to the content
|
31 |
-
content += f'{date} squeeze {top} {btm}\n'
|
32 |
-
|
33 |
-
# Filter the plug dataframe for the current well
|
34 |
-
plug_well_df = plug_df[plug_df['well'] == well_name]
|
35 |
-
|
36 |
-
# Iterate through rows of the filtered plug dataframe
|
37 |
-
for index, plug_row in plug_well_df.iterrows():
|
38 |
-
date = plug_row['date'].strftime('%d/%m/%Y')
|
39 |
-
depth = plug_row['depth']
|
40 |
-
|
41 |
-
# Filter the well dataframe based on the plug depth
|
42 |
-
filtered_well_df = well_df[(well_df['top'] >= depth) | (well_df['btm'] >= depth)]
|
43 |
-
|
44 |
-
# Iterate through rows of the filtered well dataframe
|
45 |
-
for _, filtered_row in filtered_well_df.iterrows():
|
46 |
-
top = filtered_row['top']
|
47 |
-
btm = filtered_row['btm']
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
content
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
#
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
content += f'
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
|
|
142 |
main()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime
|
4 |
+
from streamlit_ext import download_button as down_btn
|
5 |
+
|
6 |
+
|
7 |
+
def generate_perforations(df,plug_df):
|
8 |
+
content = "UNITS METRIC\n\n"
|
9 |
+
|
10 |
+
# Iterate through unique well names
|
11 |
+
for well_name in df['well'].unique():
|
12 |
+
content += f'WELLNAME "{well_name}"\n'
|
13 |
+
|
14 |
+
# Filter the dataframe for the current well
|
15 |
+
well_df = df[df['well'] == well_name]
|
16 |
+
|
17 |
+
# Iterate through rows of the filtered dataframe
|
18 |
+
for index, row in well_df.iterrows():
|
19 |
+
if row['type'] == 'p':
|
20 |
+
date = row['date'].strftime('%d/%m/%Y')
|
21 |
+
top = row['top']
|
22 |
+
btm = row['btm']
|
23 |
+
# Write the perforation line to the content
|
24 |
+
content += f'{date} perforation {top} {btm} 0.1905 0 0 0\n'
|
25 |
+
|
26 |
+
if row['type'] == 's':
|
27 |
+
date = row['date'].strftime('%d/%m/%Y')
|
28 |
+
top = row['top']
|
29 |
+
btm = row['btm']
|
30 |
+
# Write the shut-in line to the content
|
31 |
+
content += f'{date} squeeze {top} {btm}\n'
|
32 |
+
|
33 |
+
# Filter the plug dataframe for the current well
|
34 |
+
plug_well_df = plug_df[plug_df['well'] == well_name]
|
35 |
+
|
36 |
+
# Iterate through rows of the filtered plug dataframe
|
37 |
+
for index, plug_row in plug_well_df.iterrows():
|
38 |
+
date = plug_row['date'].strftime('%d/%m/%Y')
|
39 |
+
depth = plug_row['depth']
|
40 |
+
|
41 |
+
# Filter the well dataframe based on the plug depth
|
42 |
+
filtered_well_df = well_df[(well_df['top'] >= depth) | (well_df['btm'] >= depth)]
|
43 |
+
|
44 |
+
# Iterate through rows of the filtered well dataframe
|
45 |
+
for _, filtered_row in filtered_well_df.iterrows():
|
46 |
+
top = filtered_row['top']
|
47 |
+
btm = filtered_row['btm']
|
48 |
+
if depth > top and depth < btm:
|
49 |
+
# Write the plug line to the content
|
50 |
+
content += f'{date} squeeze {depth} {btm}\n'
|
51 |
+
else :# Write the squeeze line to the content
|
52 |
+
content += f'{date} squeeze {top} {btm}\n'
|
53 |
+
|
54 |
+
content += "\n" # Add a newline between well sections
|
55 |
+
|
56 |
+
return content
|
57 |
+
|
58 |
+
def generate_tubing(df,tubing=False):
|
59 |
+
content = "UNITS METRIC\n\n"
|
60 |
+
|
61 |
+
# Iterate through unique well names
|
62 |
+
for well_name in df['well'].unique():
|
63 |
+
content += f'DATE {df["date"].min().strftime("%Y-%m-%d")}\n'
|
64 |
+
|
65 |
+
# Filter the dataframe for the current well
|
66 |
+
well_df = df[df['well'] == well_name]
|
67 |
+
|
68 |
+
# Get the deepest perforation depth for the current well
|
69 |
+
deepest_depth = well_df['btm'].max() + 20
|
70 |
+
shallowest_depth = well_df['top'].min() - 20
|
71 |
+
|
72 |
+
# Write the casing information to the content
|
73 |
+
content += f'CASING "{well_name}" "Casing 1"\n'
|
74 |
+
content += '0 "C-API-6.625/J-55/20.00"\n'
|
75 |
+
content += f'{deepest_depth}\n\n'
|
76 |
+
|
77 |
+
if tubing:
|
78 |
+
# Write the tubing information to the content
|
79 |
+
content += f'TUBING "Tubing 1" "{well_name}" "{well_name}"\n'
|
80 |
+
content += '0 "T-API-5.000/J-55/11.50"\n'
|
81 |
+
content += f'{shallowest_depth}\n'
|
82 |
+
|
83 |
+
# Write the packer information to the content
|
84 |
+
content += f'PACKER "Packer 1" "{well_name}" {shallowest_depth - 30} "PK_ADD_ON1"\n\n'
|
85 |
+
|
86 |
+
return content
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
def main():
|
92 |
+
#change the page title
|
93 |
+
st.set_page_config(page_title="Petrel Perforation and Tubing File Generator",layout="wide")
|
94 |
+
#change the page icon
|
95 |
+
st.markdown(""" <style>
|
96 |
+
#MainMenu {visibility: hidden;}
|
97 |
+
footer {visibility: hidden;}
|
98 |
+
</style> """, unsafe_allow_html=True)
|
99 |
+
|
100 |
+
|
101 |
+
st.title("Petrel Perforation and Tubing File Generator")
|
102 |
+
|
103 |
+
# Upload Excel file
|
104 |
+
uploaded_file = st.sidebar.file_uploader("Upload Perforation Excel file", type=["xlsx", "xls"])
|
105 |
+
#check box for tubing
|
106 |
+
tubing = st.sidebar.checkbox("Tubing",value=False)
|
107 |
+
|
108 |
+
if uploaded_file is not None:
|
109 |
+
# Read the Excel file
|
110 |
+
df = pd.read_excel(uploaded_file,sheet_name='perforation')
|
111 |
+
plug_df = pd.read_excel(uploaded_file,sheet_name='plugs')
|
112 |
+
|
113 |
+
# Create button to begin the process
|
114 |
+
if st.sidebar.button("Generate"):
|
115 |
+
# Prevent page refresh using a callback
|
116 |
+
st.session_state.generate_clicked = True # Flag for callback
|
117 |
+
|
118 |
+
# Use a callback to execute actions only when the button is clicked
|
119 |
+
if st.session_state.get("generate_clicked", False):
|
120 |
+
# Generate content for perforations.ev and tubing.tub
|
121 |
+
perforations_content = generate_perforations(df,plug_df)
|
122 |
+
tubing_content = generate_tubing(df, tubing=tubing)
|
123 |
+
|
124 |
+
# Display perforations.ev content
|
125 |
+
st.subheader("Click the button below to download perforations.ev and tubing.tub")
|
126 |
+
# Create buttons to download files
|
127 |
+
down_btn(
|
128 |
+
label="Download perforations.ev",
|
129 |
+
data=perforations_content,
|
130 |
+
file_name="perforations.ev"
|
131 |
+
)
|
132 |
+
|
133 |
+
down_btn(
|
134 |
+
label="Download tubing.tub",
|
135 |
+
data=tubing_content,
|
136 |
+
file_name="tubing.tub"
|
137 |
+
)
|
138 |
+
|
139 |
+
# Reset the flag after execution
|
140 |
+
st.session_state.generate_clicked = False
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
if __name__ == "__main__":
|
145 |
main()
|