Skip to content

Commit

Permalink
Merge pull request #589 from blockscout/lymarenkolev/stats/fix-sectio…
Browse files Browse the repository at this point in the history
…ns-order

Fix sections order
  • Loading branch information
sevenzing authored Aug 15, 2023
2 parents e003306 + 5e743bf commit 01dcf97
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
16 changes: 13 additions & 3 deletions stats/Cargo.lock

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

6 changes: 6 additions & 0 deletions stats/config/charts.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"lines": {
"accounts": {
"title": "Accounts",
"order": 1,
"charts": {
"active_accounts": {
"title": "Active accounts",
Expand All @@ -74,6 +75,7 @@
},
"transactions": {
"title": "Transactions",
"order": 2,
"charts": {
"average_txn_fee": {
"title": "Average transaction fee",
Expand Down Expand Up @@ -106,6 +108,7 @@
},
"blocks": {
"title": "Blocks",
"order": 3,
"charts": {
"new_blocks": {
"title": "New blocks",
Expand All @@ -128,6 +131,7 @@
},
"tokens": {
"title": "Tokens",
"order": 4,
"charts": {
"new_native_coin_transfers": {
"title": "New native coins transfers",
Expand Down Expand Up @@ -157,6 +161,7 @@
},
"gas": {
"title": "Gas",
"order": 5,
"charts": {
"average_gas_limit": {
"title": "Average gas limit",
Expand All @@ -178,6 +183,7 @@
},
"contracts": {
"title": "Contracts",
"order": 6,
"charts": {
"new_verified_contracts": {
"title": "New verified contracts",
Expand Down
3 changes: 2 additions & 1 deletion stats/stats-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
blockscout-service-launcher = { version = "0.7.1", features = [ "database-0_10" ] }
cron = "0.12"
convert_case = "0.6.0"
itertools = "0.11.0"

[dev-dependencies]
reqwest-middleware = "0.2"
reqwest-retry = "0.2"
reqwest = "0.11"
serde_json = "1.0"
pretty_assertions = "1.3"
pretty_assertions = "1.3"
3 changes: 3 additions & 0 deletions stats/stats-server/src/config/json_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use super::{
toml_config,
};
use convert_case::{Case, Casing};
use itertools::Itertools;
use serde::Deserialize;
use std::collections::BTreeMap;

#[derive(Default, Debug, Clone, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct LineChartSection {
pub title: String,
pub order: Option<i64>,
pub charts: BTreeMap<String, LineChartInfo>,
}

Expand All @@ -31,6 +33,7 @@ impl From<Config> for toml_config::Config {
lines: value
.lines
.into_iter()
.sorted_by_key(|(_, section)| section.order)
.map(toml_config::LineChartSection::from)
.collect::<Vec<_>>()
.into(),
Expand Down
24 changes: 24 additions & 0 deletions stats/stats-server/tests/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ async fn test_lines_ok() {

let client = client();

let resp = client
.get(format!("{base}/api/v1/lines"))
.send()
.await
.expect("failed to connect to server");
let s = resp.status();
assert_eq!(s, 200, "invalid status for charts info: {s:?}");
let line_charts: stats_proto::blockscout::stats::v1::LineCharts =
resp.json().await.expect("failed to parse response");
let sections: Vec<&str> = line_charts
.sections
.iter()
.map(|sec| sec.id.as_str())
.collect();
let expected_sections = [
"accounts",
"transactions",
"blocks",
"tokens",
"gas",
"contracts",
];
assert_eq!(sections, expected_sections, "wrong sections response");

for line_name in [
"accountsGrowth",
"activeAccounts",
Expand Down

0 comments on commit 01dcf97

Please sign in to comment.