Commit 086fc078 authored by Xunfei's avatar Xunfei
Browse files

Modify the addReading so that it iterate through the sensorValues and put them...

Modify the addReading so that it iterate through the sensorValues and put them to cv. getColumnType is also updated to return FLOAT if the column is a sensor value.
parent aa85e626
......@@ -62,9 +62,9 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
public static final String C_PLATFORMNAME = "platformName";
public static final String C_PLATFORMTYPE = "platformType";
public static final String C_RECORDTIME = "recordTime";
public static final String C_VALUE_ONE = "value_1";
public static final String C_VALUE_TWO = "value_2";
public static final String C_VALUE_THREE = "value_3";
//public static final String C_VALUE_ONE = "value_1";
//public static final String C_VALUE_TWO = "value_2";
//public static final String C_VALUE_THREE = "value_3";
public static final String C_QUALITY = "quality";
public static final String C_READINGNOTES = "readingNotes";
public static final String C_IMAGEFILENAME = "imageFilename";
......@@ -80,7 +80,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
public static File dbPath;
public static String[] tables = {T_HOST, T_TRIP, T_SITE, T_SECTOR, T_SPOT, T_PLATFORM, T_SENSOR};
public static final String c_value = "value_";
public static final String FLOAT = "float";
public static final String INT = "integer";
public static final String TEXT = "text";
......@@ -95,7 +95,8 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
C_PLATFORMID, C_PLATFORMNAME, C_PLATFORMTYPE, C_SENSORID,
C_SENSORID, C_SENSORTYPE, C_SENSORUNITS};
public static String[] integer_columns = {C_TRIPID, C_SITEID, C_SECTORID, C_SPOTID, C_SATELLITES};
public static String[] float_columns = {C_VALUE_ONE, C_VALUE_TWO, C_VALUE_THREE, C_QUALITY, C_LATITUDE, C_LONGITUDE, C_ELEVATION, C_ACCURACY};
public static String[] float_columns = {C_QUALITY, C_LATITUDE, C_LONGITUDE, C_ELEVATION, C_ACCURACY};
//C_VALUE_ONE, C_VALUE_TWO, C_VALUE_THREE,
private static ReadingsDatabase sInstance = null;
public static final String directory = Environment.getExternalStorageDirectory().toString() +
......@@ -239,6 +240,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
Cursor c;
int i = 0;
int numberValues = 0;
String c_value_i =null;
c = dbRead.query(T_TRIP, new String[]{C_TRIPID}, "tripName = ?",
......@@ -276,27 +278,33 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
cv.put(C_SENSORID, sensor.getID());
cv.put(C_RECORDTIME, timestamp);
cv.put(C_VALUE_ONE, Double.valueOf(d.format(sensorValues[0])));
numberValues = sensor.getNumberValues();
Log.d("ReadingDatabase", "numberValues = " + numberValues);
for(i=0; i<numberValues; i++)
{
Log.d("ReadingsDatabase", " sensorValues ["+ i+ "] = " + sensorValues[i]);
if(sensorValues[i] != 0.0f){
c_value_i = c_value + Integer.toString(i+1);
Log.d("ReadingsDatabase", "c_value_i = " + c_value_i);
cv.put(c_value_i, Double.valueOf(d.format(sensorValues[i])));
}
}
/*
cv.put(C_VALUE_ONE, Double.valueOf(d.format(sensorValues[0])));
//pressure sensor has only one value, the following two if statements are running only when the length is greater than 2
//check the number of values for each sensor, and then determine if you need to access the 2nd and 3rd value
if(numberValues > 1) {
if (sensorValues[1] != 0.0f) {
cv.put(C_VALUE_TWO, Double.valueOf(d.format(sensorValues[1])));
}
if(numberValues > 2){
if (sensorValues[2] != 0.0f) {
cv.put(C_VALUE_THREE, Double.valueOf(d.format(sensorValues[2])));
}
}
}
*/
cv.put(C_QUALITY, sensorQuality);
cv.put(C_LATITUDE, geoInfo[0]);
cv.put(C_LONGITUDE, geoInfo[1]);
......@@ -420,7 +428,10 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
}
public String getColumnType(String column){
if (Arrays.asList(ReadingsDatabase.float_columns).contains(column)) {
if (column.contains(c_value))//check if it is sensor value
{
return (FLOAT);
}else if (Arrays.asList(ReadingsDatabase.float_columns).contains(column)) {
return (FLOAT);
} else if (Arrays.asList(ReadingsDatabase.text_columns).contains(column)) {
return (TEXT);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment