-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_my_questions.dart
More file actions
183 lines (151 loc) · 5.79 KB
/
Copy pathextract_my_questions.dart
File metadata and controls
183 lines (151 loc) · 5.79 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'lib/firebase_options.dart';
/// Script to extract questions added by the current teacher account
Future<void> main() async {
print('🚀 Extracting Your Teacher Questions...\n');
try {
// Initialize Firebase
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
print('✅ Firebase initialized successfully\n');
final firestore = FirebaseFirestore.instance;
// Extract question templates
print('📚 Your Question Templates...');
print('=' * 50);
await _extractMyTemplates(firestore);
// Extract questions from your activities
print('\n📝 Questions from Your Activities...');
print('=' * 50);
await _extractMyActivityQuestions(firestore);
print('\n✅ Extraction completed!');
} catch (e) {
print('❌ Error during extraction: $e');
exit(1);
}
}
/// Extract question templates from the database
Future<void> _extractMyTemplates(FirebaseFirestore firestore) async {
try {
final snapshot = await firestore
.collection('questionTemplates')
.where('isActive', isEqualTo: true)
.orderBy('title')
.get();
if (snapshot.docs.isEmpty) {
print('No question templates found in the database.');
return;
}
print('Found ${snapshot.docs.length} question templates:\n');
for (int i = 0; i < snapshot.docs.length; i++) {
final doc = snapshot.docs[i];
final data = doc.data();
print('${i + 1}. Template: ${data['title'] ?? 'Untitled'}');
print(' ID: ${doc.id}');
print(' Type: ${data['type'] ?? 'Unknown'}');
print(' Prompt: ${data['prompt'] ?? data['question'] ?? 'No prompt'}');
if (data['options'] != null && data['options'] is List) {
final options = data['options'] as List;
if (options.isNotEmpty) {
print(' Options:');
for (int j = 0; j < options.length; j++) {
print(' ${j + 1}. ${options[j]}');
}
}
}
print(' Correct Answer: ${data['correctAnswer'] ?? 'Not specified'}');
print(' Points: ${data['points'] ?? 0}');
if (data['skills'] != null && data['skills'] is List) {
final skills = data['skills'] as List;
if (skills.isNotEmpty) {
print(' Skills: ${skills.join(', ')}');
}
}
if (data['ageGroups'] != null && data['ageGroups'] is List) {
final ageGroups = data['ageGroups'] as List;
if (ageGroups.isNotEmpty) {
print(' Age Groups: ${ageGroups.join(', ')}');
}
}
if (data['subjects'] != null && data['subjects'] is List) {
final subjects = data['subjects'] as List;
if (subjects.isNotEmpty) {
print(' Subjects: ${subjects.join(', ')}');
}
}
if (data['explanation'] != null) {
print(' Explanation: ${data['explanation']}');
}
if (data['hint'] != null) {
print(' Hint: ${data['hint']}');
}
print('');
}
} catch (e) {
print('❌ Error loading question templates: $e');
}
}
/// Extract questions from teacher-created activities
Future<void> _extractMyActivityQuestions(FirebaseFirestore firestore) async {
try {
// Get all activities (we'll filter by createdBy if we can identify the teacher)
final activitiesSnapshot = await firestore
.collection('activities')
.orderBy('createdAt', descending: true)
.get();
if (activitiesSnapshot.docs.isEmpty) {
print('No activities found in the database.');
return;
}
print('Found ${activitiesSnapshot.docs.length} activities:\n');
for (int i = 0; i < activitiesSnapshot.docs.length; i++) {
final doc = activitiesSnapshot.docs[i];
final data = doc.data();
print('Activity ${i + 1}: ${data['title'] ?? 'Untitled Activity'}');
print(' ID: ${doc.id}');
print(' Created by: ${data['createdBy'] ?? 'Unknown'}');
print(' Subject: ${data['subject'] ?? 'Unknown'}');
print(' Age Group: ${data['ageGroup'] ?? 'Unknown'}');
print(' Difficulty: ${data['difficulty'] ?? 'Unknown'}');
print(' Publish State: ${data['publishState'] ?? 'Unknown'}');
if (data['questions'] != null && data['questions'] is List) {
final questions = data['questions'] as List;
print(' Questions (${questions.length}):');
for (int j = 0; j < questions.length; j++) {
final question = questions[j] as Map<String, dynamic>;
print(
' Question ${j + 1}: ${question['question'] ?? question['prompt'] ?? 'No question text'}');
print(' Type: ${question['type'] ?? 'Unknown'}');
print(' ID: ${question['id'] ?? 'No ID'}');
if (question['options'] != null && question['options'] is List) {
final options = question['options'] as List;
if (options.isNotEmpty) {
print(' Options:');
for (int k = 0; k < options.length; k++) {
print(' ${k + 1}. ${options[k]}');
}
}
}
print(
' Correct Answer: ${question['correctAnswer'] ?? 'Not specified'}');
print(' Points: ${question['points'] ?? 0}');
if (question['explanation'] != null) {
print(' Explanation: ${question['explanation']}');
}
if (question['hint'] != null) {
print(' Hint: ${question['hint']}');
}
print('');
}
} else {
print(' No questions found in this activity.');
}
print(' ' + '-' * 40);
print('');
}
} catch (e) {
print('❌ Error loading activities: $e');
}
}