Skip to content

Commit

Permalink
Add emojis to runs (#6)
Browse files Browse the repository at this point in the history
* change tag matching

* add emojis to templates

* better render, revert official deploy

* rerun sqlx prepare
  • Loading branch information
reubenwong97 authored Aug 27, 2023
1 parent 2339ef1 commit 6e19d58
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 177 deletions.
77 changes: 0 additions & 77 deletions .github/actions/deploy-action/README.md

This file was deleted.

79 changes: 0 additions & 79 deletions .github/actions/deploy-action/action.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: Shuttle Deploy
on:
push:
tags:
- "*"
- v[1-9]+.[0-9]+.[0-9]+
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: ./.github/actions/deploy-action
- uses: shuttle-hq/deploy-action@main
with:
deploy-key: ${{ secrets.SHUTTLE_DEPLOY_KEY }}
secrets: |
Expand Down

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

7 changes: 4 additions & 3 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,12 @@ pub async fn get_tally(chat_id: ChatId, connection: &PgPool) -> DBResult<Option<
if let Some(users) = users {
let user_ids: Vec<i32> = users.iter().map(|user| user.id).collect();
let tally = sqlx::query!(
"SELECT user_name, COUNT(*), SUM(distance)
"SELECT user_name, COUNT(*), SUM(distance) as total_ran
FROM runs
JOIN users ON users.id = runs.user_id
WHERE user_id = ANY($1)
GROUP BY user_name",
GROUP BY user_name
ORDER BY total_ran DESC",
&user_ids[..],
)
.fetch_all(connection)
Expand All @@ -284,7 +285,7 @@ pub async fn get_tally(chat_id: ChatId, connection: &PgPool) -> DBResult<Option<
.map(|tally| Score {
user_name: tally.user_name.clone(),
medals: tally.count.unwrap() as u32,
distance: tally.sum.unwrap(),
distance: tally.total_ran.unwrap(),
})
.collect();

Expand Down
47 changes: 41 additions & 6 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ mod tests {
];
let render = list_runs(Some(runs));
// TODO: i actually dont want this kind of html templates anyway
let ans = "
1. 1 1 1970-01-01 00:01:01 1
let ans = "1. 1 1 1970-01-01 00:01:01 1
2. 2 2 1970-01-01 00:01:22 2
";
assert_eq!(render, ans);
Expand Down Expand Up @@ -181,9 +179,7 @@ mod tests {
},
];
let render = list_users(Some(users));
let ans = "
1. 1 meme
let ans = "1. 1 meme
2. 2 youyou
";
assert_eq!(render, ans);
Expand All @@ -196,4 +192,43 @@ mod tests {
let ans = "No users in database.";
assert_eq!(render, ans);
}

#[test]
fn list_tally_template() {
let scores = vec![
Score {
user_name: "reuben".into(),
medals: 5,
distance: 20.0,
},
Score {
user_name: "milton".into(),
medals: 2,
distance: 10.0,
},
Score {
user_name: "jerrell".into(),
medals: 1,
distance: 1.0,
},
Score {
user_name: "taigy".into(),
medals: 1,
distance: 0.2,
},
Score {
user_name: "riley".into(),
medals: 2,
distance: 0.1,
},
];
let render = display_tally(Some(scores));
let ans = "🥇 1. reuben 5 20
🥈 2. milton 2 10
🥉 3. jerrell 1 1
🏃 4. taigy 1 0.2
🤡 5. riley 2 0.1
";
assert_eq!(render, ans);
}
}
4 changes: 2 additions & 2 deletions templates/list_runs.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for run in runs %}
{% for run in runs -%}
{{ loop.index }}. {{ run }}
{% endfor %}
{% endfor -%}
16 changes: 13 additions & 3 deletions templates/list_tally.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{% for score in scores %}
{{ loop.index }}. {{ score }}
{% endfor %}
{% for score in scores -%}
{% if loop.index == 1 -%}
🥇 {{ loop.index }}. {{ score }}
{% else if loop.index == 2 -%}
🥈 {{ loop.index }}. {{ score }}
{% else if loop.index == 3 -%}
🥉 {{ loop.index }}. {{ score }}
{% else if loop.last -%}
🤡 {{ loop.index }}. {{ score }}
{% else -%}
🏃 {{ loop.index }}. {{ score }}
{% endif -%}
{% endfor -%}
4 changes: 2 additions & 2 deletions templates/list_users.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for user in users %}
{% for user in users -%}
{{ loop.index }}. {{ user }}
{% endfor %}
{% endfor -%}

0 comments on commit 6e19d58

Please sign in to comment.