diff --git a/android/gradle.properties b/android/gradle.properties index 30298b3b3f04073678e48519b8c043edba635df8..6c1d873456149a8611e43a05ae56e4f50c73274f 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.18 -app.versionCode=18 +app.versionName=0.0.19 +app.versionCode=19 diff --git a/fastlane/metadata/android/en-US/changelogs/19.txt b/fastlane/metadata/android/en-US/changelogs/19.txt new file mode 100644 index 0000000000000000000000000000000000000000..076c79292e863342984285c7da84c05e64f9f527 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/19.txt @@ -0,0 +1 @@ +Add script to manage data, improve dataset. diff --git a/fastlane/metadata/android/fr-FR/changelogs/19.txt b/fastlane/metadata/android/fr-FR/changelogs/19.txt new file mode 100644 index 0000000000000000000000000000000000000000..78ffa89a70ff17e4524ada88f4d284c46b52aeb3 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/19.txt @@ -0,0 +1 @@ +Ajout d'un script de gestion des données, compléments sur le jeu de données. diff --git a/lib/data/game_data.dart b/lib/data/game_data.dart index 4566cbfcbdb18652785fc73e67541f454674a9d0..8b8534168656bc358a79ccd251784327c7e26c54 100644 --- a/lib/data/game_data.dart +++ b/lib/data/game_data.dart @@ -71,8 +71,8 @@ class GameData { "mapping": { "items": { "ABEILLE": { - "is": ["naturel", "vivant"], - "isnot": ["artificiel", "gazeux", "inerte"], + "is": ["naturel", "solide", "vivant"], + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": ["liquide"] }, "AMPOULE": { @@ -81,8 +81,8 @@ class GameData { "na": [] }, "ARBRE": { - "is": ["naturel", "vivant"], - "isnot": ["artificiel", "inerte", "liquide"], + "is": ["naturel", "solide", "vivant"], + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": [] }, "ASPIRATEUR": { @@ -96,13 +96,13 @@ class GameData { "na": [] }, "BANANE": { - "is": ["solide", "vivant"], - "isnot": ["gazeux", "inerte", "liquide"], + "is": ["naturel", "solide", "vivant"], + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": [] }, "BERCEAU": { - "is": ["artificiel", "inerte"], - "isnot": ["liquide", "naturel", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "BONBON": { @@ -116,13 +116,13 @@ class GameData { "na": [] }, "BROUETTE": { - "is": ["artificiel", "inerte"], - "isnot": ["liquide", "naturel", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "CAFETIÈRE": { - "is": ["inerte"], - "isnot": ["liquide", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "CANARD": { @@ -131,8 +131,8 @@ class GameData { "na": ["liquide"] }, "CASQUETTE": { - "is": ["artificiel", "inerte"], - "isnot": ["liquide", "naturel", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "CHAISE": { @@ -156,8 +156,8 @@ class GameData { "na": ["liquide", "solide"] }, "CONFITURE": { - "is": ["inerte", "solide"], - "isnot": ["gazeux", "liquide", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": ["liquide"] }, "CORDE": { @@ -176,8 +176,8 @@ class GameData { "na": [] }, "FENÊTRE": { - "is": ["artificiel", "inerte"], - "isnot": ["naturel", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": ["liquide"] }, "FOURMI": { @@ -191,18 +191,18 @@ class GameData { "na": [] }, "GOURDE": { - "is": ["artificiel", "solide"], - "isnot": ["gazeux", "liquide", "naturel"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "GUÊPE": { "is": ["naturel", "vivant"], "isnot": ["artificiel", "inerte"], - "na": ["liquide"] + "na": ["gazeux", "liquide", "solide"] }, "HÉLICOPTÈRE": { - "is": ["artificiel", "inerte"], - "isnot": ["gazeux", "naturel", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "KANGOUROU": { @@ -221,8 +221,8 @@ class GameData { "na": ["naturel"] }, "LIVRE": { - "is": ["artificiel"], - "isnot": ["liquide", "naturel"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "MAISON": { @@ -231,28 +231,28 @@ class GameData { "na": [] }, "MOUCHE": { - "is": ["naturel"], - "isnot": ["artificiel"], - "na": ["liquide"] + "is": ["naturel", "vivant"], + "isnot": ["artificiel", "gazeux", "inerte"], + "na": ["liquide", "solide"] }, "NOEUD": { - "is": ["inerte"], - "isnot": ["liquide", "vivant"], + "is": ["artificiel", "inerte"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": ["artificiel", "solide"] }, "ORAGE": { "is": ["inerte", "naturel"], - "isnot": ["artificiel", "vivant"], + "isnot": ["artificiel", "gazeux", "liquide", "vivant"], "na": ["solide"] }, "OURS": { "is": ["naturel", "vivant"], "isnot": ["artificiel", "gazeux", "inerte"], - "na": ["liquide"] + "na": ["liquide", "solide"] }, "PAPILLON": { "is": ["naturel", "vivant"], - "isnot": ["artificiel", "gazeux", "inerte"], + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": ["solide"] }, "PEIGNE": { @@ -271,7 +271,7 @@ class GameData { "na": [] }, "PIZZA": { - "is": ["artificiel", "inerte"], + "is": ["artificiel", "inerte", "solide"], "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, @@ -286,19 +286,19 @@ class GameData { "na": ["liquide", "solide"] }, "PUZZLE": { - "is": ["artificiel", "inerte"], + "is": ["artificiel", "inerte", "solide"], "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "PÊCHE": { - "is": ["naturel", "vivant"], + "is": ["naturel", "solide", "vivant"], "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": [] }, "REQUIN": { "is": ["naturel", "vivant"], - "isnot": ["artificiel", "inerte"], - "na": [] + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], + "na": ["solide"] }, "ROSE": { "is": ["naturel", "solide", "vivant"], @@ -311,19 +311,19 @@ class GameData { "na": [] }, "SANGLIER": { - "is": ["naturel"], - "isnot": ["artificiel", "gazeux"], + "is": ["naturel", "vivant"], + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": ["solide"] }, "SAVON": { "is": ["artificiel", "inerte"], - "isnot": ["naturel", "vivant"], + "isnot": ["gazeux", "naturel", "vivant"], "na": ["liquide", "solide"] }, "SINGE": { "is": ["naturel", "vivant"], - "isnot": ["artificiel", "inerte"], - "na": [] + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], + "na": ["solide"] }, "STADE": { "is": ["artificiel", "inerte", "solide"], @@ -351,8 +351,8 @@ class GameData { "na": ["liquide"] }, "TROMPETTE": { - "is": ["inerte", "solide"], - "isnot": ["gazeux", "liquide", "vivant"], + "is": ["artificiel", "inerte", "solide"], + "isnot": ["gazeux", "liquide", "naturel", "vivant"], "na": [] }, "VACHE": { @@ -367,7 +367,7 @@ class GameData { }, "ZÈBRE": { "is": ["naturel", "vivant"], - "isnot": ["artificiel", "gazeux", "inerte"], + "isnot": ["artificiel", "gazeux", "inerte", "liquide"], "na": ["solide"] } } diff --git a/pubspec.yaml b/pubspec.yaml index bc808043a9ba69f21af5f7e701e5157e2d434bd6..b65f68829a4a5cf7df66937f29d5483b46da92fe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A sorting game application. publish_to: 'none' -version: 0.0.18+18 +version: 0.0.19+19 environment: sdk: '^3.0.0' diff --git a/scripts/data.json b/scripts/data.json new file mode 100644 index 0000000000000000000000000000000000000000..f1143468b8db035028b96df99ed209b72a9a1423 --- /dev/null +++ b/scripts/data.json @@ -0,0 +1,963 @@ +{ + "categories": [ + "artificiel", + "gazeux", + "inerte", + "liquide", + "naturel", + "solide", + "vivant" + ], + "exclusions": [ + [ + "liquide", + "solide", + "gazeux" + ], + [ + "inerte", + "vivant" + ], + [ + "naturel", + "artificiel" + ] + ], + "items": [ + "ABEILLE", + "AMPOULE", + "ARBRE", + "ASPIRATEUR", + "BALAI", + "BANANE", + "BERCEAU", + "BONBON", + "BOUGIE", + "BROUETTE", + "CAFETIÈRE", + "CANARD", + "CASQUETTE", + "CHAISE", + "CHAUSSURE", + "CINTRE", + "COCCINELLE", + "CONFITURE", + "CORDE", + "CROCODILE", + "DROMADAIRE", + "FENÊTRE", + "FOURMI", + "FUSÉE", + "GOURDE", + "GUÊPE", + "HÉLICOPTÈRE", + "KANGOUROU", + "LAMPE", + "LICORNE", + "LIVRE", + "MAISON", + "MOUCHE", + "NOEUD", + "ORAGE", + "OURS", + "PAPILLON", + "PEIGNE", + "PENDULE", + "PIANO", + "PIZZA", + "POMME", + "POULET", + "PUZZLE", + "PÊCHE", + "REQUIN", + "ROSE", + "SAC À DOS", + "SANGLIER", + "SAVON", + "SINGE", + "STADE", + "TABOURET", + "TARTINE", + "TIROIR", + "TORTUE", + "TROMPETTE", + "VACHE", + "VOILIER", + "ZÈBRE" + ], + "mapping": { + "items": { + "ABEILLE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "liquide" + ] + }, + "AMPOULE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "ARBRE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "ASPIRATEUR": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "BALAI": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "BANANE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "BERCEAU": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "BONBON": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "BOUGIE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "BROUETTE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "CAFETIÈRE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "CANARD": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "liquide" + ] + }, + "CASQUETTE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "CHAISE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "CHAUSSURE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "CINTRE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "COCCINELLE": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte" + ], + "na": [ + "liquide", + "solide" + ] + }, + "CONFITURE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [ + "liquide" + ] + }, + "CORDE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "CROCODILE": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte" + ], + "na": [ + "liquide", + "solide" + ] + }, + "DROMADAIRE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "FENÊTRE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [ + "liquide" + ] + }, + "FOURMI": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "liquide" + ] + }, + "FUSÉE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "GOURDE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "GUÊPE": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "inerte" + ], + "na": [ + "gazeux", + "liquide", + "solide" + ] + }, + "HÉLICOPTÈRE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "KANGOUROU": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "LAMPE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "LICORNE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "naturel" + ] + }, + "LIVRE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "MAISON": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "MOUCHE": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte" + ], + "na": [ + "liquide", + "solide" + ] + }, + "NOEUD": { + "is": [ + "artificiel", + "inerte" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [ + "artificiel", + "solide" + ] + }, + "ORAGE": { + "is": [ + "inerte", + "naturel" + ], + "isnot": [ + "artificiel", + "gazeux", + "liquide", + "vivant" + ], + "na": [ + "solide" + ] + }, + "OURS": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte" + ], + "na": [ + "liquide", + "solide" + ] + }, + "PAPILLON": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "solide" + ] + }, + "PEIGNE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "PENDULE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "PIANO": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "PIZZA": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "POMME": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "POULET": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte" + ], + "na": [ + "liquide", + "solide" + ] + }, + "PUZZLE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "PÊCHE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "REQUIN": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "solide" + ] + }, + "ROSE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [] + }, + "SAC À DOS": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "SANGLIER": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "solide" + ] + }, + "SAVON": { + "is": [ + "artificiel", + "inerte" + ], + "isnot": [ + "gazeux", + "naturel", + "vivant" + ], + "na": [ + "liquide", + "solide" + ] + }, + "SINGE": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "solide" + ] + }, + "STADE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "TABOURET": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "TARTINE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "TIROIR": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "TORTUE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "liquide" + ] + }, + "TROMPETTE": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "VACHE": { + "is": [ + "naturel", + "solide", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "liquide" + ] + }, + "VOILIER": { + "is": [ + "artificiel", + "inerte", + "solide" + ], + "isnot": [ + "gazeux", + "liquide", + "naturel", + "vivant" + ], + "na": [] + }, + "ZÈBRE": { + "is": [ + "naturel", + "vivant" + ], + "isnot": [ + "artificiel", + "gazeux", + "inerte", + "liquide" + ], + "na": [ + "solide" + ] + } + } + } +} diff --git a/scripts/manage_data.php b/scripts/manage_data.php new file mode 100644 index 0000000000000000000000000000000000000000..ca5b0ee9d62e512fd6873b6d0d7c2829f4a229dc --- /dev/null +++ b/scripts/manage_data.php @@ -0,0 +1,356 @@ +<?php + +function dump(string $string) +{ + echo $string . PHP_EOL; +} + +function write_data(array $data, string $filename) +{ + \file_put_contents($filename, \json_encode($data)); +} + +function array_clean(array $array) +{ + $output = \array_unique($array); + \sort($output); + return $output; +} + +function ask(string $prompt) +{ + dump($prompt); + $input = \rtrim(\fgets(STDIN)); + return $input; +} + +function find_missing_associations(array $mappingItems, array $categories, array $items) +{ + $missing = []; + foreach ($items as $item) { + $set = \array_merge( + $mappingItems[$item]['is'], + $mappingItems[$item]['isnot'], + $mappingItems[$item]['na'], + ); + foreach ($categories as $category) { + if (!\in_array($category, $set)) { + $missing[] = [ + 'item' => $item, + 'category' => $category, + ]; + } + } + } + return $missing; +} + +function find_exclusions(array $exclusions, string $searchedCategory) +{ + $output = []; + foreach ($exclusions as $exclusionSet) { + if (\is_array($exclusionSet) && \in_array($searchedCategory, $exclusionSet)) { + foreach ($exclusionSet as $candidate) { + if ($candidate !== $searchedCategory) { + $output[] = $candidate; + } + } + } + } + + return $output; +} + +function clean_item_mappings(array $itemMappings) +{ + $itemMappings['is'] = array_clean($itemMappings['is']); + $itemMappings['isnot'] = array_clean($itemMappings['isnot']); + $itemMappings['na'] = array_clean($itemMappings['na']); + + return $itemMappings; +} + +if ($argc != 2) { + dump('Need data json file as parameter.'); + die; +} + +$jsonDataFile = $argv[1]; + +$data = []; +if (is_file($jsonDataFile)) { + $data = \json_decode(\file_get_contents($jsonDataFile), true); +} + +if (!is_writable($jsonDataFile)) { + dump('Output data json file is not writable.'); + die; +} + +$categories = (\array_key_exists('categories', $data) && \is_array($data['categories'])) ? $data['categories'] : [];; +$items = (\array_key_exists('items', $data) && \is_array($data['items'])) ? $data['items'] : [];; + +// Manage categories exclusions +$exclusions = (\array_key_exists('exclusions', $data) && \is_array($data['exclusions'])) ? $data['exclusions'] : []; + +// Merge categories with categories found in exclusions +foreach ($exclusions as $exclusionSet) { + foreach ($exclusionSet as $category) { + $categories[] = $category; + } +} +$categories = array_clean($categories); +$items = array_clean($items); + +$data['categories'] = $categories; +$data['items'] = $items; +$data['exclusions'] = $exclusions; + +dump(''); +dump('Found ' . \count($categories) . ' unique categories.'); +dump('Found ' . \count($items) . ' unique items.'); +dump('Found ' . \count($exclusions) . ' exclusions sets.'); + +// Get/init mapping data +$mapping = (\array_key_exists('mapping', $data) && \is_array($data['mapping'])) ? $data['mapping'] : []; +$mappingItems = (\array_key_exists('items', $mapping) && \is_array($mapping['items'])) ? $mapping['items'] : []; + +foreach ($items as $item) { + if (!\array_key_exists($item, $mappingItems)) { + $mappingItems[$item] = []; + } + if (!\array_key_exists('is', $mappingItems[$item]) || !\is_array($mappingItems[$item])) { + $mappingItems[$item]['is'] = []; + } + if (!\array_key_exists('isnot', $mappingItems[$item]) || !\is_array($mappingItems[$item])) { + $mappingItems[$item]['isnot'] = []; + } + if (!\array_key_exists('na', $mappingItems[$item]) || !\is_array($mappingItems[$item])) { + $mappingItems[$item]['na'] = []; + } + + $mappingItems[$item] = clean_item_mappings($mappingItems[$item]); +} + +// TODO: Should check/add unkown items from current mapping + +$data['mapping'] = [ + 'items' => $mappingItems, +]; + +function showCategories($categories) +{ + dump(\join("\n", $categories)); +} + +function showItems($items) +{ + dump(\join("\n", $items)); +} + +function showExclusions($exclusions) +{ + foreach ($exclusions as $exclusionSet) { + dump(\join(', ', $exclusionSet)); + } +} + +function showMappings($mappingItems) +{ + $columnsWidths = [ + 'items' => 0, + ]; + + $items = \array_keys($mappingItems); + $categories = []; + foreach ($mappingItems as $item => $mapping) { + if ($columnsWidths['items'] < \mb_strlen($item)) { + $columnsWidths['items'] = \mb_strlen($item); + } + + foreach (\array_merge($mapping['is'], $mapping['isnot'], $mapping['na']) as $category) { + if (!\in_array($category, $categories)) { + $categories[] = $category; + if (!\array_key_exists($category, $columnsWidths)) { + $columnsWidths[$category] = 0; + } + if ($columnsWidths[$category] < \mb_strlen($category)) { + $columnsWidths[$category] = \mb_strlen($category); + } + } + } + } + + $strIs = '✅'; + $strIsNot = '❌'; + $strNa = '⛔'; + + // separator + $line = [ + \mb_str_pad('', $columnsWidths['items'], '-', STR_PAD_BOTH), + ]; + foreach ($categories as $category) { + $line[] = \mb_str_pad('', $columnsWidths[$category], '-', STR_PAD_BOTH); + } + dump('--' . \join('---', $line) . '--'); + + // header + $line = [ + \mb_str_pad('', $columnsWidths['items'], ' ', STR_PAD_BOTH), + ]; + foreach ($categories as $category) { + $line[] = \mb_str_pad($category, $columnsWidths[$category], ' ', STR_PAD_BOTH); + } + dump('| ' . \join(' | ', $line) . ' |'); + + // separator + $line = [ + \mb_str_pad('', $columnsWidths['items'], '-', STR_PAD_BOTH), + ]; + foreach ($categories as $category) { + $line[] = \mb_str_pad('', $columnsWidths[$category], '-', STR_PAD_BOTH); + } + dump('|-' . \join('-|-', $line) . '-|'); + + foreach ($items as $item) { + $line = [ + \mb_str_pad($item, $columnsWidths['items'], ' ', STR_PAD_RIGHT), + ]; + foreach ($categories as $category) { + $value = ''; + if (\in_array($category, $mappingItems[$item]['is'])) { + $value = $strIs; + } elseif (\in_array($category, $mappingItems[$item]['isnot'])) { + $value = $strIsNot; + } elseif (\in_array($category, $mappingItems[$item]['na'])) { + $value = $strNa; + } + $line[] = \mb_str_pad($value, $columnsWidths[$category], ' ', STR_PAD_BOTH); + } + dump('| ' . \join(' | ', $line) . ' |'); + } + + // separator + $line = [ + \mb_str_pad('', $columnsWidths['items'], '-', STR_PAD_BOTH), + ]; + foreach ($categories as $category) { + $line[] = \mb_str_pad('', $columnsWidths[$category], '-', STR_PAD_BOTH); + } + dump('--' . \join('---', $line) . '--'); +} + +function editMappings($mappingItems, $categories, $items, $exclusions) +{ + // Set missing associations + $exitEditMappings = false; + $missing = find_missing_associations($mappingItems, $categories, $items); + while ((\count($missing) !== 0) && ($exitEditMappings === false)) { + dump(''); + dump('Missing associations: ' . \count($missing)); + dump(''); + $picked = $missing[mt_rand(0, \count($missing) - 1)]; + + $item = $picked['item']; + $category = $picked['category']; + + $question = 'Is "' . $item . '" can be categorised as "' . $category . '"?'; + + $ex = find_exclusions($exclusions, $category); + if (\count($ex) !== 0) { + $question .= ' (and apply accordingly to "' . join('" and "', $ex) . '")'; + } + + dump($question); + $answer = ask('1: yes ; 2: no ; 3: n/a ; 0: exit'); + + switch ($answer) { + case '0': + $exitEditMappings = true; + break; + case '1': + dump(' -> "' . $item . '" is "' . $category . '"'); + $mappingItems[$item]['is'][] = $category; + // apply "is not" to each other + foreach ($ex as $exclusion) { + dump(' -> "' . $item . '" is not "' . $exclusion . '"'); + $mappingItems[$item]['isnot'][] = $exclusion; + } + break; + case '2': + dump(' -> "' . $item . '" is not "' . $category . '"'); + $mappingItems[$item]['isnot'][] = $category; + // apply "is" only if one exclusion + if (\count($ex) === 1) { + foreach ($ex as $exclusion) { + dump(' -> "' . $item . '" is "' . $exclusion . '"'); + $mappingItems[$item]['is'][] = $exclusion; + } + } + break; + case '3': + dump(' -> "' . $item . '" does not apply as "is or is not" "' . $category . '"'); + $mappingItems[$item]['na'][] = $category; + foreach ($ex as $exclusion) { + dump(' -> "' . $item . '" does not apply as "is or is not" "' . $category . '"'); + $mappingItems[$item]['na'][] = $category; + } + break; + + default: + dump('wut? skipping...'); + break; + } + + $mappingItems[$item] = clean_item_mappings($mappingItems[$item]); + + $missing = find_missing_associations($mappingItems, $categories, $items); + } + + return $mappingItems; +} + +// Main loop +$exitMainLoop = false; +while ($exitMainLoop === false) { + dump(''); + + $menu = [ + '0: exit', + '', + '1: show categories', + '2: show items', + '3: show exclusions', + '4: show mappings', + '', + '5: edit mappings', + ]; + $answer = ask(\join("\n", $menu)); + + switch ($answer) { + case '0': + $exitMainLoop = true; + break; + case '1': + showCategories($categories); + break; + case '2': + showItems($items); + break; + case '3': + showExclusions($exclusions); + break; + case '4': + showMappings($mappingItems); + break; + case '5': + $data['mapping']['items'] = editMappings($mappingItems, $categories, $items, $exclusions); + break; + default: + break; + } +} + +write_data($data, $jsonDataFile); + +echo "ok, done." . PHP_EOL; diff --git a/scripts/manage_data.sh b/scripts/manage_data.sh new file mode 100755 index 0000000000000000000000000000000000000000..d831d7b6506ba30dc2cf1b3dc7552ee4fc73c5fa --- /dev/null +++ b/scripts/manage_data.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq (json parser) but it's not installed. Aborting."; exit 1; } + +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +BASE_DIR="$(dirname "${CURRENT_DIR}")" + +DATA_FILE="${CURRENT_DIR}/data.json" +touch "${DATA_FILE}" + +# backup current file +# NOW="$(date '+%Y%m%d_%H%M%S')" +# cp "${DATA_FILE}" "${DATA_FILE}.bak_${NOW}.json" + +cd "${CURRENT_DIR}" +php manage_data.php "${DATA_FILE}" + +# format json file +cat "${DATA_FILE}" | jq >"${DATA_FILE}.tmp" +mv "${DATA_FILE}.tmp" "${DATA_FILE}" + +# inject json file in app code +GAME_DATA_DART_FILE="${BASE_DIR}/lib/data/game_data.dart" +echo "class GameData {" >"${GAME_DATA_DART_FILE}" +echo " static const Map<String, dynamic> data = $(cat "${DATA_FILE}");" >>"${GAME_DATA_DART_FILE}" +echo "}" >>"${GAME_DATA_DART_FILE}" + +# cat "${DATA_FILE}" \ No newline at end of file