From bce1769e43b69acf44913af10013e39fcfc58461 Mon Sep 17 00:00:00 2001 From: Elena Moshnikova Date: Mon, 5 Jun 2023 22:43:10 +0300 Subject: [PATCH 1/5] 2508: fix and switch on job which clear unused pictures --- .../com/epam/brn/job/UnverifiedPicturesClearJob.kt | 12 ++++++++---- src/main/resources/application.properties | 5 +++-- .../epam/brn/job/UnverifiedPicturesClearJobTest.kt | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/epam/brn/job/UnverifiedPicturesClearJob.kt b/src/main/kotlin/com/epam/brn/job/UnverifiedPicturesClearJob.kt index bb0383f47..a5f185f52 100644 --- a/src/main/kotlin/com/epam/brn/job/UnverifiedPicturesClearJob.kt +++ b/src/main/kotlin/com/epam/brn/job/UnverifiedPicturesClearJob.kt @@ -3,6 +3,7 @@ package com.epam.brn.job import com.epam.brn.service.cloud.CloudService import org.apache.logging.log4j.kotlin.logger import org.springframework.beans.factory.annotation.Value +import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Component @Component @@ -15,11 +16,14 @@ class UnverifiedPicturesClearJob(private val cloudService: CloudService) { private val log = logger() - // todo: fix it as now it removes folder unverified - // @Scheduled(cron = "\${brn.resources.unverified-pictures.clean-job.cron}") + @Scheduled(cron = "\${brn.resources.unverified-pictures.clean-job.cron}") fun clearUnusedPictures() { - val defaultFolderPictures = cloudService.getFileNames(defaultPicturesPath) - val unverifiedFolderPictures = cloudService.getFileNames(unverifiedPicturesPath) + val unverifiedFolderPictures: List = cloudService + .getFileNames(unverifiedPicturesPath) + .filter { it != "/" } + val defaultFolderPictures: List = cloudService + .getFileNames(defaultPicturesPath) + .filter { it != "/" } val fileNamesToDelete = defaultFolderPictures .intersect(unverifiedFolderPictures) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 08ae7a846..9e00a35b3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -85,8 +85,9 @@ brn.resources.pictures.ext=png # The max size of upload unverified picture to cloud. Possible values: 1B, 1KB, 1MB, 1GB, 1TB. If not set data unit will use: BYTES brn.resources.unverified-pictures.max-size=512KB brn.resources.contributor-pictures.max-size=10MB -# Every night -brn.resources.unverified-pictures.clean-job.cron = 0 0 0 * * * +# Every week oon monday +#brn.resources.unverified-pictures.clean-job.cron = 0 0 1 * * MON +brn.resources.unverified-pictures.clean-job.cron = 0 0/5 * * * ? # Monthly brn.resources.pictures.update-job.cron = 0 0 0 1 * * diff --git a/src/test/kotlin/com/epam/brn/job/UnverifiedPicturesClearJobTest.kt b/src/test/kotlin/com/epam/brn/job/UnverifiedPicturesClearJobTest.kt index 204703996..b7045df63 100644 --- a/src/test/kotlin/com/epam/brn/job/UnverifiedPicturesClearJobTest.kt +++ b/src/test/kotlin/com/epam/brn/job/UnverifiedPicturesClearJobTest.kt @@ -28,8 +28,8 @@ internal class UnverifiedPicturesClearJobTest { ReflectionTestUtils.setField(unverifiedPicturesClearJob, "unverifiedPicturesPath", "unverifiedPicturesPath") val capturedFileNames = slot>() - every { cloudService.getFileNames("defaultPicturesPath") } returns listOf("/file1.png", "/file2.png") - every { cloudService.getFileNames("unverifiedPicturesPath") } returns listOf("/file2.png", "/file3.png") + every { cloudService.getFileNames("defaultPicturesPath") } returns listOf("/file1.png", "/file2.png", "/") + every { cloudService.getFileNames("unverifiedPicturesPath") } returns listOf("/file2.png", "/file3.png", "/") every { cloudService.deleteFiles(capture(capturedFileNames)) } just Runs // WHEN From 1c3f86775d465362e8efc444eb9dde55e8b1ce6e Mon Sep 17 00:00:00 2001 From: Elena Moshnikova Date: Wed, 7 Jun 2023 14:02:34 +0300 Subject: [PATCH 2/5] 2508: fix and switch on job which clear unused pictures --- src/main/resources/application.properties | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9e00a35b3..63b49ace1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -75,7 +75,7 @@ brn.picture.file.default.path=pictures/%s.jpg # The default path in cloud with picture brn.resources.default-pictures.path=pictures/ # The path for upload unverified picture to cloud -brn.resources.unverified-pictures.path=pictures/unverified +brn.resources.unverified-pictures.path=pictures-unverified # The path for upload contributor pictures brn.resources.contributor-pictures.path=pictures/contributors # The extensions allowed for upload unverified picture to cloud @@ -85,11 +85,14 @@ brn.resources.pictures.ext=png # The max size of upload unverified picture to cloud. Possible values: 1B, 1KB, 1MB, 1GB, 1TB. If not set data unit will use: BYTES brn.resources.unverified-pictures.max-size=512KB brn.resources.contributor-pictures.max-size=10MB -# Every week oon monday -#brn.resources.unverified-pictures.clean-job.cron = 0 0 1 * * MON -brn.resources.unverified-pictures.clean-job.cron = 0 0/5 * * * ? +# Every week on monday +brn.resources.unverified-pictures.clean-job.cron = 0 0 1 * * MON +#for testing +#brn.resources.unverified-pictures.clean-job.cron = 0 0/35 * * * ? # Monthly brn.resources.pictures.update-job.cron = 0 0 0 1 * * +#for testing +#brn.resources.pictures.update-job.cron = 0 0/1 * * * ? brn.dataFormatNumLines=5 brn.statistic.progress.day.status.bad.minimal=0 From 97db0f039c460f0781a6bab8dbfa8e139cad8f19 Mon Sep 17 00:00:00 2001 From: Elena Moshnikova Date: Fri, 4 Oct 2024 18:11:19 +0300 Subject: [PATCH 3/5] 2590 fix version update --- src/main/kotlin/com/epam/brn/config/SwaggerConfig.kt | 2 +- src/main/resources/initFiles/series_sentences_ru.csv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/epam/brn/config/SwaggerConfig.kt b/src/main/kotlin/com/epam/brn/config/SwaggerConfig.kt index d2f386855..6d4d4cc91 100644 --- a/src/main/kotlin/com/epam/brn/config/SwaggerConfig.kt +++ b/src/main/kotlin/com/epam/brn/config/SwaggerConfig.kt @@ -21,7 +21,7 @@ class SwaggerConfig { .contact( Contact() .name("Elena.Moshnikova") - .url("https://www.epam.com/") + .url("https://t.me/ElenaLovesSpb") .email("brainupproject@yandex.ru") ) diff --git a/src/main/resources/initFiles/series_sentences_ru.csv b/src/main/resources/initFiles/series_sentences_ru.csv index 23d3dd00c..a4e270f56 100644 --- a/src/main/resources/initFiles/series_sentences_ru.csv +++ b/src/main/resources/initFiles/series_sentences_ru.csv @@ -50,7 +50,7 @@ level,code,exerciseName,orderNumber,words 12,sentence_with_3_words,Пойми предложение из 3 слов,2,(();(мудрая великая);(волшебница фея);(прощает поёт);();()) 13,sentence_with_3_words,Пойми предложение из 3 слов,2,(();(великодушный трусливый);(рыцарь кузнец);(спрашивает отвечает);();()) 13,sentence_with_3_words,Пойми предложение из 3 слов,2,(();(смелая храбрая);(муха лягушка);(сражается борется);();()) -14,sentence_with_3_words,Пойми предложение из 3 слов,2,((три семь);();(поросёнка волчонка);(строят дуют);();()) +14,sentence_with_3_words,Пойми предложение из 3 слов,2,((три четыре);();(поросёнка волчонка);(строят дуют);();()) 15,sentence_with_3_words,Пойми предложение из 3 слов,2,((двенадцать семнадцать);();(лебедей червяков);(летят ползут);();()) 16,sentence_with_3_words,Пойми предложение из 3 слов,2,((три два);();(дядюшки зайца);(бегут стоят);();()) 17,sentence_with_3_words,Пойми предложение из 3 слов,2,((три четыре);();(зайчонка лисы);(пищат шумят);();()) From 8ba5f20d933e49d6240e455202eb78f85a881025 Mon Sep 17 00:00:00 2001 From: Elena Moshnikova Date: Fri, 15 Nov 2024 14:57:10 +0300 Subject: [PATCH 4/5] 2641 change audio emotion/speed management --- .../com/epam/brn/dto/AudioFileMetaData.kt | 10 ++++++ .../brn/service/YandexSpeechKitService.kt | 5 +-- .../service/impl/UserAnalyticsServiceImpl.kt | 22 ++++++------ src/main/resources/application.properties | 3 +- .../brn/service/UserAnalyticsServiceTest.kt | 36 +++++++++++++------ src/test/resources/application.properties | 1 - 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/com/epam/brn/dto/AudioFileMetaData.kt b/src/main/kotlin/com/epam/brn/dto/AudioFileMetaData.kt index a139d8e80..34b51687d 100644 --- a/src/main/kotlin/com/epam/brn/dto/AudioFileMetaData.kt +++ b/src/main/kotlin/com/epam/brn/dto/AudioFileMetaData.kt @@ -22,4 +22,14 @@ data class AudioFileMetaData( this.speedCode = AzureRates.X_SLOW this.speedFloat = "0.65" } + + fun setSpeedNormal() { + this.speedCode = AzureRates.DEFAULT + this.speedFloat = "1" + } + + fun setSpeedFaster() { + this.speedCode = AzureRates.FAST + this.speedFloat = "1.2" + } } diff --git a/src/main/kotlin/com/epam/brn/service/YandexSpeechKitService.kt b/src/main/kotlin/com/epam/brn/service/YandexSpeechKitService.kt index 101298076..ef074c941 100644 --- a/src/main/kotlin/com/epam/brn/service/YandexSpeechKitService.kt +++ b/src/main/kotlin/com/epam/brn/service/YandexSpeechKitService.kt @@ -43,8 +43,8 @@ class YandexSpeechKitService( @Value("\${yandex.format}") lateinit var format: String - @Value("\${yandex.emotion}") - lateinit var emotion: String + @Value("\${yandex.emotions}") + lateinit var emotions: List var iamToken: String = "" var iamTokenExpiresTime: LocalDateTime = LocalDateTime.now(ZoneOffset.UTC) @@ -78,6 +78,7 @@ class YandexSpeechKitService( */ fun generateAudioStream(audioFileMetaData: AudioFileMetaData): InputStream { val token = getYandexIamTokenForAudioGeneration() + val emotion = emotions.random() val parameters = ArrayList().apply { add(BasicNameValuePair("folderId", folderId)) add(BasicNameValuePair("lang", audioFileMetaData.locale)) diff --git a/src/main/kotlin/com/epam/brn/service/impl/UserAnalyticsServiceImpl.kt b/src/main/kotlin/com/epam/brn/service/impl/UserAnalyticsServiceImpl.kt index 1f7b3ae2b..919e691e3 100644 --- a/src/main/kotlin/com/epam/brn/service/impl/UserAnalyticsServiceImpl.kt +++ b/src/main/kotlin/com/epam/brn/service/impl/UserAnalyticsServiceImpl.kt @@ -66,32 +66,34 @@ class UserAnalyticsServiceImpl( } override fun prepareAudioStreamForUser(exerciseId: Long, audioFileMetaData: AudioFileMetaData): InputStream = - textToSpeechService.generateAudioOggStreamWithValidation(prepareAudioFileMetaData(exerciseId, audioFileMetaData)) + textToSpeechService + .generateAudioOggStreamWithValidation( + prepareAudioFileMetaData(exerciseId, audioFileMetaData) + ) override fun prepareAudioFileMetaData(exerciseId: Long, audioFileMetaData: AudioFileMetaData): AudioFileMetaData { val currentUserId = userAccountService.getCurrentUserId() val lastExerciseHistory = studyHistoryRepository .findLastByUserAccountIdAndExerciseId(currentUserId, exerciseId) val seriesType = ExerciseType.valueOf(exerciseRepository.findTypeByExerciseId(exerciseId)) - val text = audioFileMetaData.text if (!listTextExercises.contains(seriesType)) audioFileMetaData.text = text.replace(" ", ", ") - - if (text.contains(" ")) { - if (isDoneBad(lastExerciseHistory)) - audioFileMetaData.setSpeedSlowest() - else - audioFileMetaData.setSpeedSlow() - } else if (isDoneBad(lastExerciseHistory)) { + if (lastExerciseHistory == null) + audioFileMetaData.setSpeedNormal() + else if (isDoneBad(lastExerciseHistory)) audioFileMetaData.setSpeedSlow() - } + else if (isDoneWell(lastExerciseHistory)) + audioFileMetaData.setSpeedFaster() return audioFileMetaData } fun isDoneBad(lastHistory: StudyHistory?): Boolean = lastHistory != null && !exerciseService.isDoneWell(lastHistory) + fun isDoneWell(lastHistory: StudyHistory?): Boolean = + lastHistory != null && exerciseService.isDoneWell(lastHistory) + fun isMultiWords(seriesType: ExerciseType): Boolean = seriesType == ExerciseType.PHRASES || seriesType == ExerciseType.SENTENCE || seriesType == ExerciseType.WORDS_SEQUENCES diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1d311d189..804cc5707 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -63,8 +63,7 @@ yandex.generationAudioLink=https://tts.api.cloud.yandex.net/speech/v1/tts:synthe yandex.folderId=${YANDEX_FOLDER_ID:b1g0m877l9r22ngujisu} yandex.format=oggopus #yandex.emotion=good -yandex.emotion=neutral -yandex.speeds=0.8,1,1.2 +yandex.emotions=neutral,good yandex.folderForFiles=frontend/public brn.picture.file.default.path=pictures/%s.jpg diff --git a/src/test/kotlin/com/epam/brn/service/UserAnalyticsServiceTest.kt b/src/test/kotlin/com/epam/brn/service/UserAnalyticsServiceTest.kt index 92d593fbe..ccaec2986 100644 --- a/src/test/kotlin/com/epam/brn/service/UserAnalyticsServiceTest.kt +++ b/src/test/kotlin/com/epam/brn/service/UserAnalyticsServiceTest.kt @@ -131,8 +131,8 @@ internal class UserAnalyticsServiceTest { val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData) // THEN - metaDataResult.speedFloat shouldBe "0.8" - metaDataResult.speedCode shouldBe AzureRates.SLOW + metaDataResult.speedFloat shouldBe "1.2" + metaDataResult.speedCode shouldBe AzureRates.FAST metaDataResult.text shouldBe "мама, папа" } @@ -152,8 +152,8 @@ internal class UserAnalyticsServiceTest { val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData) // THEN - metaDataResult.speedFloat shouldBe "0.8" - metaDataResult.speedCode shouldBe AzureRates.SLOW + metaDataResult.speedFloat shouldBe "1.2" + metaDataResult.speedCode shouldBe AzureRates.FAST metaDataResult.text shouldBe "мама папа" } @@ -174,8 +174,8 @@ internal class UserAnalyticsServiceTest { val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData) // THEN - metaDataResult.speedFloat shouldBe "0.65" - metaDataResult.speedCode shouldBe AzureRates.X_SLOW + metaDataResult.speedFloat shouldBe "0.8" + metaDataResult.speedCode shouldBe AzureRates.SLOW metaDataResult.text shouldBe "мама, папа" } @@ -196,8 +196,8 @@ internal class UserAnalyticsServiceTest { val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData) // THEN - metaDataResult.speedFloat shouldBe "0.65" - metaDataResult.speedCode shouldBe AzureRates.X_SLOW + metaDataResult.speedFloat shouldBe "0.8" + metaDataResult.speedCode shouldBe AzureRates.SLOW metaDataResult.text shouldBe "мама папа" } @@ -217,8 +217,8 @@ internal class UserAnalyticsServiceTest { val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData) // THEN - metaDataResult.speedFloat shouldBe "1" - metaDataResult.speedCode shouldBe AzureRates.DEFAULT + metaDataResult.speedFloat shouldBe "1.2" + metaDataResult.speedCode shouldBe AzureRates.FAST metaDataResult.text shouldBe "мама" } @@ -242,6 +242,22 @@ internal class UserAnalyticsServiceTest { metaDataResult.speedCode shouldBe AzureRates.SLOW } + @Test + fun `should prepareAudioFileMetaData normal speed for single word`() { + // GIVEN + every { userAccountService.getCurrentUserId() } returns currentUserId + every { + studyHistoryRepository.findLastByUserAccountIdAndExerciseId(currentUserId, exerciseId) + } returns null + every { exerciseRepository.findTypeByExerciseId(exerciseId) } returns ExerciseType.SINGLE_SIMPLE_WORDS.name + val audioFileMetaData = AudioFileMetaData("text", BrnLocale.RU.locale, Voice.FILIPP.name, "1", AzureRates.DEFAULT) + // WHEN + val metaDataResult = userAnalyticsService.prepareAudioFileMetaData(exerciseId, audioFileMetaData) + // THEN + metaDataResult.speedFloat shouldBe "1" + metaDataResult.speedCode shouldBe AzureRates.DEFAULT + } + @Test fun `should prepareAudioStreamForUser`() { // GIVEN diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 9c35a137b..caa1209cc 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -49,7 +49,6 @@ yandex.generationAudioLink=https://tts.api.cloud.yandex.net/speech/v1/tts:synthe yandex.folderId=b1gqn2760f5ongt82lm3 yandex.format=oggopus yandex.emotion=good -yandex.speeds=1,1.2 yandex.folderForFiles=audioTest brn.resources.default-pictures.path=pictures/ From c8f96fe7fd4ca14fb22391cca3785596c3907991 Mon Sep 17 00:00:00 2001 From: Elena Moshnikova Date: Fri, 15 Nov 2024 15:31:52 +0300 Subject: [PATCH 5/5] 2641 change audio emotion/speed management --- src/test/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index caa1209cc..6bd08dfd7 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -48,7 +48,7 @@ yandex.getTokenLink=https://iam.api.cloud.yandex.net/iam/v1/tokens yandex.generationAudioLink=https://tts.api.cloud.yandex.net/speech/v1/tts:synthesize yandex.folderId=b1gqn2760f5ongt82lm3 yandex.format=oggopus -yandex.emotion=good +yandex.emotions=good yandex.folderForFiles=audioTest brn.resources.default-pictures.path=pictures/