-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental recommender scripts (#4)
* wip: recommender prep scripts * add db data as csv * remove unused data * implement prep scripts and recommender
- Loading branch information
Showing
12 changed files
with
699 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ data/**/* | |
|
||
.ipynb_checkpoints/ | ||
|
||
node_modules | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"printWidth": 80, | ||
"singleQuote": true, | ||
"tabWidth":2, | ||
"endOfLine": "lf", | ||
"useTabs": false, | ||
"semi": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Client } from 'pg'; | ||
import * as fs from 'fs'; | ||
|
||
const enum MediaType { | ||
TV = 1, | ||
MOVIE = 2, | ||
} | ||
|
||
const run = async () => { | ||
const client = new Client({ | ||
host: 'localhost', | ||
user: 'pgres', | ||
password: 'pgres', | ||
database: 'movie_match', | ||
}); | ||
|
||
await client.connect(); | ||
|
||
const result = await client.query(` | ||
select m.id as media_id, | ||
m.type as media_type, | ||
m.title as media_title, | ||
m.summary as media_summary, | ||
m.rating as media_rating, | ||
m.release_date as media_release_date, | ||
g.name as genre_name | ||
from media m | ||
join media_genres mg on m.id = mg.media_id | ||
join genres g on g.id = mg.genre_id | ||
`); | ||
|
||
const data: Record< | ||
string, | ||
{ | ||
mediaId: string; | ||
mediaType: MediaType; | ||
mediaTitle: string; | ||
mediaSummary: string; | ||
mediaRating: number; | ||
mediaReleaseDate: number; | ||
genre0: string | null; | ||
genre1: string | null; | ||
genre2: string | null; | ||
genre3: string | null; | ||
} | ||
> = {}; | ||
|
||
for (const row of result.rows) { | ||
if (!data[row['media_id']]) { | ||
data[row['media_id']] = { | ||
mediaId: row['media_id'], | ||
mediaType: | ||
row['media_type'] === 'movie' ? MediaType.MOVIE : MediaType.TV, | ||
mediaTitle: row['media_title'], | ||
mediaSummary: row['media_summary'], | ||
mediaRating: Number(row['media_rating']), | ||
mediaReleaseDate: Date.parse(row['media_release_date']), | ||
genre0: null, | ||
genre1: null, | ||
genre2: null, | ||
genre3: null, | ||
}; | ||
} | ||
|
||
// place genre at correct index | ||
for (let i = 0; i < 4; ++i) { | ||
const idx = `genre${i}` as 'genre0' | 'genre1' | 'genre2' | 'genre3'; | ||
|
||
if (data[row['media_id']][idx] === null) { | ||
data[row['media_id']][idx] = row['genre_name']; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
fs.writeFileSync( | ||
'../data/media_all.json', | ||
JSON.stringify(Object.values(data)), | ||
'utf-8' | ||
); | ||
|
||
await client.end(); | ||
}; | ||
|
||
run().then((r) => console.log('done!')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@movie-match/prep", | ||
"version": "1.0.0", | ||
"description": "Prep scripts for recommender", | ||
"scripts": { | ||
"voted": "ts-node vote2json.ts", | ||
"all": "ts-node all2json.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@tsconfig/node18": "^18.2.0", | ||
"@types/node": "^18.16.20", | ||
"@types/pg": "^8.10.2", | ||
"csv": "^6.3.1", | ||
"pg": "^8.11.1", | ||
"prettier": "^2.8.8", | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"ts-node": "^10.9.1" | ||
} | ||
} |
Oops, something went wrong.