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] + ";");
}
}
}
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();
}
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.");
}
});
}
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);
}
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");
}
Aggregations