Skip to content

Commit 0cb0c6c

Browse files
committed
2 parents 2509547 + 8be2c3e commit 0cb0c6c

File tree

4 files changed

+141
-47
lines changed

4 files changed

+141
-47
lines changed

functions/getCount.js

+77-33
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,84 @@
1-
const fs = require('fs');
2-
const csv = require('csv-parser');
1+
const fs = require("fs");
2+
const csv = require("csv-parser");
3+
const glob = require("glob");
34

4-
const getCount = async () => {
5-
const filePaths = ['1.csv', '2.csv'];
6-
const filterColumns = ['technical-workshop-topic', 'non-technical-workshop-topic'];
5+
const TECHNICAL_WORKSHOP_TOPIC = "technical-workshop-topic";
6+
const NON_TECHNICAL_WORKSHOP_TOPIC = "non-technical-workshop-topic";
77

8-
const columnCounts = {};
9-
filterColumns.forEach((column) => {
10-
columnCounts[column] = {};
11-
});
8+
const accountRenamings = (obj = {}) => {
9+
const renameEvent = (parent = "", oldName = "", newName = "") => {
10+
obj[parent][newName] += obj[parent][oldName];
11+
delete obj[parent][oldName];
12+
return obj;
13+
};
14+
renameEvent(
15+
TECHNICAL_WORKSHOP_TOPIC,
16+
"No Code App Building",
17+
"No-Code 101: Building No-Code WebApps with CodeDesign"
18+
);
19+
renameEvent(
20+
TECHNICAL_WORKSHOP_TOPIC,
21+
"Cloud Services Workshop",
22+
"Linux And Cloud Fundamentals"
23+
);
24+
renameEvent(
25+
NON_TECHNICAL_WORKSHOP_TOPIC,
26+
"Growth strategies for Bootstrapped startups",
27+
"Cost-Effective Ways to Grow Your Self-Funded Startup"
28+
);
29+
30+
console.log(obj);
31+
32+
console.log("After removing undefined entries:\n");
33+
34+
delete obj[TECHNICAL_WORKSHOP_TOPIC][undefined];
35+
delete obj[NON_TECHNICAL_WORKSHOP_TOPIC][undefined];
36+
37+
return obj;
38+
};
39+
40+
const getCount = () => {
41+
// const filePaths = ["csv/bothStudent.csv", "csv/workshopOnlyStudent.csv"];
42+
const filePaths = glob.sync("csv/**/*.csv");
43+
console.log(filePaths);
44+
45+
const filterColumns = [
46+
"technical-workshop-topic",
47+
"non-technical-workshop-topic",
48+
];
1249

13-
return new Promise((resolve, reject) => {
14-
let count = 0;
15-
filePaths.forEach((filePath) => {
16-
fs.createReadStream(filePath)
17-
.pipe(csv())
18-
.on('data', (row) => {
19-
filterColumns.forEach((column) => {
20-
const value = row[column];
21-
if (!columnCounts[column][value]) {
22-
columnCounts[column][value] = 0;
23-
}
24-
columnCounts[column][value]++;
25-
});
26-
})
27-
.on('end', () => {
28-
count++;
29-
if (count === filePaths.length) {
30-
resolve(columnCounts);
31-
}
32-
})
33-
.on('error', (err) => {
34-
reject(err);
35-
});
50+
const columnCounts = {};
51+
filterColumns.forEach((column) => {
52+
columnCounts[column] = {};
53+
});
54+
55+
return new Promise((resolve, reject) => {
56+
let count = 0;
57+
filePaths.forEach((filePath) => {
58+
fs.createReadStream(filePath)
59+
.pipe(csv())
60+
.on("data", (row) => {
61+
filterColumns.forEach((column) => {
62+
const value = row[column];
63+
if (!columnCounts[column][value]) {
64+
columnCounts[column][value] = 0;
65+
}
66+
columnCounts[column][value]++;
67+
});
68+
})
69+
.on("end", () => {
70+
count++;
71+
if (count === filePaths.length) {
72+
resolve(accountRenamings(columnCounts));
73+
}
74+
})
75+
.on("error", (err) => {
76+
reject(err);
3677
});
3778
});
79+
});
3880
};
3981

40-
module.exports = getCount;
82+
getCount().then((res) => console.log(res));
83+
84+
module.exports = getCount;

functions/getWorkshopCount.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ const getWorkshopCount = async () => {
2929
let elements = await page.$x(
3030
'//*[@id="navbarNav"]/ul/li[1]/div[2]/div[1]/a[1]/div/div/div'
3131
);
32-
console.log("here");
32+
console.log("events page");
3333
await elements[0].click();
3434
await page.waitForNavigation();
3535
console.log("reached events list");
3636

37-
// Clicking on manage button
38-
elements = await page.$x(
39-
"/html/body/div[2]/div/div[2]/div[1]/div[2]/div[4]/div/div[1]/div[3]/p[2]/a"
37+
await page.goto(
38+
"https://www.explara.com/em/event/manage/dashboard/eid/629077?type=ft"
4039
);
41-
await elements[0].click();
42-
await page.waitForNavigation();
40+
// // Clicking on manage button
41+
// elements = await page.$x(
42+
// "/html/body/div[2]/div/div[2]/div[1]/div[2]/div[4]/div/div[1]/div[3]/p[2]/a"
43+
// );
44+
// console.log(elements);
45+
46+
// await elements[0].click();
47+
// await page.waitForNavigation();
4348
console.log("reached dashboard");
4449

4550
// click on attendence section
@@ -87,4 +92,6 @@ const getWorkshopCount = async () => {
8792
}
8893
};
8994

95+
getWorkshopCount().then((res) => console.log(res));
96+
9097
module.exports = getWorkshopCount;

package-lock.json

+50-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"express": "^4.18.2",
2323
"jimp": "^0.22.7",
2424
"nodemailer": "^6.9.1",
25+
"glob": "^9.3.0",
2526
"puppeteer": "^19.7.2",
2627
"qrcode": "^1.5.1",
2728
"serverless-http": "^3.1.1"

0 commit comments

Comments
 (0)