Skip to content

Commit

Permalink
Move code around
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Dec 19, 2024
1 parent ff58a7f commit b658603
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions build-filtered-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,51 @@ const currentDate = new Date()
const yyyymmdd = currentDate.toISOString().split('T')[0]
const timestamp = currentDate.getTime()

async function filterDeps() {
const builtData = []
const batchSize = 500
let batchCounter = 0
console.log(`${performance.now()}: Analysis BEGIN`)

for (const repo of rawDeps.all_public_dependent_repos) {
try {
console.log(`${performance.now()}: Getting repo data...`)
const repoData = await analyseRepo(repo)
if (repoData) {
builtData.push(repoData)
batchCounter++
}
console.log(`${performance.now()}: Analysis of ${repo.name} complete`)

const index = rawDeps.all_public_dependent_repos.findIndex(
(item) => item === repo
)
console.log(
`This was repo number ${index + 1} of ${
rawDeps.all_public_dependent_repos.length
}`
)

const remaining = await getRemainingRateLimit()
console.log(`${remaining} remaining on rate limit`)
} catch (error) {
if (error instanceof RequestError) {
continue
}
}
if (batchCounter >= batchSize) {
await writeBatchToFiles(builtData)
builtData.length = 0
batchCounter = 0
}
}

if (builtData.length > 0) {
await writeBatchToFiles(builtData)
}
console.log(`${performance.now()}: We're done!`)
}

async function analyseRepo(repo) {
// Output data columns
const repoOwner = repo.owner
Expand Down Expand Up @@ -188,51 +233,6 @@ async function getExactFrontendVersion(
return frontendVersion.replace('^', '').replace('~', '')
}

async function filterDeps() {
const builtData = []
const batchSize = 500
let batchCounter = 0
console.log(`${performance.now()}: Analysis BEGIN`)

for (const repo of rawDeps.all_public_dependent_repos) {
try {
console.log(`${performance.now()}: Getting repo data...`)
const repoData = await analyseRepo(repo)
if (repoData) {
builtData.push(repoData)
batchCounter++
}
console.log(`${performance.now()}: Analysis of ${repo.name} complete`)

const index = rawDeps.all_public_dependent_repos.findIndex(
(item) => item === repo
)
console.log(
`This was repo number ${index + 1} of ${
rawDeps.all_public_dependent_repos.length
}`
)

const remaining = await getRemainingRateLimit()
console.log(`${remaining} remaining on rate limit`)
} catch (error) {
if (error instanceof RequestError) {
continue
}
}
if (batchCounter >= batchSize) {
await writeBatchToFiles(builtData)
builtData.length = 0
batchCounter = 0
}
}

if (builtData.length > 0) {
await writeBatchToFiles(builtData)
}
console.log(`${performance.now()}: We're done!`)
}

async function writeBatchToFiles(builtData) {
// Write JSON file
await writeFileSync(
Expand Down

0 comments on commit b658603

Please sign in to comment.