File size: 4,868 Bytes
9caeaea
 
 
 
50916a6
 
 
 
 
e8e508c
50916a6
e8e508c
50916a6
 
 
 
9caeaea
e8e508c
 
 
9caeaea
 
 
 
b881031
 
 
 
 
9caeaea
 
 
 
 
e8e508c
 
b881031
9caeaea
 
06c3f7f
9caeaea
06c3f7f
 
 
9caeaea
 
 
 
 
 
 
 
06c3f7f
5e4e3b1
 
 
 
 
06c3f7f
50916a6
 
 
e8e508c
 
50916a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9caeaea
 
e8e508c
 
9caeaea
e8e508c
 
9caeaea
b1d9c54
e8e508c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9caeaea
 
 
93ff3ca
9caeaea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import streamlit as st

ss = st.session_state

gc_formula_k = "short"
gc_full_key = "full name"
GC_FULL_NAMES = ['Hydrogen sulphide',
                 'Carbone dioxide', 'Nitrogen', 'Methane', 'Ethane', 'Propane', 'N-butane', 'Iso-butane', 'N-pentane',
                 'Iso-pentane', 'N-hexane',
                 'N-heptane', 'C7_PLUS_', 'Hydrogen', 'Air', 'Water', 'Oxygen']
GC_SHORT_NAMES = ['H2S', 'CO2', 'N2', "C1", "C2", "C3", "nC4", "iC4", "nC5", "iC5", "C6",
                  "C7", "C7_PLUS_", "H2", "Air", "H2O", "O2"]

GC_NAMES = []
for full_name, short_name in zip(GC_FULL_NAMES, GC_SHORT_NAMES):
    GC_NAMES.append({gc_full_key: full_name, gc_formula_k: short_name})

hydrocarbons = GC_NAMES[3:13]
non_hc = GC_NAMES[:3]
add_non_hc = GC_NAMES[13:]

sg_k = 'sg_value'
pc_k = 'p_crit_value'
tc_k = 't_crit_value'
recf_k = 'recf'
lg_k = 'lg'
if recf_k not in ss:
    ss[recf_k] = 1.04
for key in [sg_k, pc_k, tc_k, lg_k]:
    if key not in ss:
        ss[key] = 0

if st.button("Calculate"):
    ss[sg_k] = 30
    ss[tc_k] = 15
    ss[pc_k] = 20
    ss[recf_k] = ss[lg_k]*1.2

UD = "User defined"
CONDENSATE = "Condensate"
SG_LIST = [UD,
           "Gas components",
           CONDENSATE]
SG_UD, SG_GC, SG_CON = SG_LIST
sg_source = st.selectbox("sg source", SG_LIST)

if sg_source == UD:
    user_input = st.text_input("sg", value=ss[sg_k], key="input_field")
    ss[sg_k] = user_input
else:
    st.text_input("sg", value=ss[sg_k], key="input_field", disabled=True, help="Calculated")

if sg_source == SG_CON:
    with st.expander(label="Condensate", expanded=True):
        st.text_input("surface avg gas sg", value=0.74, key="avg sg")
        ss[lg_k] = float(st.text_input("liquid gravity", value=0.8, key="lg_key"))
        st.text_input("GOR", value=16630, key="gor")
        st.text_input("Recombination factor", value=ss[recf_k], key="recf_key", disabled=True, help="Calculated")


def text_for_gc(col, gc):
    # Generate unique class names for each image
    hover_class = f'hoverable_{gc[gc_formula_k]}'
    tooltip_class = f'tooltip_{gc[gc_formula_k]}'

    # Define the unique CSS for each image
    hover_css = f'''
        .{hover_class} {{
            display: flex;
            flex-direction: column;
            justify-content: center;
            height: 38px;
        }}
        .{hover_class} .{tooltip_class} {{
            visibility: hidden;
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            transition: opacity 0.5s;
            background-color: rgba(0, 0, 0, 0.8);
            color: #fff;
            padding: 4px;
            border-radius: 4px;
            text-align: center;
            white-space: nowrap;
        }}
        .{hover_class}:hover .{tooltip_class} {{
            visibility: visible;
        }}
    '''
    tooltip_css = f"<style>{hover_css}</style>"

    # Define the html for each image
    text_div = f'''
            <div class="{hover_class}">
                <span style='text-align: center; word-wrap: break-word;'>{gc[gc_formula_k]}</span>
                <div class="{tooltip_class}">{gc[gc_full_key]}</div>
            </div>
        '''
    with col:
        st.markdown(f'{text_div}{tooltip_css}', unsafe_allow_html=True)


params = []
if sg_source != SG_GC:
    curr_non_hc = non_hc
    cur_hc = None
else:
    curr_non_hc = non_hc + add_non_hc
    cur_hc = hydrocarbons
with st.expander("Gas components") as gc_exp:
    st.radio("units:", ("%", "frac"), horizontal=True, label_visibility='collapsed')

    def get_components_block(cur_gc, text):
        st.text(f'{text}')
        # st.markdown("***")
        for i in range(0, len(cur_gc), 3):
            cols = st.columns(3)
            j = i
            for col in cols:
                if j >= len(cur_gc):
                    break
                gc11, gc12 = col.columns([1, 1.5])
                text_for_gc(gc11, cur_gc[j])
                params.append(gc12.text_input(cur_gc[j][gc_formula_k], value=0, label_visibility='collapsed',
                                              help=cur_gc[j][gc_formula_k]))
                j += 1

    get_components_block(curr_non_hc, "non hydrocarbons")
    if cur_hc:
        get_components_block(cur_hc, "hydrocarbons")


CRIT_LIST = [UD]
CORRS = ["Sutton", "Standing dry gas", "Standing wet gas"]
crit_options = [UD]
if sg_source == SG_GC:
    crit_options.append("From gas components")
else:
    for c in CORRS:
        crit_options.append(c)

crit_params_source = st.selectbox("Critical params", crit_options)

# Create two columns for input fields
col1, col2 = st.columns(2)

if crit_params_source == UD:
    dis = False
else:
    dis = True
# Add input fields to the columns
param1 = col1.text_input('Pcrit', value=ss[tc_k], disabled=dis)
param2 = col2.text_input('Tcrit', value=ss[pc_k], disabled=dis)