Search in sources :

Example 21 with LocalDate

use of java.time.LocalDate 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 22 with LocalDate

use of java.time.LocalDate 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 23 with LocalDate

use of java.time.LocalDate in project Retrospector by NonlinearFruit.

the class MediaSectionController method initialize.

/**
     * Initializes the controller class.
     */
@Override
public void initialize(URL url, ResourceBundle rb) {
    chartRatingOverTime.getData().add(new XYChart.Series(FXCollections.observableArrayList(new XYChart.Data(0, 0))));
    checkTitle.setSelected(true);
    checkCreator.setSelected(true);
    checkSeason.setSelected(true);
    checkEpisode.setSelected(true);
    checkCategory.setSelected(true);
    checkTitle.selectedProperty().addListener((observe, old, neo) -> updateMedia());
    checkCreator.selectedProperty().addListener((observe, old, neo) -> updateMedia());
    checkSeason.selectedProperty().addListener((observe, old, neo) -> updateMedia());
    checkEpisode.selectedProperty().addListener((observe, old, neo) -> updateMedia());
    checkCategory.selectedProperty().addListener((observe, old, neo) -> updateMedia());
    mediaTableFilter = new FilteredList(allMedia);
    SortedList<Media> mediaSortable = new SortedList<>(mediaTableFilter);
    mediaTable.setItems(mediaSortable);
    mediaSortable.comparatorProperty().bind(mediaTable.comparatorProperty());
    mediaColumnRowNumber.setSortable(false);
    mediaColumnRowNumber.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + mediaTable.getItems().indexOf(p.getValue())));
    mediaColumnTitle.setComparator(new NaturalOrderComparator());
    mediaColumnCreator.setComparator(new NaturalOrderComparator());
    mediaColumnSeason.setComparator(new NaturalOrderComparator());
    mediaColumnEpisode.setComparator(new NaturalOrderComparator());
    mediaColumnCategory.setComparator(new NaturalOrderComparator());
    mediaColumnTitle.setCellValueFactory(new PropertyValueFactory<>("Title"));
    mediaColumnCreator.setCellValueFactory(new PropertyValueFactory<>("Creator"));
    mediaColumnSeason.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
    mediaColumnEpisode.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
    mediaColumnCategory.setCellValueFactory(new PropertyValueFactory<>("Category"));
    chartRotY.setLabel("Reviews");
    chartRotY.setAutoRanging(false);
    chartRotY.setLowerBound(0);
    chartRotY.setUpperBound(10);
    chartRotY.setTickUnit(2);
    chartRotY.setMinorTickCount(2);
    chartRotX.setLabel("Time");
    chartRotX.setAutoRanging(false);
    chartRotX.setTickUnit(1);
    chartRotX.setMinorTickCount(4);
    chartRotX.setTickLabelFormatter(new StringConverter<Number>() {

        @Override
        public String toString(Number number) {
            double x = number.doubleValue();
            double decimal = x % 1;
            double year = x - decimal;
            double days = decimal * 365.25;
            if (days > 365 || days < 1) {
                return ((int) year) + "";
            }
            LocalDate date = LocalDate.ofYearDay((int) year, (int) days);
            return date.format(DateTimeFormatter.ofPattern("MMM uuuu"));
        }

        @Override
        public Number fromString(String string) {
            //To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
}
Also used : SortedList(javafx.collections.transformation.SortedList) Media(retrospector.model.Media) LocalDate(java.time.LocalDate) FilteredList(javafx.collections.transformation.FilteredList) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) XYChart(javafx.scene.chart.XYChart) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper)

Example 24 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class DateTests method test15.

/*
     * Validate an NPE occurs when a null LocalDate is passed to valueOf
     */
@Test(expectedExceptions = NullPointerException.class)
public void test15() throws Exception {
    LocalDate ld = null;
    Date.valueOf(ld);
}
Also used : LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 25 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class DateTests method test14.

/*
     * Validate that a Date LocalDate value, made from a LocalDate are equal
     */
@Test
public void test14() {
    LocalDate ldt = LocalDate.now();
    Date d = Date.valueOf(ldt);
    assertTrue(ldt.equals(d.toLocalDate()), "Error LocalDate values are not equal");
}
Also used : LocalDate(java.time.LocalDate) LocalDate(java.time.LocalDate) Date(java.sql.Date) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Aggregations

LocalDate (java.time.LocalDate)1513 Test (org.junit.Test)472 Test (org.testng.annotations.Test)372 LocalDateTime (java.time.LocalDateTime)155 LocalTime (java.time.LocalTime)126 Date (java.util.Date)99 DateTimeFormatter (java.time.format.DateTimeFormatter)96 Ignore (org.junit.Ignore)94 ArrayList (java.util.ArrayList)87 BigDecimal (java.math.BigDecimal)69 Instant (java.time.Instant)56 ZonedDateTime (java.time.ZonedDateTime)55 Test (org.junit.jupiter.api.Test)54 List (java.util.List)50 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)46 HashMap (java.util.HashMap)44 Member (cz.metacentrum.perun.core.api.Member)41 ZoneId (java.time.ZoneId)40 TemporalField (java.time.temporal.TemporalField)40 Attribute (cz.metacentrum.perun.core.api.Attribute)39