Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,114 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
import numpy as np
|
|
|
1 |
+
def main():
|
2 |
+
# 設置頁面配置
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="114年度樂齡學習數位示範體驗場域 服務滿意度調查分析報告",
|
5 |
+
page_icon="📊",
|
6 |
+
layout="wide"
|
7 |
+
)
|
8 |
+
|
9 |
+
# 添加標題和子標題
|
10 |
+
st.markdown("""
|
11 |
+
# 114年度樂齡學習數位示範體驗場域 服務滿意度調查分析報告
|
12 |
+
## 全面理解樂齡學習者數位服務體驗
|
13 |
+
|
14 |
+
本報告提供全面的問卷調查分析與視覺化圖表,深入剖析樂齡學習者參與數位示範場域服務的滿意情形。
|
15 |
+
透過詳細的統計分析和互動式圖表,我們旨在呈現樂齡學習者的服務體驗和需求洞察。
|
16 |
+
|
17 |
+
### 報告製作單位
|
18 |
+
**國立中正大學高齡教育研究中心專案管理團隊**
|
19 |
+
""")
|
20 |
+
|
21 |
+
# 分隔線
|
22 |
+
st.markdown("---")
|
23 |
+
|
24 |
+
# 上傳 CSV 檔案
|
25 |
+
uploaded_file = st.file_uploader("上傳 CSV 檔案", type=['csv'])
|
26 |
+
|
27 |
+
# 預設數據按鈕
|
28 |
+
use_default_data = st.button('使用預設範例數據')
|
29 |
+
|
30 |
+
# 數據載入和處理
|
31 |
+
df = None
|
32 |
+
analyzer = None
|
33 |
+
|
34 |
+
if uploaded_file is not None:
|
35 |
+
# 讀取上傳的 CSV 檔案
|
36 |
+
try:
|
37 |
+
df = pd.read_csv(uploaded_file, encoding='utf-8')
|
38 |
+
st.success("CSV 檔案上傳成功!")
|
39 |
+
except Exception as e:
|
40 |
+
st.error(f"無法讀取檔案:{e}")
|
41 |
+
return
|
42 |
+
|
43 |
+
elif use_default_data:
|
44 |
+
# 使用預設數據
|
45 |
+
df = read_google_sheet(sheet_id, gid)
|
46 |
+
|
47 |
+
if df is None:
|
48 |
+
st.error("無法讀取預設數據,請上傳 CSV 檔案")
|
49 |
+
return
|
50 |
+
|
51 |
+
# 如果有數據,則進行分析
|
52 |
+
if df is not None:
|
53 |
+
analyzer = SurveyAnalyzer()
|
54 |
+
|
55 |
+
# 新增場域和月份篩選器
|
56 |
+
st.sidebar.header("🔍 數據篩選")
|
57 |
+
|
58 |
+
# 假設數據有「場域名稱」欄位,如果名稱不同請調整
|
59 |
+
if '場域名稱' in df.columns:
|
60 |
+
venues = ['全部'] + sorted(df['場域名稱'].unique().tolist())
|
61 |
+
selected_venues = st.sidebar.multiselect("選擇場域", venues, default=['全部'])
|
62 |
+
else:
|
63 |
+
# 如果沒有場域欄位,創建10個虛擬場域供選擇
|
64 |
+
venues = ['全部'] + [f'場域{i+1}' for i in range(10)]
|
65 |
+
selected_venues = st.sidebar.multiselect("選擇場域", venues, default=['全部'])
|
66 |
+
|
67 |
+
# 假設數據有「月份」欄位,如果沒有請調整
|
68 |
+
if '月份' in df.columns:
|
69 |
+
months = ['全部'] + sorted(df['月份'].unique().tolist())
|
70 |
+
selected_month = st.sidebar.selectbox("選擇月份", months)
|
71 |
+
else:
|
72 |
+
# 如果沒有月份欄位,可以創建虛擬月份選項
|
73 |
+
months = ['全部'] + [f'{i+1}月' for i in range(12)]
|
74 |
+
selected_month = st.sidebar.selectbox("選擇月份", months)
|
75 |
+
|
76 |
+
# 📌 基本統計數據
|
77 |
+
st.sidebar.header("📌 選擇數據分析")
|
78 |
+
selected_analysis = st.sidebar.radio("選擇要查看的分析",
|
79 |
+
["📋 問卷統計報告", "📊 滿意度統計", "🟠 性別分佈"])
|
80 |
+
|
81 |
+
if selected_analysis == "📋 問卷統計報告":
|
82 |
+
st.header("📋 問卷統計報告")
|
83 |
+
report = analyzer.generate_report(df)
|
84 |
+
for category, stats in report.items():
|
85 |
+
with st.expander(f"🔍 {category}", expanded=True):
|
86 |
+
for key, value in stats.items():
|
87 |
+
if key == '各項滿意度':
|
88 |
+
st.write(f"**{key}:**")
|
89 |
+
for item, item_stats in value.items():
|
90 |
+
st.write(f" - **{item}**: {', '.join([f'{k}: {v}' for k, v in item_stats.items()])}")
|
91 |
+
else:
|
92 |
+
st.write(f"**{key}**: {value}")
|
93 |
+
|
94 |
+
elif selected_analysis == "📊 滿意度統計":
|
95 |
+
st.header("📊 滿意度統計")
|
96 |
+
analyzer.plot_satisfaction_scores(df)
|
97 |
+
|
98 |
+
elif selected_analysis == "🟠 性別分佈":
|
99 |
+
st.header("🟠 性別分佈")
|
100 |
+
analyzer.plot_gender_distribution(df, selected_venues, selected_month)
|
101 |
+
|
102 |
+
# 報告說明
|
103 |
+
st.markdown("---")
|
104 |
+
st.markdown("""
|
105 |
+
### 報告說明
|
106 |
+
- **數據來源**:114年度樂齡學習數位示範體驗場域調查問卷
|
107 |
+
- **分析目的**:評估樂齡學習者對數位示範場域服務的滿意度
|
108 |
+
- **報告解讀**:本報告提供服務滿意度的客觀量化指標,旨在協助改進服務品質
|
109 |
+
""")
|
110 |
+
else:
|
111 |
+
st.info("請上傳 CSV 檔案或使用預設範例數據")import streamlit as st
|
112 |
import pandas as pd
|
113 |
import plotly.express as px
|
114 |
import numpy as np
|