commit 3c83dfb07e9879c63b902500b7f23c8a0ae6b22a Author: Nils Pukropp Date: Sat Mar 14 21:31:12 2026 +0100 init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b77b569 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM rust:1.85 as builder +WORKDIR /app +COPY backend ./backend +COPY ayto ./ayto +WORKDIR /app/backend +RUN cargo build --release + +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* +WORKDIR /app +# We need to run the binary from a directory that has ../ayto relative to it +RUN mkdir /app/backend_run +COPY --from=builder /app/backend/target/release/backend /app/backend_run/backend +COPY --from=builder /app/ayto /app/ayto +WORKDIR /app/backend_run +EXPOSE 8080 +CMD ["./backend"] diff --git a/ayto/favicon.ico b/ayto/favicon.ico new file mode 100644 index 0000000..4357deb Binary files /dev/null and b/ayto/favicon.ico differ diff --git a/ayto/index.html b/ayto/index.html new file mode 100644 index 0000000..1e06e5f --- /dev/null +++ b/ayto/index.html @@ -0,0 +1,660 @@ + + + + + + Are You The One? Calculator + + + + + + + + + + + + + + + +
+ + +
+ + +
+ +
+

Are You The One? Calculator

+

Find the remaining possibilities and probabilities for your season.

+
+ + + + + + + + +
+ +
+ +
+

1. Setup Contestants

+
+
+ + +
+
+ + +
+
+ + + + +
+ + +
+ + + +

+
+ + + + + + +
+ + +
+ + + + + +
+
+
+ + + + \ No newline at end of file diff --git a/ayto/index.html.bak b/ayto/index.html.bak new file mode 100644 index 0000000..375ff0f --- /dev/null +++ b/ayto/index.html.bak @@ -0,0 +1,698 @@ + + + + + + Are You The One? Calculator (Catppuccin) + + + + + + + + + + + + + + + + + +
+

Loading Python runtime...

+
+ + +
+ + +
+

Are You The One? Calculator

+

Find the remaining possibilities and probabilities for your season.

+
+ + + + + + + + +
+ + +
+ + +
+

1. Setup Contestants

+
+
+ + +
+
+ + +
+
+ +

