Skip to content
Snippets Groups Projects
Commit 7f5fd917 authored by BBQ's avatar BBQ
Browse files

update readercsv

parent cd59cdb6
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ public class Main { ...@@ -15,7 +15,7 @@ public class Main {
/** /**
* new data from KB * new data from KB
* */ * */
ReaderCSV reader = new ReaderCSV("datasets/backup/activity_data.csv"); ReaderCSV reader = new ReaderCSV("datasets/backup/activity_data.csv","preference");
reader.updater(); reader.updater();
//Learner learner=new Learner(); //Learner learner=new Learner();
//learner.preference_train("datasets/backup/preference_data.csv"); //learner.preference_train("datasets/backup/preference_data.csv");
......
package de.tudresden.inf.st.eraser.feedbackloop.learner_backup; package de.tudresden.inf.st.eraser.feedbackloop.learner_backup;
import java.awt.*;
import java.io.FileReader; import java.io.FileReader;
import java.io.*; import java.io.*;
import java.util.Arrays;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
import org.apache.http.client.fluent.Request; import org.apache.http.client.fluent.Request;
import org.apache.http.HttpResponse;
import org.apache.http.entity.ContentType;
public class ReaderCSV { public class ReaderCSV {
//read every 3 s from csv //read every 5 s from csv
private static int TIME_PERIOD = 5000; //activity CSV
/**
* Col 1: smartphone acceleration x
* Col 2: smartphone acceleration y
* Col 3: smartphone acceleration z
* Col 4: smartphone rotation x
* Col 5: smartphone rotation y
* Col 6: smartphone rotation z
* Col 7: watch acceleration x
* Col 8: watch acceleration y
* Col 9: watch acceleration z
* Col 10: watch rotation x
* Col 11: watch rotation y
* Col 12: watch rotation z/*/
//preference CSV
/**
* Col 1: Activity
* Col 2: watch brightness range "bright, medium, dimmer, dark"*/
private static int TIME_PERIOD = 5000; //5 second update new value
private String csv_file_path; private String csv_file_path;
private String csv_typ;
private File file; private File file;
private FileReader file_reader; private FileReader file_reader;
private CSVReader csv_reader; private CSVReader csv_reader;
private String[] next_record; private String[] next_record;
private static final String ERASER_ITEM_URI = "http://localhost:4567/model/items/"; private static final String ERASER_ITEM_URI = "http://localhost:4567/model/items/";
//TODO ITEM_NAME HAS TO BE DISCUSSED
private static final String[] ACTIVITY_ITEM_NAME = {"s_acc_x","s_acc_y","s_acc_z","s_rotation_x",
"s_rotation_y","s_rotation_z","w_acc_x","w_acc_y","w_acc_z","w_rotation_x","w_rotation_y","w_rotation_z"};
private static final String[] PREFERENCE_ITEM_NAME = {
"activity","w_brightness"
};
public ReaderCSV(String csv_file_path) { //csv_type is activity or preference
public ReaderCSV(String csv_file_path, String csv_type) {
this.csv_file_path=csv_file_path; this.csv_file_path=csv_file_path;
this.csv_typ=csv_type;
} }
public void updater(){ public void updater(){
...@@ -24,20 +58,34 @@ public class ReaderCSV { ...@@ -24,20 +58,34 @@ public class ReaderCSV {
try { try {
file_reader =new FileReader(file); file_reader =new FileReader(file);
csv_reader = new CSVReader(file_reader); csv_reader = new CSVReader(file_reader);
while ((next_record = csv_reader.readNext()) != null) { while ((next_record = csv_reader.readNext()) != null) {
//data.add(next_record);
Thread.currentThread().sleep(TIME_PERIOD); Thread.currentThread().sleep(TIME_PERIOD);
System.out.println("this is a wait" ); if (csv_typ =="activity"){
for (String value : next_record) { String[] values = Arrays.copyOf(next_record,12);
System.out.print(value + "\t"); setNewValue(values, ACTIVITY_ITEM_NAME);
//TODO identifier for different items } else {
Request.Put(ERASER_ITEM_URI+"/:itentifider/state" + value); String[] values = Arrays.copyOf(next_record,2);
setNewValue(values, PREFERENCE_ITEM_NAME);
}
} }
System.out.println(); System.out.println();
} }
catch (Exception e){
e.printStackTrace();
}
}
private void setNewValue(String[] values, String[] name){
int i = 0;
for(String value : values){
String uri = ERASER_ITEM_URI + name[i] + "/state";
try {
HttpResponse httpResponse = Request.Put(uri)
.bodyString(value, ContentType.TEXT_PLAIN)
.execute().returnResponse();
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
i+=1;
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment