-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_ar_fitting.dart
More file actions
301 lines (262 loc) · 8.99 KB
/
test_ar_fitting.dart
File metadata and controls
301 lines (262 loc) · 8.99 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
/// Test script for AR Fitting functionality
/// This script tests the backend AR fitting API endpoints
class ARFittingTester {
static const String baseUrl = 'http://localhost:8080/api/ar-fitting';
static Future<void> main() async {
print('🧪 Testing AR Fitting API...\n');
try {
// Test 1: Analyze photo
await testAnalyzePhoto();
// Test 2: Generate virtual try-on
await testVirtualTryOn();
// Test 3: Save measurements
await testSaveMeasurements();
// Test 4: Get measurements
await testGetMeasurements();
// Test 5: Get fitting history
await testGetFittingHistory();
// Test 6: Rate product fit
await testRateProductFit();
// Test 7: Get size recommendations
await testGetSizeRecommendations();
// Test 8: Get body analysis
await testGetBodyAnalysis();
print('\n✅ All AR Fitting tests completed successfully!');
} catch (e) {
print('\n❌ Test failed: $e');
}
}
/// Test photo analysis endpoint
static Future<void> testAnalyzePhoto() async {
print('📸 Testing photo analysis...');
try {
final response = await http.post(
Uri.parse('$baseUrl/analyze-photo'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'photoPath': '/test/photo.jpg',
'userId': 1,
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Photo analysis successful');
print(' Measurements: ${data['measurements']}');
print(' Message: ${data['message']}');
} else {
print('❌ Photo analysis failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Photo analysis error: $e');
}
print('');
}
/// Test virtual try-on endpoint
static Future<void> testVirtualTryOn() async {
print('👕 Testing virtual try-on...');
try {
final response = await http.post(
Uri.parse('$baseUrl/virtual-try-on'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'userId': 1,
'category': 'shirts',
'userMeasurements': {
'height': 175.0,
'chest': 95.0,
'waist': 80.0,
},
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Virtual try-on successful');
print(' Recommendations count: ${data['recommendations'].length}');
if (data['recommendations'].isNotEmpty) {
final firstRec = data['recommendations'][0];
print(' First recommendation score: ${firstRec['score']}');
print(' Fit prediction: ${firstRec['fitPrediction']}');
}
} else {
print('❌ Virtual try-on failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Virtual try-on error: $e');
}
print('');
}
/// Test save measurements endpoint
static Future<void> testSaveMeasurements() async {
print('📏 Testing save measurements...');
try {
final measurements = {
'height': 175.0,
'weight': 70.0,
'chest': 95.0,
'waist': 80.0,
'hips': 95.0,
'shoulders': 45.0,
'inseam': 80.0,
};
final response = await http.post(
Uri.parse('$baseUrl/measurements'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'userId': 1,
'measurements': measurements,
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Save measurements successful');
print(' Message: ${data['message']}');
} else {
print('❌ Save measurements failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Save measurements error: $e');
}
print('');
}
/// Test get measurements endpoint
static Future<void> testGetMeasurements() async {
print('📊 Testing get measurements...');
try {
final response = await http.get(
Uri.parse('$baseUrl/measurements/1'),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Get measurements successful');
if (data['measurements'] != null) {
final measurements = data['measurements'] as Map<String, dynamic>;
print(' Height: ${measurements['height']} cm');
print(' Weight: ${measurements['weight']} kg');
print(' Chest: ${measurements['chest']} cm');
}
} else {
print('❌ Get measurements failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Get measurements error: $e');
}
print('');
}
/// Test get fitting history endpoint
static Future<void> testGetFittingHistory() async {
print('📚 Testing get fitting history...');
try {
final response = await http.get(
Uri.parse('$baseUrl/history/1'),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Get fitting history successful');
print(' History items count: ${data['history'].length}');
if (data['history'].isNotEmpty) {
final firstItem = data['history'][0];
print(' First item: ${firstItem['productName']}');
print(' Brand: ${firstItem['brand']}');
}
} else {
print('❌ Get fitting history failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Get fitting history error: $e');
}
print('');
}
/// Test rate product fit endpoint
static Future<void> testRateProductFit() async {
print('⭐ Testing rate product fit...');
try {
final response = await http.post(
Uri.parse('$baseUrl/rate-fit'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'userId': 1,
'productId': 1,
'rating': 5,
'feedback': 'Perfect fit! Love this shirt.',
}),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Rate product fit successful');
print(' Message: ${data['message']}');
} else {
print('❌ Rate product fit failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Rate product fit error: $e');
}
print('');
}
/// Test get size recommendations endpoint
static Future<void> testGetSizeRecommendations() async {
print('👖 Testing get size recommendations...');
try {
final response = await http.get(
Uri.parse('$baseUrl/size-recommendations/shirts'),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Get size recommendations successful');
print(' Category: ${data['category']}');
final recommendations = data['recommendations'];
print(' Available sizes: ${recommendations['sizes']}');
if (recommendations['tips'] != null) {
print(' Tips count: ${recommendations['tips'].length}');
}
} else {
print('❌ Get size recommendations failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Get size recommendations error: $e');
}
print('');
}
/// Test get body analysis endpoint
static Future<void> testGetBodyAnalysis() async {
print('🔍 Testing get body analysis...');
try {
final response = await http.get(
Uri.parse('$baseUrl/body-analysis/1'),
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print('✅ Get body analysis successful');
if (data['analysis'] != null) {
final analysis = data['analysis'];
print(' Body type: ${analysis['bodyType']}');
print(' Description: ${analysis['description']}');
print(' BMI: ${analysis['bmi']}');
print(' BMI category: ${analysis['bmiCategory']}');
if (analysis['recommendations'] != null) {
print(' Style recommendations: ${analysis['recommendations'].length}');
}
}
} else {
print('❌ Get body analysis failed: ${response.statusCode}');
print(' Response: ${response.body}');
}
} catch (e) {
print('❌ Get body analysis error: $e');
}
print('');
}
}
/// Run the tests
void main() async {
await ARFittingTester.main();
}