Skip to content

Commit

Permalink
remove unused game
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Aug 27, 2024
1 parent 325aba6 commit 39c5646
Show file tree
Hide file tree
Showing 11 changed files with 1,275 additions and 875 deletions.
1,632 changes: 1,011 additions & 621 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
mongodb = "2.8"
mongodb = "3.0"
futures = "0.3"
chrono = "0.4"
influxdb2 = "0.5"
influxdb2-structmap = "0.2"
num-traits = "0.2"
serde_json = "1.0"
log = "0.4"
flexi_logger = "0.27"
flexi_logger = "0.29"
serde_derive = "1.0"
questdb-rs = "3.1"
sqlx = { version = "0.7", features = ["runtime-tokio", "postgres", "time"] }
questdb-rs = "4.0"
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "time"] }
time = { version = "0.3", features = ["macros", "rand"] }
regex = "1.10"

[dependencies.clickhouse]
version = "0.11"
version = "0.12"
features = ["time"]

[dependencies.serde]
Expand Down Expand Up @@ -51,7 +51,7 @@ git = "https://github.com/community-network/grpc-rust"
branch = "main"

[dependencies.reqwest]
version = "0.11"
version = "0.12"
default-features = false
features = ["rustls-tls", "json"]

Expand Down
126 changes: 63 additions & 63 deletions src/connectors/clickhouse_db.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
use crate::structs::server_info;
use clickhouse::{Client, Row};
use serde::Serialize;
use time::OffsetDateTime;
// use crate::structs::server_info;
// use clickhouse::{Client, Row};
// use serde::Serialize;
// use time::OffsetDateTime;

#[derive(Row, Serialize)]
struct GameServer {
#[serde(with = "clickhouse::serde::time::datetime")]
timestamp: OffsetDateTime,
soldier_amount: u32,
queue_amount: u32,
game: String,
guid: Option<String>,
game_id: Option<String>,
server_name: String,
platform: String,
region: String,
mode: Option<String>,
map: Option<String>,
is_official: Option<bool>,
}
// #[derive(Row, Serialize)]
// struct GameServer {
// #[serde(with = "clickhouse::serde::time::datetime")]
// timestamp: OffsetDateTime,
// soldier_amount: u32,
// queue_amount: u32,
// game: String,
// guid: Option<String>,
// game_id: Option<String>,
// server_name: String,
// platform: String,
// region: String,
// mode: Option<String>,
// map: Option<String>,
// is_official: Option<bool>,
// }

pub async fn push_server(
frontend_game_name: &str,
region: &str,
platform: &str,
server_infos: Vec<server_info::ServerInfo>,
) -> anyhow::Result<()> {
let client = Client::default().with_url("http://100.76.59.110:8123");
let mut insert = client.insert("game_servers")?;
for server_info in server_infos {
if !server_info.name.is_empty() {
insert
.write(&GameServer {
timestamp: OffsetDateTime::now_utc(),
soldier_amount: server_info.soldiers as u32,
queue_amount: server_info.queue as u32,
game: frontend_game_name.to_owned(),
guid: match !server_info.guid.is_empty() {
true => Some(server_info.guid),
false => None,
},
game_id: match !server_info.game_id.is_empty() {
true => Some(server_info.game_id),
false => None,
},
server_name: server_info.name,
platform: platform.to_owned(),
region: region.to_owned(),
mode: match !server_info.mode.is_empty() {
true => Some(server_info.mode),
false => None,
},
map: match !server_info.map.is_empty() {
true => Some(server_info.map),
false => None,
},
is_official: server_info.is_official,
})
.await?;
}
}
insert.end().await?;
Ok(())
}
// pub async fn push_server(
// frontend_game_name: &str,
// region: &str,
// platform: &str,
// server_infos: Vec<server_info::ServerInfo>,
// ) -> anyhow::Result<()> {
// let client = Client::default().with_url("http://100.76.59.110:8123");
// let mut insert = client.insert("game_servers")?;
// for server_info in server_infos {
// if !server_info.name.is_empty() {
// insert
// .write(&GameServer {
// timestamp: OffsetDateTime::now_utc(),
// soldier_amount: server_info.soldiers as u32,
// queue_amount: server_info.queue as u32,
// game: frontend_game_name.to_owned(),
// guid: match !server_info.guid.is_empty() {
// true => Some(server_info.guid),
// false => None,
// },
// game_id: match !server_info.game_id.is_empty() {
// true => Some(server_info.game_id),
// false => None,
// },
// server_name: server_info.name,
// platform: platform.to_owned(),
// region: region.to_owned(),
// mode: match !server_info.mode.is_empty() {
// true => Some(server_info.mode),
// false => None,
// },
// map: match !server_info.map.is_empty() {
// true => Some(server_info.map),
// false => None,
// },
// is_official: server_info.is_official,
// })
// .await?;
// }
// }
// insert.end().await?;
// Ok(())
// }
190 changes: 95 additions & 95 deletions src/connectors/influx_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures::stream;
use influxdb2::models::{data_point::DataPointError, DataPoint};
use std::collections::HashMap;

