use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class OverallSectionController method update.
protected void update(List<Media> allMedia) {
// Constants
int last__days = 20;
// Data Mining - Vars
Map<String, Integer> categories = new HashMap<>();
Map<LocalDate, Map<String, Integer>> last30Days = new HashMap<>();
InfoBlipAccumulator info = new InfoBlipAccumulator();
// Data Mining - Calcs
for (Media m : allMedia) {
categories.put(m.getCategory(), categories.getOrDefault(m.getCategory(), 0) + 1);
info.accumulate(m);
for (Review r : m.getReviews()) {
if (ChronoUnit.DAYS.between(r.getDate(), LocalDate.now()) <= last__days) {
Map<String, Integer> cat2Num = last30Days.getOrDefault(r.getDate(), new HashMap<>());
Integer num = cat2Num.getOrDefault(m.getCategory(), 1);
cat2Num.put(m.getCategory(), num + 1);
last30Days.put(r.getDate(), cat2Num);
}
info.accumulate(r);
}
}
// Stats
statsBox.getChildren().clear();
statsBox.getChildren().add(info.getInfo());
// Chart # Media / Category
chartMediaPerCategory.setData(FXCollections.observableArrayList(Arrays.asList(DataManager.getCategories()).stream().map(c -> {
int count = categories.getOrDefault(c, 0);
return new PieChart.Data(c + " - " + count, count);
}).collect(Collectors.toList())));
// Chart # Reviews / Day
ObservableList list = FXCollections.observableArrayList();
LocalDate now = LocalDate.now();
for (String category : DataManager.getCategories()) {
XYChart.Series data = new XYChart.Series();
data.setName(category);
for (int i = last__days; i > -1; i--) {
LocalDate target = now.minusDays(i);
int count = last30Days.getOrDefault(target, new HashMap<>()).getOrDefault(category, 0);
String key = target.getDayOfMonth() + "";
data.getData().add(new XYChart.Data(key, count));
}
list.add(data);
}
chartReviewsPerDay.setData(list);
}
use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class SearchTabController method updateStats.
private void updateStats() {
int totalNumberReviews = 0;
int totalNumberMedia = 0;
int totalReviewRating = 0;
int totalCurrentRating = 0;
totalNumberMedia = searchTable.getItems().size();
for (Media media : searchTable.getItems()) {
totalNumberReviews += media.getReviews().size();
for (Review review : media.getReviews()) {
totalReviewRating += review.getRating().intValue();
}
totalCurrentRating += media.getCurrentRating().intValue();
}
searchResults.setText(totalNumberMedia + "");
searchMeanAverage.setText(String.format("%.2f", totalReviewRating * 1.0 / totalNumberReviews));
searchCurrentAverage.setText(String.format("%.2f", totalCurrentRating * 1.0 / totalNumberMedia));
}
Aggregations