mirror of
https://codeberg.org/icewind/ugc-scaper.git
synced 2026-06-03 18:24:10 +02:00
wip
This commit is contained in:
parent
8dfd870f82
commit
766d0333cd
6 changed files with 65 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE matches SET map = $2, week = $3, format = $4, default_data = $5 WHERE id = $1",
|
||||
"query": "UPDATE matches SET map = $2, week = $3, format = $4, default_date = $5 WHERE id = $1",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
|
|
@ -21,5 +21,5 @@
|
|||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "037b9db0c5f69bce8930f7515a793e18b0018587dc476dedd4c756e88a2fa877"
|
||||
"hash": "7abd1664e5a53abd08cf3b437032218cac18e0dc2ca67aefa2d1cde6db125108"
|
||||
}
|
||||
|
|
@ -2,4 +2,5 @@ ALTER TABLE matches
|
|||
ADD COLUMN IF NOT EXISTS map VARCHAR,
|
||||
ADD COLUMN IF NOT EXISTS week INT,
|
||||
ADD COLUMN IF NOT EXISTS format game_mode,
|
||||
ADD COLUMN IF NOT EXISTS default_data DATE;
|
||||
ADD COLUMN IF NOT EXISTS default_date DATE,
|
||||
ADD COLUMN IF NOT EXISTS season INT;
|
||||
|
|
@ -9,10 +9,10 @@ use time::macros::format_description;
|
|||
use time::parsing::Parsed;
|
||||
use time::{Date, Duration};
|
||||
use tokio_stream::Stream;
|
||||
use tracing::{debug};
|
||||
use tracing::debug;
|
||||
use ugc_scraper_types::{
|
||||
Class, GameMode, MapHistory, MatchInfo, Membership, MembershipRole, NameChange, Player, Record,
|
||||
Region, RosterHistory, SteamID, Team,
|
||||
Region, RosterHistory, SteamID, Team, TeamSeason, TeamSeasonMatch,
|
||||
};
|
||||
|
||||
const MATCH_DATE_FORMAT: &[FormatItem<'static>] = format_description!(
|
||||
|
|
@ -560,7 +560,7 @@ impl Archive {
|
|||
let format = match_info.format.is_tf2().then_some(match_info.format);
|
||||
if let Some(date) = date {
|
||||
query!(
|
||||
"UPDATE matches SET map = $2, week = $3, format = $4, default_data = $5 WHERE id = $1",
|
||||
"UPDATE matches SET map = $2, week = $3, format = $4, default_date = $5 WHERE id = $1",
|
||||
id as i32,
|
||||
match_info.map,
|
||||
match_info.week as i32,
|
||||
|
|
@ -590,6 +590,49 @@ impl Archive {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_match_details_from_team_matches(
|
||||
&self,
|
||||
season: TeamSeason,
|
||||
) -> Result<(), ArchiveError> {
|
||||
let mut transaction = self
|
||||
.pool
|
||||
.begin()
|
||||
.await
|
||||
.map_err(|error| ArchiveError::Query {
|
||||
description: "beginning team matches transaction",
|
||||
error,
|
||||
})?;
|
||||
|
||||
for match_info in season.matches {
|
||||
if let Some(id) = match_info.result.match_id() {
|
||||
query!(
|
||||
"UPDATE matches SET map = $2, week = $3, format = $4, season = $5 WHERE id = $1",
|
||||
id as i32,
|
||||
match_info.map,
|
||||
match_info.week as i32,
|
||||
format as Option<GameMode>,
|
||||
date
|
||||
)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
.map_err(|error| ArchiveError::Query {
|
||||
description: "updating match",
|
||||
error,
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
transaction
|
||||
.commit()
|
||||
.await
|
||||
.map_err(|error| ArchiveError::Query {
|
||||
description: "commiting team matches transaction",
|
||||
error,
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_old_match_date(date: &str) -> Result<Date, time::Error> {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use serde::de::DeserializeOwned;
|
|||
use thiserror::Error;
|
||||
use ugc_scraper_types::{
|
||||
GameMode, MapHistory, MatchInfo, MembershipHistory, Player, RosterHistory, SteamID, Team,
|
||||
TeamRosterData, TeamSeasonMatch, Transaction,
|
||||
TeamRosterData, TeamSeason, TeamSeasonMatch, Transaction,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
@ -61,7 +61,7 @@ impl UgcClient {
|
|||
.map(|data| data.history)
|
||||
}
|
||||
|
||||
pub async fn get_team_matches(&self, id: u32) -> Result<Vec<TeamSeasonMatch>, UgcClientError> {
|
||||
pub async fn get_team_matches(&self, id: u32) -> Result<TeamSeason, UgcClientError> {
|
||||
self.send_request(Endpoint::TeamMatches { id }).await
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -220,8 +220,8 @@ async fn fixup_matches(client: &UgcClient, archive: &Archive) -> MainResult {
|
|||
while let Some(Ok(id)) = match_ids.next().await {
|
||||
let _span = span!(Level::INFO, "fixup_match", id = id).entered();
|
||||
let match_info = client.get_match(id).await?;
|
||||
let date = archive.get_match_date(&match_info).await?;
|
||||
if date.is_none()
|
||||
let date = None; // archive.get_match_date(&match_info).await?;
|
||||
if false && date.is_none()
|
||||
&& (match_info.format == GameMode::Highlander
|
||||
|| match_info.format == GameMode::Sixes
|
||||
|| match_info.format == GameMode::Fours
|
||||
|
|
|
|||
|
|
@ -281,6 +281,7 @@ pub struct TeamSeasonMatch {
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case", tag = "state"))]
|
||||
pub enum MatchResult {
|
||||
Played {
|
||||
id: u32,
|
||||
|
|
@ -299,6 +300,16 @@ pub enum MatchResult {
|
|||
ByeWeek,
|
||||
}
|
||||
|
||||
impl MatchResult {
|
||||
pub fn match_id(&self) -> Option<u32> {
|
||||
match self {
|
||||
MatchResult::Played { id, .. } => Some(*id),
|
||||
MatchResult::Pending { id, .. } => Some(*id),
|
||||
MatchResult::ByeWeek => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Seasons {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue