@@ -44,6 +44,7 @@ import {
4444 checkUpdateStatus ,
4545 markUpdateComplete ,
4646 updateTagName ,
47+ getTrainingRecordCount ,
4748} from "@/lib/db" ;
4849import {
4950 getNotificationPlates as getNotificationPlatesDB ,
@@ -1102,6 +1103,9 @@ export async function skipImageMigration() {
11021103
11031104export async function generateTrainingData ( ) {
11041105 try {
1106+ const config = await getConfig ( ) ;
1107+
1108+ console . log ( "Starting training data generation and upload process" ) ;
11051109 const tmpDir = path . join ( os . tmpdir ( ) , "alpr-training-" + Date . now ( ) ) ;
11061110 const generator = new TrainingDataGenerator ( tmpDir ) ;
11071111 await generator . generateAndUpload ( ) ;
@@ -1117,3 +1121,31 @@ export async function generateTrainingData() {
11171121 throw new Error ( error . message || "Failed to generate training data" ) ;
11181122 }
11191123}
1124+
1125+ export async function processTrainingData ( ) {
1126+ try {
1127+ // Check if training is enabled in settings
1128+ const config = await getConfig ( ) ;
1129+ if ( ! config ?. training ?. enabled ) {
1130+ return { success : false , message : "Training not enabled" } ;
1131+ }
1132+
1133+ // Check if we have enough records
1134+ const { newRecordsCount } = await getTrainingRecordCount ( ) ;
1135+ if ( newRecordsCount < 500 ) {
1136+ return { success : false , message : "Not enough new records" } ;
1137+ }
1138+
1139+ // Create temp directory
1140+ const tempDir = path . join ( os . tmpdir ( ) , `alpr-training-${ Date . now ( ) } ` ) ;
1141+
1142+ // Start the generator
1143+ const generator = new TrainingDataGenerator ( tempDir ) ;
1144+ await generator . generateAndUpload ( ) ;
1145+
1146+ return { success : true } ;
1147+ } catch ( error ) {
1148+ console . error ( "Error processing training data:" , error ) ;
1149+ return { success : false , error : error . message } ;
1150+ }
1151+ }
0 commit comments