From d7530b4cdfe248a768dc5c81ddea10d38d2007f7 Mon Sep 17 00:00:00 2001 From: dmitry-weirdo Date: Wed, 27 Nov 2024 01:35:57 +0100 Subject: [PATCH] feat: #98 Validate that there are no dictionary code duplicates in the json file. --- .../common/NonStandardDictionary.kt | 2 ++ .../NonStandardDictionariesCache.kt | 29 ++++++++++++++++- .../non-standard-dictionaries.json | 32 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/kgCommon/src/main/kotlin/ru/klavogonki/common/NonStandardDictionary.kt b/kgCommon/src/main/kotlin/ru/klavogonki/common/NonStandardDictionary.kt index e837300a..1bb3b874 100644 --- a/kgCommon/src/main/kotlin/ru/klavogonki/common/NonStandardDictionary.kt +++ b/kgCommon/src/main/kotlin/ru/klavogonki/common/NonStandardDictionary.kt @@ -21,6 +21,8 @@ enum class NonStandardDictionary( MINI_MARATHON(6018, "Мини-марафон, 800 знаков", "Мини-марафоне, 800 знаков"), CYBERTEXT(6562, "Кибертекст", "Кибертексте"), CYBERTEXT_2(115606, "Кибертекст 2.0", "Кибертексте 2.0"), + + // Пальцы PINKIES_PLUS(3714, "Мизинцы+", "Мизинцах+"), TRAINING_INDEX_FINGERS(226, "Тренируем указательные", "Тренируем указательные"), RING_FINGERS(8223, "Безымянные", "Безымянных"), diff --git a/kgstatsSrv/src/main/kotlin/ru/klavogonki/statistics/dictionaries/NonStandardDictionariesCache.kt b/kgstatsSrv/src/main/kotlin/ru/klavogonki/statistics/dictionaries/NonStandardDictionariesCache.kt index 0bc2ebee..2c5ecf25 100644 --- a/kgstatsSrv/src/main/kotlin/ru/klavogonki/statistics/dictionaries/NonStandardDictionariesCache.kt +++ b/kgstatsSrv/src/main/kotlin/ru/klavogonki/statistics/dictionaries/NonStandardDictionariesCache.kt @@ -20,13 +20,40 @@ object NonStandardDictionariesCache : Logging { val nonStandardDictionaries = JacksonUtils.parseNonStandardDictionaryData(fileName) + logger.info( + "Total non-standard dictionaries read from json file \"$NON_STANDARD_DICTIONARIES_JSON_RESOURCE\": " + + "${nonStandardDictionaries.size}." + ) + + // validate no duplicate ids + validate(nonStandardDictionaries) + return nonStandardDictionaries } + private fun validate(dictionaries: List) { + val repeatCodeToCount: Map = dictionaries + .groupingBy { it.code } + .eachCount() + .filter { it.value > 1 } + + if (repeatCodeToCount.isNotEmpty()) { + repeatCodeToCount.forEach { + logger.error("Duplicate dictionary code ${it.key}: used ${it.value} times.") + } + } + + check(repeatCodeToCount.isEmpty()) { + "Duplicate dictionary codes: $repeatCodeToCount" + } + + logger.info("No dictionary code duplicates.") + } + @JvmStatic fun main(args: Array) { val nonStandardDictionaries = parse() - logger.info("Total non-standard dictionaries read from json file: ${nonStandardDictionaries.size}.") + logger.info("[main]: Total non-standard dictionaries read from json file: ${nonStandardDictionaries.size}.") } } diff --git a/kgstatsSrv/src/main/resources/dictionaries/non-standard-dictionaries.json b/kgstatsSrv/src/main/resources/dictionaries/non-standard-dictionaries.json index 2ac3c6a7..8df6a6e8 100644 --- a/kgstatsSrv/src/main/resources/dictionaries/non-standard-dictionaries.json +++ b/kgstatsSrv/src/main/resources/dictionaries/non-standard-dictionaries.json @@ -13,6 +13,28 @@ } }, + { + "code": 192, + "displayName": "Частотный словарь", + "displayNamePrepositional": "Частотном словаре", + "tags": [ + "FREQUENT" + ], + "top": { + "loggerName": "FrequencyVocabulary", + "minRacesCount": 200, + + // "topByBestSpeedExcelSheetName": "Топ по рекорду в «Частотном словаре»", // 36 chars + "topByBestSpeedExcelSheetName": "Топ по рекорду в «Частотном»", // 28 chars + + // "topByRacesCountExcelSheetName": "Топ по пробегу в «Частотном словаре»", // 36 chars + "topByRacesCountExcelSheetName": "Топ по пробегу в «Частотном»", // 28 chars + + // "topByHaulExcelSheetName": "Топ по времени в «Частотном словаре»", // 36 chars + "topByHaulExcelSheetName": "Топ по времени в «Частотном»" // 28 chars + } + }, + { "code": 5539, "displayName": "Обычный in English", @@ -65,5 +87,15 @@ "CYBERTEXT", "FREQUENT" ] + }, + + { // without generated top + "code": 115606, + "displayName": "Кибертекст 2.0", + "displayNamePrepositional": "Кибертексте 2.0", + "tags": [ + "CYBERTEXT", + "FREQUENT" + ] } ] \ No newline at end of file