Skip to content

Commit

Permalink
WTA #71: Added separate classes for editor, language and os stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob3075 committed Dec 27, 2022
1 parent a7c3899 commit ab86422
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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()),
)
Original file line number Diff line number Diff line change
@@ -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<Editor>) : SecondaryStats<Editor> {

override fun plus(other: SecondaryStats<Editor>) = Editors(values + other.values)

companion object {
val NONE = Editors(emptyList())
}
}
Original file line number Diff line number Diff line change
@@ -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<Language>) : SecondaryStats<Language> {

companion object {
val NONE = Languages(emptyList())
}

override fun plus(other: SecondaryStats<Language>) = Languages(values + other.values)
}
Original file line number Diff line number Diff line change
@@ -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<OperatingSystem>) :
SecondaryStats<OperatingSystem> {

override fun plus(other: SecondaryStats<OperatingSystem>) =
OperatingSystems(values + other.values)

companion object {
val NONE = OperatingSystems(emptyList())
}
}
Original file line number Diff line number Diff line change
@@ -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<T : SecondaryStat> {
val values: Iterable<T>

operator fun plus(other: SecondaryStats<T>): SecondaryStats<T>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<LocalDate, Time>,
val languages: List<String>,
val operatingSystems: List<String>,
val editors: List<String>,
val languages: Languages,
val operatingSystems: OperatingSystems,
val editors: Editors,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalDate, Time>,
val range: StatsRange,
val languages: List<String>,
val operatingSystems: List<String>,
val editors: List<String>,
val languages: Languages,
val operatingSystems: OperatingSystems,
val editors: Editors,
) {
operator fun plus(other: ProjectStats) = ProjectStats(
totalTime = totalTime + other.totalTime,
Expand All @@ -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,
)
}
}

0 comments on commit ab86422

Please sign in to comment.