Skip to content

Commit 873dc8c

Browse files
committed
feat: add relative_ratios option to conmparison commands
1 parent 60afe33 commit 873dc8c

File tree

18 files changed

+568
-167
lines changed

18 files changed

+568
-167
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/api/src/canvas/prelude.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@ use uuid::Uuid;
88

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

11+
#[derive(Clone, Copy)]
12+
pub struct Div(pub f64, pub f64);
13+
14+
impl From<Div> for f64 {
15+
fn from(div: Div) -> Self {
16+
div.0 / div.1
17+
}
18+
}
19+
20+
impl From<Div> for u32 {
21+
fn from(div: Div) -> Self {
22+
(f64::from(div) * 100.).round() as u32
23+
}
24+
}
25+
26+
#[cfg(feature = "redis")]
27+
impl redis::ToRedisArgs for Div {
28+
fn write_redis_args<W>(&self, out: &mut W)
29+
where
30+
W: ?Sized + redis::RedisWrite,
31+
{
32+
f64::from(*self).write_redis_args(out)
33+
}
34+
}
35+
36+
impl label::ToFormatted for Div {
37+
fn to_formatted<'t, 'c: 't>(&'t self, ctx: &'c context::Context<'c>) -> Cow<'t, str> {
38+
f64::from(*self).to_formatted(ctx).into_owned().into()
39+
}
40+
}
41+
1142
#[allow(clippy::too_many_arguments)]
1243
pub trait Game {
1344
const HAS_COMPACT: bool;
@@ -23,6 +54,7 @@ pub trait Game {
2354
mode: Option<Self::Mode>,
2455
suffix: Option<&str>,
2556
background: Option<skia_safe::Color>,
57+
relative_ratios: bool,
2658
) -> (skia_safe::Surface, Self::Mode);
2759

2860
fn canvas(
@@ -43,6 +75,7 @@ pub trait Game {
4375
data_rhs: &data::Data,
4476
suffix: Option<&str>,
4577
background: Option<skia_safe::Color>,
78+
relative_ratios: bool,
4679
) -> Vec<skia_safe::Surface>;
4780

4881
fn condensed(
@@ -90,6 +123,7 @@ pub trait Game {
90123
player: &player::Player,
91124
data_lhs: &data::Data,
92125
data_rhs: &data::Data,
126+
relative_ratios: bool,
93127
) -> serenity::CreateEmbed<'c>;
94128
}
95129

crates/database/src/schema.rs

Lines changed: 143 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,184 @@
1+
// @generated automatically by Diesel CLI.
2+
13
diesel::table! {
2-
autocomplete (id) {
3-
id -> Uuid,
4-
#[max_length = 16]
5-
name -> Varchar,
6-
searches -> Int4,
7-
}
4+
autocomplete (id) {
5+
id -> Uuid,
6+
#[max_length = 16]
7+
name -> Varchar,
8+
searches -> Int4,
9+
}
810
}
911

1012
diesel::table! {
11-
bazaar (id) {
12-
id -> Int4,
13-
item_id -> Int2,
14-
sell_price -> Float8,
15-
sell_volume -> Int4,
16-
sell_orders -> Int4,
17-
buy_price -> Float8,
18-
buy_volume -> Int4,
19-
buy_orders -> Int4,
20-
created_at -> Timestamptz,
21-
}
13+
bazaar (id) {
14+
id -> Int4,
15+
item_id -> Int2,
16+
sell_price -> Float8,
17+
sell_volume -> Int4,
18+
sell_orders -> Int4,
19+
buy_price -> Float8,
20+
buy_volume -> Int4,
21+
buy_orders -> Int4,
22+
created_at -> Timestamptz,
23+
}
2224
}
2325

2426
diesel::table! {
25-
bazaar_item (id) {
26-
id -> Int2,
27-
name -> Text,
28-
}
27+
bazaar_item (id) {
28+
id -> Int2,
29+
name -> Text,
30+
}
2931
}
3032

3133
diesel::table! {
32-
boost (user_id, guild_id) {
33-
user_id -> Int8,
34-
guild_id -> Int8,
35-
created_at -> Timestamptz,
36-
}
34+
boost (user_id, guild_id) {
35+
user_id -> Int8,
36+
guild_id -> Int8,
37+
created_at -> Timestamptz,
38+
}
3739
}
3840

3941
diesel::table! {
40-
guild_autocomplete (uuid) {
41-
uuid -> Uuid,
42-
#[max_length = 32]
43-
name -> Varchar,
44-
xp -> Int4,
45-
searches -> Int4,
46-
}
42+
guild_autocomplete (uuid) {
43+
uuid -> Uuid,
44+
#[max_length = 32]
45+
name -> Varchar,
46+
xp -> Int4,
47+
searches -> Int4,
48+
}
4749
}
4850

4951
diesel::table! {
50-
guild_schedule (uuid) {
51-
uuid -> Uuid,
52-
snapshots -> Int4,
53-
hash -> Int8,
54-
prev_hash -> Nullable<Int8>,
55-
update_at -> Timestamptz,
56-
created_at -> Timestamptz,
57-
}
52+
guild_schedule (uuid) {
53+
uuid -> Uuid,
54+
snapshots -> Int4,
55+
hash -> Int8,
56+
prev_hash -> Nullable<Int8>,
57+
update_at -> Timestamptz,
58+
created_at -> Timestamptz,
59+
}
5860
}
5961

6062
diesel::table! {
61-
guild_snapshot (id) {
62-
id -> Int8,
63-
uuid -> Uuid,
64-
hash -> Int8,
65-
did_update -> Bool,
66-
data -> Bytea,
67-
created_at -> Timestamptz,
68-
updated_at -> Timestamptz,
69-
days_since_epoch -> Int4,
70-
version -> Int2,
71-
trusted -> Bool,
72-
}
63+
guild_snapshot (id) {
64+
id -> Int8,
65+
uuid -> Uuid,
66+
hash -> Int8,
67+
did_update -> Bool,
68+
data -> Bytea,
69+
created_at -> Timestamptz,
70+
updated_at -> Timestamptz,
71+
days_since_epoch -> Int4,
72+
version -> Int2,
73+
trusted -> Bool,
74+
}
7375
}
7476

7577
diesel::table! {
76-
metric (id) {
77-
id -> Int4,
78-
discord_id -> Int8,
79-
kind -> Int2,
80-
created_at -> Timestamptz,
81-
}
78+
metric (id) {
79+
id -> Int4,
80+
discord_id -> Int8,
81+
kind -> Int2,
82+
created_at -> Timestamptz,
83+
}
8284
}
8385

8486
diesel::table! {
85-
schedule (uuid) {
86-
uuid -> Uuid,
87-
update_at -> Timestamptz,
88-
created_at -> Timestamptz,
89-
snapshots -> Int4,
90-
hash -> Int8,
91-
prev_hash -> Nullable<Int8>,
92-
weekly_schedule -> Int4,
93-
active_at -> Timestamptz,
94-
vendor_update_at -> Nullable<Timestamptz>,
95-
vendor_hash -> Nullable<Int8>,
96-
vendor_prev_hash -> Nullable<Int8>,
97-
}
87+
schedule (uuid) {
88+
uuid -> Uuid,
89+
update_at -> Timestamptz,
90+
created_at -> Timestamptz,
91+
snapshots -> Int4,
92+
hash -> Int8,
93+
prev_hash -> Nullable<Int8>,
94+
weekly_schedule -> Int4,
95+
active_at -> Timestamptz,
96+
vendor_update_at -> Nullable<Timestamptz>,
97+
vendor_hash -> Nullable<Int8>,
98+
vendor_prev_hash -> Nullable<Int8>,
99+
}
98100
}
99101

100102
diesel::table! {
101-
session (id) {
102-
id -> Uuid,
103-
snapshot_id -> Int8,
104-
user_id -> Int8,
105-
uuid -> Uuid,
106-
kind -> Int2,
107-
created_at -> Timestamptz,
108-
name -> Nullable<Text>,
109-
}
103+
session (id) {
104+
id -> Uuid,
105+
snapshot_id -> Int8,
106+
user_id -> Int8,
107+
uuid -> Uuid,
108+
kind -> Int2,
109+
created_at -> Timestamptz,
110+
name -> Nullable<Text>,
111+
}
110112
}
111113

112114
diesel::table! {
113-
snapshot (id) {
114-
uuid -> Uuid,
115-
created_at -> Timestamptz,
116-
updated_at -> Timestamptz,
117-
id -> Int8,
118-
data -> Bytea,
119-
did_update -> Bool,
120-
hash -> Int8,
121-
version -> Int2,
122-
trusted -> Bool,
123-
}
115+
snapshot (id) {
116+
uuid -> Uuid,
117+
created_at -> Timestamptz,
118+
updated_at -> Timestamptz,
119+
id -> Int8,
120+
data -> Bytea,
121+
did_update -> Bool,
122+
hash -> Int8,
123+
version -> Int2,
124+
trusted -> Bool,
125+
}
124126
}
125127

126128
diesel::table! {
127-
track (channel_id, uuid, user_id) {
128-
user_id -> Int8,
129-
guild_id -> Nullable<Int8>,
130-
channel_id -> Int8,
131-
uuid -> Uuid,
132-
state -> Int2,
133-
created_at -> Timestamptz,
134-
}
129+
track (channel_id, uuid, user_id) {
130+
user_id -> Int8,
131+
guild_id -> Nullable<Int8>,
132+
channel_id -> Int8,
133+
uuid -> Uuid,
134+
state -> Int2,
135+
created_at -> Timestamptz,
136+
}
135137
}
136138

137139
diesel::table! {
138-
usage (user_id, command_name) {
139-
user_id -> Int8,
140-
command_name -> Text,
141-
count -> Int4,
142-
}
140+
usage (user_id, command_name) {
141+
user_id -> Int8,
142+
command_name -> Text,
143+
count -> Int4,
144+
}
143145
}
144146

145147
diesel::table! {
146-
user (id) {
147-
id -> Int8,
148-
uuid -> Nullable<Uuid>,
149-
updated_at -> Timestamptz,
150-
created_at -> Timestamptz,
151-
display -> Int2,
152-
#[max_length = 4]
153-
suffix -> Nullable<Varchar>,
154-
colour -> Nullable<Int4>,
155-
votes -> Int2,
156-
tracks -> Int2,
157-
max_tracks -> Int2,
158-
premium_until -> Nullable<Timestamptz>,
159-
boosts -> Int2,
160-
max_boosts -> Int2,
161-
font -> Int2,
162-
}
148+
user (id) {
149+
id -> Int8,
150+
uuid -> Nullable<Uuid>,
151+
updated_at -> Timestamptz,
152+
created_at -> Timestamptz,
153+
display -> Int2,
154+
#[max_length = 4]
155+
suffix -> Nullable<Varchar>,
156+
colour -> Nullable<Int4>,
157+
votes -> Int2,
158+
tracks -> Int2,
159+
max_tracks -> Int2,
160+
premium_until -> Nullable<Timestamptz>,
161+
boosts -> Int2,
162+
max_boosts -> Int2,
163+
font -> Int2,
164+
}
163165
}
166+
167+
diesel::joinable!(bazaar -> bazaar_item (item_id));
168+
169+
diesel::allow_tables_to_appear_in_same_query!(
170+
autocomplete,
171+
bazaar,
172+
bazaar_item,
173+
boost,
174+
guild_autocomplete,
175+
guild_schedule,
176+
guild_snapshot,
177+
metric,
178+
schedule,
179+
session,
180+
snapshot,
181+
track,
182+
usage,
183+
user,
184+
);

0 commit comments

Comments
 (0)