Skip to content

Commit 18928c6

Browse files
authored
OSS index sorting (#314)
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent 4ea5ad1 commit 18928c6

File tree

10 files changed

+58
-30
lines changed

10 files changed

+58
-30
lines changed

frontend/app/components/modules/open-source-index/services/osi.api.service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,11 @@ class OssIndexApiService {
180180
name: group.name,
181181
value: [group.totalContributors, rangeIndex],
182182
slug: group.slug,
183-
softwareValue: '',
183+
softwareValue: group.softwareValue,
184+
avgScore: group.avgScore,
184185
type: group.type,
185186
topProjects: group.topProjects.map((project) => ({
186-
id: project.id,
187-
name: project.name,
188-
count: project.count,
189-
softwareValue: '',
187+
...project,
190188
logoUrl: project.logo
191189
})),
192190
topCollections: group.topCollections,

frontend/app/components/uikit/chart/types/ChartTypes.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export interface TreeMapItem {
6161
id: string;
6262
name: string;
6363
count: number;
64-
softwareValue?: string;
64+
softwareValue: number;
65+
avgScore: number;
6566
logoUrl?: string;
6667
icon?: string;
6768
}
@@ -72,7 +73,8 @@ export interface TreeMapData {
7273
slug: string;
7374
type: string;
7475
value: [number, number];
75-
softwareValue?: string;
76+
softwareValue: number;
77+
avgScore: number;
7678
topProjects: TreeMapItem[];
7779
topCollections: TreeMapItem[];
7880
link?: string;

frontend/server/api/ossindex/categories.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {OSSIndexCategoryGroupDetails} from "~~/types/ossindex/category-grou
1616
export default defineEventHandler(async (event): Promise<OSSIndexCategoryGroupDetails | Error> => {
1717
const query = getQuery(event);
1818
const categoryGroupSlug: string = (query?.categoryGroupSlug as string);
19+
const sort: string = (query?.sort as string);
1920

2021
try {
2122
const resDetails = await fetchFromTinybird<CategoryGroup[]>(
@@ -25,36 +26,41 @@ export default defineEventHandler(async (event): Promise<OSSIndexCategoryGroupDe
2526
}
2627
);
2728

29+
const details: CategoryGroup | undefined = resDetails.data.at(0);
30+
31+
if(!details){
32+
throw createError({statusCode: 404, statusMessage: 'Category group not found'});
33+
}
34+
2835
const res = await fetchFromTinybird<OSSIndexCategoryTinybird[]>(
2936
'/v0/pipes/categories_oss_index.json',
3037
{
3138
categoryGroupSlug,
39+
orderBy: sort,
3240
}
3341
);
3442

35-
const details: CategoryGroup | undefined = resDetails.data.at(0);
36-
37-
if(!details){
38-
throw createError({statusCode: 404, statusMessage: 'Category group not found'});
39-
}
40-
4143
const categories = res.data.map((item) => ({
4244
...item,
4345
topCollections: item.topCollections.map((collection) => {
44-
const [id, count, name] = collection;
46+
const [id, count, name, softwareValue, avgScore] = collection;
4547
return {
4648
id: id as string,
4749
count: count as number,
4850
name: name as string,
51+
softwareValue: softwareValue as number,
52+
avgScore: avgScore as number,
4953
};
5054
}),
5155
topProjects: item.topProjects.map((collection) => {
52-
const [id, count, name, logo] = collection;
56+
const [id, count, name, logo, softwareValue, avgScore] = collection;
5357
return {
5458
id: id as string,
5559
count: count as number,
5660
name: name as string,
5761
logo: logo as string,
62+
softwareValue: softwareValue as number,
63+
avgScore: avgScore as number,
5864
};
5965
})
6066
}))

frontend/server/api/ossindex/collections.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default defineEventHandler(
1717
async (event): Promise<OSSIndexCategoryDetails | Error> => {
1818
const query = getQuery(event);
1919
const categorySlug: string = query?.categorySlug as string;
20+
const sort: string = query?.sort as string;
2021

2122
try {
2223
const resDetails = await fetchFromTinybird<Category[]>(
@@ -26,28 +27,31 @@ export default defineEventHandler(
2627
}
2728
);
2829

29-
const res = await fetchFromTinybird<OSSIndexCollectionTinybird[]>(
30-
'/v0/pipes/collections_oss_index.json',
31-
{
32-
categorySlug
33-
}
34-
);
35-
3630
const details: Category | undefined = resDetails.data.at(0);
3731

3832
if (!details) {
3933
throw createError({ statusCode: 404, statusMessage: 'Category not found' });
4034
}
4135

36+
const res = await fetchFromTinybird<OSSIndexCollectionTinybird[]>(
37+
'/v0/pipes/collections_oss_index.json',
38+
{
39+
categorySlug,
40+
orderBy: sort,
41+
}
42+
);
43+
4244
const collections = res.data.map((item) => ({
4345
...item,
4446
topProjects: item.topProjects.map((collection) => {
45-
const [id, count, name, logo] = collection;
47+
const [id, count, name, logo, softwareValue, avgScore] = collection;
4648
return {
4749
id: id as string,
4850
count: count as number,
4951
name: name as string,
50-
logo: logo as string
52+
logo: logo as string,
53+
softwareValue: softwareValue as number,
54+
avgScore: avgScore as number
5155
};
5256
})
5357
}));

frontend/server/api/ossindex/groups.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,38 @@ import type {OSSIndexCategoryGroup, OSSIndexCategoryGroupTinybird} from "~~/type
1414
export default defineEventHandler(async (event): Promise<OSSIndexCategoryGroup[] | Error> => {
1515
const query = getQuery(event);
1616
const type: string = (query?.type as string);
17+
const sort: string = (query?.sort as string);
1718

1819
try {
1920
const res = await fetchFromTinybird<OSSIndexCategoryGroupTinybird[]>(
2021
'/v0/pipes/category_groups_oss_index.json',
2122
{
2223
type,
24+
orderBy: sort,
2325
}
2426
);
2527

2628
return res.data.map((item) => ({
2729
...item,
2830
topCollections: item.topCollections.map((collection) => {
29-
const [id, count, name] = collection;
31+
const [id, count, name, softwareValue, avgScore] = collection;
3032
return {
3133
id: id as string,
3234
count: count as number,
3335
name: name as string,
36+
softwareValue: softwareValue as number,
37+
avgScore: avgScore as number,
3438
};
3539
}),
3640
topProjects: item.topProjects.map((collection) => {
37-
const [id, count, name, logo] = collection;
41+
const [id, count, name, logo, softwareValue, avgScore] = collection;
3842
return {
3943
id: id as string,
4044
count: count as number,
4145
name: name as string,
4246
logo: logo as string,
47+
softwareValue: softwareValue as number,
48+
avgScore: avgScore as number,
4349
};
4450
})
4551
}))

frontend/types/open-source-index/responses.types.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

frontend/types/ossindex/category-group.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export interface OSSIndexCategoryGroupTinybird {
1010
type: string;
1111
slug: string;
1212
totalContributors: number;
13+
softwareValue: number;
14+
avgScore: number;
1315
topCollections: (string | number)[][];
1416
topProjects: (string | number)[][];
1517
}
@@ -20,6 +22,8 @@ export interface OSSIndexCategoryGroup {
2022
type: string;
2123
slug: string;
2224
totalContributors: number;
25+
softwareValue: number;
26+
avgScore: number;
2327
topCollections: OSSIndexTopCollection[];
2428
topProjects: OSSIndexTopProject[];
2529
}

frontend/types/ossindex/category.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export interface OSSIndexCategoryTinybird {
99
name: string;
1010
slug: string;
1111
totalContributors: number;
12+
softwareValue: number;
13+
avgScore: number;
1214
topCollections: (string | number)[][];
1315
topProjects: (string | number)[][];
1416
}
@@ -18,6 +20,8 @@ export interface OSSIndexCategory {
1820
name: string;
1921
slug: string;
2022
totalContributors: number;
23+
softwareValue: number;
24+
avgScore: number;
2125
topCollections: OSSIndexTopCollection[];
2226
topProjects: OSSIndexTopProject[];
2327
}

frontend/types/ossindex/collection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export interface OSSIndexCollectionTinybird {
77
name: string;
88
slug: string;
99
totalContributors: number;
10+
softwareValue: number;
11+
avgScore: number;
1012
topProjects: (string | number)[][];
1113
}
1214

@@ -15,5 +17,7 @@ export interface OSSIndexCollection {
1517
name: string;
1618
slug: string;
1719
totalContributors: number;
20+
softwareValue: number;
21+
avgScore: number;
1822
topProjects: OSSIndexTopProject[];
1923
}

frontend/types/ossindex/common.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ export interface OSSIndexTopCollection {
44
id: string;
55
count: number;
66
name: string;
7+
softwareValue: number;
8+
avgScore: number;
79
}
810

911
export interface OSSIndexTopProject {
1012
id: string;
1113
count: number;
1214
name: string;
1315
logo: string;
16+
softwareValue: number;
17+
avgScore: number;
1418
}

0 commit comments

Comments
 (0)