Spaces:
Runtime error
Runtime error
AmrGharieb
commited on
Commit
•
bb86b4f
1
Parent(s):
166ebc2
Update app.py
Browse files
app.py
CHANGED
@@ -1,142 +1,142 @@
|
|
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
|
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 |
-
# Write the squeeze line to the content
|
49 |
-
content += f'{date} squeeze {top} {btm}\n'
|
50 |
-
|
51 |
-
content += "\n" # Add a newline between well sections
|
52 |
-
|
53 |
-
return content
|
54 |
-
|
55 |
-
def generate_tubing(df,tubing=False):
|
56 |
-
content = "UNITS METRIC\n\n"
|
57 |
-
|
58 |
-
# Iterate through unique well names
|
59 |
-
for well_name in df['well'].unique():
|
60 |
-
content += f'DATE {df["date"].min().strftime("%Y-%m-%d")}\n'
|
61 |
-
|
62 |
-
# Filter the dataframe for the current well
|
63 |
-
well_df = df[df['well'] == well_name]
|
64 |
-
|
65 |
-
# Get the deepest perforation depth for the current well
|
66 |
-
deepest_depth = well_df['btm'].max() + 20
|
67 |
-
shallowest_depth = well_df['top'].min() - 20
|
68 |
-
|
69 |
-
# Write the casing information to the content
|
70 |
-
content += f'CASING "{well_name}" "Casing 1"\n'
|
71 |
-
content += '0 "C-API-6.625/J-55/20.00"\n'
|
72 |
-
content += f'{deepest_depth}\n\n'
|
73 |
-
|
74 |
-
if tubing:
|
75 |
-
# Write the tubing information to the content
|
76 |
-
content += f'TUBING "Tubing 1" "{well_name}" "{well_name}"\n'
|
77 |
-
content += '0 "T-API-5.000/J-55/11.50"\n'
|
78 |
-
content += f'{shallowest_depth}\n'
|
79 |
-
|
80 |
-
# Write the packer information to the content
|
81 |
-
content += f'PACKER "Packer 1" "{well_name}" {shallowest_depth - 30} "PK_ADD_ON1"\n\n'
|
82 |
-
|
83 |
-
return content
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
def main():
|
89 |
-
#change the page title
|
90 |
-
st.set_page_config(page_title="Petrel Perforation and Tubing File Generator",layout="wide")
|
91 |
-
#change the page icon
|
92 |
-
st.markdown(""" <style>
|
93 |
-
#MainMenu {visibility: hidden;}
|
94 |
-
footer {visibility: hidden;}
|
95 |
-
</style> """, unsafe_allow_html=True)
|
96 |
-
|
97 |
-
|
98 |
-
st.title("Petrel Perforation and Tubing File Generator")
|
99 |
-
|
100 |
-
# Upload Excel file
|
101 |
-
uploaded_file = st.sidebar.file_uploader("Upload Perforation Excel file", type=["xlsx", "xls"])
|
102 |
-
#check box for tubing
|
103 |
-
tubing = st.sidebar.checkbox("Tubing",value=False)
|
104 |
-
|
105 |
-
if uploaded_file is not None:
|
106 |
-
# Read the Excel file
|
107 |
-
df = pd.read_excel(uploaded_file,sheet_name='perforation')
|
108 |
-
plug_df = pd.read_excel(uploaded_file,sheet_name='plugs')
|
109 |
-
|
110 |
-
# Create button to begin the process
|
111 |
-
if st.sidebar.button("Generate"):
|
112 |
-
# Prevent page refresh using a callback
|
113 |
-
st.session_state.generate_clicked = True # Flag for callback
|
114 |
-
|
115 |
-
# Use a callback to execute actions only when the button is clicked
|
116 |
-
if st.session_state.get("generate_clicked", False):
|
117 |
-
# Generate content for perforations.ev and tubing.tub
|
118 |
-
perforations_content = generate_perforations(df,plug_df)
|
119 |
-
tubing_content = generate_tubing(df, tubing=tubing)
|
120 |
-
|
121 |
-
# Display perforations.ev content
|
122 |
-
st.subheader("Click the button below to download perforations.ev and tubing.tub")
|
123 |
-
# Create buttons to download files
|
124 |
-
down_btn(
|
125 |
-
label="Download perforations.ev",
|
126 |
-
data=perforations_content,
|
127 |
-
file_name="perforations.ev"
|
128 |
-
)
|
129 |
-
|
130 |
-
down_btn(
|
131 |
-
label="Download tubing.tub",
|
132 |
-
data=tubing_content,
|
133 |
-
file_name="tubing.tub"
|
134 |
-
)
|
135 |
-
|
136 |
-
# Reset the flag after execution
|
137 |
-
st.session_state.generate_clicked = False
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
if __name__ == "__main__":
|
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 |
+
# Write the squeeze line to the content
|
49 |
+
content += f'{date} squeeze {top} {btm}\n'
|
50 |
+
|
51 |
+
content += "\n" # Add a newline between well sections
|
52 |
+
|
53 |
+
return content
|
54 |
+
|
55 |
+
def generate_tubing(df,tubing=False):
|
56 |
+
content = "UNITS METRIC\n\n"
|
57 |
+
|
58 |
+
# Iterate through unique well names
|
59 |
+
for well_name in df['well'].unique():
|
60 |
+
content += f'DATE {df["date"].min().strftime("%Y-%m-%d")}\n'
|
61 |
+
|
62 |
+
# Filter the dataframe for the current well
|
63 |
+
well_df = df[df['well'] == well_name]
|
64 |
+
|
65 |
+
# Get the deepest perforation depth for the current well
|
66 |
+
deepest_depth = well_df['btm'].max() + 20
|
67 |
+
shallowest_depth = well_df['top'].min() - 20
|
68 |
+
|
69 |
+
# Write the casing information to the content
|
70 |
+
content += f'CASING "{well_name}" "Casing 1"\n'
|
71 |
+
content += '0 "C-API-6.625/J-55/20.00"\n'
|
72 |
+
content += f'{deepest_depth}\n\n'
|
73 |
+
|
74 |
+
if tubing:
|
75 |
+
# Write the tubing information to the content
|
76 |
+
content += f'TUBING "Tubing 1" "{well_name}" "{well_name}"\n'
|
77 |
+
content += '0 "T-API-5.000/J-55/11.50"\n'
|
78 |
+
content += f'{shallowest_depth}\n'
|
79 |
+
|
80 |
+
# Write the packer information to the content
|
81 |
+
content += f'PACKER "Packer 1" "{well_name}" {shallowest_depth - 30} "PK_ADD_ON1"\n\n'
|
82 |
+
|
83 |
+
return content
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
def main():
|
89 |
+
#change the page title
|
90 |
+
st.set_page_config(page_title="Petrel Perforation and Tubing File Generator",layout="wide")
|
91 |
+
#change the page icon
|
92 |
+
st.markdown(""" <style>
|
93 |
+
#MainMenu {visibility: hidden;}
|
94 |
+
footer {visibility: hidden;}
|
95 |
+
</style> """, unsafe_allow_html=True)
|
96 |
+
|
97 |
+
|
98 |
+
st.title("Petrel Perforation and Tubing File Generator")
|
99 |
+
|
100 |
+
# Upload Excel file
|
101 |
+
uploaded_file = st.sidebar.file_uploader("Upload Perforation Excel file", type=["xlsx", "xls"])
|
102 |
+
#check box for tubing
|
103 |
+
tubing = st.sidebar.checkbox("Tubing",value=False)
|
104 |
+
|
105 |
+
if uploaded_file is not None:
|
106 |
+
# Read the Excel file
|
107 |
+
df = pd.read_excel(uploaded_file,sheet_name='perforation')
|
108 |
+
plug_df = pd.read_excel(uploaded_file,sheet_name='plugs')
|
109 |
+
|
110 |
+
# Create button to begin the process
|
111 |
+
if st.sidebar.button("Generate"):
|
112 |
+
# Prevent page refresh using a callback
|
113 |
+
st.session_state.generate_clicked = True # Flag for callback
|
114 |
+
|
115 |
+
# Use a callback to execute actions only when the button is clicked
|
116 |
+
if st.session_state.get("generate_clicked", False):
|
117 |
+
# Generate content for perforations.ev and tubing.tub
|
118 |
+
perforations_content = generate_perforations(df,plug_df)
|
119 |
+
tubing_content = generate_tubing(df, tubing=tubing)
|
120 |
+
|
121 |
+
# Display perforations.ev content
|
122 |
+
st.subheader("Click the button below to download perforations.ev and tubing.tub")
|
123 |
+
# Create buttons to download files
|
124 |
+
down_btn(
|
125 |
+
label="Download perforations.ev",
|
126 |
+
data=perforations_content,
|
127 |
+
file_name="perforations.ev"
|
128 |
+
)
|
129 |
+
|
130 |
+
down_btn(
|
131 |
+
label="Download tubing.tub",
|
132 |
+
data=tubing_content,
|
133 |
+
file_name="tubing.tub"
|
134 |
+
)
|
135 |
+
|
136 |
+
# Reset the flag after execution
|
137 |
+
st.session_state.generate_clicked = False
|
138 |
+
|
139 |
+
|
140 |
+
|
141 |
+
if __name__ == "__main__":
|
142 |
main()
|