Skip to content

Commit

Permalink
fix calculate global metrics (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva authored Oct 30, 2023
1 parent 80c759d commit 6888c75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/subgraph/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ const axiosSubgraph = axios.create({
headers: {
'content-type': 'application/json'
},
timeout: 5000
timeout: 10000
});
const axiosCouncilSubgraph = axios.create({
baseURL: config.councilSubgraphUrl,
headers: {
'content-type': 'application/json'
},
timeout: 5000
timeout: 10000
});
const axiosMicrocreditSubgraph = axios.create({
baseURL: config.microcreditSubgraphUrl,
headers: {
'content-type': 'application/json'
},
timeout: 5000
timeout: 10000
});
// TODO: " as any" is a temporary solution to deploy to heroku
// TODO: test this works as expected to reduce timeout
Expand Down
2 changes: 1 addition & 1 deletion services/community-metrics/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const calculate = async (event, context) => {
const today = new Date();

if (today.getHours() <= 1) {
await calcuateCommunitiesMetrics(); // community metrics must be executed before all others
await Promise.all([
calcuateCommunitiesMetrics(),
calcuateGlobalMetrics(),
calcuateCommunitiesDemographics(),
calculateGlobalDemographics()
Expand Down
8 changes: 4 additions & 4 deletions services/community-metrics/src/calcuateGlobalMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Op, col, fn } from 'sequelize';
import { Op, col, fn, literal } from 'sequelize';
import {
config,
database,
Expand Down Expand Up @@ -224,8 +224,8 @@ async function calculateUbiPulse(
attributes: [
[fn('avg', col('ubiRate')), 'avgUbiRate'],
[
fn('avg', col('estimatedDuration')),
'avgEstimatedDuration',
literal('AVG(CASE WHEN "estimatedDuration" < 10e5 THEN "estimatedDuration" ELSE NULL END)'), // ignore outliers
'avgEstimatedDuration'
],
],
where: {
Expand All @@ -246,7 +246,7 @@ async function calculateUbiPulse(
const getAvgComulativeUbi = async (): Promise<string> => {
const communityFoundingRate =
await subgraph.queries.community.communityEntities(
`where: { state_not: 2 }, first: 1000`,
`where: { state_not: 2, maxClaim_lt: 5000 }, first: 1000`,
`maxClaim`
);
const comulativeUbi = communityFoundingRate.reduce(
Expand Down

0 comments on commit 6888c75

Please sign in to comment.