Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a PR in the freecodecamp CDN repo, if you haven't already done so to add this data there.

If you have already created a PR and had it approved and merged in, then this file can be removed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's confirm the draft, then I'll would PR finalized data.json

"Computer Science and Engineering": {
"Dept_code": "CSE",
"programs": [
{
"id": "CSE101",
"name": "Database Management System",
"buildingCode": "CSE",
"room": "402",
"instructors": [
{
"id": "INS001",
"name": "Alejandro",
"email": "alejandro@edu.com",
"officeHours": "Sun-Tue 10AM-12PM"
},
{
"id": "INS002",
"name": "Kenji",
"email": "kenji@edu.com",
"officeHours": null
}
]
},
{
"id": "CSE102",
"name": "Data Structures and Algorithms",
"buildingCode": "CSE",
"room": "205",
"instructors": [
{
"id": "INS003",
"name": "Fatima",
"email": "fatima@edu.com",
"officeHours": "Mon-Wed 2PM-4PM"
},
{
"id": "INS004",
"name": "Mei",
"email": "mei@edu.com"
}
]
},
{
"id": "CSE103",
"name": "Operating Systems",
"buildingCode": "CSE",
"room": null,
"instructors": [
{
"id": "INS005",
"name": "Dmitri",
"email": "dmitri@edu.com",
"officeHours": "Thu 11AM-1PM"
}
]
},
{
"id": "CSE104",
"name": "Computer Networks",
"buildingCode": "CSE",
"room": "510",
"instructors": []
}
]
},
"Electrical and Electronic Engineering": {
"Dept_code": "EEE",
"programs": [
{
"id": "EEE101",
"name": "Digital Logic Design",
"buildingCode": "EEE",
"room": "101",
"instructors": [
{
"id": "INS006",
"name": "Javier",
"email": "javier@edu.com",
"officeHours": "Sun 9AM-11AM"
}
]
},
{
"id": "EEE102",
"name": "Electronic Devices and Circuits",
"buildingCode": "EEE",
"room": "303",
"instructors": [
{
"id": "INS007",
"name": "Isabella",
"email": "isabella@edu.com",
"officeHours": null
},
{
"id": "INS008",
"name": "Omar",
"email": null,
"officeHours": "Tue 3PM-5PM"
}
]
},
{
"id": "EEE103",
"name": "Power Systems",
"room": "404",
"instructors": [
{
"id": "INS009",
"name": "Yuki",
"email": "yuki@edu.com",
"officeHours": "Mon 10AM-12PM"
}
]
}
]
},
"Business Administration": {
"Dept_code": "BBA",
"programs": [
{
"id": "BBA101",
"name": "Financial Accounting",
"buildingCode": "BBA",
"room": "201",
"instructors": [
{
"id": "INS010",
"name": "Sofia",
"email": "sofia@edu.com",
"officeHours": "Wed 1PM-3PM"
}
]
},
{
"id": "BBA102",
"name": "Marketing Principles",
"buildingCode": "BBA",
"room": "305",
"instructors": [
{
"id": "INS011",
"name": "Mateo",
"email": "mateo@edu.com"
}
]
},
{
"id": "BBA103",
"name": "Business Analytics",
"buildingCode": "BBA",
"room": null,
"instructors": []
}
]
},
"Architecture": {
"Dept_code": "ARC",
"programs": [
{
"id": "ARC101",
"name": "Urban Design",
"buildingCode": "ARC",
"room": "601",
"instructors": [
{
"id": "INS012",
"name": "Elena",
"email": "elena@edu.com",
"officeHours": "Thu 2PM-4PM"
}
]
},
{
"id": "ARC102",
"name": "Architectural Drawing",
"buildingCode": "ARC",
"room": "603",
"instructors": [
{
"id": "INS013",
"name": "Santiago",
"email": "santiago@edu.com",
"officeHours": null
}
]
},
{
"id": "ARC103",
"name": "Landscape Planning",
"buildingCode": "ARC",
"instructors": [
{
"id": "INS014",
"name": "Aisha",
"email": "aisha@edu.com"
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
//this data will be fetched from CDN
const fs = require("fs");
const data = fs.readFileSync("data.json", "utf8");
const rawData = JSON.parse(data);
// console.log(rawData);
Comment on lines +1 to +5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a PR in the freecodecamp CDN repo, to add the data.json.

If you have already created a PR and had it approved and merged in, then this will need to be updated to come from the CDN instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After confirming the draft these lines will be removed.


function normalizeDirectory(rawData) {
// Lookup tables
const departmentsById = {};
const programsById = {};
const instructorsById = {};
const instructorsByEmail = {};

// Convert object into iterable array
const departmentEntries = Object.entries(rawData);

departmentEntries.forEach(([departmentName, departmentData], index) => {
// Generate department ID
const departmentId = departmentData.Dept_code || `dept-${index + 1}`;

// Store department
departmentsById[departmentId] = {
id: departmentId,
name: departmentName,
programIds: [],
};

// Loop through programs
departmentData.programs.forEach((program) => {
programsById[program.id] = {
...program,
departmentId,
};

departmentsById[departmentId].programIds.push(program.id);

// Normalize instructors
program.instructors.forEach((instructor) => {
instructorsById[instructor.id] = {
...instructor,
programId: program.id,
departmentId,
};

// Create fast email lookup
if (instructor.email) {
instructorsByEmail[instructor.email] = instructor.id;
}
});
});
});

return {
departmentsById,
programsById,
instructorsById,
instructorsByEmail,
};
}

const normalizedData = normalizeDirectory(rawData);
// console.log(normalizedData);



function getInstructorByEmail(email, normalizedData) {

const instructorId =
normalizedData.instructorsByEmail[email];

if (!instructorId) {
return "Instructor not found";
}

const instructor =
normalizedData.instructorsById[instructorId];

const department =
normalizedData.departmentsById[
instructor?.departmentId
];

return {
name: instructor?.name ?? "Unknown Instructor",

officeHours:
instructor?.officeHours ??
"Not Available",

department:
department?.name ??
"Unknown Department"
};
}

// console.log(
// getInstructorByEmail(
// "dmitri@edu.com",
// normalizedData
// )
// );


function listRoomsByBuilding(buildingCode, normalizedData) {

return Object.values(normalizedData.programsById)

.filter(program =>
program.buildingCode === buildingCode
)

.map(program => program.room)

.filter(room => room != null)

.sort((a, b) => a.localeCompare(b, undefined, {
numeric: true
}));
}

// List rooms
// console.log(
// listRoomsByBuilding(
// "CSE",
// normalizedData
// )
// );


function renderDirectorySummary(normalizedData) {

const departments =
Object.keys(normalizedData.departmentsById).length;

const programs =
Object.keys(normalizedData.programsById).length;

const instructors =
Object.keys(normalizedData.instructorsById).length;

const missingOfficeHours =
Object.values(normalizedData.instructorsById)
.filter(instructor =>
instructor.officeHours == null
).length;

const programsWithoutRooms =
Object.values(normalizedData.programsById)
.filter(program =>
program.room == null
).length;

return `
Campus Directory Summary
------------------------
Departments: ${departments}
Programs: ${programs}
Instructors: ${instructors}
Missing Office Hours: ${missingOfficeHours}
Programs Without Rooms: ${programsWithoutRooms}
`;
}

console.log(
renderDirectorySummary(
normalizedData
)
);