use crate::structs::{results, server_info};
use crate::structs::results;

pub fn build_data_point(
frontend_game_name: &str,
Expand Down Expand Up @@ -312,100 +312,100 @@ pub async fn push_totals(
Ok(())
}

pub fn build_server_data_point(
frontend_game_name: &str,
data_type: &str,
server_info: &server_info::ServerInfo,
region: &str,
platform: &str,
field: &str,
amount: &i64,
) -> Result<DataPoint, DataPointError> {
let mut data_point = DataPoint::builder(frontend_game_name);
// pub fn build_server_data_point(
// frontend_game_name: &str,
// data_type: &str,
// server_info: &server_info::ServerInfo,
// region: &str,
// platform: &str,
// field: &str,
// amount: &i64,
// ) -> Result<DataPoint, DataPointError> {
// let mut data_point = DataPoint::builder(frontend_game_name);

data_point = match !server_info.guid.is_empty() {
true => data_point.field("guid", server_info.guid.clone()),
false => data_point,
};
data_point = match !server_info.game_id.is_empty() {
true => data_point.field("gameId", server_info.game_id.clone()),
false => data_point,
};
data_point = match server_info.is_official {
Some(result) => data_point.tag("isOfficial", result.to_string()),
None => data_point,
};
// data_point = match !server_info.guid.is_empty() {
// true => data_point.field("guid", server_info.guid.clone()),
// false => data_point,
// };
// data_point = match !server_info.game_id.is_empty() {
// true => data_point.field("gameId", server_info.game_id.clone()),
// false => data_point,
// };
// data_point = match server_info.is_official {
// Some(result) => data_point.tag("isOfficial", result.to_string()),
// None => data_point,
// };

data_point
.tag("platform", platform)
.tag("region", region)
.tag("type", data_type)
.field("serverName", server_info.name.clone())
.field(field, *amount)
.build()
}
// data_point
// .tag("platform", platform)
// .tag("region", region)
// .tag("type", data_type)
// .field("serverName", server_info.name.clone())
// .field(field, *amount)
// .build()
// }

pub async fn push_server(
frontend_game_name: &str,
influx_client: &influxdb2::Client,
region: &str,
platform: &str,
server_infos: Vec<server_info::ServerInfo>,
) -> anyhow::Result<()> {
let bucket = "Battlefield servers";
let mut points = vec![];
for server_info in server_infos {
if !server_info.name.is_empty() {
points.extend(vec![
build_server_data_point(
frontend_game_name,
"amounts",
&server_info,
region,
platform,
"soldierAmount",
&server_info.soldiers,
)?,
build_server_data_point(
frontend_game_name,
"amounts",
&server_info,
region,
platform,
"queueAmount",
&server_info.queue,
)?,
]);
if !server_info.mode.is_empty() {
points.push(build_server_data_point(
frontend_game_name,
"mode",
&server_info,
region,
platform,
&server_info.mode,
&1,
)?);
}
if !server_info.map.is_empty() {
points.push(build_server_data_point(
frontend_game_name,
"map",
&server_info,
region,
platform,
&server_info.map,
&1,
)?);
}
}
}
influx_client
.write_with_precision(
bucket,
stream::iter(points),
influxdb2::api::write::TimestampPrecision::Seconds,
)
.await?;
Ok(())
}
// pub async fn push_server(
// frontend_game_name: &str,
// influx_client: &influxdb2::Client,
// region: &str,
// platform: &str,
// server_infos: Vec<server_info::ServerInfo>,
// ) -> anyhow::Result<()> {
// let bucket = "Battlefield servers";
// let mut points = vec![];
// for server_info in server_infos {
// if !server_info.name.is_empty() {
// points.extend(vec![
// build_server_data_point(
// frontend_game_name,
// "amounts",
// &server_info,
// region,
// platform,
// "soldierAmount",
// &server_info.soldiers,
// )?,
// build_server_data_point(
// frontend_game_name,
// "amounts",
// &server_info,
// region,
// platform,
// "queueAmount",
// &server_info.queue,
// )?,
// ]);
// if !server_info.mode.is_empty() {
// points.push(build_server_data_point(
// frontend_game_name,
// "mode",
// &server_info,
// region,
// platform,
// &server_info.mode,
// &1,
// )?);
// }
// if !server_info.map.is_empty() {
// points.push(build_server_data_point(
// frontend_game_name,
// "map",
// &server_info,
// region,
// platform,
// &server_info.map,
// &1,
// )?);
// }
// }
// }
// influx_client
// .write_with_precision(
// bucket,
// stream::iter(points),
// influxdb2::api::write::TimestampPrecision::Seconds,
// )
// .await?;
// Ok(())
// }
Loading

0 comments on commit 39c5646

Please sign in to comment.