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

2609 [BE] rename statistic to statistics #2636

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end-point specification is here: https://github.com/Brain-up/brn/blob/master/api
Note that if you are using IntelliJ, you may want to use version 2019.2 and later to avoid issues with new kotlin plugin.

#### Useful Postman scripts:
- [Script](./postman_scripts/generate_month_history.js) to generate month tasks statistic (you can use it with `brnlogin` request in `Test` tab)
- [Script](./postman_scripts/generate_month_history.js) to generate month tasks statistics (you can use it with `brnlogin` request in `Test` tab)

### Deploy Application USING DOCKER COMPOSE:
(back-end part and front-end parts, but it is rather slow. it is better to use GitPod)
Expand Down
8 changes: 4 additions & 4 deletions api-contract/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,10 @@ annotationTypes:
description: Second version of API
# STATISTICS ----------------------------------
/statistics:
description: Contains actions over user statistic details
description: Contains actions over user statistics details
/study/day:
get:
description: Get user's details daily statistic for the day. Where day is a date in the ISO date time format
description: Get user's details daily statistics for the day. Where day is a date in the ISO date time format
queryParameters:
userId:
type: integer
Expand Down Expand Up @@ -707,7 +707,7 @@ annotationTypes:
}
/study/week:
get:
description: Get user's weekly statistic for period. Where period is a two dates in the ISO date time format
description: Get user's weekly statistics for period. Where period is a two dates in the ISO date time format
queryParameters:
from:
required: true
Expand Down Expand Up @@ -737,7 +737,7 @@ annotationTypes:
}
/study/year:
get:
description: Get user's yearly statistic for period. Where period is a two dates in the ISO date time format
description: Get user's yearly statistics for period. Where period is a two dates in the ISO date time format
queryParameters:
from:
required: true
Expand Down
2 changes: 1 addition & 1 deletion roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Start to implement mobile version of application.

2022
Implement `Diagnostic` module with 3 tests for user to measure their progress in application regularly.
Implement `Statistic` module for analysing how regular user make exercises.
Implement `Statistics` module for analysing how regular user make exercises.
Implement new design for site.

Platform updates and requirements gathering.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.epam.brn.controller

import com.epam.brn.service.RoleService
import com.epam.brn.dto.response.BrnResponse
import com.epam.brn.dto.statistic.DayStudyStatistic
import com.epam.brn.dto.statistic.MonthStudyStatistic
import com.epam.brn.dto.statistic.UserDailyDetailStatisticsDto
import com.epam.brn.dto.statistics.DayStudyStatistics
import com.epam.brn.dto.statistics.MonthStudyStatistics
import com.epam.brn.dto.statistics.UserDailyDetailStatisticsDto
import com.epam.brn.enums.BrnRole
import com.epam.brn.service.StudyHistoryService
import com.epam.brn.service.statistic.UserPeriodStatisticService
import com.epam.brn.service.statistics.UserPeriodStatisticsService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
Expand All @@ -20,46 +20,46 @@ import javax.annotation.security.RolesAllowed

