LOGS
Browse files- .gitignore +3 -0
- battle_system_design.md +1 -3
- src/lib/db/trainerScanning.ts +115 -56
- src/lib/services/trainerScanService.ts +40 -6
.gitignore
CHANGED
@@ -31,3 +31,6 @@ trainer_captions*
|
|
31 |
trainer_images
|
32 |
trainer_piclets*
|
33 |
trainer_personas.csv
|
|
|
|
|
|
|
|
31 |
trainer_images
|
32 |
trainer_piclets*
|
33 |
trainer_personas.csv
|
34 |
+
pokemon_stat_calculation.md
|
35 |
+
POKEMON_STATS_AND_LEVELING.md
|
36 |
+
*.py
|
battle_system_design.md
CHANGED
@@ -197,7 +197,6 @@ All battle effects are built from these atomic operations:
|
|
197 |
```json
|
198 |
{
|
199 |
"type": "counter",
|
200 |
-
"counterType": "physical" | "special" | "any",
|
201 |
"strength": "weak" | "normal" | "strong"
|
202 |
}
|
203 |
```
|
@@ -1627,9 +1626,8 @@ Types correspond to photographed objects in the real world:
|
|
1627 |
{
|
1628 |
"if": {"properties": {"type": {"const": "counter"}}},
|
1629 |
"then": {
|
1630 |
-
"required": ["
|
1631 |
"properties": {
|
1632 |
-
"counterType": {"type": "string", "enum": ["physical", "special", "any"]},
|
1633 |
"strength": {"type": "string", "enum": ["weak", "normal", "strong"]}
|
1634 |
}
|
1635 |
}
|
|
|
197 |
```json
|
198 |
{
|
199 |
"type": "counter",
|
|
|
200 |
"strength": "weak" | "normal" | "strong"
|
201 |
}
|
202 |
```
|
|
|
1626 |
{
|
1627 |
"if": {"properties": {"type": {"const": "counter"}}},
|
1628 |
"then": {
|
1629 |
+
"required": ["strength"],
|
1630 |
"properties": {
|
|
|
1631 |
"strength": {"type": "string", "enum": ["weak", "normal", "strong"]}
|
1632 |
}
|
1633 |
}
|
src/lib/db/trainerScanning.ts
CHANGED
@@ -1,68 +1,127 @@
|
|
1 |
import { db } from './index';
|
2 |
import type { TrainerScanProgress } from './schema';
|
3 |
|
4 |
-
const TRAINER_SCAN_STORE = 'trainerScanProgress';
|
5 |
-
|
6 |
// Initialize trainer scan progress records from paths
|
7 |
export async function initializeTrainerScanProgress(imagePaths: string[]): Promise<void> {
|
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 |
-
trainerName,
|
45 |
-
imageIndex,
|
46 |
-
status: 'pending',
|
47 |
-
remoteUrl
|
48 |
-
};
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
-
} catch (error) {
|
57 |
-
console.error(`β Failed to process path entry: ${imagePath}`, error);
|
58 |
-
skippedCount++;
|
59 |
-
// Continue processing other paths despite this failure
|
60 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
}
|
62 |
-
|
63 |
-
console.log(`β
Trainer scan initialization complete: ${processedCount} records processed, ${skippedCount} skipped`);
|
64 |
-
|
65 |
-
await tx.complete;
|
66 |
}
|
67 |
|
68 |
// Get next pending image to process
|
|
|
1 |
import { db } from './index';
|
2 |
import type { TrainerScanProgress } from './schema';
|
3 |
|
|
|
|
|
4 |
// Initialize trainer scan progress records from paths
|
5 |
export async function initializeTrainerScanProgress(imagePaths: string[]): Promise<void> {
|
6 |
+
try {
|
7 |
+
console.log('π initializeTrainerScanProgress: Starting with', imagePaths.length, 'paths');
|
8 |
+
console.log('π initializeTrainerScanProgress: First few paths:', imagePaths.slice(0, 3));
|
9 |
+
|
10 |
+
console.log('π initializeTrainerScanProgress: Creating transaction...');
|
11 |
+
const tx = db.transaction([TRAINER_SCAN_STORE], 'readwrite');
|
12 |
+
console.log('π initializeTrainerScanProgress: Transaction created');
|
13 |
+
|
14 |
+
const store = tx.objectStore(TRAINER_SCAN_STORE);
|
15 |
+
console.log('π initializeTrainerScanProgress: Got object store');
|
16 |
+
|
17 |
+
let processedCount = 0;
|
18 |
+
let skippedCount = 0;
|
19 |
+
|
20 |
+
for (let i = 0; i < imagePaths.length; i++) {
|
21 |
+
const imagePath = imagePaths[i];
|
22 |
+
try {
|
23 |
+
console.log(`π initializeTrainerScanProgress: Processing path ${i}: "${imagePath}" (type: ${typeof imagePath})`);
|
24 |
+
|
25 |
+
if (typeof imagePath !== 'string') {
|
26 |
+
console.error(`β initializeTrainerScanProgress: Path at index ${i} is not a string:`, imagePath);
|
27 |
+
skippedCount++;
|
28 |
+
continue;
|
29 |
+
}
|
30 |
+
|
31 |
+
// Extract trainer name and image index from path
|
32 |
+
// Format: "trainer_images/001_Willow_Snap/image_001.jpg"
|
33 |
+
console.log(`π initializeTrainerScanProgress: Splitting path: "${imagePath}"`);
|
34 |
+
const pathParts = imagePath.split('/');
|
35 |
+
console.log(`π initializeTrainerScanProgress: Path parts:`, pathParts);
|
36 |
+
|
37 |
+
if (pathParts.length < 3) {
|
38 |
+
console.warn(`β οΈ Skipping invalid path format: ${imagePath} (length: ${pathParts.length})`);
|
39 |
+
skippedCount++;
|
40 |
+
continue;
|
41 |
+
}
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
const rawTrainerName = pathParts[1];
|
44 |
+
const rawImageFile = pathParts[2];
|
45 |
+
console.log(`π initializeTrainerScanProgress: Raw parts - trainer: "${rawTrainerName}" (${typeof rawTrainerName}), image: "${rawImageFile}" (${typeof rawImageFile})`);
|
46 |
+
|
47 |
+
const trainerName = rawTrainerName?.trim?.(); // Safe call with optional chaining
|
48 |
+
const imageFile = rawImageFile?.trim?.(); // Safe call with optional chaining
|
49 |
+
console.log(`π initializeTrainerScanProgress: Trimmed parts - trainer: "${trainerName}" (${typeof trainerName}), image: "${imageFile}" (${typeof imageFile})`);
|
50 |
+
|
51 |
+
if (!trainerName || !imageFile || typeof trainerName !== 'string' || typeof imageFile !== 'string') {
|
52 |
+
console.warn(`β οΈ Skipping path with missing or invalid parts: ${imagePath}`, {
|
53 |
+
trainerName,
|
54 |
+
imageFile,
|
55 |
+
trainerType: typeof trainerName,
|
56 |
+
imageType: typeof imageFile
|
57 |
+
});
|
58 |
+
skippedCount++;
|
59 |
+
continue;
|
60 |
+
}
|
61 |
+
|
62 |
+
console.log(`π initializeTrainerScanProgress: Matching image file: "${imageFile}"`);
|
63 |
+
const imageMatch = imageFile.match(/image_(\d+)\.jpg/);
|
64 |
+
const imageIndex = imageMatch ? parseInt(imageMatch[1]) : 1;
|
65 |
+
console.log(`π initializeTrainerScanProgress: Image index: ${imageIndex}`);
|
66 |
+
|
67 |
+
const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${imagePath}`;
|
68 |
+
console.log(`π initializeTrainerScanProgress: Remote URL: ${remoteUrl}`);
|
69 |
+
|
70 |
+
// Check if this path already exists to avoid duplicates
|
71 |
+
console.log(`π initializeTrainerScanProgress: Checking for existing record...`);
|
72 |
+
const existing = await store.get(imagePath);
|
73 |
+
console.log(`π initializeTrainerScanProgress: Existing record:`, existing ? 'found' : 'not found');
|
74 |
+
|
75 |
+
if (!existing) {
|
76 |
+
const progressRecord: Omit<TrainerScanProgress, 'id'> = {
|
77 |
+
imagePath,
|
78 |
+
trainerName,
|
79 |
+
imageIndex,
|
80 |
+
status: 'pending',
|
81 |
+
remoteUrl
|
82 |
+
};
|
83 |
+
|
84 |
+
console.log(`π initializeTrainerScanProgress: Adding record:`, progressRecord);
|
85 |
+
await store.add(progressRecord);
|
86 |
+
console.log(`π initializeTrainerScanProgress: Record added successfully`);
|
87 |
+
processedCount++;
|
88 |
+
} else {
|
89 |
+
// Record exists, don't count as processed but note it
|
90 |
+
processedCount++;
|
91 |
+
}
|
92 |
+
|
93 |
+
// Log progress every 100 items
|
94 |
+
if (i % 100 === 0) {
|
95 |
+
console.log(`π initializeTrainerScanProgress: Progress: ${i}/${imagePaths.length} (${Math.round((i/imagePaths.length)*100)}%)`);
|
96 |
+
}
|
97 |
+
|
98 |
+
} catch (error) {
|
99 |
+
console.error(`β Failed to process path entry at index ${i}: "${imagePath}"`, error);
|
100 |
+
console.error('β Error details:', {
|
101 |
+
message: error instanceof Error ? error.message : 'Unknown error',
|
102 |
+
stack: error instanceof Error ? error.stack : 'No stack trace',
|
103 |
+
pathValue: imagePath,
|
104 |
+
pathType: typeof imagePath
|
105 |
+
});
|
106 |
+
skippedCount++;
|
107 |
+
// Continue processing other paths despite this failure
|
108 |
}
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
+
|
111 |
+
console.log(`β
Trainer scan initialization complete: ${processedCount} records processed, ${skippedCount} skipped`);
|
112 |
+
|
113 |
+
console.log('π initializeTrainerScanProgress: Completing transaction...');
|
114 |
+
await tx.complete;
|
115 |
+
console.log('π initializeTrainerScanProgress: Transaction completed successfully');
|
116 |
+
|
117 |
+
} catch (error) {
|
118 |
+
console.error('β initializeTrainerScanProgress: Fatal error during initialization:', error);
|
119 |
+
console.error('β initializeTrainerScanProgress: Error details:', {
|
120 |
+
message: error instanceof Error ? error.message : 'Unknown error',
|
121 |
+
stack: error instanceof Error ? error.stack : 'No stack trace'
|
122 |
+
});
|
123 |
+
throw error;
|
124 |
}
|
|
|
|
|
|
|
|
|
125 |
}
|
126 |
|
127 |
// Get next pending image to process
|
src/lib/services/trainerScanService.ts
CHANGED
@@ -76,29 +76,63 @@ export class TrainerScanService {
|
|
76 |
// Initialize scanning database with image paths from file
|
77 |
async initializeFromFile(): Promise<void> {
|
78 |
try {
|
|
|
|
|
79 |
const response = await fetch('/trainer_image_paths.txt');
|
80 |
if (!response.ok) {
|
81 |
throw new Error(`Failed to fetch trainer_image_paths.txt: ${response.statusText}`);
|
82 |
}
|
83 |
|
|
|
|
|
84 |
const content = await response.text();
|
85 |
if (!content) {
|
86 |
throw new Error('trainer_image_paths.txt is empty');
|
87 |
}
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
if (imagePaths.length === 0) {
|
95 |
throw new Error('No valid image paths found in trainer_image_paths.txt');
|
96 |
}
|
97 |
|
|
|
98 |
await initializeTrainerScanProgress(imagePaths);
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
} catch (error) {
|
101 |
-
console.error('Failed to initialize trainer scan progress:', error);
|
|
|
102 |
throw new Error('Failed to load trainer image paths');
|
103 |
}
|
104 |
}
|
|
|
76 |
// Initialize scanning database with image paths from file
|
77 |
async initializeFromFile(): Promise<void> {
|
78 |
try {
|
79 |
+
console.log('π TrainerScanService: Starting initializeFromFile...');
|
80 |
+
|
81 |
const response = await fetch('/trainer_image_paths.txt');
|
82 |
if (!response.ok) {
|
83 |
throw new Error(`Failed to fetch trainer_image_paths.txt: ${response.statusText}`);
|
84 |
}
|
85 |
|
86 |
+
console.log('π TrainerScanService: Successfully fetched trainer_image_paths.txt');
|
87 |
+
|
88 |
const content = await response.text();
|
89 |
if (!content) {
|
90 |
throw new Error('trainer_image_paths.txt is empty');
|
91 |
}
|
92 |
|
93 |
+
console.log(`π TrainerScanService: File content length: ${content.length}`);
|
94 |
+
console.log(`π TrainerScanService: First 200 chars: ${content.substring(0, 200)}`);
|
95 |
+
|
96 |
+
const lines = content.trim().split('\n');
|
97 |
+
console.log(`π TrainerScanService: Split into ${lines.length} lines`);
|
98 |
+
|
99 |
+
const imagePaths = lines
|
100 |
+
.map((path, index) => {
|
101 |
+
console.log(`π TrainerScanService: Processing line ${index}: "${path}" (type: ${typeof path})`);
|
102 |
+
if (typeof path !== 'string') {
|
103 |
+
console.warn(`π TrainerScanService: Line ${index} is not a string:`, path);
|
104 |
+
return '';
|
105 |
+
}
|
106 |
+
const trimmed = path.trim();
|
107 |
+
console.log(`π TrainerScanService: Line ${index} trimmed: "${trimmed}"`);
|
108 |
+
return trimmed;
|
109 |
+
})
|
110 |
+
.filter((path, index) => {
|
111 |
+
const isValid = path.length > 0;
|
112 |
+
console.log(`π TrainerScanService: Line ${index} valid: ${isValid}`);
|
113 |
+
return isValid;
|
114 |
+
});
|
115 |
+
|
116 |
+
console.log(`π TrainerScanService: Loaded ${imagePaths.length} trainer image paths`);
|
117 |
+
console.log(`π TrainerScanService: First 5 paths:`, imagePaths.slice(0, 5));
|
118 |
|
119 |
if (imagePaths.length === 0) {
|
120 |
throw new Error('No valid image paths found in trainer_image_paths.txt');
|
121 |
}
|
122 |
|
123 |
+
console.log('π TrainerScanService: About to call initializeTrainerScanProgress...');
|
124 |
await initializeTrainerScanProgress(imagePaths);
|
125 |
+
console.log('π TrainerScanService: initializeTrainerScanProgress completed successfully');
|
126 |
+
|
127 |
+
console.log('π TrainerScanService: About to get current state...');
|
128 |
+
const currentState = await this.getCurrentState();
|
129 |
+
console.log('π TrainerScanService: Got current state:', currentState);
|
130 |
+
|
131 |
+
this.notifyStateChange(currentState);
|
132 |
+
console.log('π TrainerScanService: initializeFromFile completed successfully');
|
133 |
} catch (error) {
|
134 |
+
console.error('β TrainerScanService: Failed to initialize trainer scan progress:', error);
|
135 |
+
console.error('β TrainerScanService: Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
136 |
throw new Error('Failed to load trainer image paths');
|
137 |
}
|
138 |
}
|