Skip to content

Commit

Permalink
Merge pull request #85 from berkethetechnerd/device_id
Browse files Browse the repository at this point in the history
Device id implementation
  • Loading branch information
berkethetechnerd authored Feb 21, 2021
2 parents 1371e61 + 76a17ad commit 693f6cf
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DeviceTracking API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>14</source>
<target>14</target>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class SensorData {
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

private String device_id;

@Column(length = 128)
private String sensor_name;

Expand All @@ -24,8 +26,9 @@ public SensorData() {
// Hibernate requires a no-arg constructor
}

public SensorData(Integer id, String sensor_name, Date start_time, Date end_time) {
public SensorData(Integer id, String device_id, String sensor_name, Date start_time, Date end_time) {
this.id = id;
this.device_id = device_id;
this.sensor_name = sensor_name;
this.start_time = start_time;
this.end_time = end_time;
Expand All @@ -40,6 +43,14 @@ public void setId(Integer id) {
this.id = id;
}

public String getDevice_id() {
return device_id;
}

public void setDevice_id(String device_id) {
this.device_id = device_id;
}

public String getSensor_name() {
return sensor_name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void it_should_add_new_data_and_return_data() {
String testSensorName = "Bluetooth";
Date testStartTime = new Date();
Date testEndTime = new Date();
SensorData testData = new SensorData(testId, testSensorName, testStartTime, testEndTime);
SensorData testData = new SensorData(testId, "Test-id", testSensorName, testStartTime, testEndTime);

// Setup
when(deviceTrackerService.addNewData(testData)).thenReturn(testData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.widget.*
import com.alpsproject.devicetracking.helper.DataCollectionManager
import com.alpsproject.devicetracking.helper.Logger
import com.alpsproject.devicetracking.helper.RealmManager
import com.alpsproject.devicetracking.helper.SharedPreferencesManager
import java.util.*

class LoginActivity : BaseActivity() {

Expand All @@ -23,6 +25,8 @@ class LoginActivity : BaseActivity() {
setContentView(R.layout.activity_login)

initUI()
initDeviceUniqueIdentifier()

RealmManager.printAllData()
DataCollectionManager.syncDataWithCloud()
}
Expand All @@ -38,6 +42,18 @@ class LoginActivity : BaseActivity() {
btnNext.setOnClickListener { proceedToApp() }
}

private fun initDeviceUniqueIdentifier() {
val oldIdentifier = SharedPreferencesManager.read(C.DEVICE_IDENTIFIER, "")
if (oldIdentifier.isNullOrEmpty()) {
val newIdentifier = UUID.randomUUID().toString()
Logger.logUniqueIdentifier(newIdentifier, true)
SharedPreferencesManager.write(C.DEVICE_IDENTIFIER, newIdentifier)
return
}

Logger.logUniqueIdentifier(oldIdentifier, false)
}

private fun proceedToApp() {
if (SharedPreferencesManager.read(C.CONSENT_OF_USER, false)) {
startActivity(Intent(this, SensorSelectionActivity::class.java))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ object SensorMetricsAPI {
}

private fun getJsonObject(sensorData: SensorData) = JsonObject().apply {
addProperty("device_id", SharedPreferencesManager.read(ConstantsManager.DEVICE_IDENTIFIER, ConstantsManager.DEVICE_IDENTIFIER_DEFAULT))
addProperty("sensor_name", sensorData.sensorName)
addProperty("start_time", CalendarManager.dateToBackendString(sensorData.startTime))
addProperty("end_time", CalendarManager.dateToBackendString(sensorData.endTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ object ConstantsManager {
const val DEFAULT_API = "DEFAULT_API"
private const val DEFAULT_API_URL = "http://192.168.0.3:8080"

const val DEVICE_IDENTIFIER = "DEVICE_ID"
const val DEVICE_IDENTIFIER_DEFAULT = "CORRUPTED_ID"

fun getSensorName(forSensor: DeviceSensor): String {
return when (forSensor) {
DeviceSensor.ACCESS_WIFI -> SENSOR_WIFI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object Logger {
private const val SENSOR_STATUS_CHANGE = "SensorStatusChange"
private const val SENSOR_DATA_ENTRY = "SensorDataEntry"
private const val SYNC_DATA_ENTRY = "DataSentToAPI"
private const val IDENTIFIER = "SMDeviceIdentifier"

fun logServiceNotification(message: String) {
Log.d(SERVICE_NOTIFICATION, message)
Expand All @@ -23,6 +24,14 @@ object Logger {
Log.d(SENSOR_STATUS_CHANGE, "$sensor -> $status")
}

fun logUniqueIdentifier(id: String, isNew: Boolean) {
if (isNew) {
Log.d(IDENTIFIER, "A new device id has been assigned: $id")
} else {
Log.d(IDENTIFIER, "Your device id was assigned as $id")
}
}

fun logData(data: SensorData) {
Log.d(SENSOR_DATA_ENTRY, data.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class AllSensorReportFragment : Fragment() {
.offsetY(5.0)
.format("{%Value}{groupsSeparator: } Hours")

val column5: Column = cartesian.column(dataForNFC).name("NFC")
val column5: Column = cartesian.column(dataForNFC).name("NFC").fill("pink")
column5.tooltip()
.titleFormat("NFC usage")
.position(Position.CENTER_BOTTOM)
Expand All @@ -172,7 +172,7 @@ class AllSensorReportFragment : Fragment() {
.offsetY(5.0)
.format("{%Value}{groupsSeparator: } Hours")

val column6: Column = cartesian.column(dataForTorch).name("Torch")
val column6: Column = cartesian.column(dataForTorch).name("Torch").fill("purple")
column6.tooltip()
.titleFormat("Torch usage")
.position(Position.CENTER_BOTTOM)
Expand All @@ -185,7 +185,6 @@ class AllSensorReportFragment : Fragment() {
cartesian.yScale().minimum(0.0)
cartesian.yScale().maximum(6.0)
cartesian.tooltip().positionMode(TooltipPositionMode.POINT)
cartesian.interactivity().hoverMode(HoverMode.BY_X)
cartesian.xAxis(0).title(getString(R.string.report_usage_dates))
cartesian.yAxis(0).title(getString(R.string.report_usage_hours_total))
cartesian.yAxis(0).labels().format("{%Value}{groupsSeparator: }")
Expand Down Expand Up @@ -252,7 +251,7 @@ class AllSensorReportFragment : Fragment() {
.offsetY(5.0)
.format("{%Value}{groupsSeparator: } Hours")

val column5: Column = cartesian.column(dataForNFC).name("NFC")
val column5: Column = cartesian.column(dataForNFC).name("NFC").fill("pink")
column5.tooltip()
.titleFormat("NFC usage")
.position(Position.CENTER_BOTTOM)
Expand All @@ -261,7 +260,7 @@ class AllSensorReportFragment : Fragment() {
.offsetY(5.0)
.format("{%Value}{groupsSeparator: } Hours")

val column6: Column = cartesian.column(dataForTorch).name("Torch")
val column6: Column = cartesian.column(dataForTorch).name("Torch").fill("purple")
column6.tooltip()
.titleFormat("Torch usage")
.position(Position.CENTER_BOTTOM)
Expand Down

0 comments on commit 693f6cf

Please sign in to comment.