Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restoring branch so assignment can be graded and submitted #435

Merged
merged 6 commits into from
Oct 26, 2024
Merged
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
57 changes: 57 additions & 0 deletions lesson_10/libraries/src/loaders/lj_mcwilliams_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class LjMcwilliamsLoader implements Loader {
getLoaderName(): string {
return 'ljmcwilliams';
}

async loadData(): Promise<MediaItem[]> {
const credits = await this.loadCredits();
const mediaItems = await this.loadMediaItems();

console.log(
`Loaded ${credits.length} credits and ${mediaItems.length} media items`,
);

return [...mediaItems.values()];
}

async loadMediaItems(): Promise<MediaItem[]> {
// TODO: Implement this method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove this.

const media = [];
const readable = fs
.createReadStream('data/media_items.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
/**This destructures the CSV file rows. */
const { id, type, title, year } = row;
media.push(new MediaItem(id, title, type, year, []));
}
return media;
}

/*
An asyncchronous function named loadCredits
returns a Promise of an array of Credit Objects.
*/
async loadCredits(): Promise<Credit[]> {
//The empty credits array will store parsed credit data
const credits = [];
/**
* This var creates a readable stream from the CSV file and
* is piped through the csv function to parse the data.
*/
const readable = fs
.createReadStream('data/credits.csv', 'utf-8')
.pipe(csv());
//This asynchronously iterates over each row of the parsed CSV data.
for await (const row of readable) {
const { media_item_id, role, name } = row;
credits.push(new Credit(media_item_id, name, role));
}
return credits;
}
}
2 changes: 2 additions & 0 deletions lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { HummadTanweerLoader } from './hummad_tanweer_loader.js';
import { JamesCapparellLoader } from './james_capparell_loader.js';
import { JosephCaballeroLoader } from './joseph_caballero_loader.js';
import { KimberleeHaldaneLoader } from './kimberlee_haldane_loader.js';
import { LjMcwilliamsLoader } from './lj_mcwilliams_loader.js';
import { NileJacksonLoader } from './nile_jackson_loader.js';
import { OyeyemiJimohLoader } from './oyeyemi_jimoh_loader.js';
import { PabloLimonParedesLoader } from './pablo_limon_paredes_loader.js';
Expand All @@ -32,6 +33,7 @@ const LOADER_PROVIDERS = [
JamesCapparellLoader,
JosephCaballeroLoader,
KimberleeHaldaneLoader,
LjMcwilliamsLoader,
NileJacksonLoader,
OyeyemiJimohLoader,
PabloLimonParedesLoader,
Expand Down