cuju-render 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cuju/render/__init__.py +759 -0
- cuju/render/__main__.py +1065 -0
- cuju/render/_export/__init__.py +3 -0
- cuju/render/_export/feed.py +542 -0
- cuju/render/_export/sizes.py +157 -0
- cuju/render/_export/video.py +1618 -0
- cuju/render/_export/video_jobs.py +408 -0
- cuju/render/_format/__init__.py +3 -0
- cuju/render/_format/annotations.py +235 -0
- cuju/render/_format/codec.py +307 -0
- cuju/render/_format/keep.py +121 -0
- cuju/render/_format/recording.py +860 -0
- cuju/render/_format/writer.py +54 -0
- cuju/render/_guide/__init__.py +3 -0
- cuju/render/_guide/doctor.py +523 -0
- cuju/render/_guide/help.py +62 -0
- cuju/render/_guide/tutorial.py +254 -0
- cuju/render/_http/__init__.py +3 -0
- cuju/render/_http/commands.py +57 -0
- cuju/render/_http/headers.py +103 -0
- cuju/render/_http/launch.py +500 -0
- cuju/render/_http/launchers.py +408 -0
- cuju/render/_http/pwa.py +128 -0
- cuju/render/_http/server.py +2105 -0
- cuju/render/_http/window.py +360 -0
- cuju/render/_moments/__init__.py +3 -0
- cuju/render/_moments/captions.py +284 -0
- cuju/render/_moments/events.py +1123 -0
- cuju/render/_moments/search.py +694 -0
- cuju/render/_packages/__init__.py +3 -0
- cuju/render/_packages/glsl.py +746 -0
- cuju/render/_packages/loudness.py +334 -0
- cuju/render/_packages/pack.py +1959 -0
- cuju/render/_packages/presentation.py +1376 -0
- cuju/render/_packages/vocabulary.py +609 -0
- cuju/render/_playing/__init__.py +3 -0
- cuju/render/_playing/achievements.py +463 -0
- cuju/render/_playing/bench.py +609 -0
- cuju/render/_playing/challenges.py +1813 -0
- cuju/render/_playing/demo.py +323 -0
- cuju/render/_playing/draw.py +211 -0
- cuju/render/_playing/errors.py +20 -0
- cuju/render/_playing/game.py +645 -0
- cuju/render/_playing/limits.py +339 -0
- cuju/render/_playing/play.py +926 -0
- cuju/render/_playing/policy_worker.py +250 -0
- cuju/render/_playing/strict.py +810 -0
- cuju/render/_registry/__init__.py +3 -0
- cuju/render/_registry/clips.py +394 -0
- cuju/render/_registry/joints.py +108 -0
- cuju/render/_registry/teams.py +2058 -0
- cuju/render/_store/__init__.py +3 -0
- cuju/render/_store/home.py +70 -0
- cuju/render/_store/library.py +604 -0
- cuju/render/_store/samples.py +163 -0
- cuju/render/_text/__init__.py +3 -0
- cuju/render/_text/languages.py +637 -0
- cuju/render/_text/messages.py +1396 -0
- cuju/render/_tournaments/__init__.py +3 -0
- cuju/render/_tournaments/results.py +547 -0
- cuju/render/_tournaments/tournament.py +2742 -0
- cuju/render/_tournaments/tournament_cli.py +587 -0
- cuju/render/_tournaments/tournament_runner.py +1975 -0
- cuju/render/_version.py +6 -0
- cuju/render/_watch/__init__.py +3 -0
- cuju/render/_watch/grid.py +265 -0
- cuju/render/_watch/live.py +664 -0
- cuju/render/_watch/notebook.py +79 -0
- cuju/render/_watch/show.py +171 -0
- cuju/render/samples/sample-11v11.cjr +0 -0
- cuju/render/samples/sample-5v5.cjr +0 -0
- cuju/render/samples/teams/starter/main.py +33 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
- cuju/render/web/assets/adboard_polygon.webp +0 -0
- cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
- cuju/render/web/assets/ball.glb +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/corner.mp4 +0 -0
- cuju/render/web/assets/challenges/corner.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
- cuju/render/web/assets/challenges/manifest.json +375 -0
- cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one.webp +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
- cuju/render/web/assets/crowd.webp +0 -0
- cuju/render/web/assets/crowd_normal.webp +0 -0
- cuju/render/web/assets/cuju-logo-384.png +0 -0
- cuju/render/web/assets/cuju-logo.png +0 -0
- cuju/render/web/assets/cuju-logo.svg +46 -0
- cuju/render/web/assets/cuju-mark-light.svg +33 -0
- cuju/render/web/assets/cuju-mark.svg +33 -0
- cuju/render/web/assets/goal.glb +0 -0
- cuju/render/web/assets/grass.webp +0 -0
- cuju/render/web/assets/hair_black.png +0 -0
- cuju/render/web/assets/hair_blonde.png +0 -0
- cuju/render/web/assets/hair_brown.png +0 -0
- cuju/render/web/assets/hair_darkblonde.png +0 -0
- cuju/render/web/assets/hair_long01.glb +0 -0
- cuju/render/web/assets/hair_long02.glb +0 -0
- cuju/render/web/assets/hair_medium01.glb +0 -0
- cuju/render/web/assets/hair_red.png +0 -0
- cuju/render/web/assets/hair_short01.glb +0 -0
- cuju/render/web/assets/hair_short02.glb +0 -0
- cuju/render/web/assets/icons/cuju-192.png +0 -0
- cuju/render/web/assets/icons/cuju-512.png +0 -0
- cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
- cuju/render/web/assets/kit_goalkeeper.webp +0 -0
- cuju/render/web/assets/kit_mask.png +0 -0
- cuju/render/web/assets/kit_normal.webp +0 -0
- cuju/render/web/assets/manifest.json +601 -0
- cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
- cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
- cuju/render/web/assets/models/kaykit-knight.glb +0 -0
- cuju/render/web/assets/models/kaykit-knight.json +23 -0
- cuju/render/web/assets/models/kaykit-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
- cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
- cuju/render/web/assets/models/kaykit-ranger.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
- cuju/render/web/assets/pitch.webp +0 -0
- cuju/render/web/assets/pitch_normal.webp +0 -0
- cuju/render/web/assets/player.glb +0 -0
- cuju/render/web/assets/shoe.webp +0 -0
- cuju/render/web/assets/shoe_sole.png +0 -0
- cuju/render/web/assets/skin_01.png +0 -0
- cuju/render/web/assets/skin_02.png +0 -0
- cuju/render/web/assets/skin_03.png +0 -0
- cuju/render/web/assets/skin_04.png +0 -0
- cuju/render/web/assets/sounds/applause.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
- cuju/render/web/assets/sounds/city-horn.ogg +0 -0
- cuju/render/web/assets/sounds/city-loop.ogg +0 -0
- cuju/render/web/assets/sounds/city-siren.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
- cuju/render/web/assets/sounds/gulls.ogg +0 -0
- cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
- cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
- cuju/render/web/assets/sounds/sounds.json +46 -0
- cuju/render/web/assets/sounds/space-beep.ogg +0 -0
- cuju/render/web/assets/sounds/space-hum.ogg +0 -0
- cuju/render/web/assets/sounds/space-radio.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
- cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
- cuju/render/web/easy.css +357 -0
- cuju/render/web/export.html +23 -0
- cuju/render/web/feed.css +262 -0
- cuju/render/web/feed.html +28 -0
- cuju/render/web/flat.css +120 -0
- cuju/render/web/home.css +837 -0
- cuju/render/web/index.html +373 -0
- cuju/render/web/js/boot.js +50 -0
- cuju/render/web/js/broadcast/audio.js +2141 -0
- cuju/render/web/js/broadcast/celebrate.js +1238 -0
- cuju/render/web/js/broadcast/decisions.js +609 -0
- cuju/render/web/js/broadcast/hud.js +352 -0
- cuju/render/web/js/broadcast/show.js +3614 -0
- cuju/render/web/js/broadcast/transition.js +2231 -0
- cuju/render/web/js/broadcast/voices.js +153 -0
- cuju/render/web/js/capture.js +101 -0
- cuju/render/web/js/core/accessibility.js +90 -0
- cuju/render/web/js/core/api.js +429 -0
- cuju/render/web/js/core/comfort.js +135 -0
- cuju/render/web/js/core/i18n.js +705 -0
- cuju/render/web/js/core/icons.js +167 -0
- cuju/render/web/js/core/input-settings.js +156 -0
- cuju/render/web/js/core/keys.js +277 -0
- cuju/render/web/js/core/language-ui.js +125 -0
- cuju/render/web/js/core/menu.js +853 -0
- cuju/render/web/js/core/names.js +113 -0
- cuju/render/web/js/core/page-structure.js +110 -0
- cuju/render/web/js/core/scenarios.js +109 -0
- cuju/render/web/js/core/spoilers.js +236 -0
- cuju/render/web/js/core/typeahead.js +38 -0
- cuju/render/web/js/export/dom-picture.js +330 -0
- cuju/render/web/js/export/export-host.js +97 -0
- cuju/render/web/js/export/feed-dialog.js +191 -0
- cuju/render/web/js/export/feed-params.js +266 -0
- cuju/render/web/js/export/feed.js +363 -0
- cuju/render/web/js/export/mp4-mux.js +295 -0
- cuju/render/web/js/export/photo-core.js +313 -0
- cuju/render/web/js/export/photo.js +1314 -0
- cuju/render/web/js/export/safe-frame.js +59 -0
- cuju/render/web/js/export/size-fields.js +103 -0
- cuju/render/web/js/export/sizes.js +178 -0
- cuju/render/web/js/export/video-boot.js +55 -0
- cuju/render/web/js/export/video-browser.js +325 -0
- cuju/render/web/js/export/video-export.js +417 -0
- cuju/render/web/js/export/video-plan.js +207 -0
- cuju/render/web/js/export/video-range.js +185 -0
- cuju/render/web/js/export/webm-mux.js +198 -0
- cuju/render/web/js/feed-boot.js +151 -0
- cuju/render/web/js/feed-frame.js +101 -0
- cuju/render/web/js/help/doctor.js +488 -0
- cuju/render/web/js/help/firstrun.js +379 -0
- cuju/render/web/js/help/help-center.js +438 -0
- cuju/render/web/js/help/install-offer.js +164 -0
- cuju/render/web/js/help/install-state.js +104 -0
- cuju/render/web/js/help/lessons-core.js +207 -0
- cuju/render/web/js/help/lessons.js +463 -0
- cuju/render/web/js/help/palette.js +584 -0
- cuju/render/web/js/help/pwa.js +257 -0
- cuju/render/web/js/help/tour-core.js +241 -0
- cuju/render/web/js/help/tour.js +461 -0
- cuju/render/web/js/main.js +2513 -0
- cuju/render/web/js/pages/draw.js +188 -0
- cuju/render/web/js/pages/fieldpage.js +530 -0
- cuju/render/web/js/pages/home.js +521 -0
- cuju/render/web/js/pages/matches.js +779 -0
- cuju/render/web/js/pages/moments-ui.js +359 -0
- cuju/render/web/js/pages/queue-filters.js +63 -0
- cuju/render/web/js/pages/recording-groups.js +80 -0
- cuju/render/web/js/pages/recordings.js +1069 -0
- cuju/render/web/js/play/bench.js +347 -0
- cuju/render/web/js/play/challenges.js +1302 -0
- cuju/render/web/js/play/medals.js +127 -0
- cuju/render/web/js/play/play.js +1953 -0
- cuju/render/web/js/play/teasers.js +196 -0
- cuju/render/web/js/play/touch.js +350 -0
- cuju/render/web/js/play/tournament-layout.js +487 -0
- cuju/render/web/js/play/tournament-results.js +441 -0
- cuju/render/web/js/play/tournament-strict.js +560 -0
- cuju/render/web/js/play/tournament.js +2585 -0
- cuju/render/web/js/players/animate.js +972 -0
- cuju/render/web/js/players/clips.js +224 -0
- cuju/render/web/js/players/kaykit.js +162 -0
- cuju/render/web/js/players/kits.js +676 -0
- cuju/render/web/js/players/number-patch.js +82 -0
- cuju/render/web/js/players/players.js +2694 -0
- cuju/render/web/js/players/recolor.js +893 -0
- cuju/render/web/js/players/retarget.js +325 -0
- cuju/render/web/js/players/rig-numbers.js +174 -0
- cuju/render/web/js/presentation/animator.js +231 -0
- cuju/render/web/js/presentation/assign.js +85 -0
- cuju/render/web/js/presentation/behaviors.js +440 -0
- cuju/render/web/js/presentation/budget.js +209 -0
- cuju/render/web/js/presentation/catalog.js +1674 -0
- cuju/render/web/js/presentation/clocks.js +72 -0
- cuju/render/web/js/presentation/commands.js +301 -0
- cuju/render/web/js/presentation/contract.js +240 -0
- cuju/render/web/js/presentation/effects.js +904 -0
- cuju/render/web/js/presentation/flash.js +605 -0
- cuju/render/web/js/presentation/freeze-worklet.js +22 -0
- cuju/render/web/js/presentation/glsl.js +464 -0
- cuju/render/web/js/presentation/host.js +323 -0
- cuju/render/web/js/presentation/index.js +2066 -0
- cuju/render/web/js/presentation/loudness-worklet.js +235 -0
- cuju/render/web/js/presentation/loudness.js +740 -0
- cuju/render/web/js/presentation/moments.js +536 -0
- cuju/render/web/js/presentation/post.js +327 -0
- cuju/render/web/js/presentation/preview.js +180 -0
- cuju/render/web/js/presentation/protocol.js +174 -0
- cuju/render/web/js/presentation/reach.js +158 -0
- cuju/render/web/js/presentation/rigging.js +130 -0
- cuju/render/web/js/presentation/sandbox.js +157 -0
- cuju/render/web/js/presentation/shaders.js +235 -0
- cuju/render/web/js/presentation/stage.js +402 -0
- cuju/render/web/js/presentation/teamaudio.js +722 -0
- cuju/render/web/js/presentation/tracks.js +197 -0
- cuju/render/web/js/presentation/values.js +81 -0
- cuju/render/web/js/recording/annotation-data.js +203 -0
- cuju/render/web/js/recording/captions.js +491 -0
- cuju/render/web/js/recording/codec.js +185 -0
- cuju/render/web/js/recording/decode-worker.js +70 -0
- cuju/render/web/js/recording/decode.js +94 -0
- cuju/render/web/js/recording/episodes.js +46 -0
- cuju/render/web/js/recording/format.js +461 -0
- cuju/render/web/js/recording/live.js +348 -0
- cuju/render/web/js/recording/moments-query.js +59 -0
- cuju/render/web/js/recording/moments.js +149 -0
- cuju/render/web/js/recording/pose.js +86 -0
- cuju/render/web/js/recording/timeline.js +275 -0
- cuju/render/web/js/teams/art.js +50 -0
- cuju/render/web/js/teams/clip-editor.js +293 -0
- cuju/render/web/js/teams/editor.js +1979 -0
- cuju/render/web/js/teams/library.js +344 -0
- cuju/render/web/js/teams/painter.js +633 -0
- cuju/render/web/js/teams/surprise-ui.js +195 -0
- cuju/render/web/js/teams/surprise.js +497 -0
- cuju/render/web/js/teams/team-check.js +127 -0
- cuju/render/web/js/watch/annotations.js +270 -0
- cuju/render/web/js/watch/flat.js +366 -0
- cuju/render/web/js/watch/grid.js +436 -0
- cuju/render/web/js/watch/pitch2d.js +289 -0
- cuju/render/web/js/watch/player-tools.js +192 -0
- cuju/render/web/js/watch/presets.js +201 -0
- cuju/render/web/js/world/arenas.js +997 -0
- cuju/render/web/js/world/ball.js +204 -0
- cuju/render/web/js/world/cameras.js +982 -0
- cuju/render/web/js/world/crowd.js +376 -0
- cuju/render/web/js/world/field.js +227 -0
- cuju/render/web/js/world/framing.js +145 -0
- cuju/render/web/js/world/occlusion.js +48 -0
- cuju/render/web/js/world/pitch.js +703 -0
- cuju/render/web/js/world/scene.js +395 -0
- cuju/render/web/js/world/sky.js +325 -0
- cuju/render/web/js/world/stadium.js +1262 -0
- cuju/render/web/js/world/vendor-sky.js +367 -0
- cuju/render/web/js/world/weather.js +264 -0
- cuju/render/web/languages/en.json +4750 -0
- cuju/render/web/lessons.json +137 -0
- cuju/render/web/manifest.webmanifest +23 -0
- cuju/render/web/style.css +8399 -0
- cuju/render/web/sw.js +235 -0
- cuju/render/web/vendor/fabric/LICENSE +16 -0
- cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
- cuju/render/web/vendor/lucide/LICENSE +43 -0
- cuju/render/web/vendor/lucide/icons.js +141 -0
- cuju/render/web/vendor/three/LICENSE +21 -0
- cuju/render/web/vendor/three/build/three.core.js +60586 -0
- cuju/render/web/vendor/three/build/three.module.js +19719 -0
- cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
- cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
- cuju_render-0.1.0.dist-info/METADATA +116 -0
- cuju_render-0.1.0.dist-info/RECORD +382 -0
- cuju_render-0.1.0.dist-info/WHEEL +4 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
- cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""The ratings, the matrix of goal differences and the files of a tournament's results.
|
|
5
|
+
|
|
6
|
+
The ratings follow the Bradley and Terry model, in which an entrant of strength p beats one of
|
|
7
|
+
strength q with the chance of p over the sum of p and q, fitted to every match a tournament has
|
|
8
|
+
played, a draw counting as half a win for each side. They read on the Elo scale, 400 points for
|
|
9
|
+
each tenfold of strength, centred so that their mean is 1000. As its prior, each entrant also plays
|
|
10
|
+
one draw against a virtual entrant of the fixed strength 1, which keeps the rating of an entrant
|
|
11
|
+
that won or lost every match finite and pulls an entrant of few matches toward the middle. The
|
|
12
|
+
interval of each rating comes from a bootstrap, the matches drawn again with replacement as many
|
|
13
|
+
times as the resamples say, 200 by default, by a generator seeded with the digest of the
|
|
14
|
+
tournament seed, so the same results always give the same intervals. The interval runs from the
|
|
15
|
+
2.5th to the 97.5th percentile of the ratings of the resamples. The file `ratings_method.json`
|
|
16
|
+
states all of it beside the ratings.
|
|
17
|
+
|
|
18
|
+
The module uses Python's standard library alone, so the page's mock server loads it from its file,
|
|
19
|
+
as it loads the rules of the tournaments.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import csv
|
|
25
|
+
import hashlib
|
|
26
|
+
import io
|
|
27
|
+
import json
|
|
28
|
+
import math
|
|
29
|
+
import random
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
# The resamples of the bootstrap of the ratings.
|
|
33
|
+
RESAMPLES = 200
|
|
34
|
+
# The rating of an entrant of the mean strength.
|
|
35
|
+
CENTRE = 1000.0
|
|
36
|
+
# The virtual draws that each entrant plays against a virtual entrant of the fixed strength 1.
|
|
37
|
+
PRIOR = 1.0
|
|
38
|
+
# The files of a tournament's results, in the order the page and the command line list them.
|
|
39
|
+
FILES = (
|
|
40
|
+
'standings.csv',
|
|
41
|
+
'ratings.csv',
|
|
42
|
+
'ratings_method.json',
|
|
43
|
+
'pairwise_gd.csv',
|
|
44
|
+
'pairwise_counts.csv',
|
|
45
|
+
'matches.jsonl',
|
|
46
|
+
'entrants.json',
|
|
47
|
+
'excluded.json',
|
|
48
|
+
)
|
|
49
|
+
STANDINGS_COLUMNS = (
|
|
50
|
+
'position',
|
|
51
|
+
'entrant',
|
|
52
|
+
'id',
|
|
53
|
+
'name',
|
|
54
|
+
'kind',
|
|
55
|
+
'team',
|
|
56
|
+
'played',
|
|
57
|
+
'won',
|
|
58
|
+
'drawn',
|
|
59
|
+
'lost',
|
|
60
|
+
'goals_for',
|
|
61
|
+
'goals_against',
|
|
62
|
+
'goal_difference',
|
|
63
|
+
'points',
|
|
64
|
+
'forfeits',
|
|
65
|
+
'cut_short',
|
|
66
|
+
'rating',
|
|
67
|
+
)
|
|
68
|
+
RATINGS_COLUMNS = ('rank', 'entrant', 'id', 'name', 'rating', 'low', 'high', 'matches')
|
|
69
|
+
PAIRWISE_COLUMNS = (
|
|
70
|
+
'entrant',
|
|
71
|
+
'id',
|
|
72
|
+
'name',
|
|
73
|
+
'opponent',
|
|
74
|
+
'opponent_id',
|
|
75
|
+
'opponent_name',
|
|
76
|
+
'matches',
|
|
77
|
+
'mean_goal_difference',
|
|
78
|
+
)
|
|
79
|
+
_STEPS = 10000
|
|
80
|
+
_TOLERANCE = 1e-10
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _played(matches: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
84
|
+
"""Returns the matches that have a result, in the order of the schedule."""
|
|
85
|
+
return [match for match in matches if isinstance(match.get('result'), dict)]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _outcome(score: list[int]) -> float:
|
|
89
|
+
"""Returns the share of a win of the home side, 1 for a win, a half for a draw, else 0."""
|
|
90
|
+
return 1.0 if score[0] > score[1] else 0.5 if score[0] == score[1] else 0.0
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _common_scale(strength: list[float]) -> float:
|
|
94
|
+
"""Returns the factor of every strength at which the virtual draws are most likely.
|
|
95
|
+
|
|
96
|
+
The matches between entrants tell only how their strengths compare, so the scale of all of
|
|
97
|
+
them together comes from the virtual draws alone, the factor c at which the sum of the shares
|
|
98
|
+
c p over c p plus 1 is half the entrants, which Newton's method finds.
|
|
99
|
+
"""
|
|
100
|
+
shift = 0.0
|
|
101
|
+
half = len(strength) / 2
|
|
102
|
+
for _ in range(100):
|
|
103
|
+
factor = math.exp(shift)
|
|
104
|
+
shares = [factor * value / (factor * value + 1) for value in strength]
|
|
105
|
+
slope = sum(share * (1 - share) for share in shares)
|
|
106
|
+
if slope <= 0:
|
|
107
|
+
break
|
|
108
|
+
step = (sum(shares) - half) / slope
|
|
109
|
+
shift -= step
|
|
110
|
+
if abs(step) < 1e-14:
|
|
111
|
+
break
|
|
112
|
+
return math.exp(shift)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def bradley_terry(count: int, games: list[tuple[int, int, float]], prior: float = PRIOR) -> list:
|
|
116
|
+
"""Returns the rating of each of `count` entrants from games, on the Elo scale about 1000.
|
|
117
|
+
|
|
118
|
+
The strengths come from the iteration of Newman, 2023, each entrant's strength its wins
|
|
119
|
+
weighed by the strengths of those it beat over its losses weighed alike, taken in turn, with
|
|
120
|
+
the common scale set after each step by the virtual draws, until no strength moves by more
|
|
121
|
+
than a ten billionth of itself. An entrant that has won nothing, or lost nothing, with no
|
|
122
|
+
virtual draws keeps the strength it had, which only a test of the model asks for.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
count: The entrants.
|
|
126
|
+
games: Each game as the two entrants and the share of a win of the first, 1, a half or 0.
|
|
127
|
+
prior: The draws that each entrant plays against a virtual entrant of strength 1.
|
|
128
|
+
"""
|
|
129
|
+
if count == 0:
|
|
130
|
+
return []
|
|
131
|
+
wins: dict[tuple[int, int], float] = {}
|
|
132
|
+
for first, second, share in games:
|
|
133
|
+
if first == second:
|
|
134
|
+
continue
|
|
135
|
+
wins[(first, second)] = wins.get((first, second), 0.0) + share
|
|
136
|
+
wins[(second, first)] = wins.get((second, first), 0.0) + 1 - share
|
|
137
|
+
met: list[list[tuple[int, float, float]]] = [[] for _ in range(count)]
|
|
138
|
+
for (first, second), won in wins.items():
|
|
139
|
+
met[first].append((second, won, wins[(second, first)]))
|
|
140
|
+
strength = [1.0] * count
|
|
141
|
+
half = prior / 2
|
|
142
|
+
for _ in range(_STEPS):
|
|
143
|
+
old = list(strength)
|
|
144
|
+
# Each strength takes the new values of those before it, which keeps two entrants from
|
|
145
|
+
# trading places step after step.
|
|
146
|
+
for index in range(count):
|
|
147
|
+
own = strength[index]
|
|
148
|
+
above = below = half / (own + 1)
|
|
149
|
+
for other, won, lost in met[index]:
|
|
150
|
+
total = own + strength[other]
|
|
151
|
+
above += won * strength[other] / total
|
|
152
|
+
below += lost / total
|
|
153
|
+
if below > 0 and above > 0:
|
|
154
|
+
strength[index] = max(above / below, 1e-300)
|
|
155
|
+
factor = _common_scale(strength) if prior > 0 else 1.0
|
|
156
|
+
strength = [value * factor for value in strength]
|
|
157
|
+
moved = max(abs(math.log(value / was)) for value, was in zip(strength, old, strict=True))
|
|
158
|
+
if moved < _TOLERANCE:
|
|
159
|
+
break
|
|
160
|
+
logs = [400 * math.log10(value) for value in strength]
|
|
161
|
+
mean = sum(logs) / count
|
|
162
|
+
return [CENTRE + value - mean for value in logs]
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _percentile(values: list[float], share: float) -> float:
|
|
166
|
+
"""Returns a percentile of values, between the two nearest of them in sorted order."""
|
|
167
|
+
ordered = sorted(values)
|
|
168
|
+
position = share * (len(ordered) - 1)
|
|
169
|
+
low = math.floor(position)
|
|
170
|
+
high = min(low + 1, len(ordered) - 1)
|
|
171
|
+
return ordered[low] + (ordered[high] - ordered[low]) * (position - low)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _generator(seed: int) -> random.Random:
|
|
175
|
+
return random.Random(hashlib.sha256(f'{seed}/bootstrap'.encode()).digest())
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def ratings(
|
|
179
|
+
count: int, matches: list[dict[str, Any]], seed: int, resamples: int = RESAMPLES
|
|
180
|
+
) -> list[dict[str, Any]]:
|
|
181
|
+
"""Returns the rating of every entrant with its 95 percent interval and matches, best first.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
count: The entrants of the tournament.
|
|
185
|
+
matches: The matches, each with `home`, `away` and a `result` with its `score` once
|
|
186
|
+
played, as an evaluation or the runner's `get` gives them.
|
|
187
|
+
seed: The tournament seed, which seeds the bootstrap.
|
|
188
|
+
resamples: The resamples of the bootstrap.
|
|
189
|
+
"""
|
|
190
|
+
played = _played(matches)
|
|
191
|
+
games = [(m['home'], m['away'], _outcome(m['result']['score'])) for m in played]
|
|
192
|
+
fitted = bradley_terry(count, games)
|
|
193
|
+
samples: list[list[float]] = [[] for _ in range(count)]
|
|
194
|
+
if games and resamples > 0:
|
|
195
|
+
draw = _generator(seed)
|
|
196
|
+
for _ in range(resamples):
|
|
197
|
+
again = [games[draw.randrange(len(games))] for _ in games]
|
|
198
|
+
for index, value in enumerate(bradley_terry(count, again)):
|
|
199
|
+
samples[index].append(value)
|
|
200
|
+
counts = [0] * count
|
|
201
|
+
for first, second, _ in games:
|
|
202
|
+
counts[first] += 1
|
|
203
|
+
counts[second] += 1
|
|
204
|
+
rows = []
|
|
205
|
+
for index in range(count):
|
|
206
|
+
low = _percentile(samples[index], 0.025) if samples[index] else fitted[index]
|
|
207
|
+
high = _percentile(samples[index], 0.975) if samples[index] else fitted[index]
|
|
208
|
+
rows.append(
|
|
209
|
+
{
|
|
210
|
+
'entrant': index,
|
|
211
|
+
'rating': round(fitted[index], 2),
|
|
212
|
+
'low': round(min(low, fitted[index]), 2),
|
|
213
|
+
'high': round(max(high, fitted[index]), 2),
|
|
214
|
+
'matches': counts[index],
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
rows.sort(key=lambda row: (-row['rating'], row['entrant']))
|
|
218
|
+
return rows
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def goal_matrix(count: int, matches: list[dict[str, Any]]) -> dict[str, Any]:
|
|
222
|
+
"""Returns the mean goal difference of every pair, row against column, with match counts.
|
|
223
|
+
|
|
224
|
+
`mean[row][column]` is the mean of the row entrant's goals less the column entrant's over
|
|
225
|
+
their matches, whichever side was at home, `None` for a pair that has not met, and
|
|
226
|
+
`matches[row][column]` the number of those matches.
|
|
227
|
+
"""
|
|
228
|
+
totals = [[0] * count for _ in range(count)]
|
|
229
|
+
counts = [[0] * count for _ in range(count)]
|
|
230
|
+
for match in _played(matches):
|
|
231
|
+
home, away = match['home'], match['away']
|
|
232
|
+
if home == away:
|
|
233
|
+
continue
|
|
234
|
+
score = match['result']['score']
|
|
235
|
+
totals[home][away] += score[0] - score[1]
|
|
236
|
+
totals[away][home] += score[1] - score[0]
|
|
237
|
+
counts[home][away] += 1
|
|
238
|
+
counts[away][home] += 1
|
|
239
|
+
mean = [
|
|
240
|
+
[
|
|
241
|
+
round(totals[row][column] / counts[row][column], 4) if counts[row][column] else None
|
|
242
|
+
for column in range(count)
|
|
243
|
+
]
|
|
244
|
+
for row in range(count)
|
|
245
|
+
]
|
|
246
|
+
return {'mean': mean, 'matches': counts}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _side_of(rule: dict[str, Any] | None, side: int) -> bool:
|
|
250
|
+
"""Returns whether the rule that ended a match was broken by the side of index `side`."""
|
|
251
|
+
if not rule:
|
|
252
|
+
return False
|
|
253
|
+
return rule['side'] == 'both' or rule['side'] == ('home', 'away')[side]
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def standings(
|
|
257
|
+
config: dict[str, Any],
|
|
258
|
+
matches: list[dict[str, Any]],
|
|
259
|
+
ranking: list[int] | None,
|
|
260
|
+
rated: list[dict[str, Any]],
|
|
261
|
+
) -> list[dict[str, Any]]:
|
|
262
|
+
"""Returns a row of every entrant over all the matches it played, in order.
|
|
263
|
+
|
|
264
|
+
The points of a match follow its stage, and deciding matches count as the tables count them,
|
|
265
|
+
not at all. A forfeit counts against the side that broke a rule, or that lost a match
|
|
266
|
+
awarded by hand. The order is the tournament's final ranking once it has one, and before that
|
|
267
|
+
points, goal difference, goals scored and rating.
|
|
268
|
+
"""
|
|
269
|
+
count = len(config['entrants'])
|
|
270
|
+
rows = [
|
|
271
|
+
{
|
|
272
|
+
'entrant': index,
|
|
273
|
+
'played': 0,
|
|
274
|
+
'won': 0,
|
|
275
|
+
'drawn': 0,
|
|
276
|
+
'lost': 0,
|
|
277
|
+
'goals_for': 0,
|
|
278
|
+
'goals_against': 0,
|
|
279
|
+
'goal_difference': 0,
|
|
280
|
+
'points': 0,
|
|
281
|
+
'forfeits': 0,
|
|
282
|
+
'cut_short': 0,
|
|
283
|
+
}
|
|
284
|
+
for index in range(count)
|
|
285
|
+
]
|
|
286
|
+
for match in _played(matches):
|
|
287
|
+
if match.get('decider'):
|
|
288
|
+
continue
|
|
289
|
+
result = match['result']
|
|
290
|
+
score = result['score']
|
|
291
|
+
points = config['stages'][match['stage']]['points']
|
|
292
|
+
for side, entrant in enumerate((match['home'], match['away'])):
|
|
293
|
+
row = rows[entrant]
|
|
294
|
+
own, other = score[side], score[1 - side]
|
|
295
|
+
row['played'] += 1
|
|
296
|
+
row['goals_for'] += own
|
|
297
|
+
row['goals_against'] += other
|
|
298
|
+
outcome = 'win' if own > other else 'draw' if own == other else 'loss'
|
|
299
|
+
row[{'win': 'won', 'draw': 'drawn', 'loss': 'lost'}[outcome]] += 1
|
|
300
|
+
row['points'] += points[outcome]
|
|
301
|
+
rule = result.get('rule')
|
|
302
|
+
if result.get('forfeit') and (_side_of(rule, side) or (not rule and own < other)):
|
|
303
|
+
row['forfeits'] += 1
|
|
304
|
+
if _cut_short(result):
|
|
305
|
+
row['cut_short'] += 1
|
|
306
|
+
by_rating = {row['entrant']: row['rating'] for row in rated}
|
|
307
|
+
for row in rows:
|
|
308
|
+
row['goal_difference'] = row['goals_for'] - row['goals_against']
|
|
309
|
+
row['rating'] = by_rating.get(row['entrant'], CENTRE)
|
|
310
|
+
if ranking is not None and sorted(ranking) == list(range(count)):
|
|
311
|
+
place = {entrant: position for position, entrant in enumerate(ranking)}
|
|
312
|
+
rows.sort(key=lambda row: place[row['entrant']])
|
|
313
|
+
else:
|
|
314
|
+
rows.sort(
|
|
315
|
+
key=lambda row: (
|
|
316
|
+
-row['points'],
|
|
317
|
+
-row['goal_difference'],
|
|
318
|
+
-row['goals_for'],
|
|
319
|
+
-row['rating'],
|
|
320
|
+
row['entrant'],
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
for position, row in enumerate(rows):
|
|
324
|
+
row['position'] = position + 1
|
|
325
|
+
return rows
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def _cut_short(result: dict[str, Any]) -> bool:
|
|
329
|
+
"""Returns whether a match ended before its own end, by a rule that a side broke."""
|
|
330
|
+
stats = result.get('stats') or {}
|
|
331
|
+
return bool(stats.get('cut_short')) or bool(result.get('rule'))
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def entrant_ids(entrants: list[dict[str, Any]]) -> list[str]:
|
|
335
|
+
"""Returns an identifier of each entrant that no other entrant and no team name shares.
|
|
336
|
+
|
|
337
|
+
It is the entrant's key, the team's identifier for a team, `builtin:0.50` for the built-in AI
|
|
338
|
+
at an ability, `random:uniform` for the random entrant and `person:Ana` for a person, with
|
|
339
|
+
`#2`, `#3` and so on after a key that an earlier entrant holds, as two entrants of one team
|
|
340
|
+
do. A colon or a hash never stands in a team's identifier, so the built-in AI and the random
|
|
341
|
+
entrant never read as a team.
|
|
342
|
+
"""
|
|
343
|
+
seen: dict[str, int] = {}
|
|
344
|
+
found = []
|
|
345
|
+
for index, entrant in enumerate(entrants):
|
|
346
|
+
key = str(entrant.get('key') or f'entrant:{index}')
|
|
347
|
+
seen[key] = seen.get(key, 0) + 1
|
|
348
|
+
found.append(key if seen[key] == 1 else f'{key}#{seen[key]}')
|
|
349
|
+
return found
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def method(seed: int, resamples: int = RESAMPLES) -> dict[str, Any]:
|
|
353
|
+
"""Returns how the ratings are made, the model, its prior, its scale and its bootstrap."""
|
|
354
|
+
return {
|
|
355
|
+
'model': 'Bradley and Terry, a draw counting as half a win for each side',
|
|
356
|
+
'fit': 'the iteration of Newman, 2023, to a change of strength below 1e-10',
|
|
357
|
+
'scale': 'Elo, 400 points for each tenfold of strength, the mean of the ratings at 1000',
|
|
358
|
+
'centre': CENTRE,
|
|
359
|
+
'prior': {
|
|
360
|
+
'virtual_draws': PRIOR,
|
|
361
|
+
'opponent': 'a virtual entrant of the fixed strength 1, before the ratings are centred',
|
|
362
|
+
},
|
|
363
|
+
'bootstrap': {
|
|
364
|
+
'resamples': resamples,
|
|
365
|
+
'tournament_seed': seed,
|
|
366
|
+
'generator': (
|
|
367
|
+
"Python's random.Random seeded with the SHA-256 digest of '<seed>/bootstrap'"
|
|
368
|
+
),
|
|
369
|
+
'draw': 'the played matches drawn again with replacement, as many as were played',
|
|
370
|
+
'interval': 'the 2.5th and 97.5th percentiles, between the nearest resamples',
|
|
371
|
+
},
|
|
372
|
+
'matches': 'every played match, forfeits and deciding matches included',
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def match_rows(config: dict[str, Any], matches: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
377
|
+
"""Returns every played match as a line of `matches.jsonl`, in the order of the schedule.
|
|
378
|
+
|
|
379
|
+
Each line holds the key, stage, label and scenario of the match, its two sides by index and
|
|
380
|
+
name, its seed, score and steps, whether it was a forfeit with the rule a side broke, the
|
|
381
|
+
reason and the score at that moment, and for each side the calls of its policy, the mean, the
|
|
382
|
+
largest and the first compute time of a call in milliseconds, and the count of each action
|
|
383
|
+
it answered, `null` for a side without a policy of its own, such as the built-in AI.
|
|
384
|
+
"""
|
|
385
|
+
entrants = config['entrants']
|
|
386
|
+
lines = []
|
|
387
|
+
for match in _played(matches):
|
|
388
|
+
result = match['result']
|
|
389
|
+
stats = result.get('stats') or {}
|
|
390
|
+
sides = stats.get('sides') or [None, None]
|
|
391
|
+
rule = result.get('rule')
|
|
392
|
+
lines.append(
|
|
393
|
+
{
|
|
394
|
+
'key': match['key'],
|
|
395
|
+
'stage': match['stage'],
|
|
396
|
+
'label': match.get('label'),
|
|
397
|
+
'scenario': match.get('scenario'),
|
|
398
|
+
'home': match['home'],
|
|
399
|
+
'away': match['away'],
|
|
400
|
+
'home_name': entrants[match['home']]['name'],
|
|
401
|
+
'away_name': entrants[match['away']]['name'],
|
|
402
|
+
'seed': match.get('seed'),
|
|
403
|
+
'score': list(result['score']),
|
|
404
|
+
'steps': stats.get('steps'),
|
|
405
|
+
'cut_short': _cut_short(result),
|
|
406
|
+
'forfeit': bool(result.get('forfeit')),
|
|
407
|
+
'rule': None
|
|
408
|
+
if not rule
|
|
409
|
+
else {
|
|
410
|
+
'side': rule['side'],
|
|
411
|
+
'kind': rule['kind'],
|
|
412
|
+
'detail': rule.get('detail'),
|
|
413
|
+
'reason': rule['reason'],
|
|
414
|
+
'step': rule['step'],
|
|
415
|
+
'score': list(rule['at']),
|
|
416
|
+
},
|
|
417
|
+
'timings': [
|
|
418
|
+
None
|
|
419
|
+
if not side
|
|
420
|
+
else {
|
|
421
|
+
key: side.get(key)
|
|
422
|
+
for key in ('calls', 'mean_ms', 'mean_after_first_ms', 'max_ms', 'first_ms')
|
|
423
|
+
}
|
|
424
|
+
for side in sides
|
|
425
|
+
],
|
|
426
|
+
'actions': [
|
|
427
|
+
None if not side else dict(side.get('actions') or {}) for side in sides
|
|
428
|
+
],
|
|
429
|
+
'recording': result.get('match'),
|
|
430
|
+
}
|
|
431
|
+
)
|
|
432
|
+
return lines
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def analysis(entry: dict[str, Any], resamples: int = RESAMPLES) -> dict[str, Any]:
|
|
436
|
+
"""Returns the ratings, the matrix, the standings and the matches of a tournament.
|
|
437
|
+
|
|
438
|
+
Args:
|
|
439
|
+
entry: The tournament in full, as the runner's `get` gives it, with its configuration,
|
|
440
|
+
matches, ranking and the entrants that the pre-flight left out.
|
|
441
|
+
resamples: The resamples of the bootstrap.
|
|
442
|
+
"""
|
|
443
|
+
config = entry['config']
|
|
444
|
+
count = len(config['entrants'])
|
|
445
|
+
matches = entry['matches']
|
|
446
|
+
rated = ratings(count, matches, config['seed'], resamples)
|
|
447
|
+
rows = match_rows(config, matches)
|
|
448
|
+
return {
|
|
449
|
+
'ratings': rated,
|
|
450
|
+
'resamples': resamples,
|
|
451
|
+
'method': method(config['seed'], resamples),
|
|
452
|
+
'ids': entrant_ids(config['entrants']),
|
|
453
|
+
'played': len(rows),
|
|
454
|
+
'cut_short': sum(1 for row in rows if row['cut_short']),
|
|
455
|
+
'matrix': goal_matrix(count, matches),
|
|
456
|
+
'standings': standings(config, matches, entry.get('ranking'), rated),
|
|
457
|
+
'matches': rows,
|
|
458
|
+
'excluded': list(entry.get('excluded') or []),
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def _csv(columns: tuple[str, ...], rows: list[dict[str, Any]]) -> str:
|
|
463
|
+
stream = io.StringIO()
|
|
464
|
+
writer = csv.DictWriter(stream, columns, lineterminator='\n', extrasaction='ignore')
|
|
465
|
+
writer.writeheader()
|
|
466
|
+
for row in rows:
|
|
467
|
+
writer.writerow({key: '' if row.get(key) is None else row[key] for key in columns})
|
|
468
|
+
return stream.getvalue()
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def files(entry: dict[str, Any], found: dict[str, Any] | None = None) -> dict[str, str]:
|
|
472
|
+
"""Returns the text of each file of a tournament's results, by its name in `FILES`.
|
|
473
|
+
|
|
474
|
+
Args:
|
|
475
|
+
entry: The tournament in full, as the runner's `get` gives it.
|
|
476
|
+
found: Its analysis, as `analysis` gives it, or `None` to make it.
|
|
477
|
+
"""
|
|
478
|
+
found = analysis(entry) if found is None else found
|
|
479
|
+
config = entry['config']
|
|
480
|
+
entrants = config['entrants']
|
|
481
|
+
ids = entrant_ids(entrants)
|
|
482
|
+
|
|
483
|
+
def named(row: dict[str, Any]) -> dict[str, Any]:
|
|
484
|
+
entrant = entrants[row['entrant']]
|
|
485
|
+
return {
|
|
486
|
+
**row,
|
|
487
|
+
'id': ids[row['entrant']],
|
|
488
|
+
'name': entrant['name'],
|
|
489
|
+
'kind': entrant['kind'],
|
|
490
|
+
'team': entrant.get('team'),
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
rated = [{**named(row), 'rank': rank + 1} for rank, row in enumerate(found['ratings'])]
|
|
494
|
+
pairs = []
|
|
495
|
+
matrix = found['matrix']
|
|
496
|
+
for row in range(len(entrants)):
|
|
497
|
+
for column in range(len(entrants)):
|
|
498
|
+
if row == column:
|
|
499
|
+
continue
|
|
500
|
+
pairs.append(
|
|
501
|
+
{
|
|
502
|
+
'entrant': row,
|
|
503
|
+
'id': ids[row],
|
|
504
|
+
'name': entrants[row]['name'],
|
|
505
|
+
'opponent': column,
|
|
506
|
+
'opponent_id': ids[column],
|
|
507
|
+
'opponent_name': entrants[column]['name'],
|
|
508
|
+
'matches': matrix['matches'][row][column],
|
|
509
|
+
'mean_goal_difference': matrix['mean'][row][column],
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
by_entrant = {row['entrant']: row for row in found['ratings']}
|
|
513
|
+
listed = [
|
|
514
|
+
{
|
|
515
|
+
'entrant': index,
|
|
516
|
+
'id': ids[index],
|
|
517
|
+
'name': entrant['name'],
|
|
518
|
+
'kind': entrant['kind'],
|
|
519
|
+
'team': entrant.get('team'),
|
|
520
|
+
'key': entrant.get('key'),
|
|
521
|
+
'ability': entrant.get('ability'),
|
|
522
|
+
'rating': by_entrant[index]['rating'],
|
|
523
|
+
'low': by_entrant[index]['low'],
|
|
524
|
+
'high': by_entrant[index]['high'],
|
|
525
|
+
}
|
|
526
|
+
for index, entrant in enumerate(entrants)
|
|
527
|
+
]
|
|
528
|
+
counts = io.StringIO()
|
|
529
|
+
writer = csv.writer(counts, lineterminator='\n')
|
|
530
|
+
writer.writerow(['id', *ids])
|
|
531
|
+
for row in range(len(entrants)):
|
|
532
|
+
writer.writerow([ids[row], *matrix['matches'][row]])
|
|
533
|
+
sidecar = {
|
|
534
|
+
**found.get('method', method(config['seed'])),
|
|
535
|
+
'played': found.get('played'),
|
|
536
|
+
'cut_short': found.get('cut_short'),
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
'standings.csv': _csv(STANDINGS_COLUMNS, [named(row) for row in found['standings']]),
|
|
540
|
+
'ratings.csv': _csv(RATINGS_COLUMNS, rated),
|
|
541
|
+
'ratings_method.json': json.dumps(sidecar, indent=2) + '\n',
|
|
542
|
+
'pairwise_gd.csv': _csv(PAIRWISE_COLUMNS, pairs),
|
|
543
|
+
'pairwise_counts.csv': counts.getvalue(),
|
|
544
|
+
'matches.jsonl': ''.join(json.dumps(line) + '\n' for line in found['matches']),
|
|
545
|
+
'entrants.json': json.dumps(listed, indent=2) + '\n',
|
|
546
|
+
'excluded.json': json.dumps(found['excluded'], indent=2) + '\n',
|
|
547
|
+
}
|