Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add hacking force annual task #777

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/cron/tasks/hacking_force_annual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Task } from '..';
import { query } from '../../db/neo4j';
import { getClient } from '../../oss/ali';
const metrics = require('../../metrics');

const task: Task = {
cron: '0 0 20 1 *', // runs on the 20 Jan. every year
enable: true,
immediate: false,
callback: async () => {
const year = 2021;
// get OpenRank data for all Chinese users
const allData: any[] = await metrics.getUserOpenrank({labelUnion: [':regions/China'], startYear: year, endYear: year, endMonth: 12, limit: -1});

// get most active repos for all users
const activities: string[] = [];
for (let m = 1; m < 12; m++) {
activities.push(`COALESCE(a.activity_${year}${m},0.0)`);
}
for (let u of allData) {
const q = `MATCH (u:User{login:'${u.user_login}'})-[a:ACTION]->(r:Repo) RETURN r.name AS repo_name, (${activities.join('+')}) AS activity ORDER BY activity DESC LIMIT 10;`;
const result = await query(q);
u.most_active_repos = result.map(i => i.repo_name);
u.open_rank = u.open_rank[0];
}

// put data to OSS
const client = await getClient();
await client.put(`/hacking_force/annual_${year}.json`, Buffer.from(JSON.stringify(allData)));
console.log(`Run hacking force total task done for ${year}.`);
}
};

module.exports = task;