5 Commits

Author SHA1 Message Date
Lukas Wölfer
33180e95a3 Worked on fetching 2025-08-12 21:03:49 +02:00
Lukas Wölfer
f37ca5e627 Made watchdog less verbose 2025-08-01 16:21:31 +02:00
Lukas Wölfer
7ee8fb23d9 Added signature, official v0.1.0 2025-07-24 19:07:48 +02:00
Lukas Wölfer
8172d4c769 First working version of creation and update watchdog 2025-07-24 19:02:10 +02:00
Lukas Wölfer
29e85397a7 Worked on safer fetching 2025-07-24 01:56:23 +02:00
10 changed files with 334 additions and 174 deletions

91
Cargo.lock generated
View File

@@ -161,8 +161,10 @@ checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
dependencies = [ dependencies = [
"android-tzdata", "android-tzdata",
"iana-time-zone", "iana-time-zone",
"js-sys",
"num-traits", "num-traits",
"serde", "serde",
"wasm-bindgen",
"windows-link", "windows-link",
] ]
@@ -272,19 +274,6 @@ dependencies = [
"syn 2.0.104", "syn 2.0.104",
] ]
[[package]]
name = "dancing-bot-teachers"
version = "0.1.0"
dependencies = [
"mwbot",
"reqwest",
"serde",
"thiserror 2.0.12",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.14.4" version = "0.14.4"
@@ -494,7 +483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@@ -568,6 +557,21 @@ dependencies = [
"new_debug_unreachable", "new_debug_unreachable",
] ]
[[package]]
name = "futures"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
version = "0.3.31" version = "0.3.31"
@@ -575,6 +579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink",
] ]
[[package]] [[package]]
@@ -583,6 +588,34 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-executor"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
[[package]]
name = "futures-macro"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
]
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.31" version = "0.3.31"
@@ -601,10 +634,16 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [ dependencies = [
"futures-channel",
"futures-core", "futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task", "futures-task",
"memchr",
"pin-project-lite", "pin-project-lite",
"pin-utils", "pin-utils",
"slab",
] ]
[[package]] [[package]]
@@ -1748,7 +1787,7 @@ dependencies = [
"once_cell", "once_cell",
"socket2", "socket2",
"tracing", "tracing",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@@ -2034,7 +2073,7 @@ dependencies = [
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@@ -2407,6 +2446,22 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "teachertracker-rs"
version = "0.1.2"
dependencies = [
"chrono",
"futures",
"mwbot",
"rand 0.9.2",
"reqwest",
"serde",
"thiserror 2.0.12",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.20.0" version = "3.20.0"
@@ -2417,7 +2472,7 @@ dependencies = [
"getrandom 0.3.3", "getrandom 0.3.3",
"once_cell", "once_cell",
"rustix", "rustix",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@@ -2989,7 +3044,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "dancing-bot-teachers" name = "teachertracker-rs"
version = "0.1.0" version = "0.1.2"
edition = "2024" edition = "2024"
authors = ["Lukas Wölfer <coding@thasky.one>"] authors = ["Lukas Wölfer <coding@thasky.one>"]
description = "A MediaWiki bot that updates score information of teachers" description = "A MediaWiki bot that updates score information of teachers"
@@ -11,7 +11,10 @@ keywords = ["mediawiki", "bot", "teacher", "score", "automation"]
categories = ["web-programming", "api-bindings", "automation"] categories = ["web-programming", "api-bindings", "automation"]
[dependencies] [dependencies]
chrono = "0.4.41"
futures = "0.3.31"
mwbot = { git = "https://gitlab.wikimedia.org/repos/mwbot-rs/mwbot.git", rev = "05cbb12188f18e2da710de158d89a9a4f1b42689", default-features = false, features = ["generators", "mwbot_derive"] } mwbot = { git = "https://gitlab.wikimedia.org/repos/mwbot-rs/mwbot.git", rev = "05cbb12188f18e2da710de158d89a9a4f1b42689", default-features = false, features = ["generators", "mwbot_derive"] }
rand = "0.9.2"
reqwest = "0.12.22" reqwest = "0.12.22"
serde = { version = "1.0.219", features = ["derive"] } serde = { version = "1.0.219", features = ["derive"] }
thiserror = "2.0.12" thiserror = "2.0.12"

View File

@@ -1,5 +1,3 @@
use std::collections::HashMap;
#[derive(serde::Deserialize, Debug, PartialEq, Eq)] #[derive(serde::Deserialize, Debug, PartialEq, Eq)]
pub enum DanceRole { pub enum DanceRole {
Leader, Leader,
@@ -48,35 +46,6 @@ impl DanceRank {
} }
} }
#[derive(serde::Deserialize, Debug)]
enum OptionalDanceRank {
#[serde(rename = "N/A")]
NotAvailable,
#[serde(untagged)]
Rank(DanceRank),
}
#[derive(serde::Deserialize, Debug)]
enum OptionalDancePoints {
#[serde(rename = "N/A")]
NotAvailable,
#[serde(untagged)]
Points(u16),
}
#[derive(serde::Deserialize, Debug)]
struct DanceInfoParser {
pub dancer_first: String,
pub dancer_last: String,
pub short_dominate_role: DanceRole,
#[allow(dead_code)]
pub short_non_dominate_role: DanceRole,
pub dominate_role_highest_level_points: u16,
pub dominate_role_highest_level: DanceRank,
pub non_dominate_role_highest_level_points: OptionalDancePoints,
pub non_dominate_role_highest_level: OptionalDanceRank,
}
#[derive(Debug)] #[derive(Debug)]
pub struct CompState { pub struct CompState {
pub rank: DanceRank, pub rank: DanceRank,
@@ -94,63 +63,4 @@ impl DanceInfo {
pub fn name(&self) -> String { pub fn name(&self) -> String {
format!("{} {}", self.firstname, self.lastname) format!("{} {}", self.firstname, self.lastname)
} }
#[allow(dead_code)]
pub const fn non_dominant_role(&self) -> DanceRole {
self.dominant_role.other()
}
}
impl From<DanceInfoParser> for DanceInfo {
fn from(value: DanceInfoParser) -> Self {
let non_dominant_role_comp = if let OptionalDanceRank::Rank(r) =
value.non_dominate_role_highest_level
&& let OptionalDancePoints::Points(l) = value.non_dominate_role_highest_level_points
{
Some(CompState { rank: r, points: l })
} else {
None
};
Self {
firstname: value.dancer_first,
lastname: value.dancer_last,
dominant_role: value.short_dominate_role,
dominant_role_comp: CompState {
rank: value.dominate_role_highest_level,
points: value.dominate_role_highest_level_points,
},
non_dominant_role_comp,
}
}
}
#[derive(thiserror::Error, Debug)]
pub enum DanceInfoError {
#[error("Failed to build client: {0}")]
ClientBuild(reqwest::Error),
#[error("Request error: {0}")]
Request(reqwest::Error),
#[error("Failed to parse response: {0}")]
JsonParse(reqwest::Error),
}
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
let client = reqwest::ClientBuilder::new()
.build()
.map_err(DanceInfoError::ClientBuild)?;
let mut params = HashMap::new();
params.insert("q", id.to_string());
let response = client
.request(
reqwest::Method::POST,
"https://points.worldsdc.com/lookup2020/find",
)
.form(&params)
.send()
.await
.map_err(DanceInfoError::Request)?;
let x: DanceInfoParser = response.json().await.map_err(DanceInfoError::JsonParse)?;
Ok(x.into())
} }

View File

@@ -17,13 +17,16 @@ use mwbot::{
Bot, Bot,
generators::{Generator, SortDirection, categories::CategoryMemberSort}, generators::{Generator, SortDirection, categories::CategoryMemberSort},
}; };
use std::{error::Error, path::Path}; use std::path::Path;
use crate::watchdog::watch_wanted; use crate::watchdog::watch_wanted;
mod dance_info; mod dance_info;
mod updater;
mod watchdog; mod watchdog;
mod wikiinfo; mod wikiinfo;
mod wikipage;
mod worldsdc;
#[allow(dead_code)] #[allow(dead_code)]
#[allow(clippy::print_stdout, reason = "We want to print here")] #[allow(clippy::print_stdout, reason = "We want to print here")]
@@ -38,12 +41,17 @@ fn list_teacher_pages(bot: &Bot) -> tokio::sync::mpsc::Receiver<Result<mwbot::Pa
pages.generate(bot) pages.generate(bot)
} }
fn main() -> Result<(), Box<dyn Error>> { #[must_use]
pub fn app_signature() -> String {
format!("{} [{}]", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
}
fn main() {
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_level(true) .with_level(true)
.with_max_level(tracing::Level::INFO) .with_max_level(tracing::Level::INFO)
.init(); .init();
tracing::info!("Starting {}", app_signature());
let rt = match tokio::runtime::Builder::new_current_thread() let rt = match tokio::runtime::Builder::new_current_thread()
.enable_all() .enable_all()
.build() .build()
@@ -51,7 +59,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(o) => o, Ok(o) => o,
Err(e) => { Err(e) => {
tracing::error!("Could not start runtime: {e}"); tracing::error!("Could not start runtime: {e}");
return Ok(()); return;
} }
}; };
rt.block_on(async { rt.block_on(async {
@@ -59,10 +67,9 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
dbg!(e); dbg!(e);
return Ok(()); return;
} }
}; };
watch_wanted(bot).await; futures::join!(watch_wanted(bot.clone()), updater::update_wsdc(bot));
Ok(()) });
})
} }

