cleanups, formatting

This commit is contained in:
Scott Pruett 2022-06-04 15:32:23 -04:00
parent 0c4b3b7420
commit 6bbe865235
13 changed files with 157 additions and 764 deletions

613
Cargo.lock generated
View File

@ -199,12 +199,6 @@ dependencies = [
"libc",
]
[[package]]
name = "chunked_transfer"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e"
[[package]]
name = "clipboard-win"
version = "4.4.1"
@ -564,19 +558,6 @@ dependencies = [
"web-sys",
]
[[package]]
name = "ehttp"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80b69a6f9168b96c0ae04763bec27a8b06b34343c334dd2703a4ec21f0f5e110"
dependencies = [
"js-sys",
"ureq",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "either"
version = "1.6.1"
@ -592,15 +573,6 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "encoding_rs"
version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "epaint"
version = "0.18.1"
@ -642,15 +614,6 @@ dependencies = [
"threadpool",
]
[[package]]
name = "fastrand"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
dependencies = [
"instant",
]
[[package]]
name = "flate2"
version = "1.0.23"
@ -673,7 +636,7 @@ dependencies = [
"futures-sink",
"nanorand",
"pin-project",
"spin 0.9.3",
"spin",
]
[[package]]
@ -707,95 +670,18 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "futures"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]]
name = "futures-executor"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "futures-macro"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
[[package]]
name = "futures-task"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
[[package]]
name = "futures-util"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "gethostname"
version = "0.2.3"
@ -924,37 +810,12 @@ dependencies = [
"gl_generator",
]
[[package]]
name = "h2"
version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57"
dependencies = [
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http",
"indexmap",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "half"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -964,77 +825,6 @@ dependencies = [
"libc",
]
[[package]]
name = "http"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb"
dependencies = [
"bytes",
"fnv",
"itoa 1.0.2",
]
[[package]]
name = "http-body"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
dependencies = [
"bytes",
"http",
"pin-project-lite",
]
[[package]]
name = "httparse"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c"
[[package]]
name = "httpdate"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "hyper"
version = "0.14.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2"
dependencies = [
"bytes",
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"httparse",
"httpdate",
"itoa 1.0.2",
"pin-project-lite",
"socket2",
"tokio",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper-tls"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
"bytes",
"hyper",
"native-tls",
"tokio",
"tokio-native-tls",
]
[[package]]
name = "ident_case"
version = "1.0.1"
@ -1099,16 +889,6 @@ dependencies = [
"transpose 0.2.1",
]
[[package]]
name = "indexmap"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "inflate"
version = "0.4.5"
@ -1130,12 +910,6 @@ dependencies = [
"web-sys",
]
[[package]]
name = "ipnet"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b"
[[package]]
name = "itoa"
version = "0.4.8"
@ -1278,12 +1052,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "mime"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@ -1320,24 +1088,6 @@ dependencies = [
"getrandom",
]
[[package]]
name = "native-tls"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
dependencies = [
"lazy_static",
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]]
name = "ndk"
version = "0.5.0"
@ -1594,51 +1344,6 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b10983b38c53aebdf33f542c6275b0f58a238129d00c4ae0e6fb59738d783ca"
[[package]]
name = "openssl"
version = "0.10.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e"
dependencies = [
"bitflags",
"cfg-if 1.0.0",
"foreign-types",
"libc",
"once_cell",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0"
dependencies = [
"autocfg",
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "osmesa-sys"
version = "0.1.2"
@ -1737,12 +1442,6 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.25"
@ -1873,66 +1572,6 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "reqwest"
version = "0.11.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb"
dependencies = [
"base64",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http",
"http-body",
"hyper",
"hyper-tls",
"ipnet",
"js-sys",
"lazy_static",
"log",
"mime",
"native-tls",
"percent-encoding",
"pin-project-lite",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
"tokio-native-tls",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"winreg",
]
[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [
"cc",
"libc",
"once_cell",
"spin 0.5.2",
"untrusted",
"web-sys",
"winapi 0.3.9",
]
[[package]]
name = "rustdct"
version = "0.4.0"
@ -1955,18 +1594,6 @@ dependencies = [
"transpose 0.1.0",
]
[[package]]
name = "rustls"
version = "0.20.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033"
dependencies = [
"log",
"ring",
"sct",
"webpki",
]
[[package]]
name = "ryu"
version = "1.0.10"
@ -1982,16 +1609,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "schannel"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2"
dependencies = [
"lazy_static",
"windows-sys",
]
[[package]]
name = "scoped-tls"
version = "1.0.0"
@ -2022,39 +1639,6 @@ dependencies = [
"winapi 0.2.8",
]
[[package]]
name = "sct"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "security-framework"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc"
dependencies = [
"bitflags",
"core-foundation 0.9.3",
"core-foundation-sys 0.8.3",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
dependencies = [
"core-foundation-sys 0.8.3",
"libc",
]
[[package]]
name = "serde"
version = "1.0.137"
@ -2086,18 +1670,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
dependencies = [
"form_urlencoded",
"itoa 1.0.2",
"ryu",
"serde",
]
[[package]]
name = "shared_library"
version = "0.1.9"
@ -2108,21 +1680,6 @@ dependencies = [
"libc",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32"
[[package]]
name = "slotmap"
version = "1.0.6"
@ -2157,22 +1714,6 @@ dependencies = [
"wayland-protocols",
]
[[package]]
name = "socket2"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.3"
@ -2208,17 +1749,13 @@ dependencies = [
"csv",
"eframe",
"egui_extras",
"ehttp",
"futures",
"image 0.24.2",
"img_hash",
"rand",
"reqwest",
"scrap",
"serde",
"serde_json",
"time",
"tokio",
]
[[package]]
@ -2232,20 +1769,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tempfile"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if 1.0.0",
"fastrand",
"libc",
"redox_syscall",
"remove_dir_all",
"winapi 0.3.9",
]
[[package]]
name = "thiserror"
version = "1.0.31"
@ -2312,61 +1835,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395"
dependencies = [
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"once_cell",
"parking_lot 0.12.0",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi 0.3.9",
]
[[package]]
name = "tokio-macros"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c"
dependencies = [
"bytes",
"futures-core",
"futures-sink",
"pin-project-lite",
"tokio",
"tracing",
]
[[package]]
name = "toml"
version = "0.5.9"
@ -2376,12 +1844,6 @@ dependencies = [
"serde",
]
[[package]]
name = "tower-service"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
[[package]]
name = "tracing"
version = "0.1.34"
@ -2430,12 +1892,6 @@ dependencies = [
"strength_reduce",
]
[[package]]
name = "try-lock"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "ttf-parser"
version = "0.15.0"
@ -2463,29 +1919,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "ureq"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9399fa2f927a3d327187cbd201480cee55bee6ac5d3c77dd27f0c6814cff16d5"
dependencies = [
"base64",
"chunked_transfer",
"flate2",
"log",
"once_cell",
"rustls",
"url",
"webpki",
"webpki-roots",
]
[[package]]
name = "url"
version = "2.2.2"
@ -2498,12 +1931,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.4"
@ -2521,16 +1948,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "want"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0"
dependencies = [
"log",
"try-lock",
]
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
@ -2716,25 +2133,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "webpki"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf"
dependencies = [
"webpki",
]
[[package]]
name = "weezl"
version = "0.1.6"
@ -2869,15 +2267,6 @@ dependencies = [
"x11-dl",
]
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "x11-dl"
version = "2.19.1"

View File

@ -9,17 +9,12 @@ edition = "2021"
eframe = "0.18"
egui_extras = { version = "0.18", features = ["image"] }
ehttp = "0.2"
image = { version = "0.24" }
scrap = "0.5"
anyhow = "1.0"
futures = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.11", features = ["json"] }
img_hash = "3"

View File

@ -13,11 +13,12 @@ use scrap::{Capturer, Display};
use crate::{
capture,
config::Config,
image_processing::{self, extract_and_filter, hash_image, Region, to_png_bytes},
state::{AppState, DebugOcrFrame, LapState, RaceState, SharedAppState}, learned_tracks::get_track_hash, ocr_db::OcrDatabase,
image_processing::{self, extract_and_filter, hash_image, to_png_bytes, Region},
learned_tracks::get_track_hash,
ocr_db::OcrDatabase,
state::{AppState, DebugOcrFrame, LapState, RaceState, SharedAppState},
};
fn is_finished_lap(state: &AppState, frame: &LapState) -> bool {
if let Some(race) = &state.current_race {
if let Some(last_finish) = &race.last_lap_record_time {
@ -69,7 +70,9 @@ fn handle_new_frame(state: &mut AppState, frame: LapState, image: RgbImage) {
if state.current_race.is_none() {
let track_hash = get_track_hash(state.config.as_ref(), &image);
let track_name = state.learned_tracks.infer_track(&track_hash, state.config.as_ref());
let track_name = state
.learned_tracks
.infer_track(&track_hash, state.config.as_ref());
let inferred_track = track_name.is_some();
let race = RaceState {
screencap: Some(
@ -181,7 +184,7 @@ fn run_loop_once(capturer: &mut Capturer, state: &SharedAppState) -> Result<()>
(
locked.ocr_db.clone(),
locked.config.clone(),
locked.should_sample_ocr_data
locked.should_sample_ocr_data,
)
};
let ocr_results = ocr_all_regions(ocr_db.as_ref(), &frame, config.as_ref(), should_sample);

View File

@ -1,7 +1,7 @@
use std::{time::Duration, thread};
use std::{thread, time::Duration};
use anyhow::Result;
use image::{RgbImage, Rgb};
use image::{Rgb, RgbImage};
use scrap::Capturer;
fn get_raw_frame(capturer: &mut Capturer) -> Result<Vec<u8>> {
@ -35,7 +35,6 @@ pub fn get_frame(capturer: &mut Capturer) -> Result<RgbImage> {
Rgb([frame[i + 2], frame[i + 1], frame[i]]),
);
}
}
Ok(image)
}

View File

@ -1,40 +1,40 @@
use std::{path::PathBuf};
use anyhow::Result;
use serde::{Serialize, Deserialize, de::DeserializeOwned};
use crate::image_processing::Region;
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct Config {
pub ocr_regions: Vec<Region>,
pub track_region: Option<Region>,
pub ocr_interval_ms: Option<u64>,
pub track_recognition_threshold: Option<u32>,
pub dump_frame_fraction: Option<f64>,
}
impl Config {
pub fn load() -> Result<Self> {
load_config_or_make_default("config.json", include_str!("configs/config.default.json"))
}
}
pub fn load_config_or_make_default<T: DeserializeOwned>(path: &str, default: &str) -> Result<T> {
let file_path = PathBuf::from(path);
if !file_path.exists() {
std::fs::write(&path, default)?;
}
load_json_config(path)
}
fn load_json_config<T: DeserializeOwned>(path: &str) -> Result<T> {
let data = std::fs::read(path)?;
let value = serde_json::from_slice(&data)?;
Ok(value)
}
pub fn save_json_config<T: Serialize>(path: &str, val: &T) -> Result<()> {
let serialized = serde_json::to_vec_pretty(val)?;
Ok(std::fs::write(path, &serialized)?)
}
use std::path::PathBuf;
use anyhow::Result;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use crate::image_processing::Region;
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct Config {
pub ocr_regions: Vec<Region>,
pub track_region: Option<Region>,
pub ocr_interval_ms: Option<u64>,
pub track_recognition_threshold: Option<u32>,
pub dump_frame_fraction: Option<f64>,
}
impl Config {
pub fn load() -> Result<Self> {
load_config_or_make_default("config.json", include_str!("configs/config.default.json"))
}
}
pub fn load_config_or_make_default<T: DeserializeOwned>(path: &str, default: &str) -> Result<T> {
let file_path = PathBuf::from(path);
if !file_path.exists() {
std::fs::write(&path, default)?;
}
load_json_config(path)
}
fn load_json_config<T: DeserializeOwned>(path: &str) -> Result<T> {
let data = std::fs::read(path)?;
let value = serde_json::from_slice(&data)?;
Ok(value)
}
pub fn save_json_config<T: Serialize>(path: &str, val: &T) -> Result<()> {
let serialized = serde_json::to_vec_pretty(val)?;
Ok(std::fs::write(path, &serialized)?)
}

View File

@ -107,6 +107,6 @@ pub fn hash_image(image: &RgbImage) -> ImageHash {
let have_to_use_other_image_library_version =
img_hash::image::RgbImage::from_raw(image.width(), image.height(), image.as_raw().to_vec())
.unwrap();
hasher.hash_image(&have_to_use_other_image_library_version)
}

View File

@ -1,12 +1,14 @@
use std::{collections::HashMap, sync::Arc};
use crate::{config::{load_config_or_make_default, save_json_config, Config}, image_processing::{extract_and_filter, hash_image}};
use crate::{
config::{load_config_or_make_default, save_json_config, Config},
image_processing::{extract_and_filter, hash_image},
};
use anyhow::Result;
use image::RgbImage;
use img_hash::ImageHash;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct LearnedTracks {
@ -26,8 +28,9 @@ impl LearnedTracks {
for (learned_hash_b64, learned_track) in &self.learned_tracks {
let learned_hash: ImageHash<Vec<u8>> = ImageHash::from_base64(learned_hash_b64).ok()?;
let current_hash: ImageHash<Vec<u8>> = ImageHash::from_base64(hash).ok()?;
if current_hash.dist(&learned_hash) <= config.track_recognition_threshold.unwrap_or(10) {
return Some(learned_track.to_owned())
if current_hash.dist(&learned_hash) <= config.track_recognition_threshold.unwrap_or(10)
{
return Some(learned_track.to_owned());
}
}
None

View File

@ -4,12 +4,12 @@ mod analysis;
mod capture;
mod config;
mod image_processing;
mod learned_tracks;
mod ocr;
mod ocr_db;
mod state;
mod stats_writer;
mod training_ui;
mod learned_tracks;
mod ocr_db;
use std::{
collections::HashMap,
@ -228,12 +228,7 @@ fn show_race_state(
}
if ui.button("Debug").clicked() {
open_debug_lap(
ui_state,
ocr_db,
lap,
config,
)
open_debug_lap(ui_state, ocr_db, lap, config)
}
ui.end_row();
@ -278,12 +273,7 @@ fn show_config_controls(ui: &mut Ui, ui_state: &mut UiState, state: &mut AppStat
}
}
fn open_debug_lap(
ui_state: &mut UiState,
ocr_db: &OcrDatabase,
lap: &LapState,
config: &Config,
) {
fn open_debug_lap(ui_state: &mut UiState, ocr_db: &OcrDatabase, lap: &LapState, config: &Config) {
if let Some(screenshot_bytes) = &lap.screenshot {
let screenshot = from_png_bytes(screenshot_bytes);
let ocr_results = analysis::ocr_all_regions(ocr_db, &screenshot, config, false);
@ -440,7 +430,9 @@ impl eframe::App for AppUi {
if ui.button("Export").clicked() {
if let Some(track_hash) = &race.track_hash {
if !race.inferred_track {
learned_tracks.learn_and_save(track_hash, &race.track).unwrap();
learned_tracks
.learn_and_save(track_hash, &race.track)
.unwrap();
}
}
match export_race_stats(race) {

View File

@ -115,15 +115,23 @@ fn test_ocr() {
serde_json::from_str(include_str!("configs/ocr.default.json")).unwrap();
let db: OcrDatabase = (&raw).into();
let image = image::load_from_memory(include_bytes!("test_data/test-image-3.png")).unwrap().to_rgb8();
let image = image::load_from_memory(include_bytes!("test_data/test-image-3.png"))
.unwrap()
.to_rgb8();
assert_eq!(db.ocr_image(&image), "00:30.625");
let image = image::load_from_memory(include_bytes!("test_data/test-image-4.png")).unwrap().to_rgb8();
let image = image::load_from_memory(include_bytes!("test_data/test-image-4.png"))
.unwrap()
.to_rgb8();
assert_eq!(db.ocr_image(&image), "00:20.296");
let image = image::load_from_memory(include_bytes!("test_data/test-image-num-1.png")).unwrap().to_rgb8();
let image = image::load_from_memory(include_bytes!("test_data/test-image-num-1.png"))
.unwrap()
.to_rgb8();
assert_eq!(db.ocr_image(&image), "1");
let image = image::load_from_memory(include_bytes!("test_data/test-image-blank.png")).unwrap().to_rgb8();
let image = image::load_from_memory(include_bytes!("test_data/test-image-blank.png"))
.unwrap()
.to_rgb8();
assert_eq!(db.ocr_image(&image), "");
}

View File

@ -1,12 +1,15 @@
use std::{sync::{Arc, Mutex}, time::{Duration, Instant, SystemTime}, collections::{HashMap, VecDeque}};
use std::{
collections::{HashMap, VecDeque},
sync::{Arc, Mutex},
time::{Duration, Instant, SystemTime},
};
use egui_extras::RetainedImage;
use image::RgbImage;
use time::{OffsetDateTime, format_description};
use time::{format_description, OffsetDateTime};
use crate::{config::Config, learned_tracks::LearnedTracks, ocr_db::OcrDatabase};
#[derive(Debug, Clone, Default)]
pub struct LapState {
pub lap: Option<usize>,
@ -17,7 +20,7 @@ pub struct LapState {
pub best_time: Option<Duration>,
pub lap_time: Option<Duration>,
pub striked: bool,
pub screenshot: Option<Vec<u8>>,
pub debug: bool,
@ -91,7 +94,7 @@ pub struct RaceState {
pub car: String,
pub track: String,
pub comments: String,
pub inferred_track: bool,
}
@ -99,7 +102,9 @@ impl RaceState {
pub fn name(&self) -> String {
let race_time = self.race_time.unwrap_or_else(SystemTime::now);
let race_time: OffsetDateTime = race_time.into();
let mut name = race_time.format(&format_description::parse("[year]-[month]-[day]-[hour]:[minute]").unwrap()).unwrap();
let mut name = race_time
.format(&format_description::parse("[year]-[month]-[day]-[hour]:[minute]").unwrap())
.unwrap();
if !self.track.is_empty() {
name += &format!(" ({})", self.track);
}
@ -146,4 +151,4 @@ pub struct AppState {
pub ocr_db: Arc<OcrDatabase>,
}
pub type SharedAppState = Arc<Mutex<AppState>>;
pub type SharedAppState = Arc<Mutex<AppState>>;

View File

@ -1,58 +1,52 @@
use std::{
io::BufWriter,
time::{Duration},
};
use crate::state::RaceState;
use anyhow::Result;
pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
let race_name = race_stats.name();
let file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open("race_stats.csv")?;
let writer = BufWriter::new(file);
let mut csv_writer = csv::Writer::from_writer(writer);
let fastest_lap = race_stats.fastest_lap();
for lap in &race_stats.laps {
if lap.striked {
continue;
}
csv_writer.write_record(vec![
race_name.clone(),
race_stats.track.clone(),
race_stats.car.clone(),
lap.lap
.map(|x| x.to_string())
.unwrap_or_else(|| "?".to_owned()),
format!(
"{:.3}",
lap.lap_time.unwrap_or(Duration::from_secs(0)).as_secs_f64()
),
format!(
"{:.3}",
fastest_lap
.unwrap_or(Duration::from_secs(0))
.as_secs_f64()
),
lap.health
.map(|x| x.to_string())
.unwrap_or_else(|| "".to_owned()),
lap.gas
.map(|x| x.to_string())
.unwrap_or_else(|| "".to_owned()),
lap.tyres
.map(|x| x.to_string())
.unwrap_or_else(|| "".to_owned()),
race_stats.comments.clone(),
])?;
}
Ok(())
}
use std::{io::BufWriter, time::Duration};
use crate::state::RaceState;
use anyhow::Result;
pub fn export_race_stats(race_stats: &mut RaceState) -> Result<()> {
let race_name = race_stats.name();
let file = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open("race_stats.csv")?;
let writer = BufWriter::new(file);
let mut csv_writer = csv::Writer::from_writer(writer);
let fastest_lap = race_stats.fastest_lap();
for lap in &race_stats.laps {
if lap.striked {
continue;
}
csv_writer.write_record(vec![
race_name.clone(),
race_stats.track.clone(),
race_stats.car.clone(),
lap.lap
.map(|x| x.to_string())
.unwrap_or_else(|| "?".to_owned()),
format!(
"{:.3}",
lap.lap_time.unwrap_or(Duration::from_secs(0)).as_secs_f64()
),
format!(
"{:.3}",
fastest_lap.unwrap_or(Duration::from_secs(0)).as_secs_f64()
),
lap.health
.map(|x| x.to_string())
.unwrap_or_else(|| "".to_owned()),
lap.gas
.map(|x| x.to_string())
.unwrap_or_else(|| "".to_owned()),
lap.tyres
.map(|x| x.to_string())
.unwrap_or_else(|| "".to_owned()),
race_stats.comments.clone(),
])?;
}
Ok(())
}

View File

@ -1,6 +1,4 @@
use std::{
path::{PathBuf},
};
use std::path::PathBuf;
use eframe::{
egui::{self, Visuals},
@ -111,11 +109,15 @@ impl eframe::App for TrainingUi {
current_image.save_ocr_text();
}
if ui.button("Learn").clicked() {
self.ocr_db.learn_phrase(&current_image.char_hashes, &current_image.text).unwrap();
self.ocr_db
.learn_phrase(&current_image.char_hashes, &current_image.text)
.unwrap();
self.current_image_index += 1;
}
if ui.button("Learn and delete").clicked() {
self.ocr_db.learn_phrase(&current_image.char_hashes, &current_image.text).unwrap();
self.ocr_db
.learn_phrase(&current_image.char_hashes, &current_image.text)
.unwrap();
current_image.delete_data();
self.current_image_index += 1;
}

View File

@ -1,10 +1,13 @@
- Recognize
- Penalties
- Pit stops
- [DONE] ComboBox for car/track
- [DONE] Global best time not current best
- Best time from other racers
- Editable lap stats
- [DONE] Don't store uncompressed data for lap debugging
- Autocomplete for car/track
- Detect car name from load screen
- Detect car name from load screen
- TTS for pit strategies
- Detect position, max laps
- Re-do debug/learn functionality
- [DONE] ComboBox for car/track
- [DONE] Global best time not current best
- [DONE] Don't store uncompressed data for lap debugging