Skip to content

Commit 7748057

Browse files
committed
change questions format
1 parent 49c03c4 commit 7748057

File tree

2 files changed

+22
-109
lines changed

2 files changed

+22
-109
lines changed

app.py

Lines changed: 22 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,29 @@
11
from flask import Flask, render_template, request, jsonify
2+
import pandas as pd
23

34
app = Flask(__name__)
45

5-
game_data = [
6-
{
7-
"image": "image1.jpg",
8-
"question": "Hình dạng của biển báo này là gì?",
9-
"options": ["Vuông", "Tròn", "Tam giác", "Chữ nhật"],
10-
"correct": "C",
11-
"is_about_previous": False
12-
},
13-
{
14-
"image": "image2.png",
15-
"question": "Hình dạng của biển báo này là gì?",
16-
"options": ["Tam giác", "Tròn", "Vuông", "Chữ nhật"],
17-
"correct": "B",
18-
"is_about_previous": False
19-
},
20-
{
21-
"image": "image3.jpg",
22-
"question": "Hình dạng của biển báo trước đó là gì?",
23-
"options": ["Chữ nhật", "Tròn", "Tam giác", "Vuông"],
24-
"correct": "B",
25-
"is_about_previous": True
26-
},
27-
{
28-
"image": "image1.jpg",
29-
"question": "Màu sắc của biển báo trước đó là gì?",
30-
"options": ["Xanh dương", "Xanh lá", "Đen", "Đỏ"],
31-
"correct": "A",
32-
"is_about_previous": True
33-
},
34-
{
35-
"image": "image3.jpg",
36-
"question": "Hình dạng của biển báo trước đó là gì?",
37-
"options": ["Chữ nhật", "Tròn", "Vuông", "Tam giác"],
38-
"correct": "D",
39-
"is_about_previous": True
40-
},
41-
{
42-
"image": "image4.jpeg",
43-
"question": "Có bao nhiêu người trong hình ảnh này?",
44-
"options": ["1", "2", "3", "5"],
45-
"correct": "D",
46-
"is_about_previous": False
47-
},
48-
{
49-
"image": "image2.png",
50-
"question": "Dòng chữ trên tường trong hình ảnh trước đó là gì?",
51-
"options": ["Eureka", "Robotics", "Millennials", "Millennial"],
52-
"correct": "C",
53-
"is_about_previous": True
54-
},
55-
{
56-
"image": "image2.png",
57-
"question": "Hình dạng của biển báo này là gì?",
58-
"options": ["Tam giác", "Tròn", "Vuông", "Chữ nhật"],
59-
"correct": "B",
60-
"is_about_previous": False
61-
},
62-
{
63-
"image": "image5.jpg",
64-
"question": "Có hoa màu vàng trong hình ảnh này không?",
65-
"options": ["Có", "Không", "Có thể", "Không chắc"],
66-
"correct": "A",
67-
"is_about_previous": False
68-
},
69-
{
70-
"image": "image1.jpg",
71-
"question": "Có bao nhiêu bông hoa màu đỏ trong hình ảnh trước đó?",
72-
"options": ["1", "2", "3", "4"],
73-
"correct": "C",
74-
"is_about_previous": True
75-
},
76-
{
77-
"image": "image3.jpg",
78-
"question": "Có bao nhiêu mũi tên hướng lên trong hình ảnh trước đó?",
79-
"options": ["1", "2", "3", "0"],
80-
"correct": "A",
81-
"is_about_previous": True
82-
},
83-
{
84-
"image": "image6_vn.png",
85-
"question": "Có bao nhiêu màu sắc trong hình ảnh trước đó?",
86-
"options": ["1", "2", "3", "0"],
87-
"correct": "B",
88-
"is_about_previous": True
89-
},
90-
{
91-
"image": "image4.jpeg",
92-
"question": "Có bao nhiêu từ trong dòng chữ màu xanh trong hình ảnh trước đó?",
93-
"options": ["5", "6", "7", "8"],
94-
"correct": "D",
95-
"is_about_previous": True
96-
},
97-
{
98-
"image": "image8.png",
99-
"question": "Eureka Robotics đã huy động được bao nhiêu trong vòng gọi vốn series A?",
100-
"options": ["0.5M USD", "3.0M USD", "10.0M USD", "10.5M USD"],
101-
"correct": "D",
102-
"is_about_previous": True
103-
},
104-
{
105-
"image": "image7_vn.png",
106-
"question": "Bạn có muốn tham gia với chúng tôi không?",
107-
"options": ["Có", "Không", "Có thể", "Không chắc"],
108-
"correct": "A",
109-
"is_about_previous": False
110-
},
6+
# Load game data from Excel file
7+
try:
8+
# Read the Excel file
9+
excel_data = pd.read_excel('static/questions.xlsx')
11110

112-
# Add more questions
113-
]
11+
# Convert Excel data to the required format
12+
game_data = []
13+
for _, row in excel_data.iterrows():
14+
question_item = {
15+
"image": row["Anh"],
16+
"question": row["Cau_hoi"],
17+
"options": [row["A"], row["B"], row["C"], row["D"]],
18+
"correct": row["Dap_an"],
19+
"is_about_previous": bool(row["Hoi_cau_truoc_do"]) # Convert to boolean
20+
}
21+
game_data.append(question_item)
22+
23+
except Exception as e:
24+
print(f"Error loading questions from Excel: {e}")
25+
game_data = []
26+
11427

11528
# Ranking system based on score
11629
def get_rank(score):
@@ -187,4 +100,4 @@ def get_correct_answer():
187100
return jsonify({"error": "Invalid question index"})
188101

189102
if __name__ == '__main__':
190-
app.run(host='192.168.192.37', port=5041, debug=True)
103+
app.run(host='0.0.0.0', port=5001, debug=True)

static/questions.xlsx

5.98 KB
Binary file not shown.

0 commit comments

Comments
 (0)