24
src/updater.rs Normal file
View File

@@ -0,0 +1,24 @@
use std::time::Duration;
use mwbot::Bot;
use rand::seq::SliceRandom as _;
use crate::{watchdog::generate_page, wikiinfo::index_wsdc_ids};
pub async fn update_wsdc(bot: Bot) -> ! {
loop {
let mut l = index_wsdc_ids(&bot).await;
l.shuffle(&mut rand::rng());
tracing::info!("We have to update {} pages", l.len());
let wait_duration = Duration::from_secs(6 * 3600);
for (index, page) in l {
tracing::info!("Next up: #{index}");
tokio::time::sleep(wait_duration).await;
if generate_page(index, page).await {
tracing::info!("Updated {index}");
} else {
tracing::error!("Error updating {index}");
}
}
}
}

View File

@@ -1,61 +1,27 @@
use std::time::Duration; use std::time::Duration;
use crate::{ use crate::app_signature;
dance_info::{DanceInfo, fetch_wsdc_info}, use crate::{wikiinfo::wanted_ids, wikipage::page_from_info, worldsdc::fetch_wsdc_info};
wikiinfo::wanted_ids, use mwbot::Bot;
}; use mwbot::SaveOptions;
use mwbot::{
Bot,
parsoid::{self, Template, Wikicode, map::IndexMap},
};
use mwbot::{SaveOptions, parsoid::WikinodeIterator};
use tracing::Level; use tracing::Level;
#[derive(thiserror::Error, Debug)] pub async fn watch_wanted(bot: Bot) -> ! {
enum InfoCompileError {
#[error("Could not compile wikipage: {0}")]
CompileError(#[from] parsoid::Error),
}
fn page_from_info(info: DanceInfo) -> Result<Wikicode, InfoCompileError> {
let mut params = IndexMap::new();
params.insert("name".to_string(), info.name());
params.insert(
"dominant_role".to_string(),
info.dominant_role.as_str().to_string(),
);
params.insert(
"allowed_rank".to_string(),
info.dominant_role_comp.rank.as_str().to_string(),
);
params.insert(
"dominant_rank".to_string(),
info.dominant_role_comp.rank.as_str().to_string(),
);
params.insert(
"dominant_points".to_string(),
info.dominant_role_comp.points.to_string(),
);
if let Some(u) = info.non_dominant_role_comp {
params.insert("non_dominant_rank".to_string(), u.rank.as_str().to_string());
params.insert("non_dominant_points".to_string(), u.points.to_string());
}
let t = Template::new("Template:WSDCBox", &params)?;
let result = Wikicode::new("");
result.append(&t);
Ok(result)
}
pub async fn watch_wanted(bot: Bot) {
let span = tracing::span!(Level::INFO, "wanted_watchdog"); let span = tracing::span!(Level::INFO, "wanted_watchdog");
let _enter = span.enter(); let _enter = span.enter();
let mut ignored_ids = vec![]; let mut ignored_ids = vec![];
let mut watch_count = 0;
loop { loop {
if ignored_ids.is_empty() { watch_count += 1;
tracing::info!("Watchdog check..."); if watch_count >= 120 {
watch_count = 0;
let failed_id_info = if ignored_ids.is_empty() {
String::new()
} else { } else {
tracing::info!("Watchdog check [{} failed ids]...", ignored_ids.len()); format!("[{} failed ids]", ignored_ids.len())
};
tracing::info!("Watchdog check{failed_id_info}...");
} }
let wanted = wanted_ids(bot.clone()).await; let wanted = wanted_ids(bot.clone()).await;
let mut new_ignored = vec![]; let mut new_ignored = vec![];
@@ -71,8 +37,8 @@ pub async fn watch_wanted(bot: Bot) {
} }
} }
async fn generate_page(id: u32, page: mwbot::Page) -> bool { pub async fn generate_page(id: u32, page: mwbot::Page) -> bool {
tracing::info!("Taking care of {id}"); tracing::info!("Generating page for {id}");
let info = match fetch_wsdc_info(id).await { let info = match fetch_wsdc_info(id).await {
Ok(o) => o, Ok(o) => o,
Err(e) => { Err(e) => {
@@ -91,7 +57,10 @@ async fn generate_page(id: u32, page: mwbot::Page) -> bool {
match page match page
.save( .save(
code, code,
&SaveOptions::summary("Created WSDC info from worldsdc.com") &SaveOptions::summary(&format!(
"Created WSDC info from worldsdc.com -- {}",
app_signature()
))
.mark_as_bot(true) .mark_as_bot(true)
.mark_as_minor(false), .mark_as_minor(false),
) )

View File

@@ -42,8 +42,20 @@ fn parse_wsdc_page_name(name: &str) -> Result<u32, TitleParseError> {
} }
} }
// fn get_wsdc_page_date(bot: &Bot, page: &Page) -> Option<SystemTime> {
// todo!();
// let prefix = "Updated-On: ";
// page.filter_comments()
// .iter()
// .filter_map(|x| {
// let c = x.text_contents();
// if c.starts_with(prefix) { Some(c) } else { None }
// })
// .map(|x| x.trim_start_matches(prefix).parse::<u64>());
// }
#[allow(dead_code)] #[allow(dead_code)]
pub async fn index_wsdc_ids(bot: &Bot) -> Vec<u32> { pub async fn index_wsdc_ids(bot: &Bot) -> Vec<(u32, Page)> {
let mut gene = Search::new("WSDC/").generate(bot); let mut gene = Search::new("WSDC/").generate(bot);
let mut result = vec![]; let mut result = vec![];
while let Some(x) = gene.recv().await { while let Some(x) = gene.recv().await {
@@ -55,7 +67,7 @@ pub async fn index_wsdc_ids(bot: &Bot) -> Vec<u32> {
} }
}; };
if let Ok(n) = parse_wsdc_page_name(p.title()) { if let Ok(n) = parse_wsdc_page_name(p.title()) {
result.push(n); result.push((n, p));
} }
} }
result result

38
src/wikipage.rs Normal file
View File

@@ -0,0 +1,38 @@
use crate::dance_info::DanceInfo;
use mwbot::parsoid::WikinodeIterator;
use mwbot::parsoid::{self, Template, Wikicode, map::IndexMap};
#[derive(thiserror::Error, Debug)]
pub enum InfoCompileError {
#[error("Could not compile wikipage: {0}")]
CompileError(#[from] parsoid::Error),
}
pub fn page_from_info(info: DanceInfo) -> Result<Wikicode, InfoCompileError> {
let mut params = IndexMap::new();
params.insert("name".to_string(), info.name());
params.insert(
"dominant_role".to_string(),
info.dominant_role.as_str().to_string(),
);
params.insert(
"allowed_rank".to_string(),
info.dominant_role_comp.rank.as_str().to_string(),
);
params.insert(
"dominant_rank".to_string(),
info.dominant_role_comp.rank.as_str().to_string(),
);
params.insert(
"dominant_points".to_string(),
info.dominant_role_comp.points.to_string(),
);
if let Some(u) = info.non_dominant_role_comp {
params.insert("non_dominant_rank".to_string(), u.rank.as_str().to_string());
params.insert("non_dominant_points".to_string(), u.points.to_string());
}
let t = Template::new("Template:WSDCBox", &params)?;
let result = Wikicode::new("");
result.append(&t);
Ok(result)
}

48
src/worldsdc/caching.rs Normal file
View File

@@ -0,0 +1,48 @@
use std::{collections::HashMap, path::Path};
use reqwest::{Client, ClientBuilder};
use crate::{dance_info::DanceInfo, worldsdc::DanceInfoError};
use super::DanceInfoParser;
struct CachingFetcher {
hitcache: Vec<(u32, String)>,
errorcache: Vec<(u32, String)>,
client: Client,
}
#[derive(thiserror::Error, Debug)]
enum CachingFetcherCreationError {
#[error("Could not create client: {0}")]
ClientError(#[from] reqwest::Error),
}
impl CachingFetcher {
pub fn new(cachepath: &Path) -> Result<Self, CachingFetcherCreationError> {
let client = ClientBuilder::new().build()?;
Ok(Self {
hitcache: vec![],
errorcache: vec![],
client,
})
}
pub async fn fetch(&mut self, id: u32) -> Result<DanceInfo, DanceInfoError> {
let mut params = HashMap::new();
params.insert("q", id.to_string());
let response = self
.client
.request(
reqwest::Method::POST,
"https://points.worldsdc.com/lookup2020/find",
)
.form(&params)
.send()
.await
.map_err(DanceInfoError::Request)?;
let x: DanceInfoParser = response.json().await.map_err(DanceInfoError::JsonParse)?;
Ok(x.into())
}
}

94
src/worldsdc/mod.rs Normal file
View File

@@ -0,0 +1,94 @@
use std::collections::HashMap;
use reqwest::ClientBuilder;
use crate::dance_info::{CompState, DanceInfo, DanceRank, DanceRole};
// mod caching;
pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
let client = ClientBuilder::new()
.build()
.map_err(DanceInfoError::ClientBuild)?;
let mut params = HashMap::new();
params.insert("num", id.to_string());
let request = client
.request(
reqwest::Method::POST,
"https://points.worldsdc.com/lookup2020/find",
)
.form(&params)
.build()
.map_err(DanceInfoError::RequestBuild)?;
let response = client
.execute(request)
.await
.map_err(DanceInfoError::Request)?;
let x: DanceInfoParser = response.json().await.map_err(DanceInfoError::JsonParse)?;
Ok(x.into())
}
#[derive(thiserror::Error, Debug)]
pub enum DanceInfoError {
#[error("Failed to build client: {0}")]
ClientBuild(reqwest::Error),
#[error("Failed to build request: {0}")]
RequestBuild(reqwest::Error),
#[error("Request error: {0}")]
Request(reqwest::Error),
#[error("Failed to parse response: {0}")]
JsonParse(reqwest::Error),
}
#[derive(serde::Deserialize, Debug)]
enum OptionalDanceRank {
#[serde(rename = "N/A")]
NotAvailable,
#[serde(untagged)]
Rank(DanceRank),
}
#[derive(serde::Deserialize, Debug)]
enum OptionalDancePoints {
#[serde(rename = "N/A")]
NotAvailable,
#[serde(untagged)]
Points(u16),
}
#[derive(serde::Deserialize, Debug)]
struct DanceInfoParser {
pub dancer_first: String,
pub dancer_last: String,
pub short_dominate_role: DanceRole,
#[allow(dead_code)]
pub short_non_dominate_role: DanceRole,
pub dominate_role_highest_level_points: u16,
pub dominate_role_highest_level: DanceRank,
pub non_dominate_role_highest_level_points: OptionalDancePoints,
pub non_dominate_role_highest_level: OptionalDanceRank,
}
impl From<DanceInfoParser> for DanceInfo {
fn from(value: DanceInfoParser) -> Self {
let non_dominant_role_comp = if let OptionalDanceRank::Rank(r) =
value.non_dominate_role_highest_level
&& let OptionalDancePoints::Points(l) = value.non_dominate_role_highest_level_points
{
Some(CompState { rank: r, points: l })
} else {
None
};
Self {
firstname: value.dancer_first,
lastname: value.dancer_last,
dominant_role: value.short_dominate_role,
dominant_role_comp: CompState {
rank: value.dominate_role_highest_level,
points: value.dominate_role_highest_level_points,
},
non_dominant_role_comp,
}
}
}