+
+ + + + + + + +
+ + +
+ + + + + +
+
+
+ + + + diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1 @@ +/target diff --git a/backend/Cargo.lock b/backend/Cargo.lock new file mode 100644 index 0000000..7de660c --- /dev/null +++ b/backend/Cargo.lock @@ -0,0 +1,708 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +dependencies = [ + "axum-core", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "backend" +version = "0.1.0" +dependencies = [ + "axum", + "rayon", + "serde", + "serde_json", + "tokio", + "tower-http", +] + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "http-range-header" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "bytes", + "http", + "http-body", + "hyper", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rayon" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "http-range-header", + "httpdate", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/backend/Cargo.toml b/backend/Cargo.toml new file mode 100644 index 0000000..5faf63a --- /dev/null +++ b/backend/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "backend" +version = "0.1.0" +edition = "2024" + +[dependencies] +axum = "0.8.8" +rayon = "1.11.0" +serde = { version = "1.0.228", features = ["derive"] } +serde_json = "1.0.149" +tokio = { version = "1.50.0", features = ["full"] } +tower-http = { version = "0.6.8", features = ["cors", "fs"] } diff --git a/backend/src/main.rs b/backend/src/main.rs new file mode 100644 index 0000000..c58d686 --- /dev/null +++ b/backend/src/main.rs @@ -0,0 +1,259 @@ +use axum::{ + extract::State, + routing::{get, post}, + Json, Router, +}; +use rayon::prelude::*; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::sync::Arc; +use tower_http::cors::{Any, CorsLayer}; +use tower_http::services::{ServeDir, ServeFile}; + +#[derive(Deserialize, Debug)] +struct TruthBooth { + p1: String, // from group 1 + p2: String, // from group 2 + match_: bool, +} + +#[derive(Deserialize, Debug)] +struct Ceremony { + pairs: HashMap, // p1 -> p2 + beams: usize, +} + +#[derive(Deserialize, Debug)] +struct SolveRequest { + group1: Vec, + group2: Vec, + truth_booths: Vec, + ceremonies: Vec, +} + +#[derive(Serialize)] +struct GridData { + index: Vec, + columns: Vec, + data: Vec>, +} + +#[derive(Serialize)] +struct SolveResponse { + possibilities: usize, + grid_data: GridData, +} + +struct Solver { + n: usize, + m: usize, + allowed: Vec, // bitmask of allowed g1 for each g2 + ceremonies: Vec<(Vec<(usize, usize)>, usize)>, +} + +impl Solver { + fn new(req: &SolveRequest) -> Result<(Self, HashMap, HashMap), String> { + let n = req.group1.len(); + let m = req.group2.len(); + + if n > m { + return Err("Group 1 cannot be larger than Group 2".to_string()); + } + if n > 32 { + return Err("Group 1 size too large".to_string()); // fit in u32 + } + + let mut g1_map = HashMap::new(); + for (i, name) in req.group1.iter().enumerate() { + g1_map.insert(name.clone(), i); + } + + let mut g2_map = HashMap::new(); + for (i, name) in req.group2.iter().enumerate() { + g2_map.insert(name.clone(), i); + } + + let mut allowed = vec![(1 << n) - 1; m]; + + for tb in &req.truth_booths { + let g1_idx = *g1_map.get(&tb.p1).ok_or("Invalid p1 in TB")?; + let g2_idx = *g2_map.get(&tb.p2).ok_or("Invalid p2 in TB")?; + + if tb.match_ { + allowed[g2_idx] = 1 << g1_idx; + } else { + allowed[g2_idx] &= !(1 << g1_idx); + } + } + + let mut ceremonies = Vec::new(); + for c in &req.ceremonies { + let mut pairs = Vec::new(); + for (p1, p2) in &c.pairs { + let g1_idx = *g1_map.get(p1).ok_or("Invalid p1 in ceremony")?; + let g2_idx = *g2_map.get(p2).ok_or("Invalid p2 in ceremony")?; + pairs.push((g2_idx, g1_idx)); + } + ceremonies.push((pairs, c.beams)); + } + + Ok((Solver { + n, + m, + allowed, + ceremonies, + }, g1_map, g2_map)) + } + + fn solve(&self) -> (usize, Vec>) { + // We will generate combinations using a parallel recursive approach. + // A full state is an array of size M, where A[g2] = g1. + // To parallelize, we generate all valid prefixes of length `prefix_len`. + let prefix_len = self.m.min(4); // generate up to length 4 sequentially, then parallelize + + let mut prefixes = Vec::new(); + self.generate_prefixes(0, 0, 0, &mut Vec::new(), prefix_len, &mut prefixes); + + let results: Vec<(usize, Vec>)> = prefixes.into_par_iter().map(|(mask_used, mut prefix)| { + let mut counts = vec![vec![0; self.m]; self.n]; + let mut valid_count = 0; + self.dfs(prefix_len, mask_used, &mut prefix, &mut valid_count, &mut counts); + (valid_count, counts) + }).collect(); + + let mut total_valid = 0; + let mut total_counts = vec![vec![0; self.m]; self.n]; + + for (v_count, counts) in results { + total_valid += v_count; + for i in 0..self.n { + for j in 0..self.m { + total_counts[i][j] += counts[i][j]; + } + } + } + + (total_valid, total_counts) + } + + fn generate_prefixes(&self, g2_idx: usize, mask_used: u32, current_allowed: u32, current: &mut Vec, target_len: usize, out: &mut Vec<(u32, Vec)>) { + if g2_idx == target_len { + out.push((mask_used, current.clone())); + return; + } + + let mut allowed = self.allowed[g2_idx]; + + // Minor optimization: if we have (M - g2_idx) elements left, and we need to cover (N - bits_set) elements, + // we can prune if it's impossible. + let needed = self.n as u32 - mask_used.count_ones(); + let remaining = (self.m - g2_idx) as u32; + if needed > remaining { + return; // cannot form surjective mapping + } + + while allowed > 0 { + let bit = allowed & (!allowed + 1); // get lowest set bit + allowed &= !bit; + let g1_idx = bit.trailing_zeros() as usize; + + current.push(g1_idx); + self.generate_prefixes(g2_idx + 1, mask_used | bit, 0, current, target_len, out); + current.pop(); + } + } + + fn dfs(&self, g2_idx: usize, mask_used: u32, current: &mut Vec, valid_count: &mut usize, counts: &mut Vec>) { + if g2_idx == self.m { + if mask_used.count_ones() as usize != self.n { + return; + } + + // Check ceremonies + for (pairs, beams) in &self.ceremonies { + let mut actual_beams = 0; + for &(g2, g1) in pairs { + if current[g2] == g1 { + actual_beams += 1; + } + } + if actual_beams != *beams { + return; + } + } + + // Valid scenario + *valid_count += 1; + for (g2, &g1) in current.iter().enumerate() { + counts[g1][g2] += 1; + } + return; + } + + let needed = self.n as u32 - mask_used.count_ones(); + let remaining = (self.m - g2_idx) as u32; + if needed > remaining { + return; + } + + let mut allowed = self.allowed[g2_idx]; + + // To aggressively prune with ceremonies, if we are at the end of checking pairs, but that's complex since we evaluate g2 sequentially. + // It's usually fast enough to just prune at the leaf for M=11. + + while allowed > 0 { + let bit = allowed & (!allowed + 1); + allowed &= !bit; + let g1_idx = bit.trailing_zeros() as usize; + + current.push(g1_idx); + self.dfs(g2_idx + 1, mask_used | bit, current, valid_count, counts); + current.pop(); + } + } +} + +async fn solve_handler(Json(payload): Json) -> Result, axum::http::StatusCode> { + // We process the solve in a blocking thread to avoid blocking the async runtime + let (solver, _g1_map, _g2_map) = Solver::new(&payload).map_err(|_| axum::http::StatusCode::BAD_REQUEST)?; + + let (total, counts) = tokio::task::spawn_blocking(move || { + solver.solve() + }).await.unwrap(); + + let mut data = vec![vec![0.0; payload.group2.len()]; payload.group1.len()]; + if total > 0 { + for i in 0..payload.group1.len() { + for j in 0..payload.group2.len() { + data[i][j] = counts[i][j] as f64 / total as f64; + } + } + } + + Ok(Json(SolveResponse { + possibilities: total, + grid_data: GridData { + index: payload.group1, + columns: payload.group2, + data, + }, + })) +} + +#[tokio::main] +async fn main() { + let cors = CorsLayer::new() + .allow_origin(Any) + .allow_methods(Any) + .allow_headers(Any); + + let app = Router::new() + .route("/api/solve", post(solve_handler)) + .fallback_service(ServeDir::new("../ayto").fallback(ServeFile::new("../ayto/index.html"))) + .layer(cors); + + let addr = "0.0.0.0:8080"; + println!("Starting server on {}", addr); + let listener = tokio::net::TcpListener::bind(addr).await.unwrap(); + axum::serve(listener, app).await.unwrap(); +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..15e0df4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +networks: + narl: + external: true + +services: + ayto-calculator: + build: . + restart: unless-stopped + networks: + - narl + labels: + - "traefik.enable=true" + # Listen on the domain ayto.narl.io + - "traefik.http.routers.ayto.rule=Host(`ayto.narl.io`)" + - "traefik.http.routers.ayto.entrypoints=websecure" + - "traefik.http.routers.ayto.tls.certresolver=https_resolver" + # The Rust backend listens on port 8080 inside the container + - "traefik.http.services.ayto.loadbalancer.server.port=8080"