emidiosouza commited on
Commit
b0e7098
·
1 Parent(s): 2a1a0bb

Add application file

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. filter.py +83 -0
  3. query.sql +67 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ secrets.toml
filter.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ from pandas.api.types import (
4
+ is_categorical_dtype,
5
+ is_datetime64_any_dtype,
6
+ is_numeric_dtype,
7
+ is_object_dtype,
8
+ )
9
+
10
+ def filter_dataframe(df: pd.DataFrame) -> pd.DataFrame:
11
+ df = df.copy()
12
+
13
+ # Tentar converter datas para um formato padrão (datetime, sem fuso horário)
14
+ for col in df.columns:
15
+ if is_object_dtype(df[col]):
16
+ try:
17
+ df[col] = pd.to_datetime(df[col])
18
+ except Exception:
19
+ pass
20
+
21
+ if is_datetime64_any_dtype(df[col]):
22
+ df[col] = df[col].dt.tz_localize(None)
23
+
24
+ modification_container = st.container()
25
+
26
+ with modification_container:
27
+ to_filter_columns = st.multiselect("Filtrar por valor", df.columns)
28
+ for column in to_filter_columns:
29
+ left, right = st.columns((1, 20))
30
+ left.write("↳")
31
+ # Tratar colunas com < 10 valores únicos como categóricos
32
+ if is_categorical_dtype(df[column]) or df[column].nunique() < 10:
33
+ user_cat_input = right.multiselect(
34
+ f"Valores para {column}",
35
+ df[column].unique(),
36
+ default=[], # Lista vazia para não ter valores pré-selecionados
37
+ )
38
+ if user_cat_input: # Filtrar apenas se houver seleção
39
+ df = df[df[column].isin(user_cat_input)]
40
+ elif is_numeric_dtype(df[column]):
41
+ _min = float(df[column].min())
42
+ _max = float(df[column].max())
43
+ step = (_max - _min) / 100
44
+ user_num_input = right.slider(
45
+ f"Valores para {column}",
46
+ min_value=_min,
47
+ max_value=_max,
48
+ value=(_min, _max),
49
+ step=step,
50
+ )
51
+ df = df[df[column].between(*user_num_input)]
52
+ elif is_datetime64_any_dtype(df[column]):
53
+ user_date_input = right.date_input(
54
+ f"Valores para {column}",
55
+ value=(
56
+ df[column].min(),
57
+ df[column].max(),
58
+ ),
59
+ format="YYYY-MM-DD",
60
+ )
61
+ if len(user_date_input) == 2:
62
+ user_date_input = tuple(map(pd.to_datetime, user_date_input))
63
+ start_date, end_date = user_date_input
64
+ df = df.loc[df[column].between(start_date, end_date)]
65
+ else:
66
+ # Para colunas de texto, mostre uma seleção múltipla se houver poucos valores únicos
67
+ unique_values = df[column].dropna().unique()
68
+ if len(unique_values) < 100: # Ajuste o limite conforme necessário
69
+ user_text_input = right.multiselect(
70
+ f"Valores para {column}",
71
+ unique_values,
72
+ default=[], # Lista vazia para não ter valores pré-selecionados
73
+ )
74
+ if user_text_input: # Filtrar apenas se houver seleção
75
+ df = df[df[column].isin(user_text_input)]
76
+ else:
77
+ user_text_input = right.text_input(
78
+ f"Substring ou regex em {column}",
79
+ )
80
+ if user_text_input:
81
+ df = df[df[column].astype(str).str.contains(user_text_input, na=False)]
82
+
83
+ return df
query.sql ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ SELECT
2
+ COALESCE(NULLIF(data->'responseData'->0->>'name', '[null]'), '') AS "Nome documento",
3
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->>'city', '[null]'), '') AS "Cidade",
4
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->>'state', '[null]'), '') AS "Estado",
5
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->>'region', '[null]'), '') AS "Região",
6
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->>'country', '[null]'), '') AS "País",
7
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->>'extra_info', '[null]'), '') AS "Informações adicionais",
8
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->>'target_or_deposit', '[null]'), '') AS "Alvo ou depósito",
9
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->'geological_context'->>'tectonic_context', '[null]'), '') AS "Contexto tectônico",
10
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->'geological_context'->>'geological_context', '[null]'), '') AS "Contexto geológico",
11
+ COALESCE(NULLIF(data->'responseData'->0->'data'->0->'response'->'geological_context'->>'context_of_present_rocks', '[null]'), '') AS "Contexto das rochas presentes",
12
+
13
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'sedimentares'->0->>'name', '[null]'), '') AS "Nome sedimentares",
14
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'sedimentares'->0->>'type', '[null]'), '') AS "Tipo sedimentares",
15
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'sedimentares'->0->>'scientificName', '[null]'), '') AS "Nome científico sedimentares",
16
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'sedimentares'->0->>'contact_relations', '[null]'), '') AS "Relações de contato sedimentares",
17
+
18
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'metamórficas'->0->>'name', '[null]'), '') AS "Nome metamórficas",
19
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'metamórficas'->0->>'type', '[null]'), '') AS "Tipo metamórficas",
20
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'metamórficas'->0->>'scientificName', '[null]'), '') AS "Nome científico metamórficas",
21
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'metamórficas'->0->>'contact_relations', '[null]'), '') AS "Relações de contato metamórficas",
22
+
23
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'ígneas_intrusivas'->0->>'name', '[null]'), '') AS "Nome ígneas intrusivas",
24
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'ígneas_intrusivas'->0->>'type', '[null]'), '') AS "Tipo ígneas intrusivas",
25
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'ígneas_intrusivas'->0->>'scientificName', '[null]'), '') AS "Nome científico ígneas intrusivas",
26
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'ígneas_intrusivas'->0->>'contact_relations', '[null]'), '') AS "Relações de contato ígneas intrusivas",
27
+
28
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'vulcânicas_e_subvulcânicas'->0->>'name', '[null]'), '') AS "Nome vulcânicas e subvulcânicas",
29
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'vulcânicas_e_subvulcânicas'->0->>'type', '[null]'), '') AS "Tipo vulcânicas e subvulcânicas",
30
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'vulcânicas_e_subvulcânicas'->0->>'scientificName', '[null]'), '') AS "Nome científico vulcânicas e subvulcânicas",
31
+ COALESCE(NULLIF(data->'responseData'->0->'data'->1->'response'->'rockTypes'->'vulcânicas_e_subvulcânicas'->0->>'contact_relations', '[null]'), '') AS "Relações de contato vulcânicas e subvulcânicas",
32
+
33
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'oreType', '[null]'), '') AS "Tipo de minério",
34
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'rockType', '[null]'), '') AS "Tipo de rocha",
35
+
36
+ COALESCE(NULLIF((data->'responseData'->0->'data'->2->'response'->'host_rocks'->>'name')::text, '[null]'), '') AS "Nomes rochas hospedeiras",
37
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->'host_rocks'->>'geologicalEnvironments', '[null]'), '') AS "Eventos geológicos rochas hospedeiras",
38
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->'host_rocks'->>'mineralizationStructures', '[null]'), '') AS "Estruturas de mineralização de rochas hospedeiras",
39
+
40
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'structures', '[null]'), '') AS "Estruturas",
41
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'mineralFabric', '[null]'), '') AS "Textura mineral",
42
+
43
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'definedEstimate', '[null]'), '') AS "Estimativa definida",
44
+
45
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'associatedMinerals', '[null]'), '') AS "Minerais associados",
46
+
47
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'estimatedQuantities', '[null]'), '') AS "Quantidades estimadas",
48
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'definedConcentration', '[null]'), '') AS "Concentração definida",
49
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'estimatedConcentration', '[null]'), '') AS "Concentração estimada",
50
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'fluidInclusionsAnalysis', '[null]'), '') AS "Análise de inclusões fluidas",
51
+
52
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->'hydrotermal_alterations'->>'alterationTypes', '[null]'), '') AS "Tipos de alterações hidrotermais",
53
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->'hydrotermal_alterations'->>'associatedMinerals', '[null]'), '') AS "Minerais associados a alterações hidrotermais",
54
+
55
+ COALESCE(NULLIF(data->'responseData'->0->'data'->2->'response'->>'mineralizationSignatures', '[null]'), '') AS "Assinaturas de mineralização",
56
+ COALESCE(NULLIF(data->'responseData'->0->'data'->3->'response'->>'structural_mapping', '[null]'), '') AS "Mapeamento estrutural",
57
+ COALESCE(NULLIF(data->'responseData'->0->'data'->4->'response'->>'structureMineralizationRelation', '[null]'), '') AS "Relação estrutura-mineralização",
58
+ COALESCE(NULLIF(data->'responseData'->0->'data'->5->'response'->>'stableIsotopes', '[null]'), '') AS "Isótopos estáveis",
59
+ COALESCE(NULLIF(data->'responseData'->0->'data'->5->'response'->>'traceElementsAndRareEarths', '[null]'), '') AS "Elementos traço e terras raras",
60
+ COALESCE(NULLIF(data->'responseData'->0->'data'->6->'response'->>'geophysicalSignatures', '[null]'), '') AS "Assinaturas geofísicas",
61
+ COALESCE(NULLIF(data->'responseData'->0->'data'->6->'response'->>'mineralizationSignatures', '[null]'), '') AS "Assinaturas de mineralização geofísica",
62
+ COALESCE(NULLIF(data->'responseData'->0->'data'->7->'response'->>'additionalInformation', '[null]'), '') AS "Informações adicionais de mineralização",
63
+ COALESCE(NULLIF(data->'responseData'->0->'data'->8->'response'->>'estimates', '[null]'), '') AS "Estimativas de minério",
64
+ COALESCE(NULLIF(data->'responseData'->0->'data'->9->'response'->>'potential', '[null]'), '') AS "Potencial de descoberta"
65
+ FROM
66
+ public."Extraction";
67
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ pandas==2.2.2
2
+ SQLAlchemy==2.0.31
3
+ streamlit
4
+ toml==0.10.2