Skip to content

Commit

Permalink
update etl
Browse files Browse the repository at this point in the history
to remove mapping
  • Loading branch information
swellander committed Jul 27, 2024
1 parent aae588a commit ee2f4c6
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions packages/nextjs/pages/api/etl/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import weightingsJSON from "./weightings.json";
import weightData from "./impact_metric_weights.json";
import { FlattenMaps, Types, startSession } from "mongoose";
import type { NextApiRequest, NextApiResponse } from "next";
import { OnchainMetricsByProject } from "~~/app/types/OSO";
import { RF4ImpactMetricsByProject } from "~~/app/types/OSO";
import dbConnect from "~~/services/mongodb/dbConnect";
import ETLLog from "~~/services/mongodb/models/etlLog";
import GlobalScore, { TempGlobalScore } from "~~/services/mongodb/models/globalScore";
Expand All @@ -10,6 +10,8 @@ import Project from "~~/services/mongodb/models/project";
import ProjectMovement, { IProjectMovement, TempProjectMovement } from "~~/services/mongodb/models/projectMovement";
import ProjectScore, { IProjectScore, TempProjectScore } from "~~/services/mongodb/models/projectScore";

const { metrics: weightingsJSON } = weightData;

// Vercel Serverless Function Config
export const config = {
maxDuration: 60, // seconds
Expand Down Expand Up @@ -47,8 +49,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await TempProjectScore.deleteMany({});
await TempProjectMovement.deleteMany({});

// Get all the mapping data
const { mapping } = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/stub/mapping`).then(res => res.json());
// Get metrics that are activated
const metrics = await Metric.findAllActivated();
if (!metrics) {
Expand All @@ -70,24 +70,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (!seriesResponse) {
throw new Error(`No OSO Data for ${day}`);
}
const osoData = seriesResponse.data as OnchainMetricsByProject[];
const osoData = seriesResponse.data as RF4ImpactMetricsByProject[];
console.log(`Processing OSO response for each project on ${day.toISOString().split("T")[0]}`);

const globalScoreData = Object.assign({}, metricNamesObj) as { [key in keyof Metrics]: number };
const projectScoreOps = [];

for (const project of osoData) {
const projectMapping = mapping.find((map: any) => map.oso_name === project.project_name);
if (!projectMapping) {
console.error(`No mapping found for ${project.project_name}`);
continue;
}
const projectId = projectMapping.application_id;
const projectId = project.application_id;
const impact_index = getImpactIndex(project as unknown as Metrics, weightings);

const projectMetrics = {} as { [key in keyof Metrics]: number };
for (const metric of metrics) {
const metricValue = project[metric.name as keyof OnchainMetricsByProject];
const metricValue = project[metric.name as keyof RF4ImpactMetricsByProject];
if (!isNaN(metricValue as number)) {
projectMetrics[metric.name as keyof Metrics] = parseInt(metricValue as string);
}
Expand Down

0 comments on commit ee2f4c6

Please sign in to comment.