Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

162 prepare on device training #182

Merged
merged 56 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ea1a608
Add screen and tab for on device training
tfiedlerdev Apr 22, 2022
9e78e2d
Make training screen optional
tfiedlerdev Apr 22, 2022
74969fe
Prepare onDeviceTrainingScreen
tfiedlerdev Apr 25, 2022
cbb04c7
Merge branch '154-recording-label-editor-based-on-video' into 163-on-…
tfiedlerdev Apr 25, 2022
14061c6
init useCases
treyfel Apr 25, 2022
97b0c03
Populate on-device-training screen
tfiedlerdev Apr 25, 2022
b8080cf
further implements default useCase
treyfel Apr 25, 2022
5778220
Add training history
tfiedlerdev Apr 26, 2022
95e51ff
init useCases
treyfel Apr 26, 2022
905dc9f
adds use case selection dialog and refactors global values
treyfel Apr 26, 2022
b53829b
Refactor activity labels storage
tfiedlerdev Apr 26, 2022
d4bb9c8
Merge remote-tracking branch 'origin/161-support-multiple-models' int…
tfiedlerdev Apr 26, 2022
facf4ba
make it work
treyfel Apr 26, 2022
ac3aad0
Merge remote-tracking branch 'origin/161-support-multiple-models' int…
tfiedlerdev Apr 26, 2022
05abce1
makes use case dir
treyfel Apr 26, 2022
c9fc0f7
Improve
tfiedlerdev Apr 26, 2022
5eff1f1
makes use case dir
treyfel Apr 26, 2022
565a539
makes use case dir
treyfel Apr 26, 2022
48dcfe2
Merge remote-tracking branch 'origin/161-support-multiple-models' int…
tfiedlerdev Apr 27, 2022
0f931be
Satisfy @alexanderwischmann
tfiedlerdev Apr 27, 2022
367f99b
Fix neutral button
tfiedlerdev Apr 27, 2022
f0a5bfb
remove unused imports
tfiedlerdev Apr 27, 2022
5af744e
Merge branch '161-support-multiple-models' into 163-on-device-trainin…
tfiedlerdev Apr 27, 2022
06ad5a5
makes use case recordings subDir
treyfel Apr 27, 2022
6e41344
Merge remote-tracking branch 'origin/161-support-multiple-models' int…
treyfel Apr 27, 2022
649db67
Merge branch '161-support-multiple-models' into 163-on-device-trainin…
tfiedlerdev Apr 27, 2022
883562c
Satisfy Linter and resolve post merge problems
tfiedlerdev Apr 27, 2022
ac39d4d
Improve subdir logic
tfiedlerdev Apr 27, 2022
dcf2a71
makes use case recordings subDir persistent in use case storage
treyfel Apr 27, 2022
7befa13
Adapt training screen to use case concept
tfiedlerdev Apr 27, 2022
d3bf041
creates first defaut use case on first app start
treyfel Apr 27, 2022
e23b27c
Merge remote-tracking branch 'origin/162-prepare-on-device-training' …
tfiedlerdev Apr 28, 2022
cb08f02
Fix bugs, improve UI
tfiedlerdev Apr 28, 2022
fd793e8
Fix bugs, improve UI
tfiedlerdev Apr 28, 2022
4cdb19e
fix bugs and loads model from assets
treyfel Apr 29, 2022
9775fcc
Merge remote-tracking branch 'origin/162-prepare-on-device-training' …
treyfel Apr 29, 2022
e9ff8b9
satisfy linter
treyfel Apr 29, 2022
4a7be3d
satisfy linter
treyfel Apr 29, 2022
e848f79
Work on making use cases deletable and clonable
tfiedlerdev May 2, 2022
adbede8
Work on Use Case Dialog
tfiedlerdev May 2, 2022
bf7bcd1
Fix bugs in UseCaseDialog.kt and react to changes in use case sub dir…
tfiedlerdev May 2, 2022
a49a90d
Satisfy Linter (a bit)
tfiedlerdev May 2, 2022
3572d04
refactors use case storage
treyfel May 3, 2022
0599396
completes use case storage refactoring
treyfel May 3, 2022
a70b072
satisfy linter
treyfel May 3, 2022
263f3e4
implements default(HAR) prediction
treyfel May 3, 2022
2ce6eb2
Refactor
tfiedlerdev May 3, 2022
3f2d58f
Refactor
tfiedlerdev May 4, 2022
f0a460b
Merge branch 'master' into 162-prepare-on-device-training
tfiedlerdev May 4, 2022
b1cbcb1
Satisfy linter, fix merge errors
tfiedlerdev May 4, 2022
6b8741b
Improve layout
tfiedlerdev May 4, 2022
66d3641
Remove global recordings subdir preference. It's now use case local
tfiedlerdev May 4, 2022
88e02da
Remove unnecessary parameter
tfiedlerdev May 5, 2022
2d8302b
Satisfy Chefe
tfiedlerdev May 5, 2022
3778d8e
Satisfy Chefe even more
tfiedlerdev May 5, 2022
42d221a
Fix bug
tfiedlerdev May 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.preference:preference-ktx:1.2.0'
Expand All @@ -96,7 +96,7 @@ dependencies {
implementation project(path: ':Xsens_DOT_Core')
implementation "androidx.core:core-ktx:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.21")
implementation("com.android.volley:volley:1.2.1")
testImplementation("junit:junit:4.13.2")
testImplementation('androidx.test:core:1.4.0')
Expand All @@ -106,20 +106,21 @@ dependencies {
implementation("androidx.cardview:cardview:1.0.0")
implementation 'com.google.android.material:material:1.5.0'

def camerax_version = "1.1.0-beta02"
def camerax_version = "1.1.0-beta03"
implementation("androidx.camera:camera-camera2:${camerax_version}")
implementation("androidx.camera:camera-video:${camerax_version}")
implementation("androidx.camera:camera-view:${camerax_version}")

implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'

implementation("org.jcodec:jcodec:0.2.3")
implementation("org.jcodec:jcodec-android:0.2.2")
implementation("com.opencsv:opencsv:4.6")
}
repositories {
mavenCentral()
maven {
name 'ossrh-snapshot'
url 'https://oss.sonatype.org/content/repositories/snapshots'
url 'https://jitpack.io'
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package sensors_in_paradise.sonar

import android.content.Context
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.*
import org.junit.Before
import org.junit.Test
import sensors_in_paradise.sonar.screen_recording.CategoryItemStorage
import java.io.File

class CategoryLabelsStorageTest {
private val appContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
private val baseDir = File(appContext.cacheDir, "RecordingsTest")

@Before
fun init() {
baseDir.mkdir()
}

@Test
fun testLoadDefaultData() {
val file = baseDir.resolve("categoryLabels1.json")
file.delete()
val storage = CategoryItemStorage(file)
Log.d(
"CategoryLabelsStorageTest-testLoadDefaultData",
"Storage after creation: ${storage.getJsonString(1)}"
)

for ((activity, category) in CategoryItemStorage.DEFAULT_ACTIVITIES) {
Log.d(
"CategoryLabelsStorageTest-testLoadDefaultData",
"Asserting that activity $activity is added in category $category"
)
assertFalse(storage.isCategoryDeletable(category))
assertTrue(storage.isEntryAdded(activity, category))
assertTrue(storage.isEntryAdded(activity))
}
file.delete()
}

@Test
fun testSave() {
val file = baseDir.resolve("categoryLabels2.json")
file.delete()
val storage = CategoryItemStorage(file)
Log.d("CategoryLabelsStorageTest", "Storage after creation: ${storage.getJsonString(1)}")
storage.addCategoryIfNotAdded("reinigung")
Log.d(
"CategoryLabelsStorageTest",
"Storage after adding category: ${storage.getJsonString(1)}"
)
storage.addEntry("wischen", "reinigung", save = true)
Log.d(
"CategoryLabelsStorageTest",
"Storage after adding entry: ${storage.getJsonString(1)}"
)
assertTrue(storage.isEntryAdded("wischen", "reinigung"))
val storage2 = CategoryItemStorage(file)
Log.d(
"CategoryLabelsStorageTest",
"Storage2 after loading from file: ${storage2.getJsonString(1)}"
)
assertTrue(storage2.isEntryAdded("wischen", "reinigung"))

file.delete()
}
}
60 changes: 29 additions & 31 deletions app/src/main/java/sensors_in_paradise/sonar/GlobalValues.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,18 @@ package sensors_in_paradise.sonar
import android.Manifest
import android.content.Context
import android.os.Build
import android.util.Log
import com.xsens.dot.android.sdk.models.XsensDotPayload
import java.io.File
import java.net.NetworkInterface
import java.net.SocketException
import java.util.*
import kotlin.collections.ArrayList

class GlobalValues private constructor() {
companion object {
const val NULL_ACTIVITY = "null - activity"
const val OTHERS_CATEGORY = "Others"
val DEFINED_ACTIVITIES = linkedMapOf<String, String>(
NULL_ACTIVITY to OTHERS_CATEGORY,
"aufräumen" to OTHERS_CATEGORY,
"aufwischen (Staub)" to OTHERS_CATEGORY,
"Accessoires (Parfüm) anlegen" to "Morgenpflege",
"Bett machen" to "Morgenpflege",
"Bett beziehen" to "Morgenpflege",
"Haare kämmen" to "Morgenpflege",
"Hautpflege" to "Morgenpflege",
"Medikamente geben" to "Morgenpflege",
"Mundpflege" to "Morgenpflege",
"Umkleiden" to "Morgenpflege",
"Gesamtwaschen im Bett" to "Morgenpflege",
"Essen auf Teller geben" to "Mahlzeiten",
"Essen reichen" to "Mahlzeiten",
"Getränke ausschenken" to "Mahlzeiten",
"Getränk geben" to "Mahlzeiten",
"Assistieren - aufstehen" to "Assistieren",
"Patient umlagern (Lagerung)" to "Assistieren",
"Rollstuhl Transfer" to "Assistieren",
"Dokumentation" to "Organisation",
"Medikamente stellen" to "Organisation",
)
const val UNKNOWN_PERSON = "unknown"
const val METADATA_JSON_FILENAME = "metadata.json"
const val MEASUREMENT_MODE = XsensDotPayload.PAYLOAD_TYPE_CUSTOM_MODE_4
Expand All @@ -50,14 +32,6 @@ class GlobalValues private constructor() {
return context.dataDir.resolve("poseTemp")
}

fun getActivityLabelsJSONFile(context: Context): File {
return File(context.getExternalFilesDir(null) ?: context.dataDir, "labels.json")
}

fun getPeopleJSONFile(context: Context): File {
return File(context.getExternalFilesDir(null) ?: context.dataDir, "people.json")
}

fun getRequiredPermissions(): ArrayList<String> {
val result = arrayListOf(
Manifest.permission.BLUETOOTH,
Expand Down Expand Up @@ -90,5 +64,29 @@ class GlobalValues private constructor() {

return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0')
}
fun getMacAddress(): String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the Device Mac Address for On Device Training? What is the benefit?

I saw the usage but I am not entirely sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get your point but I can imagine a situation where one would like to know on which device the model was trained and as it does no harm, I'd just keep it now

try {
val all = Collections.list(NetworkInterface.getNetworkInterfaces())
for (nif in all) {
if (!nif.name.equals("wlan0", ignoreCase=true)) continue

val macBytes = nif.hardwareAddress ?: return ""

val res1 = StringBuilder()
for (b in macBytes) {
res1.append(String.format(Locale.US, "%02X:", b))
}

if (res1.isNotEmpty()) {
res1.deleteCharAt(res1.length - 1)
}
return res1.toString()
}
} catch (ex: SocketException) {
ex.message?.let { Log.e("GlobalValues", it) }
}

return "02:00:00:00:00:00"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.annotation.UiThread
import com.xsens.dot.android.sdk.events.XsensDotData
import com.xsens.dot.android.sdk.interfaces.XsensDotMeasurementCallback
import com.xsens.dot.android.sdk.models.XsensDotDevice
import sensors_in_paradise.sonar.page1.ConnectionInterface
import sensors_in_paradise.sonar.screen_connection.ConnectionInterface

class HeadingResetHandler(
private val context: Context,
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/sensors_in_paradise/sonar/JSONStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class JSONStorage @Throws(
constructor(file: File) : this(file, null)

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
lateinit var json: JSONObject
var json: JSONObject

init {
if (initialJson == null) {
Expand Down Expand Up @@ -57,4 +57,8 @@ abstract class JSONStorage @Throws(

/** */
abstract fun onJSONInitialized()

fun getJsonString(indentSpaces: Int = 4): String {
return json.toString(indentSpaces)
}
}
Loading