use of retrospector.model.Media in project Retrospector by NonlinearFruit.
the class SearchTabController method initSearchTab.
private void initSearchTab() {
searchEditMedia.setDisable(true);
searchDeleteMedia.setDisable(true);
// Table Double Click
searchTable.setRowFactory(tv -> {
TableRow<Media> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
setMedia(row.getItem());
setTab(TAB.MEDIA);
}
});
return row;
});
// Table data setup
searchTableData = DataManager.getMedia();
FilteredList<Media> mediaFiltered = new FilteredList(searchTableData, x -> true);
SortedList<Media> mediaSortable = new SortedList<>(mediaFiltered);
searchTable.setItems(mediaSortable);
mediaSortable.comparatorProperty().bind(searchTable.comparatorProperty());
// Link to data properties
searchTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
searchCreatorColumn.setCellValueFactory(new PropertyValueFactory<>("Creator"));
searchSeasonColumn.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
searchEpisodeColumn.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
searchCategoryColumn.setCellValueFactory(new PropertyValueFactory<>("Category"));
// Values for special columns
searchNumberColumn.setSortable(false);
searchNumberColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + searchTable.getItems().indexOf(p.getValue())));
searchReviewsColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, Integer>, ObservableValue<Integer>>() {
@Override
public ObservableValue<Integer> call(TableColumn.CellDataFeatures<Media, Integer> p) {
return new ReadOnlyObjectWrapper(p.getValue().getReviews().size());
}
});
searchMeanRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {
@Override
public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
return new ReadOnlyObjectWrapper(p.getValue().getAverageRating());
}
});
searchCurrentRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {
@Override
public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
return new ReadOnlyObjectWrapper(p.getValue().getCurrentRating());
}
});
// Comparators for string columns
searchTitleColumn.setComparator(new NaturalOrderComparator());
searchCreatorColumn.setComparator(new NaturalOrderComparator());
searchSeasonColumn.setComparator(new NaturalOrderComparator());
searchEpisodeColumn.setComparator(new NaturalOrderComparator());
searchCategoryColumn.setComparator(new NaturalOrderComparator());
searchTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
setMedia(neo);
});
searchBox.textProperty().addListener((observa, old, neo) -> {
String query = neo;
if (query == null || query.equals(""))
mediaFiltered.setPredicate(x -> true);
else {
String[] queries = query.split(":");
mediaFiltered.setPredicate(x -> QueryProcessor.isMatchForMedia(query, x));
}
updateStats();
});
// Buttons
searchNewMedia.setOnAction(e -> {
Media neo = new Media();
neo.setId(DataManager.createDB(neo));
setMedia(neo);
setTab(TAB.MEDIA);
});
searchQuickEntry.setOnAction(e -> {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("QuickEntry.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
QuickEntryController qec = fxmlLoader.getController();
qec.setup(currentTab);
Stage stage = new Stage();
stage.setTitle("Quick Entry");
stage.setScene(new Scene(root1));
stage.show();
} catch (Exception ex) {
}
});
searchStandardEntry.setOnAction(e -> {
Media neo = new Media();
neo.setId(DataManager.createDB(neo));
setMedia(neo);
setTab(TAB.MEDIA);
});
searchBackup.setOnAction(e -> DataManager.makeBackup());
searchCheatsheet.setOnAction(e -> {
new Cheatsheet().start(new Stage());
});
searchEditMedia.setOnAction(e -> {
setTab(TAB.MEDIA);
});
searchDeleteMedia.setOnAction(e -> {
if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
DataManager.deleteDB(getMedia());
updateSearchTab();
}
});
// Init stuff
updateStats();
}
use of retrospector.model.Media 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.Media 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.Media in project Retrospector by NonlinearFruit.
the class QuickEntryController method initialize.
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
defaultCat = DataManager.getCategories()[0];
category.setItems(FXCollections.observableArrayList(DataManager.getCategories()));
category.setValue(defaultCat);
ratingTitle.setText(DataManager.getDefaultUser() + "'s Rating");
rating.textProperty().addListener((obs, old, neo) -> {
if (!neo.equals("")) {
try {
Integer r = Integer.parseInt(neo);
if (r > DataManager.getMaxRating() || r < 1)
rating.setText(old);
} catch (Exception ex) {
System.out.println("Bad int: " + neo);
rating.setText(old);
}
}
});
date.textProperty().addListener((obs, old, neo) -> {
if (!neo.equals("")) {
try {
Integer d = Integer.parseInt(neo);
if (d > 99 || d < 0)
date.setText(old);
} catch (Exception ex) {
System.out.println("Bad int: " + neo);
date.setText(old);
}
}
});
saveClose.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
saveClose.getScene().getWindow().hide();
});
brandNew.setOnAction(e -> {
DataManager.createDB(getMedia());
causeRefresh();
clear();
title.requestFocus();
});
newKeepT.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
clear();
title.setText(m.getTitle());
creator.requestFocus();
});
newKeepCr.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
clear();
creator.setText(m.getCreator());
title.requestFocus();
});
newKeepCa.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
clear();
category.setValue(m.getCategory());
title.requestFocus();
});
newKeepTCr.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
clear();
title.setText(m.getTitle());
creator.setText(m.getCreator());
category.requestFocus();
});
newKeepTCrCa.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
clear();
title.setText(m.getTitle());
creator.setText(m.getCreator());
category.setValue(m.getCategory());
season.requestFocus();
});
newKeepTCrCaS.setOnAction(e -> {
Media m = getMedia();
DataManager.createDB(m);
causeRefresh();
clear();
title.setText(m.getTitle());
creator.setText(m.getCreator());
category.setValue(m.getCategory());
season.setText(m.getSeasonId());
episode.requestFocus();
});
discard.setOnAction(e -> {
clear();
title.requestFocus();
});
clear();
}
use of retrospector.model.Media 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