AmrGharieb commited on
Commit
d033940
1 Parent(s): d802139

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +116 -0
  2. requirements.txt +49 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):
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
+ date = row['date'].strftime('%d/%m/%Y')
20
+ top = row['top']
21
+ btm = row['btm']
22
+
23
+ # Write the perforation line to the content
24
+ content += f'{date} perforation {top} {btm} 0.1905 0 0 0\n'
25
+
26
+ content += "\n" # Add a newline between well sections
27
+
28
+ return content
29
+
30
+ def generate_tubing(df,tubing=False):
31
+ content = "UNITS METRIC\n\n"
32
+
33
+ # Iterate through unique well names
34
+ for well_name in df['well'].unique():
35
+ content += f'DATE {df["date"].min().strftime("%Y-%m-%d")}\n'
36
+
37
+ # Filter the dataframe for the current well
38
+ well_df = df[df['well'] == well_name]
39
+
40
+ # Get the deepest perforation depth for the current well
41
+ deepest_depth = well_df['btm'].max() + 20
42
+ shallowest_depth = well_df['top'].min() - 20
43
+
44
+ # Write the casing information to the content
45
+ content += f'CASING "{well_name}" "Casing 1"\n'
46
+ content += '0 "C-API-6.625/J-55/20.00"\n'
47
+ content += f'{deepest_depth}\n\n'
48
+
49
+ if tubing:
50
+ # Write the tubing information to the content
51
+ content += f'TUBING "Tubing 1" "{well_name}" "{well_name}"\n'
52
+ content += '0 "T-API-5.000/J-55/11.50"\n'
53
+ content += f'{shallowest_depth}\n'
54
+
55
+ # Write the packer information to the content
56
+ content += f'PACKER "Packer 1" "{well_name}" {shallowest_depth - 30} "PK_ADD_ON1"\n\n'
57
+
58
+ return content
59
+
60
+
61
+
62
+
63
+ def main():
64
+ #change the page title
65
+ st.set_page_config(page_title="Petrel Perforation and Tubing File Generator",layout="wide")
66
+ #change the page icon
67
+ st.markdown(""" <style>
68
+ #MainMenu {visibility: hidden;}
69
+ footer {visibility: hidden;}
70
+ </style> """, unsafe_allow_html=True)
71
+
72
+
73
+ st.title("Petrel Perforation and Tubing File Generator")
74
+
75
+ # Upload Excel file
76
+ uploaded_file = st.sidebar.file_uploader("Upload Perforation Excel file", type=["xlsx", "xls"])
77
+ #check box for tubing
78
+ tubing = st.sidebar.checkbox("Tubing",value=False)
79
+
80
+ if uploaded_file is not None:
81
+ # Read the Excel file
82
+ df = pd.read_excel(uploaded_file)
83
+
84
+ # Create button to begin the process
85
+ if st.sidebar.button("Generate"):
86
+ # Prevent page refresh using a callback
87
+ st.session_state.generate_clicked = True # Flag for callback
88
+
89
+ # Use a callback to execute actions only when the button is clicked
90
+ if st.session_state.get("generate_clicked", False):
91
+ # Generate content for perforations.ev and tubing.tub
92
+ perforations_content = generate_perforations(df)
93
+ tubing_content = generate_tubing(df, tubing=tubing)
94
+
95
+ # Display perforations.ev content
96
+ st.subheader("Click the button below to download perforations.ev and tubing.tub")
97
+ # Create buttons to download files
98
+ down_btn(
99
+ label="Download perforations.ev",
100
+ data=perforations_content,
101
+ file_name="perforations.ev"
102
+ )
103
+
104
+ down_btn(
105
+ label="Download tubing.tub",
106
+ data=tubing_content,
107
+ file_name="tubing.tub"
108
+ )
109
+
110
+ # Reset the flag after execution
111
+ st.session_state.generate_clicked = False
112
+
113
+
114
+
115
+ if __name__ == "__main__":
116
+ main()
requirements.txt ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.2.0
2
+ attrs==23.2.0
3
+ blinker==1.7.0
4
+ cachetools==5.3.2
5
+ certifi==2023.11.17
6
+ charset-normalizer==3.3.2
7
+ click==8.1.7
8
+ colorama==0.4.6
9
+ et-xmlfile==1.1.0
10
+ gitdb==4.0.11
11
+ GitPython==3.1.41
12
+ idna==3.6
13
+ importlib-metadata==7.0.1
14
+ Jinja2==3.1.3
15
+ jsonschema==4.21.1
16
+ jsonschema-specifications==2023.12.1
17
+ markdown-it-py==3.0.0
18
+ MarkupSafe==2.1.4
19
+ mdurl==0.1.2
20
+ numpy==1.26.3
21
+ openpyxl==3.1.2
22
+ packaging==23.2
23
+ pandas==2.2.0
24
+ pillow==10.2.0
25
+ protobuf==4.25.2
26
+ pyarrow==15.0.0
27
+ pydeck==0.8.1b0
28
+ Pygments==2.17.2
29
+ python-dateutil==2.8.2
30
+ pytz==2023.4
31
+ referencing==0.33.0
32
+ requests==2.31.0
33
+ rich==13.7.0
34
+ rpds-py==0.17.1
35
+ six==1.16.0
36
+ smmap==5.0.1
37
+ streamlit==1.30.0
38
+ streamlit-ext==0.1.9
39
+ tenacity==8.2.3
40
+ toml==0.10.2
41
+ toolz==0.12.1
42
+ tornado==6.4
43
+ typing_extensions==4.9.0
44
+ tzdata==2023.4
45
+ tzlocal==5.2
46
+ urllib3==2.2.0
47
+ validators==0.22.0
48
+ watchdog==3.0.0
49
+ zipp==3.17.0