-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThirdRatings.java
74 lines (57 loc) · 2.06 KB
/
ThirdRatings.java
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
/**
* Write a description of class thirdRatings here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class ThirdRatings
{
private ArrayList<EfficientRater> myRaters;
public ThirdRatings() {
this("ratings.csv");
}
public ThirdRatings(String ratingsfile) {
FirstRatings fr = new FirstRatings();
myRaters = fr.loadRaters(ratingsfile);
}
public int getRaterSize() {
return myRaters.size();
}
private double getAverageByID(String id, int minimalRaters){
double count = 0.0;
double sum = 0.0;
for(EfficientRater r : myRaters){
if(r.hasRating(id)) {
sum += r.getRating(id);
count ++;
}
}
return (count >= minimalRaters) ? (double)(sum/count) : 0.0;
}
public ArrayList<Rating> getAverageRatings( int minimalRaters) {
ArrayList<Rating> averageRatings = new ArrayList<Rating>();
ArrayList<String> movies = MovieDatabase.filterBy(new TrueFilter());
for (String movieID : movies) {
double rating = getAverageByID(movieID, minimalRaters);
Rating movieAvgRate = new Rating(movieID, rating);
if(rating != 0){
averageRatings.add(movieAvgRate);
}
}
return averageRatings;
}
public ArrayList<Rating> getAverageRatingsByFilter(int minimalRaters,
Filter filterCriteria){
ArrayList<Rating> avgRatingsByFilter = new ArrayList<Rating>();
ArrayList<String> movies = MovieDatabase.filterBy(filterCriteria);
for (String movieID : movies){
double rating = getAverageByID(movieID, minimalRaters);
Rating movieAvgRate = new Rating(movieID, rating);
if(rating != 0){
avgRatingsByFilter.add(movieAvgRate);
}
}
return avgRatingsByFilter;
}
}