-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_munging.js
77 lines (67 loc) · 2.44 KB
/
data_munging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var movies_filtered = [];
var actors = []
var awards = []
var budgets = []
var directors = []
var genres = []
var months = []
var ratings = []
var releaseDates = []
var revenues = []
var rois = []
var titles = []
var years = []
var imdb_scores = []
var rotten_scores = []
var meta_scores = []
var number_awards = []
// create list of filtered movie objects
function filter() {
movies_filtered = [];
movies_filtered.push(movies.filter(movies => movies.year.includes(selectedYear) && movies.actor.includes(selectedActor) && movies.month.includes(selectedMonth) && movies.genre.includes(selectedGenre) && movies.director.includes(selectedDirector)))
}
// grab individual aspects of each movie and push into lists
function format() {
for (let i = 0; i < movies_filtered[0].length; i++) {
actors.push(movies_filtered[0][i].actor)
awards.push(movies_filtered[0][i].awards)
budgets.push(movies_filtered[0][i].budget)
directors.push(movies_filtered[0][i].director)
genres.push(movies_filtered[0][i].genre)
months.push(movies_filtered[0][i].month)
ratings.push(movies_filtered[0][i].ratings)
releaseDates.push(movies_filtered[0][i].releaseDate)
revenues.push(movies_filtered[0][i].revenue)
rois.push(movies_filtered[0][i].roi)
titles.push(movies_filtered[0][i].title)
years.push(movies_filtered[0][i].year)
};
}
// separate imdb, rotten tomato and metacritic ratings into individual lists
function separate_ratings() {
for (i = 0; i < ratings.length; i++) {
if (ratings[i][0].Value && ratings[i][1] && ratings[i][2]){
imdb_scores.push(parseFloat(ratings[i][0].Value))
rotten_scores.push(parseFloat(ratings[i][1].Value))
meta_scores.push(parseFloat(ratings[i][2].Value))
}
else if (ratings[i].length < 3) {
imdb_scores.push(0)
rotten_scores.push(0)
meta_scores.push(0)
console.log("UNDEFINED")
}
}
}
// from a string containing number of awards and nominations, sum them together to get a single value for "awards and nominations"
function extract_awards() {
for (var i = 0; i < awards.length; i++) {
var numbers = []
var numbers = awards[i].match(/\d+/g).map(Number)
var sum = 0
for (var j = 0; j <numbers.length; j++) {
sum += numbers[j]
}
number_awards.push(sum)
};
}