Skip to content

Commit

Permalink
feat: add relative_ratios option to conmparison commands
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopolak committed Jul 3, 2024
1 parent 60afe33 commit 873dc8c
Show file tree
Hide file tree
Showing 18 changed files with 568 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions crates/api/src/canvas/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@ use uuid::Uuid;

use crate::player::{self, data, status};

#[derive(Clone, Copy)]
pub struct Div(pub f64, pub f64);

impl From<Div> for f64 {
fn from(div: Div) -> Self {
div.0 / div.1
}
}

impl From<Div> for u32 {
fn from(div: Div) -> Self {
(f64::from(div) * 100.).round() as u32
}
}

#[cfg(feature = "redis")]
impl redis::ToRedisArgs for Div {
fn write_redis_args<W>(&self, out: &mut W)
where
W: ?Sized + redis::RedisWrite,
{
f64::from(*self).write_redis_args(out)
}
}

impl label::ToFormatted for Div {
fn to_formatted<'t, 'c: 't>(&'t self, ctx: &'c context::Context<'c>) -> Cow<'t, str> {
f64::from(*self).to_formatted(ctx).into_owned().into()
}
}

#[allow(clippy::too_many_arguments)]
pub trait Game {
const HAS_COMPACT: bool;
Expand All @@ -23,6 +54,7 @@ pub trait Game {
mode: Option<Self::Mode>,
suffix: Option<&str>,
background: Option<skia_safe::Color>,
relative_ratios: bool,
) -> (skia_safe::Surface, Self::Mode);

fn canvas(
Expand All @@ -43,6 +75,7 @@ pub trait Game {
data_rhs: &data::Data,
suffix: Option<&str>,
background: Option<skia_safe::Color>,
relative_ratios: bool,
) -> Vec<skia_safe::Surface>;

fn condensed(
Expand Down Expand Up @@ -90,6 +123,7 @@ pub trait Game {
player: &player::Player,
data_lhs: &data::Data,
data_rhs: &data::Data,
relative_ratios: bool,
) -> serenity::CreateEmbed<'c>;
}

Expand Down
265 changes: 143 additions & 122 deletions crates/database/src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,163 +1,184 @@
// @generated automatically by Diesel CLI.

diesel::table! {
autocomplete (id) {
id -> Uuid,
#[max_length = 16]
name -> Varchar,
searches -> Int4,
}
autocomplete (id) {
id -> Uuid,
#[max_length = 16]
name -> Varchar,
searches -> Int4,
}
}

diesel::table! {
bazaar (id) {
id -> Int4,
item_id -> Int2,
sell_price -> Float8,
sell_volume -> Int4,
sell_orders -> Int4,
buy_price -> Float8,
buy_volume -> Int4,
buy_orders -> Int4,
created_at -> Timestamptz,
}
bazaar (id) {
id -> Int4,
item_id -> Int2,
sell_price -> Float8,
sell_volume -> Int4,
sell_orders -> Int4,
buy_price -> Float8,
buy_volume -> Int4,
buy_orders -> Int4,
created_at -> Timestamptz,
}
}

diesel::table! {
bazaar_item (id) {
id -> Int2,
name -> Text,
}
bazaar_item (id) {
id -> Int2,
name -> Text,
}
}

diesel::table! {
boost (user_id, guild_id) {
user_id -> Int8,
guild_id -> Int8,
created_at -> Timestamptz,
}
boost (user_id, guild_id) {
user_id -> Int8,
guild_id -> Int8,
created_at -> Timestamptz,
}
}

diesel::table! {
guild_autocomplete (uuid) {
uuid -> Uuid,
#[max_length = 32]
name -> Varchar,
xp -> Int4,
searches -> Int4,
}
guild_autocomplete (uuid) {
uuid -> Uuid,
#[max_length = 32]
name -> Varchar,
xp -> Int4,
searches -> Int4,
}
}

diesel::table! {
guild_schedule (uuid) {
uuid -> Uuid,
snapshots -> Int4,
hash -> Int8,
prev_hash -> Nullable<Int8>,
update_at -> Timestamptz,
created_at -> Timestamptz,
}
guild_schedule (uuid) {
uuid -> Uuid,
snapshots -> Int4,
hash -> Int8,
prev_hash -> Nullable<Int8>,
update_at -> Timestamptz,
created_at -> Timestamptz,
}
}

diesel::table! {
guild_snapshot (id) {
id -> Int8,
uuid -> Uuid,
hash -> Int8,
did_update -> Bool,
data -> Bytea,
created_at -> Timestamptz,
updated_at -> Timestamptz,
days_since_epoch -> Int4,
version -> Int2,
trusted -> Bool,
}
guild_snapshot (id) {
id -> Int8,
uuid -> Uuid,
hash -> Int8,
did_update -> Bool,
data -> Bytea,
created_at -> Timestamptz,
updated_at -> Timestamptz,
days_since_epoch -> Int4,
version -> Int2,
trusted -> Bool,
}
}

diesel::table! {
metric (id) {
id -> Int4,
discord_id -> Int8,
kind -> Int2,
created_at -> Timestamptz,
}
metric (id) {
id -> Int4,
discord_id -> Int8,
kind -> Int2,
created_at -> Timestamptz,
}
}

diesel::table! {
schedule (uuid) {
uuid -> Uuid,
update_at -> Timestamptz,
created_at -> Timestamptz,
snapshots -> Int4,
hash -> Int8,
prev_hash -> Nullable<Int8>,
weekly_schedule -> Int4,
active_at -> Timestamptz,
vendor_update_at -> Nullable<Timestamptz>,
vendor_hash -> Nullable<Int8>,
vendor_prev_hash -> Nullable<Int8>,
}
schedule (uuid) {
uuid -> Uuid,
update_at -> Timestamptz,
created_at -> Timestamptz,
snapshots -> Int4,
hash -> Int8,
prev_hash -> Nullable<Int8>,
weekly_schedule -> Int4,
active_at -> Timestamptz,
vendor_update_at -> Nullable<Timestamptz>,
vendor_hash -> Nullable<Int8>,
vendor_prev_hash -> Nullable<Int8>,
}
}

diesel::table! {
session (id) {
id -> Uuid,
snapshot_id -> Int8,
user_id -> Int8,
uuid -> Uuid,
kind -> Int2,
created_at -> Timestamptz,
name -> Nullable<Text>,
}
session (id) {
id -> Uuid,
snapshot_id -> Int8,
user_id -> Int8,
uuid -> Uuid,
kind -> Int2,
created_at -> Timestamptz,
name -> Nullable<Text>,
}
}

diesel::table! {
snapshot (id) {
uuid -> Uuid,
created_at -> Timestamptz,
updated_at -> Timestamptz,
id -> Int8,
data -> Bytea,
did_update -> Bool,
hash -> Int8,
version -> Int2,
trusted -> Bool,
}
snapshot (id) {
uuid -> Uuid,
created_at -> Timestamptz,
updated_at -> Timestamptz,
id -> Int8,
data -> Bytea,
did_update -> Bool,
hash -> Int8,
version -> Int2,
trusted -> Bool,
}
}

diesel::table! {
track (channel_id, uuid, user_id) {
user_id -> Int8,
guild_id -> Nullable<Int8>,
channel_id -> Int8,
uuid -> Uuid,
state -> Int2,
created_at -> Timestamptz,
}
track (channel_id, uuid, user_id) {
user_id -> Int8,
guild_id -> Nullable<Int8>,
channel_id -> Int8,
uuid -> Uuid,
state -> Int2,
created_at -> Timestamptz,
}
}

diesel::table! {
usage (user_id, command_name) {
user_id -> Int8,
command_name -> Text,
count -> Int4,
}
usage (user_id, command_name) {
user_id -> Int8,
command_name -> Text,
count -> Int4,
}
}

diesel::table! {
user (id) {
id -> Int8,
uuid -> Nullable<Uuid>,
updated_at -> Timestamptz,
created_at -> Timestamptz,
display -> Int2,
#[max_length = 4]
suffix -> Nullable<Varchar>,
colour -> Nullable<Int4>,
votes -> Int2,
tracks -> Int2,
max_tracks -> Int2,
premium_until -> Nullable<Timestamptz>,
boosts -> Int2,
max_boosts -> Int2,
font -> Int2,
}
user (id) {
id -> Int8,
uuid -> Nullable<Uuid>,
updated_at -> Timestamptz,
created_at -> Timestamptz,
display -> Int2,
#[max_length = 4]
suffix -> Nullable<Varchar>,
colour -> Nullable<Int4>,
votes -> Int2,
tracks -> Int2,
max_tracks -> Int2,
premium_until -> Nullable<Timestamptz>,
boosts -> Int2,
max_boosts -> Int2,
font -> Int2,
}
}

diesel::joinable!(bazaar -> bazaar_item (item_id));

diesel::allow_tables_to_appear_in_same_query!(
autocomplete,
bazaar,
bazaar_item,
boost,
guild_autocomplete,
guild_schedule,
guild_snapshot,
metric,
schedule,
session,
snapshot,
track,
usage,
user,
);
Loading

0 comments on commit 873dc8c

Please sign in to comment.