Skip to content

Commit

Permalink
[LEIP-182] Add file counts to meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Oct 26, 2023
1 parent 79a1f05 commit e54d3d5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ ext {

// Cyface dependencies
cyfaceUtilsVersion = "4.0.4"
cyfaceSerializationVersion = "3.0.0"
cyfaceUploaderVersion = "1.0.0"
cyfaceSerializationVersion = "3.2.0-alpha1"
cyfaceUploaderVersion = "1.2.0-alpha2"

// Android SDK versions
minSdkVersion = 21 // device support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import de.cyface.persistence.content.BaseColumns
import de.cyface.persistence.content.FileTable
import de.cyface.persistence.model.File
import de.cyface.persistence.model.FileStatus
import de.cyface.protos.model.File.FileType

/**
* Data access object which provides the API to interact with the [File] database table.
Expand Down Expand Up @@ -65,6 +66,12 @@ interface FileDao {
@Query("SELECT COUNT(*) FROM ${FileTable.URI_PATH} WHERE ${BaseColumns.MEASUREMENT_ID} = :measurementId")
fun countByMeasurementId(measurementId: Long): Int

/**
* Returns the number of files found for a specific [measurementId] and [type].
*/
@Query("SELECT COUNT(*) FROM ${FileTable.URI_PATH} WHERE ${BaseColumns.MEASUREMENT_ID} = :measurementId AND ${FileTable.COLUMN_TYPE} = :type")
fun countByMeasurementIdAndType(measurementId: Long, type: FileType): Int

@Query("DELETE FROM ${FileTable.URI_PATH} WHERE ${BaseColumns.MEASUREMENT_ID} = :measurementId")
fun deleteItemByMeasurementId(measurementId: Long): Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ class SyncAdapter private constructor(
authority: String
) {
val measurementCount = measurements.size
var error = false
var error: Boolean

for (index in 0 until measurementCount) {
val measurement = measurements[index]

val fileCount = persistence.fileDao!!.countByMeasurementId(measurement.id)
Log.d(TAG, "Preparing to upload Measurement (id ${measurement.id}) with $fileCount attachments.")
validateMeasurementFormat(measurement)

val metaData = loadMetaData(measurement, persistence, deviceId, context)
val fileCount = metaData.logCount + metaData.imageCount + metaData.videoCount

Log.d(TAG, "Preparing to upload Measurement (id ${measurement.id}) with $fileCount attachments.")

// Upload measurement binary first
if (measurement.status === MeasurementStatus.FINISHED) {
Expand Down Expand Up @@ -612,29 +612,41 @@ class SyncAdapter private constructor(
endLocation = RequestMetaData.GeoLocation(l!!.timestamp, l.lat, l.lon)
}

// Non location meta data
val deviceType = Build.MODEL
val osVersion = "Android " + Build.VERSION.RELEASE
val appVersion: String
val packageManager = context.packageManager
appVersion = try {
packageManager.getPackageInfo(context.packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
throw IllegalStateException(e)
// Attachments
return runBlocking {
val logCount = persistence.fileDao!!.countByMeasurementIdAndType(measurement.id, FileType.CSV)
val imageCount = persistence.fileDao!!.countByMeasurementIdAndType(measurement.id, FileType.JPG)
val otherFiles = persistence.fileDao!!.countByMeasurementId(measurement.id)
val unsupportedFiles = otherFiles - logCount - imageCount
require(unsupportedFiles == 0) { "Number of unsupported files: $unsupportedFiles" }

// Non location meta data
val deviceType = Build.MODEL
val osVersion = "Android " + Build.VERSION.RELEASE
val appVersion: String
val packageManager = context.packageManager
appVersion = try {
packageManager.getPackageInfo(context.packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
throw IllegalStateException(e)
}
return@runBlocking RequestMetaData(
deviceId,
measurement.id.toString(),
osVersion,
deviceType,
appVersion,
measurement.distance,
locationCount.toLong(),
startLocation,
endLocation,
measurement.modality.databaseIdentifier,
RequestMetaData.CURRENT_TRANSFER_FILE_FORMAT_VERSION,
logCount,
imageCount,
0
)
}
return RequestMetaData(
deviceId,
measurement.id.toString(),
osVersion,
deviceType,
appVersion,
measurement.distance,
locationCount.toLong(),
startLocation,
endLocation,
measurement.modality.databaseIdentifier,
RequestMetaData.CURRENT_TRANSFER_FILE_FORMAT_VERSION
)
}

/**
Expand Down

0 comments on commit e54d3d5

Please sign in to comment.