diff --git a/java/com.sap.sailing.windestimation.lab/src/com/sap/sailing/windestimation/ExportedModelsGenerator.java b/java/com.sap.sailing.windestimation.lab/src/com/sap/sailing/windestimation/ExportedModelsGenerator.java new file mode 100644 index 00000000000..9b3d0f5621f --- /dev/null +++ b/java/com.sap.sailing.windestimation.lab/src/com/sap/sailing/windestimation/ExportedModelsGenerator.java @@ -0,0 +1,49 @@ +package com.sap.sailing.windestimation; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.sap.sailing.windestimation.integration.ExportedModels; +import com.sap.sailing.windestimation.model.store.FileSystemModelStoreImpl; +import com.sap.sailing.windestimation.model.store.ModelDomainType; +import com.sap.sailing.windestimation.model.store.ModelStore; +import com.sap.sailing.windestimation.util.LoggingUtil; + +public class ExportedModelsGenerator { + + private static final File file = new File("windEstimationModels.dat"); + + public static void main(String[] args) throws FileNotFoundException, IOException { + ModelStore modelStore = new FileSystemModelStoreImpl("trained_wind_estimation_models"); + // RegularManeuversForEstimationPersistenceManager persistenceManager = new + // RegularManeuversForEstimationPersistenceManager(); + // ModelStore modelStore = new MongoDbModelStoreImpl(persistenceManager.getDb()); + LoggingUtil.logInfo("Generation a single file with all trained models started"); + ExportedModels exportedModels = new ExportedModels(); + List nonEmptyDomainTypes = new ArrayList<>(); + for (ModelDomainType domainType : ModelDomainType.values()) { + LoggingUtil.logInfo("Started serialization of models belonging to domain type " + domainType); + Map exportedModelsForDomainType = modelStore.exportAllPersistedModels(domainType); + if (!exportedModelsForDomainType.isEmpty()) { + exportedModels.addSerializedModelsForDomainType(domainType, exportedModelsForDomainType); + LoggingUtil.logInfo("Finished serialization of " + exportedModelsForDomainType.size() + + " models belonging to domain type " + domainType); + nonEmptyDomainTypes.add(domainType); + } + } + LoggingUtil.logInfo("Serializing the exported models and writing it into a single file"); + try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { + oos.writeObject(exportedModels); + } + LoggingUtil.logInfo("Models have been generated"); + LoggingUtil.logInfo("The following domain types were considered: " + nonEmptyDomainTypes); + LoggingUtil.logInfo("File with all exported models was persisted in: " + file.getAbsolutePath()); + } + +}