-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add oss client and hypercrx task (#772)
Signed-off-by: Frankzhaopku <syzhao1988@126.com>
- Loading branch information
Showing
10 changed files
with
167 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { existsSync, mkdirSync, writeFileSync } from 'fs'; | ||
import { Task } from '..'; | ||
import { getClient as getNeo4jClient, parseRecord } from '../../db/neo4j'; | ||
import { forEveryMonth } from '../../metrics/basic'; | ||
|
||
const task: Task = { | ||
cron: '0 0 7 * *', // runs on the 5th day of every month at 00:00 | ||
enable: true, | ||
immediate: false, | ||
callback: async () => { | ||
const neo4jClient = await getNeo4jClient(); | ||
const session = neo4jClient.session(); | ||
const now = new Date(); | ||
const lastMonth = new Date(now.getTime() - 30 * 24 * 60 * 60); | ||
const year = lastMonth.getFullYear(), month = lastMonth.getMonth() + 1; | ||
const q = `MATCH (u:User) WHERE u.activity_${year}${month} IS NOT NULL RETURN u;`; | ||
const result = session.run(q); | ||
let count = 0; | ||
result.subscribe({ | ||
onNext: async r => { | ||
const user = parseRecord(r); | ||
const userInfo = { | ||
login: user.login, | ||
id: user.id, | ||
activity: {}, | ||
influence: {}, | ||
}; | ||
forEveryMonth(2015, 1, year, month, (y, m) => { | ||
userInfo.activity[`${y}-${m}`] = user[`activity_${y}${m}`] ?? 0; | ||
userInfo.influence[`${y}-${m}`] = user[`open_rank_${y}${m}`] ?? 0; | ||
}); | ||
const dir = `./local_files/hypercrx_actor/${user.login.charAt(0).toLowerCase()}`; | ||
if (!existsSync(dir)) { | ||
mkdirSync(dir); | ||
} | ||
writeFileSync(`${dir}/${user.login}.json`, JSON.stringify(userInfo)); | ||
count++; | ||
if (count % 10000 === 0) console.log(`Finish write ${count} files.`); | ||
}, | ||
onCompleted: () => { | ||
session.close().then(() => { | ||
console.log(`Process ${count} users done.`); | ||
}); | ||
}, | ||
onError: console.log, | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = task; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { writeFileSync, existsSync, mkdirSync } from 'fs'; | ||
import { Task } from '..'; | ||
import { getClient as getNeo4jClient, parseRecord } from '../../db/neo4j'; | ||
import { forEveryMonth } from '../../metrics/basic'; | ||
|
||
const task: Task = { | ||
cron: '0 0 6 * *', // runs on the 5th day of every month at 00:00 | ||
enable: true, | ||
immediate: false, | ||
callback: async () => { | ||
const neo4jClient = await getNeo4jClient(); | ||
const session = neo4jClient.session(); | ||
const now = new Date(); | ||
const lastMonth = new Date(now.getTime() - 30 * 24 * 60 * 60); | ||
const year = lastMonth.getFullYear(), month = lastMonth.getMonth() + 1; | ||
const q = `MATCH (r:Repo) WHERE r.activity_${year}${month} IS NOT NULL RETURN r;`; | ||
const result = session.run(q); | ||
let count = 0; | ||
result.subscribe({ | ||
onNext: async r => { | ||
const repo = parseRecord(r); | ||
const repoInfo = { | ||
id: repo.id, | ||
name: repo.name, | ||
org: repo.org_login, | ||
org_id: repo.org_id, | ||
activity: {}, | ||
influence: {}, | ||
}; | ||
forEveryMonth(2015, 1, year, month, (y, m) => { | ||
repoInfo.activity[`${y}-${m}`] = repo[`activity_${y}${m}`] ?? 0; | ||
repoInfo.influence[`${y}-${m}`] = repo[`open_rank_${y}${m}`] ?? 0; | ||
}); | ||
const [owner, name] = repoInfo.name.split('/'); | ||
const dir = `./local_files/hypercrx_repo/${owner}`; | ||
if (!existsSync(dir)) { | ||
mkdirSync(dir); | ||
} | ||
writeFileSync(`${dir}/${name}.json`, JSON.stringify(repoInfo)); | ||
count++; | ||
if (count % 10000 === 0) console.log(`Finish write ${count} files.`); | ||
}, | ||
onCompleted: () => { | ||
session.close().then(() => { | ||
console.log(`Process ${count} repos done.`); | ||
}); | ||
}, | ||
onError: console.log, | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = task; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters