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/SecondaryStatsMapper.kt new file mode 100644 index 00000000..6f9373f1 --- /dev/null +++ b/core/common/src/main/java/com/jacob/wakatimeapp/core/common/data/mappers/SecondaryStatsMapper.kt @@ -0,0 +1,24 @@ +package com.jacob.wakatimeapp.core.common.data.mappers // ktlint-disable filename + +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.models.Time +import com.jacob.wakatimeapp.core.models.secondarystats.Editor +import com.jacob.wakatimeapp.core.models.secondarystats.Language +import com.jacob.wakatimeapp.core.models.secondarystats.OperatingSystem + +fun LanguageDTO.toModel() = Language( + name = name, + time = Time.fromDecimal(decimal.toFloat()), +) + +fun EditorDTO.toModel() = Editor( + name = name, + time = Time.fromDecimal(decimal.toFloat()), +) + +fun OperatingSystemDTO.toModel() = OperatingSystem( + name = name, + time = Time.fromDecimal(decimal.toFloat()), +) diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/Editor.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/Editor.kt new file mode 100644 index 00000000..ecdca4d0 --- /dev/null +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/Editor.kt @@ -0,0 +1,14 @@ +package com.jacob.wakatimeapp.core.models.secondarystats + +import com.jacob.wakatimeapp.core.models.Time + +data class Editor(override val name: String, override val time: Time) : SecondaryStat + +data class Editors(override val values: List) : SecondaryStats { + + override fun plus(other: SecondaryStats) = Editors(values + other.values) + + companion object { + val NONE = Editors(emptyList()) + } +} diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/Language.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/Language.kt new file mode 100644 index 00000000..903de192 --- /dev/null +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/Language.kt @@ -0,0 +1,14 @@ +package com.jacob.wakatimeapp.core.models.secondarystats + +import com.jacob.wakatimeapp.core.models.Time + +data class Language(override val name: String, override val time: Time) : SecondaryStat + +data class Languages(override val values: List) : SecondaryStats { + + companion object { + val NONE = Languages(emptyList()) + } + + override fun plus(other: SecondaryStats) = Languages(values + other.values) +} diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/OperatingSystem.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/OperatingSystem.kt new file mode 100644 index 00000000..f547d277 --- /dev/null +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/OperatingSystem.kt @@ -0,0 +1,16 @@ +package com.jacob.wakatimeapp.core.models.secondarystats + +import com.jacob.wakatimeapp.core.models.Time + +data class OperatingSystem(override val name: String, override val time: Time) : SecondaryStat + +data class OperatingSystems(override val values: List) : + SecondaryStats { + + override fun plus(other: SecondaryStats) = + OperatingSystems(values + other.values) + + companion object { + val NONE = OperatingSystems(emptyList()) + } +} diff --git a/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/SecondaryStat.kt b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/SecondaryStat.kt new file mode 100644 index 00000000..144a9a56 --- /dev/null +++ b/core/models/src/main/java/com/jacob/wakatimeapp/core/models/secondarystats/SecondaryStat.kt @@ -0,0 +1,14 @@ +package com.jacob.wakatimeapp.core.models.secondarystats + +import com.jacob.wakatimeapp.core.models.Time + +interface SecondaryStat { + val name: String + val time: Time +} + +interface SecondaryStats { + val values: Iterable + + operator fun plus(other: SecondaryStats): SecondaryStats +} 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 c957df15..3c0be09f 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 @@ -3,8 +3,12 @@ package com.jacob.wakatimeapp.details.data.mappers // ktlint-disable filename 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.mappers.toModel import com.jacob.wakatimeapp.core.models.StatsRange import com.jacob.wakatimeapp.core.models.Time +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 com.jacob.wakatimeapp.details.data.dtos.DetailedProjectStatsDTO import com.jacob.wakatimeapp.details.data.dtos.DetailedProjectStatsDTO.Data import com.jacob.wakatimeapp.details.domain.models.ProjectStats @@ -16,13 +20,16 @@ fun DetailedProjectStatsDTO.toModel(): ProjectStats { } val editors = data.flatMap(Data::editors) - .map(EditorDTO::name) + .map(EditorDTO::toModel) + .let(::Editors) val languages = data.flatMap(Data::languages) - .map(LanguageDTO::name) + .map(LanguageDTO::toModel) + .let(::Languages) val operatingSystems = data.flatMap(Data::operatingSystems) - .map(OperatingSystemDTO::name) + .map(OperatingSystemDTO::toModel) + .let(::OperatingSystems) return ProjectStats( totalTime = Time.fromDecimal(cummulativeTotal.decimal.toFloat()), diff --git a/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/DetailedProjectStatsUiData.kt b/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/DetailedProjectStatsUiData.kt index d8b9a621..b3e5b5fe 100644 --- a/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/DetailedProjectStatsUiData.kt +++ b/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/DetailedProjectStatsUiData.kt @@ -1,13 +1,16 @@ package com.jacob.wakatimeapp.details.domain.models import com.jacob.wakatimeapp.core.models.Time +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.datetime.LocalDate data class DetailedProjectStatsUiData( val totalProjectTime: TotalProjectTime, val averageTime: Time, val dailyProjectStats: Map, - val languages: List, - val operatingSystems: List, - val editors: List, + val languages: Languages, + val operatingSystems: OperatingSystems, + val editors: Editors, ) diff --git a/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/ProjectStats.kt b/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/ProjectStats.kt index 2682a007..cbc05577 100644 --- a/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/ProjectStats.kt +++ b/details/src/main/java/com/jacob/wakatimeapp/details/domain/models/ProjectStats.kt @@ -2,15 +2,18 @@ package com.jacob.wakatimeapp.details.domain.models import com.jacob.wakatimeapp.core.models.StatsRange import com.jacob.wakatimeapp.core.models.Time +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.datetime.LocalDate data class ProjectStats( val totalTime: Time, val dailyProjectStats: Map, val range: StatsRange, - val languages: List, - val operatingSystems: List, - val editors: List, + val languages: Languages, + val operatingSystems: OperatingSystems, + val editors: Editors, ) { operator fun plus(other: ProjectStats) = ProjectStats( totalTime = totalTime + other.totalTime, @@ -26,9 +29,9 @@ data class ProjectStats( totalTime = Time.ZERO, dailyProjectStats = mapOf(), range = StatsRange.ZERO, - languages = listOf(), - operatingSystems = listOf(), - editors = listOf(), + languages = Languages.NONE, + operatingSystems = OperatingSystems.NONE, + editors = Editors.NONE, ) } }