Fraser commited on
Commit
c0fc1ad
Β·
1 Parent(s): 36364af
.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": ["counterType", "strength"],
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
- const tx = db.transaction([TRAINER_SCAN_STORE], 'readwrite');
9
- const store = tx.objectStore(TRAINER_SCAN_STORE);
10
-
11
- let processedCount = 0;
12
- let skippedCount = 0;
13
-
14
- for (const imagePath of imagePaths) {
15
- try {
16
- // Extract trainer name and image index from path
17
- // Format: "trainer_images/001_Willow_Snap/image_001.jpg"
18
- const pathParts = imagePath.split('/');
19
- if (pathParts.length < 3) {
20
- console.warn(`⚠️ Skipping invalid path format: ${imagePath}`);
21
- skippedCount++;
22
- continue;
23
- }
24
-
25
- const trainerName = pathParts[1]?.trim(); // "001_Willow_Snap"
26
- const imageFile = pathParts[2]?.trim(); // "image_001.jpg"
27
-
28
- if (!trainerName || !imageFile || typeof trainerName !== 'string' || typeof imageFile !== 'string') {
29
- console.warn(`⚠️ Skipping path with missing or invalid parts: ${imagePath}`, { trainerName, imageFile });
30
- skippedCount++;
31
- continue;
32
- }
33
-
34
- const imageMatch = imageFile.match(/image_(\d+)\.jpg/);
35
- const imageIndex = imageMatch ? parseInt(imageMatch[1]) : 1;
36
-
37
- const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${imagePath}`;
38
-
39
- // Check if this path already exists to avoid duplicates
40
- const existing = await store.get(imagePath);
41
- if (!existing) {
42
- const progressRecord: Omit<TrainerScanProgress, 'id'> = {
43
- imagePath,
44
- trainerName,
45
- imageIndex,
46
- status: 'pending',
47
- remoteUrl
48
- };
49
 
50
- await store.add(progressRecord);
51
- processedCount++;
52
- } else {
53
- // Record exists, don't count as processed but note it
54
- processedCount++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- const imagePaths = content.trim().split('\n')
90
- .map(path => typeof path === 'string' ? path.trim() : '')
91
- .filter(path => path.length > 0);
92
- console.log(`Loaded ${imagePaths.length} trainer image paths`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- this.notifyStateChange(await this.getCurrentState());
 
 
 
 
 
 
 
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
  }