Skip to content

Commit

Permalink
Upgrade dependencies. Kotlin 2.0, new Garmin Fit SDK and various othe…
Browse files Browse the repository at this point in the history
…r dependency tweaks
  • Loading branch information
james-millner committed Jul 16, 2024
1 parent a887d41 commit bd9fdd8
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kotlin Fit Converter

[![Kotlin](https://img.shields.io/badge/kotlin-1.9.23-blue.svg)](https://kotlinlang.org/)
[![Latest Release](https://img.shields.io/badge/0.4.7-alpha-red)](https://github.com/example/garmin-fit-converter/releases)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.0-blue.svg)](https://kotlinlang.org/)
[![Latest Release](https://img.shields.io/badge/0.4.8-alpha-red)](https://github.com/example/garmin-fit-converter/releases)
[![Gradle Build & Test](https://github.com/james-millner/kotlin-fit-converter/actions/workflows/gradle.yml/badge.svg)](https://github.com/james-millner/kotlin-fit-converter/actions/workflows/gradle.yml)

The Kotlin Fit Converter Library is a Kotlin-based utility that allows users to convert Garmin FIT files into different formats.
Expand Down
16 changes: 8 additions & 8 deletions kotlin-fit-converter-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import java.io.FileWriter

plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.9.23"
id ("org.jetbrains.kotlin.plugin.serialization") version "1.9.23"
id("org.jetbrains.kotlin.jvm") version "2.0.0"
id ("org.jetbrains.kotlin.plugin.serialization") version "2.0.0"

// For my fat JAR needs
id("com.github.johnrengelman.shadow") version "8.1.1"
Expand All @@ -31,24 +31,24 @@ plugins {
}

group = "kjm.fit.converter"
version = "0.4.7-alpha"
version = "0.4.8-alpha"

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
implementation("com.garmin:fit:21.135.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.6.3")
implementation("com.garmin:fit:21.141.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.7.0")

// Use the Kotlin JUnit 5 integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")

// Use the JUnit 5 integration.
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.3")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.3")
}

val jvmTargetMajorVersion = 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class KFitDataClassHandler {
val events =
fitMessages.eventMesgs?.mapNotNull { conversionService.convert(it, FitEvent::class.java) }?.toSet() ?: emptySet()
val products = fitMessages.deviceInfoMesgs.mapNotNull { conversionService.convert(it, FitProduct::class.java) }
.filter { it.productName != "GPS" }.toSet()
.sortedBy { it.productDataConnection }.toSet()
val records = fitMessages.recordMesgs?.mapNotNull { conversionService.convert(it, LocationRecord::class.java) }?.toSet()
?: emptySet()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ internal class FitDeviceInfoConverter: Converter<FitDeviceInfoData, FitProduct>
return FitProduct(
productName = productName,
productDataConnection = source.sourceType?.toString(),
manufacturer = Manufacturer.getStringFromValue(source.manufacturer)
manufacturer = Manufacturer.getStringFromValue(source.manufacturer),
description = source.descriptor?.toString()
)
}

private fun getProductName(source: FitDeviceInfoData): String =
if(source.garminProduct != null) {
GarminProduct.getStringFromValue(source.garminProduct)
var garminProductName = GarminProduct.getStringFromValue(source.garminProduct)
garminProductName.ifEmpty {
source?.productName ?: "Unknown"
}
} else if(source.faveroProduct != null) {
FaveroProduct.getStringFromValue(source.faveroProduct)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import com.garmin.fit.RecordMesg as FitLocationData
* @see LocationRecord
*/
internal class FitLocationDataConverter: Converter<FitLocationData, LocationRecord> {

private val SCALING_FACTOR = 11930465.0

override fun convert(source: FitLocationData): LocationRecord =
LocationRecord(
timestamp = source.timestamp.date.toInstant().toString(),
Expand All @@ -26,8 +29,8 @@ internal class FitLocationDataConverter: Converter<FitLocationData, LocationReco
Location(
gpsAccuracy = source.gpsAccuracy?.toDouble(),
grade = source.grade?.toDouble(),
latitude = source.positionLat.div(11930465.0),
longitude = source.positionLong.div(11930465.0),
latitude = source.positionLat.div(SCALING_FACTOR),
longitude = source.positionLong.div(SCALING_FACTOR),
altitude = source.altitude,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data class FitProduct(
val productName: String,
val productDataConnection: String?, // sourceType
val manufacturer: String,
val description: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ class KFitDataClassHandlerTest {
assertNotNull(fitData)
assertEquals(20, fitData.events.size)
assertEquals(38.35, fitData.totalDistance)
assertEquals(3, fitData.productsUsed.size)
assertEquals(4, fitData.productsUsed.size)
assertEquals(16222, fitData.locationRecords.size)
assertEquals(fitData.totalDistance, measurementUtils.distanceInRequestedUnit(fitData.locationRecords.last().distance!!.toFloat(), MeasurementUnit.METRIC))
}

@Test
fun canConvertLongerFile() {
val fileUnderTest: InputStream? = this.javaClass.classLoader.getResourceAsStream("fitfiles/longer-fit-file.fit")
val fitData = kFitDataClassHandler.convertToDataClass("my-test-file", true, fileUnderTest!!)
var events = fitData.events.filter { it.eventName != "REAR_GEAR_CHANGE" && it.eventName != "FRONT_GEAR_CHANGE" }
assertNotNull(fitData)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@file:OptIn(ExperimentalSerializationApi::class)

package kjm.fit.converter

import kotlinx.serialization.ExperimentalSerializationApi
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ message FitProduct {
required string productName = 1;
optional string productDataConnection = 2;
required string manufacturer = 3;
optional string description = 4;
}

// serial name 'kjm.fit.converter.out.models.FitEvent'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ message FitProduct {
string productName = 1;
string productDataConnection = 2;
string manufacturer = 3;
string description = 4;
}

// serial name 'kjm.fit.converter.out.models.FitEvent'
Expand Down
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {

plugins {
// Apply the foojay-resolver plugin to allow automatic download of JDKs
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

rootProject.name = "kotlin-fit-converter"
Expand Down

0 comments on commit bd9fdd8

Please sign in to comment.