Skip to content

Commit a597199

Browse files
samcunliffeCopilot
andauthored
Remove unused conda data-fetcher function and therefore remove DuckDB dependency. (#106)
* Can actually remove the whole function and the dependency!? * And now these are unused. * Regenerate package-lock.json. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ac3139e commit a597199

File tree

5 files changed

+1324
-4846
lines changed

5 files changed

+1324
-4846
lines changed

backend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"esno": "^4.8.0",
5959
"fs-extra": "^11.3.3",
6060
"octokit": "^5.0.5",
61-
"yaml": "^2.8.2",
62-
"duckdb-async": "^1.4.2"
61+
"yaml": "^2.8.2"
6362
}
6463
}
Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import fs from 'fs';
2-
import os from 'os';
3-
import path from 'path';
42
import * as https from 'node:https';
5-
import { Config, Result } from '../index';
6-
import { CustomOctokit } from '../lib/octokit';
7-
import { queryRepoNames } from './fetcher_utils';
8-
9-
import { Database } from 'duckdb-async';
103

114
async function downloadParquetFile(url: string, outputPath: string) {
125
return new Promise((resolve, reject) => {
@@ -25,81 +18,3 @@ async function downloadParquetFile(url: string, outputPath: string) {
2518
});
2619
});
2720
}
28-
29-
export const addCondaData = async (result: Result, octokit: CustomOctokit, config: Config, startYear: number=2018) => {
30-
const repos = await queryRepoNames(octokit, config);
31-
const baseDir = path.join(os.homedir(), '.dashboard');
32-
33-
const packages = repos.map((repo) => {return repo.name });
34-
35-
if (!fs.existsSync(baseDir)) {
36-
fs.mkdirSync(baseDir);
37-
}
38-
39-
let currYear = new Date().getFullYear();
40-
let lastMonth = 1;
41-
42-
for (let i = startYear; i <= currYear; i++) {
43-
for (let j = 1; j <= 12; j++) {
44-
const fileName = path.join(baseDir, `${i}-${String(j).padStart(2, '0')}.parquet`);
45-
46-
if (!fs.existsSync(fileName)) {
47-
const url = `https://anaconda-package-data.s3.amazonaws.com/conda/monthly/${i}/${i}-${String(j).padStart(2, '0')}.parquet`;
48-
49-
// Check if the URL for the given month exists (status code 2xx)
50-
// The updates can take some time to be available, so there's
51-
// no easy way to know which month to stop at.
52-
const checkURLReq = await new Promise((resolve, reject) => {
53-
fetch(url, {
54-
method: "HEAD"
55-
}).then(response => {
56-
resolve(response.status.toString()[0] === "2")
57-
}).catch(error => {
58-
reject(false)
59-
})
60-
})
61-
62-
// If the URL does not exist, assume that there are no more
63-
// files to download and break the loop
64-
if (!checkURLReq) {
65-
lastMonth = j > 1 ? j - 1 : 12;
66-
// Make sure we break out of the outer loop as well
67-
// Update teh current year to the last year we downloaded
68-
currYear = i;
69-
break;
70-
} else {
71-
await downloadParquetFile(url, fileName);
72-
}
73-
}
74-
}
75-
}
76-
77-
const db = await Database.create( `:memory:` );
78-
const formattedString = packages.map((pkg) => `'${pkg}'`).join(',');
79-
80-
const totalDownloads = await db.all(`SELECT pkg_name, SUM(counts)::INTEGER AS total FROM '${baseDir}/*.parquet' WHERE pkg_name IN (${formattedString}) GROUP BY pkg_name`);
81-
82-
if (lastMonth == 12) {
83-
currYear -= 1;
84-
}
85-
86-
const lastMonthDownloads = await db.all(`SELECT pkg_name, SUM(counts)::INTEGER AS total FROM '${baseDir}/${currYear}-${String(lastMonth).padStart(2, '0')}.parquet' WHERE pkg_name IN (${formattedString}) GROUP BY pkg_name`);
87-
88-
totalDownloads.forEach((row) => {
89-
if ( !result.repositories[row.pkg_name].condaTotalDownloads ) {
90-
result.repositories[row.pkg_name].condaTotalDownloads = row.total;
91-
} else {
92-
result.repositories[row.pkg_name].condaTotalDownloads += row.total;
93-
}
94-
})
95-
96-
lastMonthDownloads.forEach((row) => {
97-
if (!result.repositories[row.pkg_name].condaMonthlyDownloads) {
98-
result.repositories[row.pkg_name].condaMonthlyDownloads = row.total;
99-
} else {
100-
result.repositories[row.pkg_name].condaMonthlyDownloads += row.total;
101-
}
102-
})
103-
104-
return result;
105-
};

backend/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
addRepositoriesToResult,
1414
} from './fetchers';
1515
import { CustomOctokit, checkRateLimit, personalOctokit } from './lib/octokit';
16-
import { addCondaData } from './fetchers/fetch_parquet';
1716

1817
export interface Result {
1918
meta: {
@@ -133,8 +132,7 @@ for (const orgName of configOrganizationName) {
133132
addRepositoriesToResult,
134133
addIssueAndPrData,
135134
addDiscussionData,
136-
addIssueMetricsData,
137-
addCondaData
135+
addIssueMetricsData
138136
);
139137

140138
outputResult(result, orgName);

0 commit comments

Comments
 (0)