AmrGharieb commited on
Commit
7a3bca6
1 Parent(s): bb86b4f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +144 -141
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
- # 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
+ 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()