Auto save classifier model

This commit is contained in:
M66B 2021-01-02 21:11:31 +01:00
parent 9c3fd46905
commit c2404bdce2
2 changed files with 20 additions and 1 deletions

View File

@ -239,7 +239,6 @@ public class MessageClassifier {
File file = getFile(context); File file = getFile(context);
Helper.writeText(file, jroot.toString(2)); Helper.writeText(file, jroot.toString(2));
loaded = false;
Log.i("Classifier saved classes=" + classMessages.size() + " words=" + wordClassFrequency.size()); Log.i("Classifier saved classes=" + classMessages.size() + " words=" + wordClassFrequency.size());
} }

View File

@ -113,6 +113,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "sync"); private static ExecutorService executor = Helper.getBackgroundExecutor(1, "sync");
private static final long BACKUP_DELAY = 30 * 1000L; // milliseconds
private static final long PURGE_DELAY = 30 * 1000L; // milliseconds private static final long PURGE_DELAY = 30 * 1000L; // milliseconds
private static final long QUIT_DELAY = 5 * 1000L; // milliseconds private static final long QUIT_DELAY = 5 * 1000L; // milliseconds
private static final long STILL_THERE_THRESHOLD = 3 * 60 * 1000L; // milliseconds private static final long STILL_THERE_THRESHOLD = 3 * 60 * 1000L; // milliseconds
@ -350,6 +351,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
WorkerFts.cancel(ServiceSynchronize.this); WorkerFts.cancel(ServiceSynchronize.this);
} }
getMainHandler().removeCallbacks(backup);
getMainHandler().postDelayed(backup, BACKUP_DELAY);
if (!isBackgroundService(ServiceSynchronize.this)) if (!isBackgroundService(ServiceSynchronize.this))
try { try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@ -542,6 +546,22 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
}); });
} }
private Runnable backup = new Runnable() {
@Override
public void run() {
queue.submit(new Runnable() {
@Override
public void run() {
try {
MessageClassifier.save(ServiceSynchronize.this);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
};
}); });
final TwoStateOwner cowner = new TwoStateOwner(this, "liveUnseenNotify"); final TwoStateOwner cowner = new TwoStateOwner(this, "liveUnseenNotify");