Search in sources :

Example 1 with Media

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();
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) URL(java.net.URL) ButtonType(javafx.scene.control.ButtonType) Factoid(retrospector.model.Factoid) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Media(retrospector.model.Media) Application(javafx.application.Application) BigDecimal(java.math.BigDecimal) Parent(javafx.scene.Parent) ResourceBundle(java.util.ResourceBundle) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) FXMLLoader(javafx.fxml.FXMLLoader) QuickEntryController(retrospector.fxml.QuickEntryController) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) SortedList(javafx.collections.transformation.SortedList) Alert(javafx.scene.control.Alert) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) Review(retrospector.model.Review) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) TableRow(javafx.scene.control.TableRow) FilteredList(javafx.collections.transformation.FilteredList) TAB(retrospector.fxml.CoreController.TAB) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) List(java.util.List) Stage(javafx.stage.Stage) MenuButton(javafx.scene.control.MenuButton) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) DataManager(retrospector.model.DataManager) QuickEntryController(retrospector.fxml.QuickEntryController) Parent(javafx.scene.Parent) SortedList(javafx.collections.transformation.SortedList) ObservableValue(javafx.beans.value.ObservableValue) FXMLLoader(javafx.fxml.FXMLLoader) FilteredList(javafx.collections.transformation.FilteredList) Stage(javafx.stage.Stage) Media(retrospector.model.Media) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) TableRow(javafx.scene.control.TableRow) Alert(javafx.scene.control.Alert) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper)

Example 2 with Media

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] + ";");
        }
    }
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) StackedBarChart(javafx.scene.chart.StackedBarChart) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Factoid(retrospector.model.Factoid) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Media(retrospector.model.Media) HashSet(java.util.HashSet) LineChart(javafx.scene.chart.LineChart) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) Circle(javafx.scene.shape.Circle) HBox(javafx.scene.layout.HBox) ObjectProperty(javafx.beans.property.ObjectProperty) Label(javafx.scene.control.Label) Review(retrospector.model.Review) Node(javafx.scene.Node) Set(java.util.Set) Rectangle(javafx.scene.shape.Rectangle) CategoryAxis(javafx.scene.chart.CategoryAxis) BarChart(javafx.scene.chart.BarChart) Collectors(java.util.stream.Collectors) ChoiceBox(javafx.scene.control.ChoiceBox) TAB(retrospector.fxml.CoreController.TAB) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) PieChart(javafx.scene.chart.PieChart) Stroolean(retrospector.util.Stroolean) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) LocalDate(java.time.LocalDate) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) DataManager(retrospector.model.DataManager) Shape(javafx.scene.shape.Shape) Shape(javafx.scene.shape.Shape) HashMap(java.util.HashMap) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) Review(retrospector.model.Review) LocalDate(java.time.LocalDate) PieChart(javafx.scene.chart.PieChart) Factoid(retrospector.model.Factoid) Circle(javafx.scene.shape.Circle) Media(retrospector.model.Media) XYChart(javafx.scene.chart.XYChart) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Media

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();
}
Also used : Stroolean(retrospector.util.Stroolean) MediaComparator(retrospector.util.MediaComparator) Media(retrospector.model.Media) List(java.util.List) ObservableList(javafx.collections.ObservableList) Review(retrospector.model.Review) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) LocalDate(java.time.LocalDate)

Example 4 with Media

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();
}
Also used : Media(retrospector.model.Media)

Example 5 with Media

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;
}
Also used : Media(retrospector.model.Media) Review(retrospector.model.Review)

Aggregations

Media (retrospector.model.Media)15 Review (retrospector.model.Review)12 XYChart (javafx.scene.chart.XYChart)7 List (java.util.List)6 ObservableList (javafx.collections.ObservableList)6 Factoid (retrospector.model.Factoid)6 URL (java.net.URL)5 LocalDate (java.time.LocalDate)5 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 ResourceBundle (java.util.ResourceBundle)5 FXML (javafx.fxml.FXML)5 Initializable (javafx.fxml.Initializable)5 DataManager (retrospector.model.DataManager)5 NaturalOrderComparator (retrospector.util.NaturalOrderComparator)5 ArrayList (java.util.ArrayList)4 ObjectProperty (javafx.beans.property.ObjectProperty)4 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)4 Text (javafx.scene.text.Text)4 TAB (retrospector.fxml.CoreController.TAB)4