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/29 add sample project data #52

Merged
merged 2 commits into from
Mar 24, 2024
Merged
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
62 changes: 41 additions & 21 deletions sample/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,58 @@ package dev.hossain.timeline
import okio.BufferedSource
import okio.buffer
import okio.source
import java.io.BufferedReader
import java.io.File

/**
* Main entry point for the sample application that tests the Google Location History [Parser].
* Drop your unzipped Google Location History JSON files from `Takeout\Location History (Timeline)`
* into `sample/src/main/resources` and run to test app.
*
* Sample directory structure for `Takeout\Location History (Timeline)`:
* ```
* |- Semantic Location History
* | |- 2022
* | | |- 2022_January.json
* |- Records.json
* |- Settings.json
* |- Timeline Edits.json
* ```
*/
fun main() {
println("Sample app for timeline project.")
parseRecords()
parseSemanticRecords()
println("Sample app for Google Location History Parser project.")
val resourcesDir = File("sample/src/main/resources")
if(!resourcesDir.exists() || !resourcesDir.isDirectory) {
println("Resources directory not found. Please create `sample/src/main/resources` and put your Google Location History JSON files.")
return
}
val parser = Parser()
parseRecords(resourcesDir, parser)
parseSemanticRecords(resourcesDir, parser)
}

private fun parseRecords() {
val parser = Parser()
// load "Records.json" file
val recordsFile = File("sample/src/main/resources/Records.json")
val buffer: BufferedSource = recordsFile.source().buffer()
val records = parser.parseRecords(buffer)
private fun parseRecords(resourcesDir: File, parser: Parser) {

val recordsFile = File(resourcesDir, "Records.json")
val bufferedSource: BufferedSource = recordsFile.source().buffer()
val records = parser.parseRecords(bufferedSource)

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

fun parseSemanticRecords() {
val parser = Parser()

val directory = File("sample/src/main/resources/Location_History/2022/")
val files = directory.listFiles()
files?.forEach {
// List each files of directory
println("Parsing file: ${it.name}")
fun parseSemanticRecords(resourcesDir: File, parser: Parser) {
val directory = File(resourcesDir, "Semantic Location History")

val jsonText: String = it.readText()
val semanticTimeline = parser.parseSemanticTimeline(jsonText)
val semanticYears = directory.listFiles()
semanticYears?.forEach { yearDirectory ->
val files = yearDirectory.listFiles()
files?.forEach {
// List each files of directory
println("Parsing file: ${it.name}")
val bufferedSource: BufferedSource = it.source().buffer()
val semanticTimeline = parser.parseSemanticTimeline(bufferedSource)

println("Got timeline items: ${semanticTimeline.timelineObjects.size}")
println("Got timeline items: ${semanticTimeline.timelineObjects.size}")
}
}
}
Loading