Skip to content

Commit

Permalink
Prepare stats to support more maturities (#1431)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
Signed-off-by: Cintia Sanchez Garcia <[email protected]>
Co-authored-by: Sergio Castaño Arteaga <[email protected]>
Co-authored-by: Cintia Sanchez Garcia <[email protected]>
  • Loading branch information
tegioz and cynthia-sg authored Feb 12, 2024
1 parent 324ff58 commit 968278a
Show file tree
Hide file tree
Showing 16 changed files with 382 additions and 609 deletions.
158 changes: 71 additions & 87 deletions database/migrations/functions/stats/get_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ returns json as $$
select p.maturity, p.rating, count(*) as total
from project p
where p.rating is not null
and
case when p_foundation is not null then
p.foundation_id = p_foundation else true end
and p.foundation_id = p_foundation
group by p.maturity, p.rating
)
select json_strip_nulls(json_build_object(
Expand All @@ -19,12 +17,7 @@ returns json as $$
from (
select date
from stats_snapshot
where
case when p_foundation is not null then
foundation_id = p_foundation
else
foundation_id is null
end
where foundation_id = p_foundation
order by date desc
) s
),
Expand All @@ -44,9 +37,7 @@ returns json as $$
count(*) as total
from project p
where p.accepted_at is not null
and
case when p_foundation is not null then
p.foundation_id = p_foundation else true end
and p.foundation_id = p_foundation
group by date_trunc('month', p.accepted_at)
) mt
) rt
Expand All @@ -60,82 +51,79 @@ returns json as $$
count(*) as total
from project p
where p.accepted_at is not null
and
case when p_foundation is not null then
p.foundation_id = p_foundation else true end
and p.foundation_id = p_foundation
group by
extract('year' from p.accepted_at),
extract('month' from p.accepted_at)
order by year desc, month desc
) entry_count
),
'rating_distribution', json_build_object(
'all', (
select json_agg(json_build_object(rating, total))
from (
select rating, sum(total) as total
from ratings
group by rating
order by rating asc
) rg
),
'graduated', (
select json_agg(json_build_object(rating, total))
from (
select rating, sum(total) as total
from ratings where maturity = 'graduated'
group by rating
order by rating asc
) rg
),
'incubating', (
select json_agg(json_build_object(rating, total))
from (
select rating, sum(total) as total
from ratings where maturity = 'incubating'
group by rating
order by rating asc
) rg
),
'sandbox', (
select json_agg(json_build_object(rating, total))
from (
select rating, sum(total) as total
from ratings where maturity = 'sandbox'
group by rating
order by rating asc
) rg
)
'rating_distribution', (
select json_object_agg(maturity, rating_totals)
from (
(
select
'all' as maturity,
jsonb_agg(jsonb_build_object(rating, total)) as rating_totals
from (
select rating, sum(total) as total
from ratings
where maturity is not null
group by rating
order by rating asc
) as all_rating_totals
)
union
(
select
maturity,
jsonb_agg(jsonb_build_object(rating, total)) as rating_totals
from (
select maturity, rating, sum(total) as total
from ratings
where maturity is not null
group by maturity, rating
order by maturity, rating asc
) as maturity_rating_totals
group by maturity
order by maturity asc
)
) as rating_distribution
),
'sections_average', json_build_object(
'all', json_build_object(
'documentation', (average_section_score(p_foundation, 'documentation', null)),
'license', (average_section_score(p_foundation, 'license', null)),
'best_practices', (average_section_score(p_foundation, 'best_practices', null)),
'security', (average_section_score(p_foundation, 'security', null)),
'legal', (average_section_score(p_foundation, 'legal', null))
),
'graduated', json_build_object(
'documentation', (average_section_score(p_foundation, 'documentation', 'graduated')),
'license', (average_section_score(p_foundation, 'license', 'graduated')),
'best_practices', (average_section_score(p_foundation, 'best_practices', 'graduated')),
'security', (average_section_score(p_foundation, 'security', 'graduated')),
'legal', (average_section_score(p_foundation, 'legal', 'graduated'))
),
'incubating', json_build_object(
'documentation', (average_section_score(p_foundation, 'documentation', 'incubating')),
'license', (average_section_score(p_foundation, 'license', 'incubating')),
'best_practices', (average_section_score(p_foundation, 'best_practices', 'incubating')),
'security', (average_section_score(p_foundation, 'security', 'incubating')),
'legal', (average_section_score(p_foundation, 'legal', 'incubating'))
),
'sandbox', json_build_object(
'documentation', (average_section_score(p_foundation, 'documentation', 'sandbox')),
'license', (average_section_score(p_foundation, 'license', 'sandbox')),
'best_practices', (average_section_score(p_foundation, 'best_practices', 'sandbox')),
'security', (average_section_score(p_foundation, 'security', 'sandbox')),
'legal', (average_section_score(p_foundation, 'legal', 'sandbox'))
)
'sections_average', (
select json_object_agg(maturity, sections_average)
from (
(
select
'all' as maturity,
(
select jsonb_build_object(
'documentation', (average_section_score(p_foundation, 'documentation', null)),
'license', (average_section_score(p_foundation, 'license', null)),
'best_practices', (average_section_score(p_foundation, 'best_practices', null)),
'security', (average_section_score(p_foundation, 'security', null)),
'legal', (average_section_score(p_foundation, 'legal', null))
) as sections_average
)
from project
)
union
(
select
distinct maturity,
(
select jsonb_build_object(
'documentation', (average_section_score(p_foundation, 'documentation', maturity)),
'license', (average_section_score(p_foundation, 'license', maturity)),
'best_practices', (average_section_score(p_foundation, 'best_practices', maturity)),
'security', (average_section_score(p_foundation, 'security', maturity)),
'legal', (average_section_score(p_foundation, 'legal', maturity))
) as sections_average
)
from project
where maturity is not null
)
) sections_average
),
'views_daily', (
select json_agg(json_build_array(extract(epoch from day)*1000, total))
Expand All @@ -144,9 +132,7 @@ returns json as $$
from project_views pv
join project p using (project_id)
where pv.day >= current_date - '1 month'::interval
and
case when p_foundation is not null then
p.foundation_id = p_foundation else true end
and p.foundation_id = p_foundation
group by day
order by day asc
) dt
Expand All @@ -158,9 +144,7 @@ returns json as $$
from project_views pv
join project p using (project_id)
where pv.day >= current_date - '2 year'::interval
and
case when p_foundation is not null then
p.foundation_id = p_foundation else true end
and p.foundation_id = p_foundation
group by month
order by month asc
) mt
Expand Down
14 changes: 6 additions & 8 deletions database/tests/functions/stats/get_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ select is(
[1643673600000, 3]
],
"rating_distribution": {
"all": [
"all": [
{"a": 1},
{"b": 1},
{"c": 1}
Expand All @@ -557,19 +557,17 @@ select is(
"documentation": 73,
"best_practices": 70
},
"sandbox": {
"license": 100,
"security": 100,
"documentation": 80,
"best_practices": 100
},
"graduated": {
"license": 65,
"security": 60,
"documentation": 70,
"best_practices": 55
},
"incubating": {
"sandbox": {
"license": 100,
"security": 100,
"documentation": 80,
"best_practices": 100
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"apexcharts": "^3.45.1",
"classnames": "^2.5.1",
"clo-ui": "https://github.com/cncf/clo-ui.git#v0.2.0",
"clo-ui": "https://github.com/cncf/clo-ui.git#v0.2.1",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"nth-check": "^2.0.1",
Expand Down
73 changes: 47 additions & 26 deletions web/src/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ChecksPerCategory,
FilterKind,
FiltersSection,
MaturityFilters,
Rating,
ReportOption,
ReportOptionInfo,
Expand All @@ -40,27 +41,30 @@ import {
SortOption,
} from './types';

export const FOUNDATIONS: FoundationInfo = {
[Foundation.cdf]: {
name: 'CDF',
},
[Foundation.cncf]: {
name: 'CNCF',
},
[Foundation.lfaidata]: {
name: 'LF AI & Data',
},
};

export const DEFAULT_FOUNDATION = Foundation.cncf;

export const DEFAULT_SORT_BY = SortBy.Name;
export const DEFAULT_SORT_DIRECTION = SortDirection.ASC;

export const FILTERS: FiltersSection[] = [
{
name: FilterKind.Foundation,
title: 'Foundation',
filters: [
{ name: Foundation.cdf, label: 'CDF' },
{ name: Foundation.cncf, label: 'CNCF' },
{ name: Foundation.lfaidata, label: 'LF AI & Data' },
],
},
{
name: FilterKind.Maturity,
title: 'Maturity level',
filters: [
{ name: Maturity.graduated, label: 'Graduated' },
{ name: Maturity.incubating, label: 'Incubating' },
{ name: Maturity.sandbox, label: 'Sandbox' },
],
filters: Object.keys(FOUNDATIONS).map((f: string) => {
return { name: f, label: FOUNDATIONS[f as Foundation]!.name };
}),
},
{
name: FilterKind.Rating,
Expand Down Expand Up @@ -94,6 +98,35 @@ export const FILTERS: FiltersSection[] = [
},
];

export const MATURITY_FILTERS: MaturityFilters = {
[Foundation.cdf]: {
name: FilterKind.Maturity,
title: 'Maturity level',
filters: [
{ name: Maturity.graduated, label: 'Graduated' },
{ name: Maturity.incubating, label: 'Incubating' },
],
},
[Foundation.cncf]: {
name: FilterKind.Maturity,
title: 'Maturity level',
filters: [
{ name: Maturity.graduated, label: 'Graduated' },
{ name: Maturity.incubating, label: 'Incubating' },
{ name: Maturity.sandbox, label: 'Sandbox' },
],
},
[Foundation.lfaidata]: {
name: FilterKind.Maturity,
title: 'Maturity level',
filters: [
{ name: Maturity.graduated, label: 'Graduated' },
{ name: Maturity.incubating, label: 'Incubating' },
{ name: Maturity.sandbox, label: 'Sandbox' },
],
},
};

export const SORT_OPTIONS: SortOption[] = [
{
label: 'Alphabetically (A-Z)',
Expand Down Expand Up @@ -505,18 +538,6 @@ export const REPORT_OPTIONS: ReportOptionInfo = {
},
};

export const FOUNDATIONS: FoundationInfo = {
[Foundation.cdf]: {
name: 'CDF',
},
[Foundation.cncf]: {
name: 'CNCF',
},
[Foundation.lfaidata]: {
name: 'LF AI & Data',
},
};

export type FoundationInfo = {
[key in Foundation]?: {
name: string;
Expand Down
Loading

0 comments on commit 968278a

Please sign in to comment.