use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class Dumpster method getRandomReview.
public static Review getRandomReview() {
Review r = new Review();
r.setRating(BigDecimal.valueOf(random.nextInt(10) + 1));
r.setUser(users[random.nextInt(users.length)]);
r.setDate(LocalDate.of(random.nextInt(LocalDate.now().getYear() - earliestYear) + earliestYear, random.nextInt(12) + 1, random.nextInt(28) + 1));
return r;
}
use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class AchievementFactory method getAchievements.
/* Unimplemented:
Binge
Spree
Marathon
Paranoia
A True Masterpiece
Inconsistency
*/
public static List<Achievement> getAchievements() {
List<Achievement> achievements = new ArrayList<>();
achievements.addAll(Arrays.asList(new Achievement("", "Star Gazer", "Star Retrospector", 1, () -> {
int result = 0;
try (Scanner scanner = new Scanner(new URL("https://api.github.com/repos/NonlinearFruit/Retrospector/stargazers").openStream())) {
String responseBody = scanner.useDelimiter("\\A").next();
result = Arrays.asList(responseBody.split("\n")).stream().anyMatch(s -> s.contains("login") && s.contains(DataManager.getGithubUser()) && !DataManager.getGithubUser().isEmpty()) ? 100 : 0;
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
return result;
}), new Achievement("", "Spectrum", "Have more categories than colors", 1, () -> (int) (DataManager.getCategories().length * 100.0 / (StatsTabController.colors.length + 1))), new Achievement("", "Inspector", "Edit the .config file", 2, () -> {
PropertyManager.Configuration dusty = new PropertyManager.Configuration();
if (dusty.getDefaultUser().equals(DataManager.getDefaultUser()) && dusty.getCategories().length == DataManager.getCategories().length)
return 0;
return 100;
}), new Achievement("", "Paranoia", "Keep a backup", 2, () -> {
try {
return new File(PropertyManager.retroFolder + "/Backup").list().length > 0 ? 100 : 0;
} catch (Exception ex) {
return 0;
}
}), new Achievement("", "Never Again", "Give a 1 star review", 3, () -> DataManager.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).anyMatch(r -> r.getRating().equals(BigDecimal.ONE)) ? 100 : 0), new Achievement("", "Trivial Pursuit", "Have 5 factoid types", 3, () -> DataManager.getFactiodTypes().length * 20), new Achievement("", "Diversify", "Have 5 categories", 3, () -> DataManager.getCategories().length * 20), new Achievement("", "Social", "Have 3 users", 3, () -> DataManager.getUsers().size() * 34), new Achievement("", "Rock", "Media with Rock in the title", 3, () -> DataManager.getMedia().stream().anyMatch(m -> m.getTitle().contains("Rock")) ? 100 : 0), new Achievement("", "Paper", "Media with Paper in the title", 3, () -> DataManager.getMedia().stream().anyMatch(m -> m.getTitle().contains("Paper")) ? 100 : 0), new Achievement("", "Scissors", "Media with Scissor in the title", 3, () -> DataManager.getMedia().stream().anyMatch(m -> m.getTitle().contains("Scissor")) ? 100 : 0), new Achievement("", "Lizard", "Media with Lizard in the title", 3, () -> DataManager.getMedia().stream().anyMatch(m -> m.getTitle().contains("Lizard")) ? 100 : 0), new Achievement("", "Spock", "Media with Star Trek in the title", 3, () -> DataManager.getMedia().stream().anyMatch(m -> m.getTitle().contains("Star Trek")) ? 100 : 0), new Achievement("", "Star Wars", "Media with Star Wars in the title", 3, () -> DataManager.getMedia().stream().anyMatch(m -> m.getTitle().contains("Star Wars")) ? 100 : 0), new Achievement("", "Master", "Retrospect for 10 years", 1, () -> (int) Math.floor(ChronoUnit.DAYS.between(DataManager.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).reduce((a, b) -> a.getDate().isBefore(b.getDate()) ? a : b).get().getDate(), LocalDate.now()) * 0.027)), new Achievement("", "Journeyman", "Retrospect for 5 years", 2, () -> (int) Math.floor(ChronoUnit.DAYS.between(DataManager.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).reduce((a, b) -> a.getDate().isBefore(b.getDate()) ? a : b).get().getDate(), LocalDate.now()) * 0.055)), new Achievement("", "Apprentice", "Retrospect for 1 year", 3, () -> (int) Math.floor(ChronoUnit.DAYS.between(DataManager.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).reduce((a, b) -> a.getDate().isBefore(b.getDate()) ? a : b).get().getDate(), LocalDate.now()) * 0.274)), new Achievement("", "Unemployed", "10 review/day for 20 days", 1, () -> (int) (getLongestConsecutiveDays(10) * 5)), new Achievement("", "Vacation", "10 review/day for a week", 2, () -> (int) (getLongestConsecutiveDays(10) * 14.3)), new Achievement("", "Weekend", "10 review/day for 3 days", 3, () -> (int) (getLongestConsecutiveDays(10) * 33.4)), new Achievement("", "Academic", "Category with 10,000 media", 1, () -> Arrays.asList(DataManager.getCategories()).stream().mapToInt(c -> getReviewsPerCategory(c)).max().orElse(0) / 100), new Achievement("", "Enthusiast", "Category with 1,000 media", 2, () -> Arrays.asList(DataManager.getCategories()).stream().mapToInt(c -> getReviewsPerCategory(c)).max().orElse(0) / 10), new Achievement("", "Dabbler", "Category with 100 media", 3, () -> Arrays.asList(DataManager.getCategories()).stream().mapToInt(c -> getReviewsPerCategory(c)).max().orElse(0)), new Achievement("", "Iconic", "Review 1 media 20 times", 1, () -> Math.toIntExact(DataManager.getMedia().stream().mapToLong(m -> m.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).count()).max().getAsLong() * 5)), new Achievement("", "Classic", "Review 1 media 10 times", 2, () -> Math.toIntExact(DataManager.getMedia().stream().mapToLong(m -> m.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).count()).max().getAsLong() * 10)), new Achievement("", "Favorite", "Review 1 media 5 times", 3, () -> Math.toIntExact(DataManager.getMedia().stream().mapToLong(m -> m.getReviews().stream().filter(r -> r.getUser().equals(DataManager.getDefaultUser())).count()).max().getAsLong() * 20)), new Achievement("", "Renaissance Man", "1,000 reviews in each category", 1, () -> Arrays.asList(DataManager.getCategories()).stream().mapToInt(c -> getReviewsPerCategory(c)).min().orElse(0) / 10), new Achievement("", "Well Rounded", "100 reviews in each category", 2, () -> Arrays.asList(DataManager.getCategories()).stream().mapToInt(c -> getReviewsPerCategory(c)).min().orElse(0)), new Achievement("", "Jack of All Trades", "10 reviews in each category", 3, () -> Arrays.asList(DataManager.getCategories()).stream().mapToInt(c -> getReviewsPerCategory(c)).min().orElse(0) * 10), new Achievement("", "Enigmatologist", "Factoid with 10,000 facts", 1, () -> Arrays.stream(DataManager.getFactiodTypes()).mapToInt(f -> DataManager.getFactoidsByType(f).size()).max().orElse(0) / 100), new Achievement("", "Riddler", "Factoid with 1,000 facts", 2, () -> Arrays.stream(DataManager.getFactiodTypes()).mapToInt(f -> DataManager.getFactoidsByType(f).size()).max().orElse(0) / 10), new Achievement("", "Puzzler", "Factoid with 100 facts", 3, () -> Arrays.stream(DataManager.getFactiodTypes()).mapToInt(f -> DataManager.getFactoidsByType(f).size()).max().orElse(0)), new Achievement("", "Researcher", "1,000 facts for each factoid", 1, () -> DataManager.getFactiodTypes().length < 5 ? 0 : Arrays.stream(DataManager.getFactiodTypes()).mapToInt(f -> DataManager.getFactoidsByType(f).size()).min().orElse(0) / 10), new Achievement("", "Scientist", "100 facts for each factoid", 2, () -> DataManager.getFactiodTypes().length < 5 ? 0 : Arrays.stream(DataManager.getFactiodTypes()).mapToInt(f -> DataManager.getFactoidsByType(f).size()).min().orElse(0)), new Achievement("", "Objective", "10 facts for each factoid", 3, () -> DataManager.getFactiodTypes().length < 5 ? 0 : Arrays.stream(DataManager.getFactiodTypes()).mapToInt(f -> DataManager.getFactoidsByType(f).size()).min().orElse(0) * 10), new Achievement("", "Scholarly", "Give 100 looong reviews", 1, () -> Math.toIntExact(DataManager.getReviews().filtered(r -> r.getUser().equals(DataManager.getDefaultUser())).stream().mapToInt(r -> r.getReview().length()).filter(i -> i >= 1000).count())), new Achievement("", "Thoughtful", "Give 10 looong reviews", 2, () -> DataManager.getReviews().filtered(r -> r.getUser().equals(DataManager.getDefaultUser())).stream().mapToInt(r -> r.getReview().length()).max().orElse(0) / 10), new Achievement("", "Wordy", "Give a looong review", 3, () -> DataManager.getReviews().filtered(r -> r.getUser().equals(DataManager.getDefaultUser())).stream().mapToInt(r -> r.getReview().length()).max().orElse(0) / 10), new Achievement("", "BFFs", "1,000 reviews from a user", 1, () -> DataManager.getUsers().stream().filter(u -> !u.equals(DataManager.getDefaultUser())).mapToInt(u -> getReviewsPerUser(u)).max().orElse(0) / 10), new Achievement("", "Chums", "100 reviews from a user", 2, () -> DataManager.getUsers().stream().filter(u -> !u.equals(DataManager.getDefaultUser())).mapToInt(u -> getReviewsPerUser(u)).max().orElse(0)), new Achievement("", "Friends", "10 reviews from a user", 3, () -> DataManager.getUsers().stream().filter(u -> !u.equals(DataManager.getDefaultUser())).mapToInt(u -> getReviewsPerUser(u)).max().orElse(0) * 10), new Achievement("", "Trivia Expert", "Collect 10,000 factoids", 1, () -> DataManager.getFactoids().size() / 100), new Achievement("", "Trivia Pro", "Collect 1,000 factoids", 2, () -> DataManager.getFactoids().size() / 10), new Achievement("", "Trivia Whiz", "Collect 100 factoids", 3, () -> DataManager.getFactoids().size()), new Achievement("", "Connoisseur", "Collect 10,000 media", 1, () -> DataManager.getMedia().size() / 100), new Achievement("", "Collector", "Collect 1,000 media", 2, () -> DataManager.getMedia().size() / 10), new Achievement("", "Hobbyist", "Collect 100 media", 3, () -> DataManager.getMedia().size()), new Achievement("", "Fanatic", "1 review/day for a year", 1, () -> (int) (getLongestConsecutiveDays(1) * 0.274)), new Achievement("", "Obsessed", "1 review/day for a 90 days", 2, () -> (int) (getLongestConsecutiveDays(1) * 3.33)), new Achievement("", "Hooked", "1 review/day for a month", 3, () -> (int) (getLongestConsecutiveDays(1) * 3.33)), new Achievement("", "Anthropologist", "10,000 reviews from users", 1, () -> (int) ((DataManager.getReviews().size() - getReviewsPerUser(DataManager.getDefaultUser())) / 100)), new Achievement("", "Famous", "1,000 reviews from users", 2, () -> (int) ((DataManager.getReviews().size() - getReviewsPerUser(DataManager.getDefaultUser())) / 10)), new Achievement("", "Popular", "100 reviews from users", 3, () -> (int) ((DataManager.getReviews().size() - getReviewsPerUser(DataManager.getDefaultUser()))))));
return achievements;
}
use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class StatsTabController method updateOverall.
private void updateOverall() {
// Constants
int last__days = DataManager.getPastDays();
// Graph Title
chartReviewsPerDay.setTitle("Past " + last__days + " Days");
// 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) {
boolean used = false;
for (Review r : m.getReviews()) {
if (strooleans.stream().anyMatch(x -> x.getString().equalsIgnoreCase(r.getUser()) && x.isBoolean())) {
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(), 0);
cat2Num.put(m.getCategory(), num + 1);
last30Days.put(r.getDate(), cat2Num);
}
info.accumulate(r);
used = true;
}
}
if (used) {
categories.put(m.getCategory(), categories.getOrDefault(m.getCategory(), 0) + 1);
info.accumulate(m);
for (Factoid f : m.getFactoids()) {
info.accumulate(f);
}
// media++;
}
}
if (overallContainer.getChildren().size() > 3)
overallContainer.getChildren().remove(2);
overallContainer.getChildren().add(2, info.getInfo());
// Chart # Media / Category
chartMediaPerCategory.setData(FXCollections.observableArrayList(Arrays.asList(DataManager.getCategories()).stream().map(c -> {
int count = categories.getOrDefault(c, 0);
PieChart.Data data = new PieChart.Data(c + " - " + count, count);
return data;
}).collect(Collectors.toList())));
for (PieChart.Data data : chartMediaPerCategory.getData()) {
String category = data.getName().substring(0, data.getName().indexOf(" - "));
int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
data.getNode().setStyle("-fx-pie-color: " + colors[(i > 0 ? i : 0) % colors.length] + ";");
}
for (Node node : chartMediaPerCategory.lookupAll("Label.chart-legend-item")) {
Shape symbol = new Circle(5);
Label label = (Label) node;
String category = label.getText().substring(0, label.getText().indexOf(" - "));
int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
symbol.setStyle("-fx-fill: " + colors[(i > 0 ? i : 0) % colors.length]);
label.setGraphic(symbol);
}
// Chart # Reviews / Day
ObservableList<XYChart.Series<String, Number>> 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);
for (Node node : chartReviewsPerDay.lookupAll("Label.chart-legend-item")) {
Shape symbol = new Rectangle(7, 7);
Label label = (Label) node;
String category = label.getText();
int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
symbol.setStyle("-fx-fill: " + colors[(i > 0 ? i : 0) % colors.length]);
label.setGraphic(symbol);
}
for (XYChart.Series<String, Number> serie : chartReviewsPerDay.getData()) {
String category = serie.getName();
int i = Arrays.asList(DataManager.getCategories()).indexOf(category);
for (XYChart.Data<String, Number> data : serie.getData()) {
data.getNode().setStyle("-fx-background-color: " + colors[(i > 0 ? i : 0) % colors.length] + ";");
}
}
}
use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class ListsTabController method updateListTab.
private void updateListTab() {
listTableData.clear();
if (!listGroupCreator.isSelected())
return;
boolean creator = listGroupCreator.isSelected();
boolean title = listGroupTitle.isSelected();
boolean season = listGroupSeason.isSelected();
boolean episode = listGroupEpisode.isSelected();
Chartagories chartagory = episode ? Chartagories.CURRENT_MEDIA : season ? Chartagories.SEASON : title ? Chartagories.TITLE : Chartagories.CREATOR;
Integer top = listTop10.isSelected() ? 10 : listTop25.isSelected() ? 25 : listTop50.isSelected() ? 50 : listTop100.isSelected() ? 100 : listTop500.isSelected() ? 500 : 1000;
LocalDate start = listCustomDateRange.isSelected() ? listStartDate.getValue().minus(1, ChronoUnit.DAYS) : LocalDate.of(Integer.parseInt(listYear.getText()) - 1, 12, 31);
start = listUseAllTime.isSelected() ? LocalDate.MIN : start;
LocalDate end = listCustomDateRange.isSelected() ? listEndDate.getValue().plus(1, ChronoUnit.DAYS) : LocalDate.of(Integer.parseInt(listYear.getText()) + 1, 1, 1);
end = listUseAllTime.isSelected() ? LocalDate.MAX : end;
String user = listUser.getText();
for (Media media : DataManager.getMedia()) {
for (Stroolean stroolean : strooleans) {
if (stroolean.isBoolean() && media.getCategory().equals(stroolean.getString())) {
boolean homeless = true;
for (Media data : listTableData) {
Media temp = new Media();
temp.clone(media);
temp.setCategory(data.getCategory());
temp.setType(data.getType());
if (UtilityCloset.isSameMedia(chartagory, data, temp)) {
homeless = false;
for (Review review : media.getReviews()) {
if (review.getDate().isBefore(end) && review.getDate().isAfter(start) && review.getUser().equals(user)) {
data.getReviews().add(review);
}
}
break;
}
}
if (homeless) {
Media m = new Media();
if (creator)
m.setCreator(media.getCreator());
if (title)
m.setTitle(media.getTitle());
if (season)
m.setSeasonId(media.getSeasonId());
if (episode)
m.setEpisodeId(media.getEpisodeId());
m.setCategory(media.getCategory());
for (Review review : media.getReviews()) {
if (review.getUser().equals(user)) {
if (review.getDate().isBefore(end) && review.getDate().isAfter(start)) {
m.getReviews().add(review);
}
}
}
listTableData.add(m);
}
}
}
}
List rankedResults = listTableData.stream().sorted(new MediaComparator()).limit(top).collect(Collectors.toList());
listTable.setItems(FXCollections.observableArrayList(rankedResults));
listRankColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + rankedResults.indexOf(p.getValue())));
listTable.refresh();
}
use of retrospector.model.Review in project Retrospector by NonlinearFruit.
the class QuickEntryController method getMedia.
private Media getMedia() {
Media m = new Media();
m.setTitle(title.getText());
m.setCreator(creator.getText());
m.setCategory(category.getValue());
m.setSeasonId(season.getText());
m.setEpisodeId(episode.getText());
// Rating
if (!rating.getText().equals("")) {
Review r = new Review(BigDecimal.valueOf(Integer.parseInt(rating.getText())));
int yy = Integer.parseInt(date.getText());
if (yy > (LocalDate.now().getYear() % 100) + 1)
r.setDate(LocalDate.of(1900 + yy, 1, 1));
else
r.setDate(LocalDate.of(2000 + yy, 1, 1));
m.getReviews().add(r);
}
// Type
if (m.getSeasonId().equals("") && m.getEpisodeId().equals(""))
m.setType(Media.Type.SINGLE);
else if (m.getSeasonId().equals(""))
m.setType(Media.Type.MINISERIES);
else
m.setType(Media.Type.SERIES);
return m;
}
Aggregations