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

Feat/use parser #36

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ timeline/.idea/copilot/

### Project Specific Files ###
**/resources/*.schema.json
/sample/**/*.json
1 change: 1 addition & 0 deletions parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ repositories {

dependencies {
implementation("com.squareup.moshi:moshi-kotlin:1.15.1")
implementation("com.squareup.moshi:moshi-adapters:1.15.1")
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.1")
implementation("com.squareup.okio:okio:3.9.0")
testImplementation("org.jetbrains.kotlin:kotlin-test")
Expand Down
5 changes: 0 additions & 5 deletions parser/src/main/kotlin/Main.kt

This file was deleted.

6 changes: 6 additions & 0 deletions parser/src/main/kotlin/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package dev.hossain.timeline

import ZonedDateTimeAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapters.EnumJsonAdapter
import dev.hossain.timeline.model.ActivityType
import dev.hossain.timeline.model.Records
import dev.hossain.timeline.model.SemanticTimeline
import dev.hossain.timeline.model.Settings
Expand All @@ -14,6 +16,10 @@ class Parser constructor() {
private val moshi: Moshi =
Moshi.Builder()
.add(ZonedDateTimeAdapter())
.add(
ActivityType::class.java,
EnumJsonAdapter.create(ActivityType::class.java).withUnknownFallback(ActivityType.UNKNOWN),
)
.build()

/**
Expand Down
10 changes: 8 additions & 2 deletions parser/src/main/kotlin/model/Records.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ data class AccessPoint(
/**
* Whether the device that scanned the access point is connected to it.
*/
val isConnected: Boolean,
val isConnected: Boolean?,
)

/**
Expand Down Expand Up @@ -178,26 +178,32 @@ enum class ActivityType(val title: String, val extraColor: String) {
BOATING("Boating", "#01579b"),
CATCHING_POKEMON("Catching Pokémon", "#db4437"),
CYCLING("Cycling", "#4db6ac"),
EXITING_VEHICLE("Exiting a vehicle", "#01579b"),
FLYING("Flying", "#3f51b5"),
HIKING("Hiking", "#c2185b"),
HORSEBACK_RIDING("Horseback riding", "#4db6ac"),
IN_BUS("On a bus", "#01579b"),
IN_CABLECAR("In a cable car", "#01579b"),
IN_CAR("In a car", "#01579b"),
IN_FERRY("On a ferry", "#01579b"),
IN_FOUR_WHEELER_VEHICLE("In a four wheeler vehicle", "#01579b"),
IN_FUNICULAR("On a funicular", "#01579b"),
IN_GONDOLA_LIFT("In a gondola lift", "#01579b"),
IN_PASSENGER_VEHICLE("Driving", "#01579b"),
IN_RAIL_VEHICLE("In a rail vehicle", "#01579b"),
IN_ROAD_VEHICLE("In a road vehicle", "#03a9f4"),
IN_SUBWAY("On the subway", "#01579b"),
IN_TAXI("In a taxi", "#01579b"),
IN_TRAIN("On a train", "#01579b"),
IN_TRAM("On a tram", "#01579b"),
IN_TWO_WHEELER_VEHICLE("On a two wheeler vehicle", "#01579b"),
IN_VEHICLE("In a vehicle", "#03a9f4"),
IN_WHEELCHAIR("By wheelchair", "#03a9f4"),
KAYAKING("Kayaking", "#4db6ac"),
KITESURFING("Kitesurfing", "#4db6ac"),
MOTORCYCLING("Motorcycling", "#01579b"),
ON_FOOT("On foot", "#c2185b"),
ON_BICYCLE("On a bicycle", "#4db6ac"),
ON_FOOT("On foot", "#c2185b"),
PARAGLIDING("Paragliding", "#4db6ac"),
ROWING("Rowing", "#c2185b"),
RUNNING("Running", "#c2185b"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class RecordsTestCopilot {
assertEquals("00:00:00:00:00:00", accessPoint.mac)
assertEquals(100, accessPoint.strength)
assertEquals(2400, accessPoint.frequencyMhz)
assertTrue(accessPoint.isConnected)
assertTrue(accessPoint.isConnected!!)
}

@Test
Expand Down
11 changes: 10 additions & 1 deletion sample/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package dev.hossain.timeline

import java.io.File

fun main() {
println("Sample app for timeline project.")
println("Sample app for timeline project.")
val parser = Parser()
// load "Records.json" file
val recordsJson = parser::class.java.classLoader.getResource("Records.json")?.readText()!!
val records = parser.parseRecords(recordsJson)

println("Got records: ${records.locations.size} records.")
println()
}
Loading