コード例 #1
0
  private void saveFeatures() throws IOException, ClassNotFoundException {
    File file = new File(getExternalFilesDir(null), _exerciseName + ".txt");
    if (!file.exists()) {
      file.createNewFile();
    }
    ObjectOutputStream oostream = new ObjectOutputStream(new FileOutputStream(file));
    for (int i = 1; i <= _reps; i++) {
      File readingFile = new File(_directory, i + ".txt");
      FileInputStream fistream = new FileInputStream(readingFile);
      ObjectInputStream oistream = new ObjectInputStream(fistream);
      ArrayList<SensorReading> reading = new ArrayList<>();
      while (fistream.available() > 0) { // Check if the file stream is at the end
        reading.add((SensorReading) oistream.readObject());
      }
      // TODO: Get feature object here
      // Create ExerciseData object from the readings
      ExerciseData exerciseData = new ExerciseData(reading);
      Feature feature = new Feature();
      Log.d("reading_size", reading.size() + "");
      feature._features = exerciseData.getFeatureVector();
      feature._time = exerciseData.getTime();
      feature._classLabel = Globals._numExercises + 1;
      oostream.writeObject(feature);
    }
    if (Globals._exerciseLabels == null) {
      Globals._exerciseLabels = new HashMap<>();
    }
    Globals._exerciseLabels.put(_exerciseName, Globals._numExercises + 1);
    Globals._numExercises++;
    Globals.saveExerciseLabels(this);

    Classifier.trainModel(this);
  }