Skip to content

Commit

Permalink
Feat : Lesson-10 adding Yafiah Loader provider (code-differently#334)
Browse files Browse the repository at this point in the history
* Feat : Lesson-10 adding Yafiah Loader provider

* fix-up: remove

* Fix-Up: removed

---------

Co-authored-by: Yafiaha <[email protected]>
Co-authored-by: Anthony D. Mays <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 748fdef commit 903d387
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import { PabloLimonParedesLoader } from './pablo_limon_paredes_loader.js';
import { ShawnDunsmoreLoader } from './shawn_dunsmore_loader.js';
import { TommyTranLoader } from './tommy_tran_loader.js';
import { XavierCruzLoader } from './xavier_cruz_loader.js';
import { YafiahAbdullahLoader } from './yafiah_abdullah_loader.js';
import { ZionBuchananLoader } from './zion_buchanan_loader.js';

export const Loaders = Symbol.for('Loaders');

// Add your quiz provider here.

const LOADER_PROVIDERS = [
AmiyahJonesLoader,
AngelicaCastilloLoader,
Expand All @@ -37,6 +37,7 @@ const LOADER_PROVIDERS = [
ShawnDunsmoreLoader,
TommyTranLoader,
XavierCruzLoader,
YafiahAbdullahLoader,
ZionBuchananLoader,
];

Expand Down
47 changes: 47 additions & 0 deletions lesson_10/libraries/src/loaders/yafiah_abdullah_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class YafiahAbdullahLoader implements Loader {
getLoaderName(): string {
return 'yafiahabdullah';
}

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

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

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

async loadMediaItems(): Promise<MediaItem[]> {
const media = [];
const readable = fs
.createReadStream('data/media_items.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { id, type, title, year } = row;
media.push(new MediaItem(id, title, type, year, []));
}
return media;
}

async loadCredits(): Promise<Credit[]> {
const credits = [];
const readable = fs
.createReadStream('data/credits.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { media_item_id, role, name } = row;
credits.push(new Credit(media_item_id, name, role));
}
return credits;
}
}

0 comments on commit 903d387

Please sign in to comment.