diff --git a/kgCommon/src/main/kotlin/ru/klavogonki/common/Car.kt b/kgCommon/src/main/kotlin/ru/klavogonki/common/Car.kt index 3ed8744f..b32c6653 100644 --- a/kgCommon/src/main/kotlin/ru/klavogonki/common/Car.kt +++ b/kgCommon/src/main/kotlin/ru/klavogonki/common/Car.kt @@ -4,7 +4,12 @@ package ru.klavogonki.common * List of cars with ids and Russian names. */ @SuppressWarnings("MagicNumber") -enum class Car { +enum class Car( + @JvmField val id: Int, + @JvmField val displayName: String, + @JvmField val ownerId: Int?, // for personal autos + @JvmField val personalId: Int?, // for personal autos that have been made public +) { // common/public autos ZAZ_965(1, "ЗАЗ 965"), VAZ_2104(2, "ВАЗ 2104"), @@ -106,31 +111,10 @@ enum class Car { FERRARI_F2(1024, "Ferrari F12", 320247), // http://klavogonki.ru/u/#/320247/car/ ; - constructor(id: Int, displayName: String) { - this.id = id - this.displayName = displayName - this.ownerId = null - this.personalId = null - } + constructor(id: Int, displayName: String) : this(id, displayName, null, null) - constructor(id: Int, displayName: String, ownerId: Int) { // for personal cars that have not been made public - this.id = id - this.displayName = displayName - this.ownerId = ownerId - this.personalId = null - } - - constructor( - id: Int, - displayName: String, - ownerId: Int, - personalId: Int - ) { // for personal cars that have not been made public - this.id = id - this.displayName = displayName - this.ownerId = ownerId - this.personalId = personalId - } + // for personal cars that have not been made public + constructor(id: Int, displayName: String, ownerId: Int) : this(id, displayName, ownerId, null) @Suppress("Unused") fun isPersonalOnly() = (ownerId != null) && (personalId == null) @@ -141,11 +125,6 @@ enum class Car { @Suppress("Unused") fun isPublic() = (id < FIRST_PERSONAL_CAR_ID) - val id: Int - val displayName: String - val ownerId: Int? // for personal autos - val personalId: Int? // for personal autos that have been made public - companion object { fun isPersonalId(carId: Int): Boolean { return carId >= FIRST_PERSONAL_CAR_ID diff --git a/kgCommon/src/main/kotlin/ru/klavogonki/common/DictionaryMode.kt b/kgCommon/src/main/kotlin/ru/klavogonki/common/DictionaryMode.kt new file mode 100644 index 00000000..82a5ec2a --- /dev/null +++ b/kgCommon/src/main/kotlin/ru/klavogonki/common/DictionaryMode.kt @@ -0,0 +1,33 @@ +package ru.klavogonki.common + +import ru.klavogonki.common.DictionaryUtils.isStandard + +enum class DictionaryMode( + + /** + * Имя в API клавогонок. Все буквы в нижнем регистре. + */ + @JvmField val klavogonkiName: String, +) { + normal("normal"), + + noerror("noerror"), + + sprint("sprint"), + + marathon("marathon"), + ; + + companion object { + + @JvmStatic + fun getDictionaryMode(dictionaryCode: String): DictionaryMode { + if (!isStandard(dictionaryCode)) { + return normal + } + + val standardDictionary = StandardDictionary.getByKlavogonkiName(dictionaryCode) + return standardDictionary.dictionaryMode + } + } +} diff --git a/kgCommon/src/main/kotlin/ru/klavogonki/common/StandardDictionary.kt b/kgCommon/src/main/kotlin/ru/klavogonki/common/StandardDictionary.kt index 9f91001a..bfc44399 100644 --- a/kgCommon/src/main/kotlin/ru/klavogonki/common/StandardDictionary.kt +++ b/kgCommon/src/main/kotlin/ru/klavogonki/common/StandardDictionary.kt @@ -3,7 +3,7 @@ package ru.klavogonki.common /** * Энум с названиями стандартных словарей (режимов), как они используются в AJAX-API. */ -@SuppressWarnings("MagicNumber") +@SuppressWarnings("MagicNumber", "LongParameterList") enum class StandardDictionary( /** @@ -35,7 +35,13 @@ enum class StandardDictionary( * Тип текста словаря. * Для нестандартных словарей будет равен идентификатору словаря. */ - @JvmField val textType: Int + @JvmField val textType: Int, + + /** + * Режим текста словаря. + * Возвращается в поле `mode` в `/get-stats-overview -> ... -> info`. + */ + @JvmField val dictionaryMode: DictionaryMode ) { /** * Обычный. @@ -46,7 +52,8 @@ enum class StandardDictionary( displayNamePrepositional = "Обычном", color = "#333333", wikiPageUrl = Wiki.getUrl("%D0%9E%D0%B1%D1%8B%D1%87%D0%BD%D1%8B%D0%B9"), - textType = 0 + textType = 0, + dictionaryMode = DictionaryMode.normal ), /** @@ -58,7 +65,8 @@ enum class StandardDictionary( displayNamePrepositional = "Безошибочном", color = "#4692AA", wikiPageUrl = Wiki.getUrl("%D0%91%D0%B5%D0%B7%D0%BE%D1%88%D0%B8%D0%B1%D0%BE%D1%87%D0%BD%D1%8B%D0%B9"), - textType = 0 + textType = 0, + dictionaryMode = DictionaryMode.noerror ), /** @@ -70,7 +78,8 @@ enum class StandardDictionary( displayNamePrepositional = "Буквах", color = "#B55900", wikiPageUrl = Wiki.getUrl("%D0%91%D1%83%D0%BA%D0%B2%D1%8B"), - textType = -4 + textType = -4, + dictionaryMode = DictionaryMode.normal ), /** @@ -82,7 +91,8 @@ enum class StandardDictionary( displayNamePrepositional = "Марафоне", color = "#D43E68", wikiPageUrl = Wiki.getUrl("%D0%9C%D0%B0%D1%80%D0%B0%D1%84%D0%BE%D0%BD"), - textType = 0 + textType = 0, + dictionaryMode = DictionaryMode.marathon ), /** @@ -94,7 +104,8 @@ enum class StandardDictionary( displayNamePrepositional = "Абракадабре", color = "#3D4856", wikiPageUrl = Wiki.getUrl("%D0%90%D0%B1%D1%80%D0%B0%D0%BA%D0%B0%D0%B4%D0%B0%D0%B1%D1%80%D0%B0"), - textType = -1 + textType = -1, + dictionaryMode = DictionaryMode.normal ), /** @@ -106,7 +117,8 @@ enum class StandardDictionary( displayNamePrepositional = "Яндекс.Рефератах", color = "#698725", wikiPageUrl = Wiki.getUrl("%D0%AF%D0%BD%D0%B4%D0%B5%D0%BA%D1%81.%D0%A0%D0%B5%D1%84%D0%B5%D1%80%D0%B0%D1%82%D1%8B"), - textType = -3 + textType = -3, + dictionaryMode = DictionaryMode.normal ), /** @@ -118,7 +130,8 @@ enum class StandardDictionary( displayNamePrepositional = "Цифрах", color = "#777777", wikiPageUrl = Wiki.getUrl("%D0%A6%D0%B8%D1%84%D1%80%D1%8B"), - textType = -2 + textType = -2, + dictionaryMode = DictionaryMode.normal ), /** @@ -130,7 +143,8 @@ enum class StandardDictionary( displayNamePrepositional = "Спринте", color = "#833F3A", wikiPageUrl = Wiki.getUrl("%D0%A1%D0%BF%D1%80%D0%B8%D0%BD%D1%82"), - textType = 0 + textType = 0, + dictionaryMode = DictionaryMode.sprint ), ; diff --git a/kgparserSrv/src/main/java/ru/klavogonki/kgparser/DictionaryMode.java b/kgparserSrv/src/main/java/ru/klavogonki/kgparser/DictionaryMode.java deleted file mode 100644 index 3570729b..00000000 --- a/kgparserSrv/src/main/java/ru/klavogonki/kgparser/DictionaryMode.java +++ /dev/null @@ -1,46 +0,0 @@ -package ru.klavogonki.kgparser; - -import ru.klavogonki.common.DictionaryUtils; -import ru.klavogonki.common.StandardDictionary; - -public enum DictionaryMode { - - normal, - - noerror, - - sprint, - - marathon, - - ; - - public static DictionaryMode getDictionaryMode(String dictionaryCode) { - if (!DictionaryUtils.isStandard(dictionaryCode)) { - return normal; - } - - StandardDictionary standardDictionary = StandardDictionary.getByKlavogonkiName(dictionaryCode); - - switch (standardDictionary) { - case normal: - case chars: - case abra: - case referats: - case digits: - return normal; - - case sprint: - return sprint; - - case noerror: - return noerror; - - case marathon: - return marathon; - - default: - throw new IllegalArgumentException(String.format("Unknown standard dictionary code: %s", dictionaryCode)); - } - } -} diff --git a/kgstatsSrv/src/main/java/ru/klavogonki/statistics/download/PlayerJsonParser.java b/kgstatsSrv/src/main/java/ru/klavogonki/statistics/download/PlayerJsonParser.java index c1ae42c8..ce31e597 100644 --- a/kgstatsSrv/src/main/java/ru/klavogonki/statistics/download/PlayerJsonParser.java +++ b/kgstatsSrv/src/main/java/ru/klavogonki/statistics/download/PlayerJsonParser.java @@ -4,9 +4,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import ru.klavogonki.common.Car; +import ru.klavogonki.common.DictionaryMode; import ru.klavogonki.common.DictionaryUtils; import ru.klavogonki.common.StandardDictionary; -import ru.klavogonki.kgparser.DictionaryMode; import ru.klavogonki.kgparser.Rank; import ru.klavogonki.openapi.model.GetIndexDataResponse; import ru.klavogonki.openapi.model.GetIndexDataStats; @@ -608,7 +608,7 @@ private static void validateInfo(final int playerId, final String statsOverviewF DictionaryMode expectedMode = DictionaryMode.getDictionaryMode(vocabularyCode); // todo: mapper conversion VocabularyMode -> DictionaryMode? - if (!mode.toString().equals(expectedMode.toString())) { + if (!mode.toString().equals(expectedMode.klavogonkiName)) { throw new ParserException("Stats overview file %s: Vocabulary %s: info.mode %s is not equal to expected mode = %d.", statsOverviewFilePath, vocabularyCode, mode, expectedMode); } diff --git a/kgstatsSrv/src/main/java/ru/klavogonki/statistics/entity/PlayerVocabularyStatsEntity.java b/kgstatsSrv/src/main/java/ru/klavogonki/statistics/entity/PlayerVocabularyStatsEntity.java index f228c1a8..2913ff38 100644 --- a/kgstatsSrv/src/main/java/ru/klavogonki/statistics/entity/PlayerVocabularyStatsEntity.java +++ b/kgstatsSrv/src/main/java/ru/klavogonki/statistics/entity/PlayerVocabularyStatsEntity.java @@ -1,7 +1,7 @@ package ru.klavogonki.statistics.entity; import lombok.Data; -import ru.klavogonki.kgparser.DictionaryMode; +import ru.klavogonki.common.DictionaryMode; import ru.klavogonki.kgparser.NonStandardDictionaryType; import javax.persistence.Entity; @@ -67,7 +67,7 @@ public class PlayerVocabularyStatsEntity implements Serializable { * * @see DictionaryMode#getDictionaryMode */ - @Enumerated(EnumType.STRING) + @Enumerated(EnumType.STRING) // todo: save using the klavogonikiName field, NOT the enum itself private DictionaryMode vocabularyMode; /** diff --git a/kgstatsSrv/src/main/java/ru/klavogonki/statistics/mapper/PlayerVocabularyStatsMapper.java b/kgstatsSrv/src/main/java/ru/klavogonki/statistics/mapper/PlayerVocabularyStatsMapper.java index 7d65342a..f74c890e 100644 --- a/kgstatsSrv/src/main/java/ru/klavogonki/statistics/mapper/PlayerVocabularyStatsMapper.java +++ b/kgstatsSrv/src/main/java/ru/klavogonki/statistics/mapper/PlayerVocabularyStatsMapper.java @@ -7,15 +7,15 @@ import org.mapstruct.MappingTarget; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; -import ru.klavogonki.kgparser.DictionaryMode; +import ru.klavogonki.common.DictionaryMode; import ru.klavogonki.kgparser.NonStandardDictionaryType; -import ru.klavogonki.statistics.entity.PlayerEntity; -import ru.klavogonki.statistics.entity.PlayerVocabularyStatsEntity; -import ru.klavogonki.statistics.util.DateUtils; import ru.klavogonki.openapi.model.GetStatsOverviewGameType; import ru.klavogonki.openapi.model.GetStatsOverviewResponse; import ru.klavogonki.openapi.model.NonStandardVocabularyType; import ru.klavogonki.openapi.model.VocabularyMode; +import ru.klavogonki.statistics.entity.PlayerEntity; +import ru.klavogonki.statistics.entity.PlayerVocabularyStatsEntity; +import ru.klavogonki.statistics.util.DateUtils; import java.time.LocalDateTime; diff --git a/kgstatsSrv/src/test/java/ru/klavogonki/statistics/util/JacksonUtilsTest.java b/kgstatsSrv/src/test/java/ru/klavogonki/statistics/util/JacksonUtilsTest.java index c854680d..c610ddf5 100644 --- a/kgstatsSrv/src/test/java/ru/klavogonki/statistics/util/JacksonUtilsTest.java +++ b/kgstatsSrv/src/test/java/ru/klavogonki/statistics/util/JacksonUtilsTest.java @@ -87,7 +87,7 @@ void existingPlayer() { CarAssert .assertThat(car) .isNotNull() - .hasCar(Car.F1.getId()) + .hasCar(Car.F1.id) .hasColor("#BF1300"); Map tuning = getNonEmptyTuning(car); @@ -132,7 +132,7 @@ void playerWithPersonalCarId() { CarAssert .assertThat(car) .isNotNull() - .hasCar(Car.CARAVEL.getPersonalId()) + .hasCar(Car.CARAVEL.personalId) .hasColor("#000000"); assertEmptyTunning(car); @@ -172,7 +172,7 @@ void brandNewPlayer() { CarAssert .assertThat(car) .isNotNull() - .hasCar(Car.ZAZ_965.getId()) + .hasCar(Car.ZAZ_965.id) .hasColor("#777777"); assertEmptyTunning(car); @@ -213,7 +213,7 @@ void klavoMechanicWithHiddenProfile() { CarAssert .assertThat(car) .isNotNull() - .hasCar(Car.AUDI_TT.getId()) + .hasCar(Car.AUDI_TT.id) .hasColor("#893425"); Map tuning = getNonEmptyTuning(car);