Commit 6f2099b4 authored by Xunfei's avatar Xunfei
Browse files

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/src/main/java/fieldscience/cs/earlham/edu/fieldday/ReadingsDatabase.java
parents 086fc078 7cc76a06
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
......@@ -32,12 +32,12 @@ def computeVersionCode = { ->
return VersionCode
}
android {
compileSdkVersion 28
compileSdkVersion 22
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "fieldscience.cs.earlham.edu.fieldday"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 22
versionName "fieldDay_" + getGitHash() + "_" + getVersionCode() + ".apk"
}
buildTypes {
......
......@@ -11,6 +11,7 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
......@@ -44,7 +45,7 @@ public class DatabaseActionsActivity extends Activity {
EditText dbName, username, password, server, port;
Button setup, upload, clean;
private String uname, database, pass, host, pNum;
static final String hostid = android.os.Build.SERIAL;
static final String hostid = Build.SERIAL;
public static String trip, url;
public static int tripID, downloadColumnCount = 0, uploadColumnCount = 0;
......@@ -501,8 +502,14 @@ public class DatabaseActionsActivity extends Activity {
Log.d("Table index:", Integer.toString(index));
Log.d("Table:", table);
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("insert into ").append(table).append(" values ");
queryBuilder.append("insert into ").append(table).append(" (");
for (int i=0; i<columns.length; i++) {
String piece = c.getColumnName(i);
queryBuilder.append(piece).append(",");
}
queryBuilder.setLength(queryBuilder.length() - 1); //strip trailing comma
queryBuilder.append(") values ");
// fieldday_spot table has special characteristics so we handle that separately
if (table.equals("fieldday_spot")) {
while (c.moveToNext()) {
......
......@@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.util.Pair;
......@@ -76,7 +77,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
public Context context;
static final String host = android.os.Build.SERIAL;
static final String host = Build.SERIAL;
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};
......@@ -174,6 +175,8 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
String create_streaming = "create table " + T_STREAM + "(" +
"tripID int not null," +
" siteID int not null," +
" sectorID int not null," +
" platformID varchar(8) not null," +
" sensorID varchar(8) not null," +
" hostID varchar(30) not null," +
......@@ -187,11 +190,14 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
" satellites int not null," +
" value_2 decimal," +
" value_3 decimal," +
" primary key(tripID, sensorID, hostID, recordTime)," +
" foreign key(tripID) references fieldday_trip(tripID), " +
//check if these keys are correct (e.g. recordtime sensible for a stream?)
" primary key(tripID, siteID, sectorID, hostID, sensorID, recordTime)," +
" foreign key(tripID, siteID, sectorID) references fieldday_sector(tripID, siteID, sectorID)," +
" foreign key(hostID) references fieldday_host(hostID), " +
" foreign key(platformID, sensorID) references fieldday_sensor(platformID, sensorID));";
db.execSQL(create_streaming);
Log.d("STREAMSITESECTOR", create_streaming);
Log.d("STREAMSITESECTOR", "Created new streaming table locally");
String create_reading = "create table " + T_READING + "(" +
"tripID int not null," +
......@@ -248,8 +254,6 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
c.moveToFirst();
cv.put(C_TRIPID, c.getInt(c.getColumnIndex("tripID")));
c.close();
if (table.equals("fieldday_reading")) {
c = dbRead.query(T_SECTOR, new String[]{C_SECTORID}, "sectorName = ?",
new String[]{sector}, null, null, null);
c.moveToFirst();
......@@ -262,6 +266,8 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
cv.put(C_SITEID, c.getInt(c.getColumnIndex("siteID")));
c.close();
// only the readings table cares about spots
if (table.equals("fieldday_reading")) {
cv.put(C_SPOTID, Integer.parseInt(spot));
cv.put(C_READINGNOTES, readingNotes);
cv.put(C_IMAGEFILENAME, imageFilename);
......
......@@ -188,10 +188,13 @@ public class SensorSampleActivity extends Activity {
// Start the SensorSampleService supplying the type of sensor connected --
// bluetooth or built-in and the logging interval to use.
Log.d("STREAMSITESECTOR","starting");
Intent i = new Intent(context, SensorSampleService.class);
i.putExtra(SensorSampleService.LOG_INTERVAL, logInterval);
i.putExtra(SensorSampleService.SAMPLE_ONCE, false);
i.putExtra(SensorSampleService.TRIP_NAME, tripName);
i.putExtra(SensorSampleService.SITE, site);
i.putExtra(SensorSampleService.SECTOR, sector);
startService(i);
} else {
// Stop the SensorSampleService from writing to the database. Change the button
......
......@@ -512,10 +512,12 @@ public class SensorSampleService extends Service implements SensorEventListener
String table;
if (!sampleOnce) {
table = "fieldday_streaming";
db.addReading(sensor, lastValues, sensor.getLastValueQuality(), getTimestamp(),
site, sector, spot, geoInfo, tripName, lastAccuracy, lastSatellites, sampleNotes, "", table);
} else {
table = "fieldday_reading";
Log.d(TAG, sensor.getName() +"lastValues: " + Arrays.toString(lastValues) + " sensor.getLastValueQuality(): "+ sensor.getLastValueQuality() + " " + getTimestamp() + " " + site + " " + sector + " " + spot);
success = db.addReading(sensor, lastValues, sensor.getLastValueQuality(), getTimestamp(),
site, sector, spot, geoInfo, tripName, lastAccuracy, lastSatellites, sampleNotes, pictureName, table);
......
......@@ -5,6 +5,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import static java.lang.Math.round;
public class aSensor implements Parcelable {
private float[] lastValues;
......@@ -59,11 +61,16 @@ public class aSensor implements Parcelable {
public String getStringType() { return type; }
// To me this is a kludge of sorts but it appears to be the "accepted" way of rounding floats in Java to N
// decimal places. If you want less or more change by a factor of 10.
public String getLastValueString() {
StringBuilder result = new StringBuilder(Float.toString(lastValues[0]));
float displayWidth = 10000.0f;
StringBuilder result = new StringBuilder(Float.toString(round(lastValues[0] * displayWidth) / displayWidth));
for (int i=1; i<numberValues; i++) {
result.append(",").append(Float.toString(lastValues[i]));
result.append(",").append(Float.toString(round(lastValues[i] * displayWidth) / displayWidth));
}
return result.toString();
}
......
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