Skip to content

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahdigh committed Sep 27, 2024
1 parent 2e78e36 commit bda9672
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions src/rpgf5-data-import/submit.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { projects } from './osrad';
import * as fs from 'fs';
// async function getAllProjects(): Promise<Project[]> {
// const baseUrl =
// 'https://vote.optimism.io/api/v1/retrofunding/rounds/5/projects';
// const limit = 100; // Maximum allowed limit
// let offset = 0;
// let allProjects: Project[] = [];
// let hasNext = true;
// import { projects } from './osrad';
// import * as fs from 'fs';
// // async function getAllProjects(): Promise<Project[]> {
// // const baseUrl =
// // 'https://vote.optimism.io/api/v1/retrofunding/rounds/5/projects';
// // const limit = 100; // Maximum allowed limit
// // let offset = 0;
// // let allProjects: Project[] = [];
// // let hasNext = true;

// while (hasNext) {
// try {
// const response = await axios.get<AgoraApiResponse>(baseUrl, {
// params: {
// offset,
// limit,
// },
// headers: {
// Authorization: 'Bearer 80963194-c250-4a37-921a-302bf50dee34',
// },
// timeout: 30 * 1000,
// });
// // while (hasNext) {
// // try {
// // const response = await axios.get<AgoraApiResponse>(baseUrl, {
// // params: {
// // offset,
// // limit,
// // },
// // headers: {
// // Authorization: 'Bearer 80963194-c250-4a37-921a-302bf50dee34',
// // },
// // timeout: 30 * 1000,
// // });

// allProjects = allProjects.concat(response.data.data);
// hasNext = response.data.meta.has_next;
// offset = response.data.meta.next_offset;
// } catch (error) {
// console.error('Error fetching projects:', error);
// break;
// }
// }
// // allProjects = allProjects.concat(response.data.data);
// // hasNext = response.data.meta.has_next;
// // offset = response.data.meta.next_offset;
// // } catch (error) {
// // console.error('Error fetching projects:', error);
// // break;
// // }
// // }

// return allProjects;
// }
// // return allProjects;
// // }

export type AgoraBallotPost = {
projects: {
Expand All @@ -41,37 +41,37 @@ export type AgoraBallotPost = {
}[];
};

const createFakeDistribution = (total: number) => {
const distribution = [];
// const createFakeDistribution = (total: number) => {
// const distribution = [];

for (let i = 0; i < total; i++) {
distribution.push(Math.random());
}
// for (let i = 0; i < total; i++) {
// distribution.push(Math.random());
// }

const initialSum = distribution.reduce((a, b) => a + b, 0);
// const initialSum = distribution.reduce((a, b) => a + b, 0);

const coefficient = 100 / initialSum;
// const coefficient = 100 / initialSum;

return distribution.map((el) => Math.round(el * coefficient * 1000) / 1000);
};
// return distribution.map((el) => Math.round(el * coefficient * 1000) / 1000);
// };

export const main = async () => {
const dist = createFakeDistribution(projects.length);
const ballot = projects.map((item, index) => ({
project_id: item.id,
allocation: `${dist[index]}`,
impact: Math.round(Math.random() * 4) + 1,
}));
// export const main = async () => {
// const dist = createFakeDistribution(projects.length);
// const ballot = projects.map((item, index) => ({
// project_id: item.id,
// allocation: `${dist[index]}`,
// impact: Math.round(Math.random() * 4) + 1,
// }));

const jsonString = JSON.stringify(ballot, null, 2);
// const jsonString = JSON.stringify(ballot, null, 2);

fs.writeFile('ballot.json', jsonString, (err) => {
if (err) {
console.error('Error writing file', err);
} else {
console.log('JSON file saved successfully');
}
});
};
// fs.writeFile('ballot.json', jsonString, (err) => {
// if (err) {
// console.error('Error writing file', err);
// } else {
// console.log('JSON file saved successfully');
// }
// });
// };

void main();
// void main();

0 comments on commit bda9672

Please sign in to comment.