Search in sources :

Example 11 with Media

use of retrospector.model.Media in project Retrospector by NonlinearFruit.

the class MediaSectionController method updateMedia.

private void updateMedia() {
    // Media Filtering
    Boolean title = checkTitle.isSelected();
    Boolean creator = checkCreator.isSelected();
    Boolean season = checkSeason.isSelected();
    Boolean episode = checkEpisode.isSelected();
    Boolean category = checkCategory.isSelected();
    // Filter Table
    mediaTableFilter.setPredicate(m -> ((checkTitle.isSelected() && currentMedia.getTitle().equals(((Media) m).getTitle())) || !checkTitle.isSelected()) && ((checkCreator.isSelected() && currentMedia.getCreator().equals(((Media) m).getCreator())) || !checkCreator.isSelected()) && ((checkSeason.isSelected() && currentMedia.getSeasonId().equals(((Media) m).getSeasonId())) || !checkSeason.isSelected()) && ((checkEpisode.isSelected() && currentMedia.getEpisodeId().equals(((Media) m).getEpisodeId())) || !checkEpisode.isSelected()) && ((checkCategory.isSelected() && currentMedia.getCategory().equals(((Media) m).getCategory())) || !checkCategory.isSelected()));
    // Data Mining - Vars
    XYChart.Series data = new XYChart.Series();
    InfoBlipAccumulator info = new InfoBlipAccumulator();
    // Data Mining - Calcs
    for (Media m : mediaTable.getItems()) {
        info.accumulate(m);
        for (Review r : m.getReviews()) {
            data.getData().add(new XYChart.Data(dateToDouble(r.getDate()), r.getRating().intValue()));
            info.accumulate(r);
        }
    }
    // Stats
    statsBox.getChildren().clear();
    statsBox.getChildren().add(info.getInfo());
    // Chart
    chartRatingOverTime.getData().clear();
    if (data.getData().size() < 1500)
        chartRatingOverTime.getData().add(data);
    chartRotX.setLowerBound(dateToDouble(info.getEarliest()) - 1.0 / 12);
    chartRotX.setUpperBound(dateToDouble(LocalDate.now()) + 1.0 / 12);
}
Also used : Media(retrospector.model.Media) XYChart(javafx.scene.chart.XYChart) Review(retrospector.model.Review)

Example 12 with Media

use of retrospector.model.Media 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);
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) Review(retrospector.model.Review) StackedBarChart(javafx.scene.chart.StackedBarChart) URL(java.net.URL) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) CategoryAxis(javafx.scene.chart.CategoryAxis) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) Media(retrospector.model.Media) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) ResourceBundle(java.util.ResourceBundle) LocalDate(java.time.LocalDate) Map(java.util.Map) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) DataManager(retrospector.model.DataManager) HashMap(java.util.HashMap) Media(retrospector.model.Media) Review(retrospector.model.Review) LocalDate(java.time.LocalDate) PieChart(javafx.scene.chart.PieChart) ObservableList(javafx.collections.ObservableList) XYChart(javafx.scene.chart.XYChart) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with Media

use of retrospector.model.Media in project Retrospector by NonlinearFruit.

the class SearchTabController method isMatchForMedia.

private boolean isMatchForMedia(String query, Media media) {
    boolean pass = true;
    if (query.endsWith("|") && !query.endsWith("||"))
        query = query.substring(0, query.length() - 1);
    String[] queries = query.toLowerCase().split(":");
    List<String> searchables = new ArrayList<>();
    searchables.addAll(Arrays.asList(media.getTitle().toLowerCase(), media.getCreator().toLowerCase(), media.getSeasonId().toLowerCase(), media.getEpisodeId().toLowerCase(), media.getCategory().toLowerCase()));
    for (Factoid fact : media.getFactoids()) {
        searchables.add(fact.getContent().toLowerCase());
    }
    for (String q : queries) {
        String[] optns = q.split("\\|\\|");
        boolean minorPass = false;
        for (String optn : optns) {
            boolean negator = optn.length() > 1 && optn.startsWith("!");
            if (!negator && searchables.stream().anyMatch(s -> s.contains(optn)))
                minorPass = true;
            if (negator && !searchables.stream().anyMatch(s -> s.contains(optn.substring(1))))
                minorPass = true;
        }
        if (!minorPass) {
            pass = false;
        }
    }
    return pass;
}
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) ArrayList(java.util.ArrayList) Factoid(retrospector.model.Factoid)

Example 14 with Media

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

Example 15 with Media

use of retrospector.model.Media in project Retrospector by NonlinearFruit.

the class Dumpster method getRandomMedia.

public static Media getRandomMedia(int numOfReviews) {
    Media m = new Media();
    String[] uuid = UUID.randomUUID().toString().split("-");
    m.setTitle(uuid[0]);
    m.setCreator(uuid[1]);
    if (random.nextBoolean()) {
        m.setEpisodeId(uuid[2]);
        if (random.nextBoolean()) {
            m.setSeasonId(uuid[3]);
            m.setType(Media.Type.SERIES);
        }
        m.setType(Media.Type.MINISERIES);
    } else {
        m.setType(Media.Type.SINGLE);
    }
    m.setCategory(DataManager.getCategories()[random.nextInt(DataManager.getCategories().length)]);
    for (int i = 0; i < numOfReviews; i++) {
        m.getReviews().add(getRandomReview());
    }
    return m;
}
Also used : Media(retrospector.model.Media)

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