-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_cache.py
More file actions
115 lines (100 loc) · 2.55 KB
/
Copy pathdb_cache.py
File metadata and controls
115 lines (100 loc) · 2.55 KB
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
# db_cache.py
from __future__ import annotations
import streamlit as st
import pandas as pd
from db_utils_pg import (
load_stocks,
load_plans,
load_templates,
load_template_items,
get_eps_db,
get_cf_db,
)
# =================================================
# cache policy
# - DB connection ❌
# - DataFrame만 cache
# =================================================
@st.cache_data
def cached_load_stocks() -> pd.DataFrame:
return load_stocks(None)
@st.cache_data
def cached_load_plans() -> pd.DataFrame:
return load_plans(None)
@st.cache_data
def cached_load_templates() -> pd.DataFrame:
return load_templates(None)
@st.cache_data
def cached_load_template_items(template_id: str) -> pd.DataFrame:
return load_template_items(None, template_id)
@st.cache_data
def cached_eps_db() -> pd.DataFrame:
return get_eps_db(None)
@st.cache_data
def cached_cf_db() -> pd.DataFrame:
return get_cf_db(None)
@st.cache_data
def cached_reactions_in_plan(plan_id: str) -> pd.DataFrame:
from db_utils_pg import fetchall
rows = fetchall(
"""
SELECT
r.reaction_id,
r.title,
r.category,
r.created_by,
r.final_volume,
r.final_volume_unit,
r.created_at
FROM reactions r
WHERE r.plan_id = %s
ORDER BY r.created_at
""",
(plan_id,),
)
# ✅ SELECT 컬럼 수(7개) == columns 길이(7개) 맞춰야 함
return pd.DataFrame(
rows,
columns=[
"reaction_id",
"title",
"category",
"created_by",
"final_volume",
"final_volume_unit",
"created_at",
],
)
@st.cache_data
def cached_labeling_records() -> pd.DataFrame:
from db_utils_pg import fetchall
rows = fetchall(
"""
SELECT
title,
created_at,
created_by,
target_name,
dye_name,
labeling_ratio,
etoh_efficiency,
uv_purity,
note
FROM labeling_records
ORDER BY created_at DESC
"""
)
return pd.DataFrame(
rows,
columns=[
"title",
"created_at",
"created_by",
"target_name",
"dye_name",
"labeling_ratio",
"etoh_efficiency",
"uv_purity",
"note",
],
)