コード例 #1
0
ファイル: Battery.java プロジェクト: okoye/teenylime
  public void receivedSample(SourceId sourceId, Sample sample) {
    Vector<Double> sampleValue = (Vector<Double>) sample.getValue();
    if (console) {
      String fileName = "";
      if (dirName.length() > 0) fileName += dirName + File.separator;
      Calendar cal = Calendar.getInstance(Locale.ITALY);

      // session type
      String currentSessionType = feature.id();

      // step timestamp
      String currentDay =
          cal.get(Calendar.YEAR)
              + "-"
              + (1 + cal.get(Calendar.MONTH))
              + "-"
              + cal.get(Calendar.DAY_OF_MONTH);

      // building formatted filename
      fileName +=
          currentSessionType
              + "_"
              /* day YYYY-MM-DD */
              + currentDay
              + ".txt";

      FileWriter writer;
      try {
        writer = new FileWriter(fileName, true);
        writer.write("SENSOR: " + sourceId.toString());
        writer.write("\tBATTERY: " + sampleValue.get(0));
        writer.write(" (" + sampleValue.get(1).intValue() + ")");
        writer.write("\t" + sample.getTimestamp());
        if (sample.isEndingSession()) writer.write("\tCLOSING SESSION");
        writer.write("\n");
        writer.flush();
        writer.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    if (gui && panel != null) {
      panel.addPoint(sourceId, sample.getTimestamp().getTime(), sampleValue.get(0).doubleValue());
    }
  }
コード例 #2
0
ファイル: MeanTemperature.java プロジェクト: okoye/teenylime
 public void receivedSample(SourceId sourceId, Sample sample) {
   Vector<Double> sampleValue = (Vector<Double>) sample.getValue();
   FileWriter writer;
   if (console) {
     try {
       writer = new FileWriter(fileName, true);
       writer.write("SENSOR: " + sourceId.toString());
       writer.write("\tPERIOD: " + sample.getSamplingPeriod());
       writer.write("\tMEANTEMPERATURE: " + sampleValue.get(0));
       writer.write(" (" + sampleValue.get(1).longValue() + ")");
       writer.write("\tTIMESTAMP:" + sample.getTimestamp());
       writer.write("\n");
       writer.flush();
       writer.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   if (gui && panel != null) {
     panel.addPoint(sourceId, sample.getTimestamp().getTime(), sampleValue.get(0).doubleValue());
   }
 }