JUNGU commited on
Commit
9463232
ยท
1 Parent(s): 5449034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -36
app.py CHANGED
@@ -1,45 +1,63 @@
 
1
  import streamlit as st
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
 
 
 
4
 
5
- # ํŒŒ์ผ ์—…๋กœ๋“œ
6
  uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
7
 
8
- # ๋ฐ์ดํ„ฐ ํƒ€์ž„ ํ”„๋ ˆ์ž„ ์„ ํƒ
9
- time_frame_options = ["1์ดˆ", "5์ดˆ", "10์ดˆ", "30์ดˆ", "1๋ถ„", "5๋ถ„", "10๋ถ„", "30๋ถ„", "60๋ถ„"]
10
- time_frame = st.selectbox("๋ฐ์ดํ„ฐ ํƒ€์ž„ ํ”„๋ ˆ์ž„ ์„ ํƒ:", time_frame_options)
11
- time_frame_map = {"1์ดˆ": 1/60, "5์ดˆ": 5/60, "10์ดˆ": 10/60, "30์ดˆ": 30/60, "1๋ถ„": 1, "5๋ถ„": 5, "10๋ถ„": 10, "30๋ถ„": 30, "60๋ถ„": 60}
12
- time_frame_minutes = time_frame_map[time_frame]
 
 
 
 
 
 
 
 
13
 
14
- if uploaded_file:
15
  # CSV ํŒŒ์ผ ์ฝ๊ธฐ
16
- df = pd.read_csv(uploaded_file)
17
-
18
- # timestamp๋ฅผ datetime ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜
19
- df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
20
-
21
- # ์„ ํƒ๋œ ํƒ€์ž„ ํ”„๋ ˆ์ž„์œผ๋กœ ๋ฆฌ์ƒ˜ํ”Œ๋ง
22
- df_resampled = df.resample(f'{time_frame_minutes}T', on='timestamp').mean()
23
-
24
- # RGB ๊ทธ๋ž˜ํ”„
25
- fig_rgb, ax_rgb = plt.subplots(figsize=(15, 5))
26
- ax_rgb.plot(df_resampled['R'], label='R')
27
- ax_rgb.plot(df_resampled['G'], label='G')
28
- ax_rgb.plot(df_resampled['B'], label='B')
29
- ax_rgb.set_title('RGB Color Variation')
30
- ax_rgb.set_xlabel('Time')
31
- ax_rgb.set_ylabel('Value')
32
- ax_rgb.legend()
33
- st.pyplot(fig_rgb)
34
-
35
- # HSV ๊ทธ๋ž˜ํ”„
36
- fig_hsv, ax_hsv = plt.subplots(figsize=(15, 5))
37
- ax_hsv.plot(df_resampled['H'], label='H')
38
- ax_hsv.plot(df_resampled['S'], label='S')
39
- ax_hsv.plot(df_resampled['V'], label='V')
40
- ax_hsv.set_title('HSV Color Variation')
41
- ax_hsv.set_xlabel('Time')
42
- ax_hsv.set_ylabel('Value')
43
- ax_hsv.legend()
44
- st.pyplot(fig_hsv)
 
 
 
 
 
 
45
 
 
 
1
+
2
  import streamlit as st
3
  import pandas as pd
4
  import matplotlib.pyplot as plt
5
+ import io
6
+
7
+ st.title("Webcam Color Detection Charting")
8
 
 
9
  uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
10
 
11
+ time_frame_options = [
12
+ "All",
13
+ "1 second",
14
+ "5 seconds",
15
+ "10 seconds",
16
+ "30 seconds",
17
+ "1 minute",
18
+ "5 minutes",
19
+ "10 minutes",
20
+ "30 minutes",
21
+ "60 minutes",
22
+ ]
23
+ time_frame = st.selectbox("Data Time Frame", time_frame_options)
24
 
25
+ if uploaded_file is not None:
26
  # CSV ํŒŒ์ผ ์ฝ๊ธฐ
27
+ data = pd.read_csv(uploaded_file)
28
+
29
+ # ์‹œ๊ฐ„ ํ”„๋ ˆ์ž„์— ๋”ฐ๋ฅธ ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ง
30
+ if time_frame != "All":
31
+ seconds = {
32
+ "1 second": 1,
33
+ "5 seconds": 5,
34
+ "10 seconds": 10,
35
+ "30 seconds": 30,
36
+ "1 minute": 60,
37
+ "5 minutes": 300,
38
+ "10 minutes": 600,
39
+ "30 minutes": 1800,
40
+ "60 minutes": 3600,
41
+ }
42
+ data['timestamp'] = pd.to_datetime(data['timestamp'], unit='ms')
43
+ data.set_index('timestamp', inplace=True)
44
+ data = data.resample(f"{seconds[time_frame]}S").mean().dropna().reset_index()
45
+
46
+ # ์ฐจํŠธ ์ƒ์„ฑ
47
+ fig, axes = plt.subplots(2, 1, figsize=(10, 8))
48
+
49
+ # RGB ์ฐจํŠธ
50
+ axes[0].plot(data['R'], 'r', label='R')
51
+ axes[0].plot(data['G'], 'g', label='G')
52
+ axes[0].plot(data['B'], 'b', label='B')
53
+ axes[0].legend(loc='upper right')
54
+ axes[0].set_title('RGB Values')
55
+
56
+ # HSV ์ฐจํŠธ
57
+ axes[1].plot(data['H'], 'r', label='H')
58
+ axes[1].plot(data['S'], 'g', label='S')
59
+ axes[1].plot(data['V'], 'b', label='V')
60
+ axes[1].legend(loc='upper right')
61
+ axes[1].set_title('HSV Values')
62
 
63
+ st.pyplot(fig)