diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CoreDTOs.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CoreDTOs.kt index bf96c1c7..d169de41 100644 --- a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CoreDTOs.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CoreDTOs.kt @@ -13,7 +13,7 @@ data class DependencyDTO( val percent: Double, val seconds: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) @Serializable @@ -26,7 +26,7 @@ data class EditorDTO( val percent: Double, val seconds: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) @Serializable @@ -39,7 +39,7 @@ data class LanguageDTO( val percent: Double, val seconds: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) @Serializable @@ -53,7 +53,7 @@ data class MachineDTO( val seconds: Int, val text: String, @SerialName("machine_name_id") val machineNameId: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) @Serializable @@ -66,7 +66,7 @@ data class OperatingSystemDTO( val percent: Double, val seconds: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) @Serializable @@ -80,7 +80,7 @@ data class EntityDTO( val seconds: Int, val text: String, val type: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) @Serializable @@ -93,5 +93,5 @@ data class CategoryDTO( val percent: Double, val seconds: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt index 579ddef3..bed8a1a8 100644 --- a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/CumulativeTotalDTO.kt @@ -6,6 +6,6 @@ import kotlinx.serialization.Serializable data class CumulativeTotalDTO( val decimal: String, val digital: String, - val seconds: Double, + val seconds: Long, val text: String, ) diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ExtractedDataDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ExtractedDataDTO.kt index 5c32a399..e172d281 100644 --- a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ExtractedDataDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/ExtractedDataDTO.kt @@ -45,7 +45,7 @@ data class ExtractedDataDTO( val percent: Double, val seconds: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) } } diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt index bffe2240..c888341c 100644 --- a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/dtos/GrandTotalDTO.kt @@ -10,5 +10,5 @@ data class GrandTotalDTO( val hours: Int, val minutes: Int, val text: String, - @SerialName("total_seconds") val totalSeconds: Double, + @SerialName("total_seconds") val totalSeconds: Long, ) diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/SecondaryStatsMapper.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/CommonMapper.kt similarity index 60% rename from core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/SecondaryStatsMapper.kt rename to core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/CommonMapper.kt index 14a4d425..02668530 100644 --- a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/SecondaryStatsMapper.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/CommonMapper.kt @@ -1,8 +1,9 @@ -package com.jacob.wakatimeapp.core.common.data.mappers // ktlint-disable filename +package com.jacob.wakatimeapp.core.common.data.mappers import com.jacob.wakatimeapp.core.common.data.dtos.EditorDTO import com.jacob.wakatimeapp.core.common.data.dtos.LanguageDTO import com.jacob.wakatimeapp.core.common.data.dtos.OperatingSystemDTO +import com.jacob.wakatimeapp.core.common.data.dtos.ProjectDTO import com.jacob.wakatimeapp.core.models.Time import com.jacob.wakatimeapp.core.models.secondarystats.Editor import com.jacob.wakatimeapp.core.models.secondarystats.Editors @@ -10,20 +11,31 @@ import com.jacob.wakatimeapp.core.models.secondarystats.Language import com.jacob.wakatimeapp.core.models.secondarystats.Languages import com.jacob.wakatimeapp.core.models.secondarystats.OperatingSystem import com.jacob.wakatimeapp.core.models.secondarystats.OperatingSystems +import kotlinx.collections.immutable.toImmutableList + +fun List.toModel() = map(LanguageDTO::toModel).let(::Languages) + +fun List.toModel() = map(EditorDTO::toModel).let(::Editors) + +fun List.toModel() = map(OperatingSystemDTO::toModel).let(::OperatingSystems) + +fun List.toModel() = filterNot(ProjectDTO::isUnknownProject) + .map(ProjectDTO::toModel) + .toImmutableList() fun LanguageDTO.toModel() = Language( name = name, - time = Time.fromDecimal(decimal.toFloat()), + time = Time.fromTotalSeconds(totalSeconds), ) fun EditorDTO.toModel() = Editor( name = name, - time = Time.fromDecimal(decimal.toFloat()), + time = Time.fromTotalSeconds(totalSeconds), ) fun OperatingSystemDTO.toModel() = OperatingSystem( name = name, - time = Time.fromDecimal(decimal.toFloat()), + time = Time.fromTotalSeconds(totalSeconds), ) fun List.fromDto() = map(EditorDTO::toModel).let(::Editors) diff --git a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ExtractedDataDtoMapper.kt b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ExtractedDataDtoMapper.kt index 3d2a7a88..3d3ef308 100644 --- a/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ExtractedDataDtoMapper.kt +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/ExtractedDataDtoMapper.kt @@ -18,7 +18,7 @@ fun DayDTO.toEntity() = DayEntity( machines = this.machines.map { machine -> Machine( name = machine.name, - time = Time.fromDecimal(machine.totalSeconds.toFloat()), + time = Time.fromTotalSeconds(machine.totalSeconds), ) }, ) @@ -27,13 +27,13 @@ fun ProjectDTO.toEntity(dayId: Long): ProjectPerDay { val branches = branches.map { branch -> com.jacob.wakatimeapp.core.models.Branch( name = branch.name, - time = Time.fromDecimal(branch.totalSeconds.toFloat()), + time = Time.fromTotalSeconds(branch.totalSeconds), ) } val machines = machines.map { machine -> Machine( name = machine.name, - time = Time.fromDecimal(machine.totalSeconds.toFloat()), + time = Time.fromTotalSeconds(machine.totalSeconds), ) } diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DailyStats.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DailyStats.kt index f670a729..9c74f03c 100644 --- a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DailyStats.kt +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DailyStats.kt @@ -10,4 +10,5 @@ data class DailyStats( val mostUsedEditor: String, val mostUsedOs: String, val date: LocalDate, -) +) { +} diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DetailedDailyStats.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DetailedDailyStats.kt new file mode 100644 index 00000000..9de7d603 --- /dev/null +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/DetailedDailyStats.kt @@ -0,0 +1,16 @@ +package com.jacob.wakatimeapp.core.models + +import com.jacob.wakatimeapp.core.models.secondarystats.Editors +import com.jacob.wakatimeapp.core.models.secondarystats.Languages +import com.jacob.wakatimeapp.core.models.secondarystats.OperatingSystems +import kotlinx.collections.immutable.ImmutableList +import kotlinx.datetime.LocalDate + +data class DetailedDailyStats( + val date: LocalDate, + val projects: ImmutableList, + val languages: Languages, + val editors: Editors, + val operatingSystems: OperatingSystems, + val timeSpent: Time, +) diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt index 77717e35..0a85bc26 100644 --- a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/Time.kt @@ -7,23 +7,36 @@ data class Time( val hours: Int, val minutes: Int, val decimal: Float, - val totalSeconds: Int = calculateTotalSeconds(hours, minutes), + val totalSeconds: Long = calculateTotalSeconds(hours.toLong(), minutes.toLong()), ) { fun toMinutes(): Int = (hours * MINUTES_IN_HOURS) + minutes fun formattedPrint() = "${hours}H, ${minutes}M" fun longFormattedPrint() = "$hours Hours, $minutes Minutes" - operator fun plus(other: Time) = fromDecimal(decimal + other.decimal) + + operator fun plus(other: Time) = fromTotalSeconds(totalSeconds + other.totalSeconds) companion object { val ZERO = Time(0, 0, 0f) + fun fromTotalSeconds(totalSeconds: Long): Time { + val hours = totalSeconds / (SECONDS_IN_MINUTES * MINUTES_IN_HOURS) + val minutes = (totalSeconds % (SECONDS_IN_MINUTES * MINUTES_IN_HOURS)) / MINUTES_IN_HOURS + val decimal = hours + (minutes.toFloat() / MINUTES_IN_HOURS) + return Time( + decimal = decimal, + hours = hours.toInt(), + minutes = minutes.toInt(), + totalSeconds = totalSeconds, + ) + } + fun fromDecimal(decimal: Float): Time { val hours = decimal.toInt() val minutesDecimal = (decimal - hours) * MINUTES_IN_HOURS val minutes = minutesDecimal.toInt() - val totalSeconds = calculateTotalSeconds(hours, minutes) + val totalSeconds = calculateTotalSeconds(hours.toLong(), minutes.toLong()) return Time( decimal = decimal, hours = hours, @@ -38,9 +51,10 @@ data class Time( return Time(hours, minutes, decimal.toFloat()) } - private fun calculateTotalSeconds(hours: Int, minutes: Int) = - (hours * MINUTES_IN_HOURS * MINUTES_IN_HOURS) + (minutes * MINUTES_IN_HOURS) + private fun calculateTotalSeconds(hours: Long, minutes: Long): Long = + (hours * MINUTES_IN_HOURS * SECONDS_IN_MINUTES) + (minutes * SECONDS_IN_MINUTES) private const val MINUTES_IN_HOURS = 60 + private const val SECONDS_IN_MINUTES = 60 } } diff --git a/details/src/main/java/com/jacob/wakatimeapp/details/data/dtos/DetailedProjectStatsDTO.kt b/details/src/main/java/com/jacob/wakatimeapp/details/data/dtos/DetailedProjectStatsDTO.kt index b74cc5b7..ce734889 100644 --- a/details/src/main/java/com/jacob/wakatimeapp/details/data/dtos/DetailedProjectStatsDTO.kt +++ b/details/src/main/java/com/jacob/wakatimeapp/details/data/dtos/DetailedProjectStatsDTO.kt @@ -5,6 +5,7 @@ import com.jacob.wakatimeapp.core.common.data.dtos.CumulativeTotalDTO import com.jacob.wakatimeapp.core.common.data.dtos.DependencyDTO import com.jacob.wakatimeapp.core.common.data.dtos.EditorDTO import com.jacob.wakatimeapp.core.common.data.dtos.EntityDTO +import com.jacob.wakatimeapp.core.common.data.dtos.ExtractedDataDTO.DayDTO.ProjectDTO.BranchDTO import com.jacob.wakatimeapp.core.common.data.dtos.GrandTotalDTO import com.jacob.wakatimeapp.core.common.data.dtos.LanguageDTO import com.jacob.wakatimeapp.core.common.data.dtos.MachineDTO @@ -35,18 +36,5 @@ data class DetailedProjectStatsDTO( val range: RangeDTO, @SerialName("operating_systems") val operatingSystems: List, @SerialName("grand_total") val grandTotal: GrandTotalDTO, - ) { - @Serializable - data class BranchDTO( - val decimal: String, - val digital: String, - val hours: Int, - val minutes: Int, - val name: String, - val percent: Double, - val seconds: Int, - val text: String, - @SerialName("total_seconds") val totalSeconds: Double, - ) - } + ) } diff --git a/details/src/main/java/com/jacob/wakatimeapp/details/data/mappers/DetailedProjectStatsDTOMapper.kt b/details/src/main/java/com/jacob/wakatimeapp/details/data/mappers/DetailedProjectStatsDTOMapper.kt index 2cb3c03c..f11f9cf8 100644 --- a/details/src/main/java/com/jacob/wakatimeapp/details/data/mappers/DetailedProjectStatsDTOMapper.kt +++ b/details/src/main/java/com/jacob/wakatimeapp/details/data/mappers/DetailedProjectStatsDTOMapper.kt @@ -15,7 +15,7 @@ import kotlinx.datetime.toLocalDate fun DetailedProjectStatsDTO.toModel(name: String): ProjectStats { val dailyStats = data.associate { - it.range.date.toLocalDate() to Time.fromDecimal(it.grandTotal.decimal.toFloat()) + it.range.date.toLocalDate() to Time.fromTotalSeconds(it.grandTotal.totalSeconds) } val editors = data.flatMap(Data::editors) @@ -31,7 +31,7 @@ fun DetailedProjectStatsDTO.toModel(name: String): ProjectStats { .map { branch -> Branch( name = branch.name, - time = Time.fromDecimal(branch.totalSeconds.toFloat()), + time = Time.fromTotalSeconds(branch.totalSeconds), ) } @@ -39,13 +39,13 @@ fun DetailedProjectStatsDTO.toModel(name: String): ProjectStats { .map { machine -> Machine( name = machine.name, - time = Time.fromDecimal(machine.totalSeconds.toFloat()), + time = Time.fromTotalSeconds(machine.totalSeconds), ) } return ProjectStats( name = name, - totalTime = Time.fromDecimal(cumulativeTotal.decimal.toFloat()), + totalTime = Time.fromTotalSeconds(cumulativeTotal.seconds), dailyProjectStats = dailyStats, range = Range(startDate = start, endDate = end), languages = languages, diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/domain/models/HomePageUiData.kt b/home/src/main/java/com/jacob/wakatimeapp/home/domain/models/HomePageUiData.kt index 51caedee..2d7604b2 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/domain/models/HomePageUiData.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/domain/models/HomePageUiData.kt @@ -54,8 +54,8 @@ data class Streak( operator fun plus(other: Streak) = when { this == ZERO -> other other == ZERO -> this - this in other -> Streak(other.start, other.end) - other in this -> Streak(start, end) + this in other -> other + other in this -> this other.start in padded() -> Streak(start, other.end) start in other.padded() -> Streak(other.start, end) else -> {