@RestController
@RequestMapping("/v2/statistics")
@Tag(name = "Statistics", description = "Contains actions over user statistic details")
@Tag(name = "Statistics", description = "Contains actions over user statistics details")
@RolesAllowed(BrnRole.USER)
class UserStatisticControllerV2(
private val userDayStatisticService: UserPeriodStatisticService<DayStudyStatistic>,
private val userMonthStatisticService: UserPeriodStatisticService<MonthStudyStatistic>,
private val userDayStatisticService: UserPeriodStatisticsService<DayStudyStatistics>,
private val userMonthStatisticService: UserPeriodStatisticsService<MonthStudyStatistics>,
private val historyService: StudyHistoryService,
private val roleService: RoleService
) {
@GetMapping("/study/year")
@Operation(summary = "Get user's yearly statistic for the period. Where period is a two dates in the ISO date time format")
fun getUserYearlyStatistic(
@Operation(summary = "Get user's yearly statistics for the period. Where period is a two dates in the ISO date time format")
fun getUserYearlyStatistics(
@RequestParam(name = "from", required = true) from: LocalDateTime,
@RequestParam(name = "to", required = true) to: LocalDateTime,
@RequestParam(name = "userId") userId: Long?
): ResponseEntity<BrnResponse<List<MonthStudyStatistic>>> {
): ResponseEntity<BrnResponse<List<MonthStudyStatistics>>> {
val result = if (userId != null && roleService.isCurrentUserAdmin()) {
userMonthStatisticService.getStatisticForPeriod(from, to, userId)
userMonthStatisticService.getStatisticsForPeriod(from, to, userId)
} else {
userMonthStatisticService.getStatisticForPeriod(from, to)
userMonthStatisticService.getStatisticsForPeriod(from, to)
}
return ResponseEntity.ok().body(BrnResponse(data = result))
}

@GetMapping("/study/week")
@Operation(summary = "Get user's weekly statistic for the period. Where period is a two dates in the ISO date time format")
fun getUserWeeklyStatistic(
@Operation(summary = "Get user's weekly statistics for the period. Where period is a two dates in the ISO date time format")
fun getUserWeeklyStatistics(
@RequestParam(name = "from", required = true) from: LocalDateTime,
@RequestParam(name = "to", required = true) to: LocalDateTime,
@RequestParam(name = "userId") userId: Long?
): ResponseEntity<BrnResponse<List<DayStudyStatistic>>> {
): ResponseEntity<BrnResponse<List<DayStudyStatistics>>> {
val result = if (userId != null && roleService.isCurrentUserAdmin()) {
userDayStatisticService.getStatisticForPeriod(from, to, userId)
userDayStatisticService.getStatisticsForPeriod(from, to, userId)
} else {
userDayStatisticService.getStatisticForPeriod(from, to)
userDayStatisticService.getStatisticsForPeriod(from, to)
}
return ResponseEntity.ok().body(BrnResponse(data = result))
}

@GetMapping("/study/day")
@Operation(summary = "Get user's details daily statistic for the day. Where day is a date in the ISO date time format")
@Operation(summary = "Get user's details daily statistics for the day. Where day is a date in the ISO date time format")
fun getUserDailyDetailsStatistics(
@RequestParam(name = "day", required = true) day: LocalDateTime,
@RequestParam(name = "userId") userId: Long?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.epam.brn.controller

import com.epam.brn.dto.response.BrnResponse
import com.epam.brn.dto.response.SubGroupStatisticResponse
import com.epam.brn.dto.response.SubGroupStatisticsResponse
import com.epam.brn.enums.BrnRole
import com.epam.brn.service.statistic.UserStatisticService
import com.epam.brn.service.statistics.UserStatisticService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
Expand All @@ -15,16 +15,16 @@ import javax.annotation.security.RolesAllowed

@RestController
@RequestMapping("/statistics")
@Tag(name = "Statistics", description = "Contains actions over user statistic details")
@Tag(name = "Statistics", description = "Contains actions over user statistics details")
@RolesAllowed(BrnRole.USER)
class UserSubGroupStatisticController(
private val userStatisticService: UserStatisticService<SubGroupStatisticResponse>,
private val userStatisticService: UserStatisticService<SubGroupStatisticsResponse>,
) {
@GetMapping("/subgroups")
@Operation(summary = "Get user's subgroup statistics")
fun getUserSubGroupStatistic(
@RequestParam(value = "ids", required = true) ids: List<Long>
): ResponseEntity<BrnResponse<List<SubGroupStatisticResponse>>> {
): ResponseEntity<BrnResponse<List<SubGroupStatisticsResponse>>> {
val userStatistic = userStatisticService.getSubGroupStatistic(ids)
return ResponseEntity.ok().body(BrnResponse(data = userStatistic))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.epam.brn.dto.response

import com.epam.brn.dto.statistic.Statistic
import com.epam.brn.dto.statistics.Statistics

/**
*@author Nikolai Lazarev
*/
data class SubGroupStatisticResponse(
data class SubGroupStatisticsResponse(
val subGroupId: Long,
val completedExercises: Int = 0,
val totalExercises: Int
) : Statistic(progress = null)
) : Statistics(progress = null)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.epam.brn.dto.response

import com.epam.brn.dto.statistic.DayStudyStatistic
import com.epam.brn.dto.statistics.DayStudyStatistics
import com.epam.brn.enums.AudiometryType
import com.epam.brn.enums.BrnGender
import com.fasterxml.jackson.annotation.JsonInclude
Expand All @@ -18,7 +18,7 @@ data class UserWithAnalyticsResponse(
var active: Boolean = true,
var firstDone: LocalDateTime? = null, // generally first done exercise
var lastDone: LocalDateTime? = null, // generally last done exercise
var lastWeek: List<DayStudyStatistic> = emptyList(),
var lastWeek: List<DayStudyStatistics> = emptyList(),
var studyDaysInCurrentMonth: Int = 0, // amount of days in current month when user made any exercises
var diagnosticProgress: Map<AudiometryType, Boolean> = mapOf(AudiometryType.SIGNALS to true), // todo fill by user
var doneExercises: Int = 0, // for all time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

/**
* This class created to support legacy date format in responses and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

data class DayStudyStatistic(
data class DayStudyStatistics(
val date: LocalDateTime,
val exercisingTimeSeconds: Int,
var progress: UserExercisingProgressStatus? = null
) : Statistic(progress) {
) : Statistics(progress) {
fun toDto(): DayStudyStatisticDto =
DayStudyStatisticDto(
date = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

/**
* This class created to support legacy date format in responses and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

data class MonthStudyStatistic(
data class MonthStudyStatistics(
val date: LocalDateTime,
val exercisingTimeSeconds: Int,
val exercisingDays: Int,
var progress: UserExercisingProgressStatus?
) : Statistic(progress) {
) : Statistics(progress) {
fun toDto(): MonthStudyStatisticDto =
MonthStudyStatisticDto(
date = date.format(DateTimeFormatter.ofPattern("yyyy-MM")),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

/**
*@author Nikolai Lazarev
*/
abstract class Statistic(
abstract class Statistics(
progress: UserExercisingProgressStatus?
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

/**
*@author Nikolai Lazarev
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

import kotlin.time.Duration

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

/**
*@author Nikolai Lazarev
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.epam.brn.dto.statistic
package com.epam.brn.dto.statistics

/**
*@author Nikolai Lazarev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ interface StudyHistoryRepository : CrudRepository<StudyHistory, Long> {
" COALESCE(SUM(s.spentTimeInSeconds), 0) AS spentTime, COUNT (DISTINCT s.exercise.id) as doneExercises" +
" FROM StudyHistory s WHERE user_id = :userId"
)
fun getStatisticByUserAccountId(userId: Long?): UserStatisticView
fun getStatisticsByUserAccountId(userId: Long?): UserStatisticView

@Query(
"SELECT s FROM StudyHistory s " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.epam.brn.service

import com.epam.brn.dto.StudyHistoryDto
import com.epam.brn.dto.statistic.UserDailyDetailStatisticsDto
import com.epam.brn.dto.statistics.UserDailyDetailStatisticsDto
import com.epam.brn.exception.EntityNotFoundException
import com.epam.brn.model.StudyHistory
import com.epam.brn.repo.ExerciseRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.epam.brn.service.impl

import com.epam.brn.dto.AudioFileMetaData
import com.epam.brn.dto.response.UserWithAnalyticsResponse
import com.epam.brn.dto.statistic.DayStudyStatistic
import com.epam.brn.dto.statistics.DayStudyStatistics
import com.epam.brn.enums.ExerciseType
import com.epam.brn.model.StudyHistory
import com.epam.brn.repo.ExerciseRepository
Expand All @@ -13,7 +13,7 @@ import com.epam.brn.service.TextToSpeechService
import com.epam.brn.service.TimeService
import com.epam.brn.service.UserAccountService
import com.epam.brn.service.UserAnalyticsService
import com.epam.brn.service.statistic.UserPeriodStatisticService
import com.epam.brn.service.statistics.UserPeriodStatisticsService
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import java.io.InputStream
Expand All @@ -28,7 +28,7 @@ class UserAnalyticsServiceImpl(
private val userAccountRepository: UserAccountRepository,
private val studyHistoryRepository: StudyHistoryRepository,
private val exerciseRepository: ExerciseRepository,
private val userDayStatisticService: UserPeriodStatisticService<DayStudyStatistic>,
private val userDayStatisticService: UserPeriodStatisticsService<DayStudyStatistics>,
private val timeService: TimeService,
private val textToSpeechService: TextToSpeechService,
private val userAccountService: UserAccountService,
Expand All @@ -48,17 +48,17 @@ class UserAnalyticsServiceImpl(
val startOfCurrentMonth = now.withDayOfMonth(1).with(LocalTime.MIN)

users.onEach { user ->
user.lastWeek = userDayStatisticService.getStatisticForPeriod(from, to, user.id)
user.lastWeek = userDayStatisticService.getStatisticsForPeriod(from, to, user.id)
user.studyDaysInCurrentMonth = countWorkDaysForMonth(
userDayStatisticService.getStatisticForPeriod(startOfCurrentMonth, now, user.id)
userDayStatisticService.getStatisticsForPeriod(startOfCurrentMonth, now, user.id)
)

val userStatistic = studyHistoryRepository.getStatisticByUserAccountId(user.id)
val userStatistics = studyHistoryRepository.getStatisticsByUserAccountId(user.id)
user.apply {
this.firstDone = userStatistic.firstStudy
this.lastDone = userStatistic.lastStudy
this.spentTime = userStatistic.spentTime.toDuration(DurationUnit.SECONDS)
this.doneExercises = userStatistic.doneExercises
this.firstDone = userStatistics.firstStudy
this.lastDone = userStatistics.lastStudy
this.spentTime = userStatistics.spentTime.toDuration(DurationUnit.SECONDS)
this.doneExercises = userStatistics.doneExercises
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ class UserAnalyticsServiceImpl(
fun isMultiWords(seriesType: ExerciseType): Boolean =
seriesType == ExerciseType.PHRASES || seriesType == ExerciseType.SENTENCE || seriesType == ExerciseType.WORDS_SEQUENCES

fun countWorkDaysForMonth(dayStudyStatistics: List<DayStudyStatistic>): Int =
fun countWorkDaysForMonth(dayStudyStatistics: List<DayStudyStatistics>): Int =
dayStudyStatistics
.map { it.date }
.groupBy { it.dayOfMonth }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.epam.brn.service.statistics

import com.epam.brn.dto.statistics.Statistics
import java.time.LocalDateTime

/**
*@author Nikolai Lazarev
*/
interface UserPeriodStatisticsService<T : Statistics> {

/**
* Should return statistics as Statistics implementation for period for from to to date
* @param from - beginning date of the period
* @param to - ending date of the period
* @param userId - id of the user for how get statistics
* @return list of implementations of Statistics
*/
fun getStatisticsForPeriod(from: LocalDateTime, to: LocalDateTime, userId: Long? = null): List<T>
}
Loading
Loading