Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Brain-up/brn into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Elena Moshnikova committed Nov 15, 2024
2 parents 45902ae + a107081 commit 64d47dc
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/certbot-update-cert.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Update TLS certificates for vscale
name: Update TLS certificates for selectel

on:
workflow_dispatch:
Expand All @@ -7,26 +7,26 @@ on:

jobs:
update_certs:
runs-on: vscale
runs-on: selectel
steps:
- uses: actions/checkout@v4
- name: Configure secrets
run: |
echo "$S3_KEY"|base64 -d > aws-key.properties
echo "$FIREBASE_CONFIG"|base64 -d > firebase_config.json
mv docker-compose-run.yml docker-compose.yml
sed -i -e "s/_YANDEX_AUTH_TOKEN_/\\$YANDEX_AUTH_TOKEN/" docker-compose.yml
sed -i -e "s/_YANDEX_FOLDER_ID_/\\$YANDEX_FOLDER_ID/" docker-compose.yml
sed -i -e "s/_POSTGRES_PASSWORD_/\\$POSTGRES_PASSWORD/" docker-compose.yml
sed -i -e "s/_API_GITHUB_TOKEN_/\\$API_GITHUB_TOKEN/" docker-compose.yml
env:
S3_KEY: ${{ secrets.S3_KEY }}
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
YANDEX_AUTH_TOKEN: ${{ secrets.YANDEX_AUTH_TOKEN }}
YANDEX_FOLDER_ID: ${{ secrets.YANDEX_FOLDER_ID }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
- name: Update certs
run: |
docker compose pull
docker compose run --rm certbot renew --allow-subset-of-names
docker compose restart brn_fe_with_tls
docker image prune -af
6 changes: 4 additions & 2 deletions .github/workflows/create_cert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ on: [workflow_dispatch]

jobs:
update_certs:
runs-on: vscale
runs-on: selectel
steps:
- uses: actions/checkout@v4
- name: Configure secrets
run: |
echo "$S3_KEY"|base64 -d > aws-key.properties
echo "$FIREBASE_CONFIG"|base64 -d > firebase_config.json
mv docker-compose-run.yml docker-compose.yml
sed -i -e "s/_YANDEX_AUTH_TOKEN_/\\$YANDEX_AUTH_TOKEN/" docker-compose.yml
sed -i -e "s/_YANDEX_FOLDER_ID_/\\$YANDEX_FOLDER_ID/" docker-compose.yml
sed -i -e "s/_POSTGRES_PASSWORD_/\\$POSTGRES_PASSWORD/" docker-compose.yml
sed -i -e "s/_API_GITHUB_TOKEN_/\\$API_GITHUB_TOKEN/" docker-compose.yml
env:
S3_KEY: ${{ secrets.S3_KEY }}
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }}
YANDEX_AUTH_TOKEN: ${{ secrets.YANDEX_AUTH_TOKEN }}
YANDEX_FOLDER_ID: ${{ secrets.YANDEX_FOLDER_ID }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
- name: Create cert
run: |
docker compose run --rm certbot certonly --webroot --webroot-path=/var/www/html --email brainupproject@yandex.ru -d brainup.fun
docker compose run --rm certbot certonly --webroot --webroot-path=/var/www/html --email brainupproject@yandex.ru
2 changes: 1 addition & 1 deletion .github/workflows/instances-redeploy.yml_tmp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.runners }}
strategy:
matrix:
runners: [ epam, vscale ]
runners: [ selectel ]
steps:
- uses: actions/checkout@v4
- name: Configure secrets
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ services:
- web-root-for-certbot:/var/www/html
depends_on:
- brn_fe_with_tls
command: certonly --webroot --webroot-path=/var/www/html --email brainupspbproject@gmail.com --agree-tos --no-eff-email --force-renewal -d brainup.fun
command: certonly --webroot --webroot-path=/var/www/html --email brainupspbproject@gmail.com --agree-tos --no-eff-email
secrets:
aws-key:
file: aws-key.properties
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/com/epam/brn/dto/AudioFileMetaData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>

var iamToken: String = ""
var iamTokenExpiresTime: LocalDateTime = LocalDateTime.now(ZoneOffset.UTC)
Expand Down Expand Up @@ -78,6 +78,7 @@ class YandexSpeechKitService(
*/
fun generateAudioStream(audioFileMetaData: AudioFileMetaData): InputStream {
val token = getYandexIamTokenForAudioGeneration()
val emotion = emotions.random()
val parameters = ArrayList<NameValuePair>().apply {
add(BasicNameValuePair("folderId", folderId))
add(BasicNameValuePair("lang", audioFileMetaData.locale))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 26 additions & 10 deletions src/test/kotlin/com/epam/brn/service/UserAnalyticsServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "мама, папа"
}

Expand All @@ -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 "мама папа"
}

Expand All @@ -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 "мама, папа"
}

Expand All @@ -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 "мама папа"
}

Expand All @@ -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 "мама"
}

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +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.speeds=1,1.2
yandex.emotions=good
yandex.folderForFiles=audioTest

brn.resources.default-pictures.path=pictures/
Expand Down

0 comments on commit 64d47dc

Please sign in to comment.