-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
254 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
details/src/main/java/com/jacob/wakatimeapp/details/data/Mappers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.jacob.wakatimeapp.details.data | ||
|
||
import com.jacob.wakatimeapp.core.common.data.local.entities.ProjectPerDay | ||
import com.jacob.wakatimeapp.core.models.Range | ||
import com.jacob.wakatimeapp.core.models.Time | ||
import com.jacob.wakatimeapp.details.domain.models.ProjectDetails | ||
|
||
internal fun List<ProjectPerDay>.toProjectDetails() = groupBy(ProjectPerDay::name) | ||
.map { | ||
it.value | ||
.fold( | ||
ProjectDetails( | ||
name = it.key, | ||
time = Time.ZERO, | ||
range = Range( | ||
startDate = it.value.minOf(ProjectPerDay::day), | ||
endDate = it.value.maxOf(ProjectPerDay::day), | ||
), | ||
), | ||
) { acc, projectPerDay -> | ||
acc.copy(time = acc.time + projectPerDay.grandTotal) | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
details/src/main/java/com/jacob/wakatimeapp/details/data/ProjectDetailsNetworkData.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
details/src/main/java/com/jacob/wakatimeapp/details/data/mappers/ProjectDetailsDTOMapper.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
details/src/main/java/com/jacob/wakatimeapp/details/domain/models/ProjectDetails.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
package com.jacob.wakatimeapp.details.domain.models | ||
|
||
import com.jacob.wakatimeapp.core.models.Range | ||
import com.jacob.wakatimeapp.core.models.Time | ||
|
||
data class ProjectDetails( | ||
val name: String, | ||
val time: Time, | ||
val range: Range, | ||
) |
6 changes: 3 additions & 3 deletions
6
details/src/main/java/com/jacob/wakatimeapp/details/domain/usecases/GetProjectDetailsUC.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package com.jacob.wakatimeapp.details.domain.usecases | ||
|
||
import com.jacob.wakatimeapp.core.common.data.local.WakaTimeAppDB | ||
import com.jacob.wakatimeapp.details.data.ProjectDetailsNetworkData | ||
import com.jacob.wakatimeapp.core.common.data.local.entities.ProjectPerDay | ||
import com.jacob.wakatimeapp.details.data.toProjectDetails | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
internal class GetProjectDetailsUC @Inject constructor( | ||
private val projectDetailsNetworkData: ProjectDetailsNetworkData, | ||
private val wakaTimeAppDB: WakaTimeAppDB, | ||
) { | ||
suspend operator fun invoke(projectName: String) = | ||
wakaTimeAppDB.getDetailsForProject(projectName) | ||
wakaTimeAppDB.getDetailsForProject(projectName).map(List<ProjectPerDay>::toProjectDetails) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ata/local/mappers/Last7DaysStatsMapper.kt → ...home/data/mappers/Last7DaysStatsMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
home/src/main/java/com/jacob/wakatimeapp/home/data/mappers/Mappers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.jacob.wakatimeapp.home.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.common.data.local.entities.DayWithProjects | ||
import com.jacob.wakatimeapp.core.common.data.mappers.toModel | ||
import com.jacob.wakatimeapp.core.models.DailyStats | ||
import com.jacob.wakatimeapp.core.models.DailyStatsAggregate | ||
import com.jacob.wakatimeapp.core.models.Range | ||
import com.jacob.wakatimeapp.core.models.Time | ||
import com.jacob.wakatimeapp.core.models.WeeklyStats | ||
import com.jacob.wakatimeapp.core.models.project.Project | ||
import com.jacob.wakatimeapp.home.data.network.dtos.GetDailyStatsResDTO | ||
import com.jacob.wakatimeapp.home.data.network.dtos.GetLast7DaysStatsResDTO | ||
import com.jacob.wakatimeapp.home.data.network.dtos.GetStatsForRangeResDTO | ||
import com.jacob.wakatimeapp.home.data.network.dtos.GetStatsForRangeResDTO.Data | ||
import kotlinx.collections.immutable.toImmutableList | ||
import kotlinx.datetime.toLocalDate | ||
|
||
internal fun List<DayWithProjects>.toDailyStateAggregate() = DailyStatsAggregate( | ||
values = map { | ||
DailyStats( | ||
timeSpent = it.day.grandTotal, | ||
projectsWorkedOn = it.projectsForDay.map { projectPerDay -> | ||
Project( | ||
time = projectPerDay.grandTotal, | ||
name = projectPerDay.name, | ||
percent = projectPerDay.grandTotal.totalSeconds / it.day.grandTotal.totalSeconds, | ||
) | ||
}.toImmutableList(), | ||
mostUsedLanguage = "", | ||
mostUsedEditor = "", | ||
mostUsedOs = "", | ||
date = it.day.date, | ||
) | ||
}, | ||
) | ||
|
||
internal fun GetDailyStatsResDTO.toModel() = DailyStats( | ||
timeSpent = Time.createFrom(cumulativeTotal.digital, cumulativeTotal.decimal), | ||
projectsWorkedOn = data.first().projects.map(ProjectDTO::toModel).toImmutableList(), | ||
mostUsedLanguage = "", | ||
mostUsedEditor = "", | ||
mostUsedOs = "", | ||
date = data.first().range.date.toLocalDate(), | ||
) | ||
|
||
internal fun GetStatsForRangeResDTO.toModel() = DailyStatsAggregate( | ||
values = getDailyStatsFromDto(data), | ||
) | ||
|
||
private fun getDailyStatsFromDto(data: List<Data>) = data.map { | ||
DailyStats( | ||
timeSpent = Time.createFrom( | ||
digitalString = it.grandTotal.digital, | ||
decimal = it.grandTotal.decimal, | ||
), | ||
mostUsedEditor = it.editors.maxByOrNull(EditorDTO::percent)?.name ?: "NA", | ||
mostUsedLanguage = it.languages.maxByOrNull(LanguageDTO::percent)?.name ?: "NA", | ||
mostUsedOs = it.operatingSystems.maxByOrNull(OperatingSystemDTO::percent)?.name ?: "NA", | ||
date = it.range.date.toLocalDate(), | ||
projectsWorkedOn = it.projects | ||
.filterNot(ProjectDTO::isUnknownProject) | ||
.map(ProjectDTO::toModel) | ||
.toImmutableList(), | ||
) | ||
} | ||
|
||
internal fun GetLast7DaysStatsResDTO.toModel() = WeeklyStats( | ||
totalTime = Time.createFrom(cumulativeTotal.digital, cumulativeTotal.decimal), | ||
dailyStats = getDailyStatsFromDto(data), | ||
range = Range(startDate = start, endDate = end), | ||
) | ||
|
||
private fun getDailyStatsFromDto(data: List<GetLast7DaysStatsResDTO.Data>) = data.map { | ||
DailyStats( | ||
timeSpent = Time.createFrom( | ||
digitalString = it.grandTotal.digital, | ||
decimal = it.grandTotal.decimal, | ||
), | ||
mostUsedEditor = it.editors.maxByOrNull(EditorDTO::percent)?.name ?: "NA", | ||
mostUsedLanguage = it.languages.maxByOrNull(LanguageDTO::percent)?.name ?: "NA", | ||
mostUsedOs = it.operatingSystems.maxByOrNull(OperatingSystemDTO::percent)?.name ?: "NA", | ||
date = it.range.date.toLocalDate(), | ||
projectsWorkedOn = it.projects | ||
.filterNot(ProjectDTO::isUnknownProject) | ||
.map(ProjectDTO::toModel) | ||
.toImmutableList(), | ||
) | ||
}.toImmutableList() |
Oops, something went wrong.