DigitalTransG2 commited on
Commit
93dc3b1
·
verified ·
1 Parent(s): f768588

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -1,14 +1,12 @@
1
  import streamlit as st
2
  import requests
3
  import json
4
- from datetime import datetime
5
 
6
  # ==========================
7
  # Firebase Realtime Database
8
  # ==========================
9
- FIREBASE_URL = "https://smartedu-3d5bf-default-rtdb.asia-southeast1.firebasedatabase.app" # adjust if needed
10
 
11
- # --------------------------
12
  def write_student_info(student_id, name, classroom):
13
  url = f"{FIREBASE_URL}/{student_id}.json"
14
  data = {
@@ -17,12 +15,10 @@ def write_student_info(student_id, name, classroom):
17
  }
18
  requests.patch(url, json=data)
19
 
20
-
21
  def write_quiz_score(student_id, quiz_name, score):
22
  url = f"{FIREBASE_URL}/{student_id}/{quiz_name}.json"
23
  requests.put(url, json=score)
24
 
25
-
26
  def get_student_data(student_id):
27
  url = f"{FIREBASE_URL}/{student_id}.json"
28
  res = requests.get(url)
@@ -55,7 +51,6 @@ if role == "Master":
55
  correct_answer = st.text_input("Đáp án đúng")
56
 
57
  if st.button("Lưu Quiz"):
58
- # Store quiz definitions in firebase
59
  url = f"{FIREBASE_URL}/quiz_definitions/{quiz_name}.json"
60
  requests.put(url, json={
61
  "question": question,
@@ -81,19 +76,16 @@ if role == "Học sinh":
81
  else:
82
  st.error("Vui lòng nhập đầy đủ thông tin!")
83
 
84
- # Load quiz definitions
85
  st.subheader("Làm Quiz")
86
  res = requests.get(f"{FIREBASE_URL}/quiz_definitions.json")
87
  quizzes = res.json() if res.status_code == 200 else {}
88
 
89
- if student_id:
90
- student_data = get_student_data(student_id)
91
 
92
  if quizzes:
93
  for quiz_name, content in quizzes.items():
94
  st.markdown(f"### {quiz_name}")
95
 
96
- # Check if student already completed
97
  if student_data and quiz_name in student_data:
98
  st.info(f"Bạn đã làm Quiz này rồi. Điểm: {student_data[quiz_name]}")
99
  continue
@@ -106,6 +98,7 @@ if role == "Học sinh":
106
  score = "10/10"
107
  else:
108
  score = "0/10"
 
109
  write_quiz_score(student_id, quiz_name, score)
110
  st.success(f"Đã nộp! Điểm: {score}")
111
  else:
 
1
  import streamlit as st
2
  import requests
3
  import json
 
4
 
5
  # ==========================
6
  # Firebase Realtime Database
7
  # ==========================
8
+ FIREBASE_URL = "https://smartedu-3d5bf-default-rtdb.asia-southeast1.firebasedatabase.app"
9
 
 
10
  def write_student_info(student_id, name, classroom):
11
  url = f"{FIREBASE_URL}/{student_id}.json"
12
  data = {
 
15
  }
16
  requests.patch(url, json=data)
17
 
 
18
  def write_quiz_score(student_id, quiz_name, score):
19
  url = f"{FIREBASE_URL}/{student_id}/{quiz_name}.json"
20
  requests.put(url, json=score)
21
 
 
22
  def get_student_data(student_id):
23
  url = f"{FIREBASE_URL}/{student_id}.json"
24
  res = requests.get(url)
 
51
  correct_answer = st.text_input("Đáp án đúng")
52
 
53
  if st.button("Lưu Quiz"):
 
54
  url = f"{FIREBASE_URL}/quiz_definitions/{quiz_name}.json"
55
  requests.put(url, json={
56
  "question": question,
 
76
  else:
77
  st.error("Vui lòng nhập đầy đủ thông tin!")
78
 
 
79
  st.subheader("Làm Quiz")
80
  res = requests.get(f"{FIREBASE_URL}/quiz_definitions.json")
81
  quizzes = res.json() if res.status_code == 200 else {}
82
 
83
+ student_data = get_student_data(student_id) if student_id else {}
 
84
 
85
  if quizzes:
86
  for quiz_name, content in quizzes.items():
87
  st.markdown(f"### {quiz_name}")
88
 
 
89
  if student_data and quiz_name in student_data:
90
  st.info(f"Bạn đã làm Quiz này rồi. Điểm: {student_data[quiz_name]}")
91
  continue
 
98
  score = "10/10"
99
  else:
100
  score = "0/10"
101
+
102
  write_quiz_score(student_id, quiz_name, score)
103
  st.success(f"Đã nộp! Điểm: {score}")
104
  else: