Skip to content

Commit

Permalink
webapp: Change problems per project graph to "per 1000 projects" for …
Browse files Browse the repository at this point in the history
…more comprehensible values
  • Loading branch information
AMDmi3 committed Nov 20, 2024
1 parent abf0613 commit 4b1579b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions repology-webapp/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub enum Endpoint {
#[strum(props(path = "/graph/repo/:repository_name/projects_vulnerable_percent.svg"))]
GraphRepoProjectsVulnerablePercent,

#[strum(props(path = "/graph/repo/:repository_name/problems_per_project.svg"))]
GraphRepoProblemsPerProject,
#[strum(props(path = "/graph/repo/:repository_name/problems_per_1000_projects.svg"))]
GraphRepoProblemsPer1000Projects,
#[strum(props(path = "/graph/repo/:repository_name/projects_per_maintainer.svg"))]
GraphRepoProjectsPerMaintainer,

Expand Down
2 changes: 1 addition & 1 deletion repology-webapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub async fn create_app(pool: PgPool) -> Result<Router, Error> {
.route(GraphRepoProjectsProblematicPercent.path(), get(views::graph_repository_projects_problematic_percent))
.route(GraphRepoProjectsVulnerablePercent.path(), get(views::graph_repository_projects_vulnerable_percent))
.route(GraphRepoProjectsPerMaintainer.path(), get(views::graph_repository_projects_per_maintainer))
.route(GraphRepoProblemsPerProject.path(), get(views::graph_repository_problems_per_project))
.route(GraphRepoProblemsPer1000Projects.path(), get(views::graph_repository_problems_per_1000_projects))
.route(Log.path(), get(views::log))
.route(MaintainerRepoFeed.path(), get(views::maintainer_repo_feed))
.route(MaintainerRepoFeedAtom.path(), get(views::maintainer_repo_feed_atom))
Expand Down
14 changes: 9 additions & 5 deletions repology-webapp/src/views/graph/repository_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async fn graph_generic(
state: &AppState,
repository_name: &str,
experimental_history: bool,
multiplier: f32,
divident_field_name: &str,
divisor_field_name: &str,
stroke: &str,
Expand All @@ -48,7 +49,7 @@ async fn graph_generic(
CASE
WHEN {1} = 0 THEN NULL
ELSE {0}::real / {1}::real
END AS value
END * $5 AS value
FROM repositories_history_new
WHERE repository_id = (SELECT id FROM repositories WHERE name = $1) AND ts < now() - $4
ORDER BY ts DESC
Expand All @@ -61,7 +62,7 @@ async fn graph_generic(
CASE
WHEN {1} = 0 THEN NULL
ELSE {0}::real / {1}::real
END AS value
END * $5 AS value
FROM repositories_history_new
WHERE repository_id = (SELECT id FROM repositories WHERE name = $1) AND ts >= now() - $4
ORDER BY ts
Expand All @@ -79,7 +80,7 @@ async fn graph_generic(
CASE
WHEN (snapshot->$1->>$3)::integer = 0 THEN NULL
ELSE (snapshot->$1->>$2)::real / (snapshot->$1->>$3)::real
END AS value
END * $5 AS value
FROM repositories_history
WHERE ts < now() - $4
ORDER BY ts DESC
Expand All @@ -92,7 +93,7 @@ async fn graph_generic(
CASE
WHEN (snapshot->$1->>$3)::integer = 0 THEN NULL
ELSE (snapshot->$1->>$2)::real / (snapshot->$1->>$3)::real
END AS value
END * $5 AS value
FROM repositories_history
WHERE ts >= now() - $4
ORDER BY ts
Expand All @@ -105,6 +106,7 @@ async fn graph_generic(
.bind(&divident_field_name.replace("num_projects", "num_metapackages"))
.bind(&divisor_field_name.replace("num_projects", "num_metapackages"))
.bind(&GRAPH_PERIOD)
.bind(&multiplier)
.fetch_all(&state.pool)
.await?;

Expand All @@ -130,7 +132,7 @@ async fn graph_generic(
}

#[cfg_attr(not(feature = "coverage"), tracing::instrument(skip(state)))]
pub async fn graph_repository_problems_per_project(
pub async fn graph_repository_problems_per_1000_projects(
Path(repository_name): Path<String>,
Query(query): Query<QueryParams>,
State(state): State<AppState>,
Expand All @@ -139,6 +141,7 @@ pub async fn graph_repository_problems_per_project(
&state,
&repository_name,
query.experimental_history,
1000.0,
"num_problems",
"num_projects",
"#c0c000",
Expand All @@ -156,6 +159,7 @@ pub async fn graph_repository_projects_per_maintainer(
&state,
&repository_name,
query.experimental_history,
1.0,
"num_projects",
"num_maintainers",
"#c0c000",
Expand Down
4 changes: 2 additions & 2 deletions repology-webapp/tests/graphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn test_graphs_repository(pool: PgPool) {
);
check_response!(
pool,
"/graph/repo/freebsd/problems_per_project.svg",
"/graph/repo/freebsd/problems_per_1000_projects.svg",
status OK,
content_type IMAGE_SVG,
svg_xpath "count(//svg:g[1]/svg:line[1])" 1_f64,
Expand Down Expand Up @@ -255,7 +255,7 @@ async fn test_graphs_repository(pool: PgPool) {
);
check_response!(
pool,
"/graph/repo/freebsd/problems_per_project.svg?experimental_history=1",
"/graph/repo/freebsd/problems_per_1000_projects.svg?experimental_history=1",
status OK,
content_type IMAGE_SVG,
svg_xpath "count(//svg:g[1]/svg:line[1])" 1_f64,
Expand Down

0 comments on commit 4b1579b

Please sign in to comment.