Skip to content

Commit bff1e56

Browse files
Merge pull request #3596 from gitcoinco/fix-oso
Fix OpenSource Observer queries
2 parents c168f21 + fe4e8ea commit bff1e56

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed

packages/grant-explorer/src/features/api/oso.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const graphQLClient = new GraphQLClient(osoUrl, {
1313
let hasFetched = false;
1414

1515
interface IOSOId {
16-
artifacts_by_project: {
16+
projects_v1: {
1717
project_id: Hex;
1818
};
1919
}
2020

2121
export interface IOSOStats {
22-
code_metrics_by_project: {
23-
contributors: number;
22+
code_metrics_by_project_v1: {
23+
contributor_count: number;
2424
first_commit_date: number;
2525
};
2626
events_monthly_to_project: [
@@ -53,8 +53,8 @@ export interface IOSOStats {
5353

5454
export function useOSO(projectGithub?: string) {
5555
const emptyReturn: IOSOStats = {
56-
code_metrics_by_project: {
57-
contributors: 0,
56+
code_metrics_by_project_v1: {
57+
contributor_count: 0,
5858
first_commit_date: 0,
5959
},
6060
events_monthly_to_project: [
@@ -90,7 +90,7 @@ export function useOSO(projectGithub?: string) {
9090
if (osoApiKey === "")
9191
throw new Error("OpenSourceObserver API key not set.");
9292
const queryId = gql`{
93-
artifacts_by_project(where: {artifact_name: {_ilike: "%${projectRegistryGithub}/%"}}
93+
projects_v1(where: {display_name: {_ilike: "${projectRegistryGithub}"}}
9494
distinct_on: project_id
9595
) {
9696
project_id
@@ -101,22 +101,22 @@ export function useOSO(projectGithub?: string) {
101101
hasFetched = true;
102102
const idData: IOSOId = await graphQLClient.request<IOSOId>(queryId);
103103

104-
if (!Array.isArray(idData.artifacts_by_project)) {
104+
if (!Array.isArray(idData.projects_v1)) {
105105
setStats(emptyReturn);
106106
return;
107107
}
108108

109109
const parsedId: IOSOId = {
110-
artifacts_by_project: idData.artifacts_by_project[0],
110+
projects_v1: idData.projects_v1[0],
111111
};
112112

113113
const queryStats = gql`{
114-
code_metrics_by_project(where: {project_id: {_eq: "${parsedId.artifacts_by_project.project_id}"}}) {
115-
contributors
114+
code_metrics_by_project_v1(where: {project_id: {_eq: "${parsedId.projects_v1.project_id}"}}) {
115+
contributor_count
116116
first_commit_date
117117
}
118118
events_monthly_to_project(
119-
where: {project_id: {_eq: "${parsedId.artifacts_by_project.project_id}"}, event_type: {_eq: "COMMIT_CODE"}}
119+
where: {project_id: {_eq: "${parsedId.projects_v1.project_id}"}, event_type: {_eq: "COMMIT_CODE"}}
120120
limit: 6
121121
order_by: {bucket_month: desc}
122122
) {
@@ -128,20 +128,20 @@ export function useOSO(projectGithub?: string) {
128128
const items: IOSOStats =
129129
await graphQLClient.request<IOSOStats>(queryStats);
130130

131-
if (!Array.isArray(items.code_metrics_by_project)) {
131+
if (!Array.isArray(items.code_metrics_by_project_v1)) {
132132
setStats(emptyReturn);
133133
return;
134134
}
135135

136136
if (items.events_monthly_to_project.length === 6) {
137137
const parsedItems: IOSOStats = {
138-
code_metrics_by_project: items.code_metrics_by_project[0],
138+
code_metrics_by_project_v1: items.code_metrics_by_project_v1[0],
139139
events_monthly_to_project: items.events_monthly_to_project,
140140
};
141141
setStats(parsedItems);
142142
} else {
143143
const parsedItems: IOSOStats = {
144-
code_metrics_by_project: items.code_metrics_by_project[0],
144+
code_metrics_by_project_v1: items.code_metrics_by_project_v1[0],
145145
events_monthly_to_project: emptyReturn.events_monthly_to_project,
146146
};
147147
setStats(parsedItems);

packages/grant-explorer/src/features/round/OSO/ImpactStats.tsx

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,80 @@ import { Flex, Link, Text } from "@chakra-ui/react";
44
import { Stat } from "../ViewProjectDetails";
55
import { formatTimeAgo } from "../../common/utils/utils";
66

7-
87
export const StatList = ({ stats }: { stats: IOSOStats | null }) => {
98
if (stats === null) return;
10-
return (
11-
stats.code_metrics_by_project.contributors > 0 ? (
12-
<React.Fragment>
13-
<h4 className="text-3xl mt-5 ml-4" >Impact stats</h4>
14-
<Flex gap={2} flexDir={{base: 'column', md: 'row'}} py={6} px={3} >
15-
<div
16-
className={
9+
return stats.code_metrics_by_project_v1.contributor_count > 0 ? (
10+
<React.Fragment>
11+
<h4 className="text-3xl mt-5 ml-4">Impact stats</h4>
12+
<Flex gap={2} flexDir={{ base: "column", md: "row" }} py={6} px={3}>
13+
<div
14+
className={
1715
"rounded-2xl bg-gray-50 flex-auto p-3 md:p-6 gap-4 flex flex-col"
18-
}
19-
>
20-
<div> <Stat
16+
}
17+
>
18+
<div>
19+
{" "}
20+
<Stat
2121
isLoading={false}
22-
value={`${formatTimeAgo(stats.code_metrics_by_project.first_commit_date)}`}
22+
value={`${formatTimeAgo(stats.code_metrics_by_project_v1.first_commit_date)}`}
2323
>
2424
Project age
2525
</Stat>
2626
</div>
2727
</div>
2828
<div
2929
className={
30-
"rounded-2xl bg-gray-50 flex-auto p-3 md:p-6 gap-4 flex flex-col"
30+
"rounded-2xl bg-gray-50 flex-auto p-3 md:p-6 gap-4 flex flex-col"
3131
}
3232
>
3333
<Stat
3434
isLoading={false}
35-
value={`${stats.code_metrics_by_project.contributors}`}
35+
value={`${stats.code_metrics_by_project_v1.contributor_count}`}
3636
>
3737
Unique code contributors
3838
</Stat>
3939
</div>
40-
<div
40+
<div
4141
className={
42-
"rounded-2xl bg-gray-50 flex-auto p-3 md:p-6 gap-4 flex flex-col"
42+
"rounded-2xl bg-gray-50 flex-auto p-3 md:p-6 gap-4 flex flex-col"
4343
}
4444
>
45-
<Stat
46-
isLoading={false}
47-
value={`${projectVelocity(stats)}`}
48-
>
45+
<Stat isLoading={false} value={`${projectVelocity(stats)}`}>
4946
Velocity
5047
</Stat>
5148
</div>
5249
</Flex>
53-
<Text fontFamily="DM Mono" textAlign="center" mt={0} className={"text-xs"}>
54-
Data provided by {" "}
50+
<Text
51+
fontFamily="DM Mono"
52+
textAlign="center"
53+
mt={0}
54+
className={"text-xs"}
55+
>
56+
Data provided by{" "}
5557
<Link href={"https://www.opensource.observer/"} target="_blank">
56-
<Text as="span" className="text-gitcoin-violet-500">
58+
<Text as="span" className="text-gitcoin-violet-500">
5759
opensource.observer
5860
</Text>
5961
</Link>
6062
</Text>
61-
</React.Fragment>
62-
) : (
63-
<div>
64-
</div>
65-
)
63+
</React.Fragment>
64+
) : (
65+
<div></div>
6666
);
6767
};
6868

69-
function projectVelocity(stats : IOSOStats) {
70-
const recentCommits = stats.events_monthly_to_project[0].amount + stats.events_monthly_to_project[1].amount + stats.events_monthly_to_project[2].amount;
71-
const olderCommits = stats.events_monthly_to_project[3].amount + stats.events_monthly_to_project[4].amount + stats.events_monthly_to_project[5].amount;
69+
function projectVelocity(stats: IOSOStats) {
70+
const recentCommits =
71+
stats.events_monthly_to_project[0].amount +
72+
stats.events_monthly_to_project[1].amount +
73+
stats.events_monthly_to_project[2].amount;
74+
const olderCommits =
75+
stats.events_monthly_to_project[3].amount +
76+
stats.events_monthly_to_project[4].amount +
77+
stats.events_monthly_to_project[5].amount;
7278

73-
if (recentCommits === 0 && olderCommits === 0) return 'unknown';
74-
if (recentCommits >= (1.5 * olderCommits)) return 'increasing';
75-
if (recentCommits <= 0.5 * olderCommits) return 'decreasing';
76-
return 'steady';
77-
}
79+
if (recentCommits === 0 && olderCommits === 0) return "unknown";
80+
if (recentCommits >= 1.5 * olderCommits) return "increasing";
81+
if (recentCommits <= 0.5 * olderCommits) return "decreasing";
82+
return "steady";
83+
}

0 commit comments

Comments
 (0)