public static void saveAnalysisData( ExperimentAnalysis.AnalysisEntry analysisEntry, IDataAnalysis sensorAnalysis, File storageDir, List<ISensorData> allSensorData) throws IOException { Bundle bundle = new Bundle(); // save plugin bundle.putString(PLUGIN_ID_KEY, analysisEntry.plugin.getIdentifier()); bundle.putString(ANALYSIS_UID_KEY, analysisEntry.analysisUid); // save used data ISensorData[] dataList = sensorAnalysis.getData(); int integerList[] = new int[dataList.length]; for (int i = 0; i < integerList.length; i++) integerList[i] = allSensorData.indexOf(dataList[i]); bundle.putIntArray(SENSOR_DATA_LIST_KEY, integerList); // save experiment data Bundle experimentData = sensorAnalysis.exportAnalysisData(storageDir); bundle.putBundle(USED_DATA_KEY, experimentData); // save the bundle File projectFile = new File(storageDir, IDataAnalysis.EXPERIMENT_ANALYSIS_FILE_NAME); FileWriter fileWriter = new FileWriter(projectFile); PersistentBundle persistentBundle = new PersistentBundle(); persistentBundle.flattenBundle(bundle, fileWriter); }
// Tries to load an existing analysis. public static ExperimentAnalysis.AnalysisEntry loadSensorAnalysis( File storageDir, List<ISensorData> allSensorData) { // try to load old analysis File projectFile = new File(storageDir, IDataAnalysis.EXPERIMENT_ANALYSIS_FILE_NAME); Bundle bundle = loadBundleFromFile(projectFile); if (bundle == null) return null; Bundle analysisDataBundle = bundle.getBundle(USED_DATA_KEY); if (analysisDataBundle == null) return null; int[] integerList = bundle.getIntArray(SENSOR_DATA_LIST_KEY); ISensorData[] dataList = new ISensorData[integerList.length]; for (int i = 0; i < dataList.length; i++) dataList[i] = allSensorData.get(integerList[i]); String analysisPluginId = bundle.getString(PLUGIN_ID_KEY); ExperimentPluginFactory factory = ExperimentPluginFactory.getFactory(); IAnalysisPlugin plugin = factory.findAnalysisPlugin(analysisPluginId); IDataAnalysis dataAnalysis = plugin.createDataAnalysis(dataList); if (!dataAnalysis.loadAnalysisData(analysisDataBundle, storageDir)) return null; String analysisUid = bundle.getString(ANALYSIS_UID_KEY); return new ExperimentAnalysis.AnalysisEntry(dataAnalysis, analysisUid, plugin, storageDir); }