Search in sources :

Example 6 with DateBean

use of com.github.drbookings.ui.beans.DateBean in project drbookings by DrBookings.

the class ProfitChartController method flushBin.

@Override
protected void flushBin() {
    if (bin.isEmpty()) {
        return;
    }
    final Optional<LocalDate> xValue = bin.stream().map(d -> d.getDate()).max((d1, d2) -> d1.compareTo(d2));
    final Map<String, Number> yValue = new TreeMap<>();
    final double costsToCover = getCostsToCover();
    final double refColdRentLongTerm = getRefColdRentLongTerm();
    for (final DateBean d : bin) {
        for (final Entry<String, Number> e : d.getEarningsPerOrigin().entrySet()) {
            double n = yValue.getOrDefault(e.getKey(), Double.valueOf(0)).doubleValue();
            final double earnings = e.getValue().doubleValue();
            final double sizeThis = 1;
            final double sizeAll = allBookingEntries.get();
            System.err.println(sizeThis);
            System.err.println(sizeAll);
            final double percent = sizeThis / sizeAll;
            if (logger.isDebugEnabled()) {
                logger.debug("percent: " + percent);
                logger.debug("earnings: " + earnings);
                logger.debug("costsToCover: " + (costsToCover * percent));
                logger.debug("refColdRent: " + (refColdRentLongTerm * percent));
            }
            final double performance = (earnings - (costsToCover * percent) - (refColdRentLongTerm * percent));
            n += performance / bin.size();
            yValue.put(e.getKey(), n);
            System.err.println("yValue: " + yValue);
        }
    }
    for (final Entry<String, Number> e : yValue.entrySet()) {
        // System.err.println("Entry " + e);
        Series<String, Number> s = mapSeries.get(e.getKey());
        if (s == null) {
            s = new Series<>();
            s.setName(e.getKey());
            mapSeries.put(e.getKey(), s);
            chart.getData().add(s);
        }
        final XYChart.Data<String, Number> data = new XYChart.Data<>(xValue.get().toString(), e.getValue());
        categories.add(xValue.get().toString());
        s.getData().add(data);
    // System.err.println("Adding " + data);
    }
    bin.clear();
}
Also used : BookingSelectionManager(com.github.drbookings.ui.selection.BookingSelectionManager) Initializable(javafx.fxml.Initializable) Logger(org.slf4j.Logger) StackedBarChart(javafx.scene.chart.StackedBarChart) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Series(javafx.scene.chart.XYChart.Series) Callable(java.util.concurrent.Callable) DoubleProperty(javafx.beans.property.DoubleProperty) CategoryAxis(javafx.scene.chart.CategoryAxis) XYChart(javafx.scene.chart.XYChart) DateBean(com.github.drbookings.ui.beans.DateBean) Bindings(javafx.beans.binding.Bindings) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) ResourceBundle(java.util.ResourceBundle) TreeMap(java.util.TreeMap) LocalDate(java.time.LocalDate) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) NumberAxis(javafx.scene.chart.NumberAxis) TreeMap(java.util.TreeMap) LocalDate(java.time.LocalDate) DateBean(com.github.drbookings.ui.beans.DateBean) XYChart(javafx.scene.chart.XYChart)

Example 7 with DateBean

use of com.github.drbookings.ui.beans.DateBean in project drbookings by DrBookings.

the class MainManager method addUiDataBooking.

private void addUiDataBooking(final BookingEntry bookingEntry) {
    final Room room = bookingEntry.getRoom();
    DateBean db = uiDataMap.get(bookingEntry.getDate());
    if (db == null) {
        db = new DateBean(bookingEntry.getDate(), this);
        addDateBean(db);
    }
    db.getRoom(room.getName()).addBookingEntry(bookingEntry);
    fillMissing();
}
Also used : DateBean(com.github.drbookings.ui.beans.DateBean)

Example 8 with DateBean

use of com.github.drbookings.ui.beans.DateBean in project drbookings by DrBookings.

the class MainManager method fillMissing.

private void fillMissing() {
    final List<LocalDate> dates = new ArrayList<>(uiDataMap.keySet());
    Collections.sort(dates);
    final Collection<LocalDate> toAdd = new HashSet<>();
    LocalDate last = null;
    for (final LocalDate d : dates) {
        if (last != null) {
            if (d.equals(last.plusDays(1))) {
            // ok
            } else {
                toAdd.addAll(new DateRange(last.plusDays(1), d.minusDays(1)).toList());
            }
        }
        last = d;
    }
    for (final LocalDate d : toAdd) {
        addDateBean(new DateBean(d, this));
    }
}
Also used : DateRange(com.github.drbookings.DateRange) DateBean(com.github.drbookings.ui.beans.DateBean) LocalDate(java.time.LocalDate)

Example 9 with DateBean

use of com.github.drbookings.ui.beans.DateBean in project drbookings by DrBookings.

the class MainManager method addUiDataCleaning.

private void addUiDataCleaning(final CleaningEntry cleaningEntry) {
    final Room room = cleaningEntry.getRoom();
    DateBean db = uiDataMap.get(cleaningEntry.getDate());
    if (db == null) {
        db = new DateBean(cleaningEntry.getDate(), this);
        uiData.add(db);
        uiDataMap.put(db.getDate(), db);
    }
    db.getRoom(room.getName()).setCleaningEntry(cleaningEntry);
}
Also used : DateBean(com.github.drbookings.ui.beans.DateBean)

Example 10 with DateBean

use of com.github.drbookings.ui.beans.DateBean in project drbookings by DrBookings.

the class BinYearMonth method addToMap.

private void addToMap(final List<? extends DateBean> addedSubList) {
    for (final DateBean db : addedSubList) {
        final YearMonth ym = YearMonth.from(db.getDate());
        Collection<DateBean> col = yearMonth2DateBeanMap.get(ym);
        if (col == null) {
            col = new HashSet<>();
        }
        col.add(db);
        // re-add, to trigger change event
        yearMonth2DateBeanMap.remove(ym);
        yearMonth2DateBeanMap.put(ym, col);
    }
}
Also used : DateBean(com.github.drbookings.ui.beans.DateBean) YearMonth(java.time.YearMonth)

Aggregations

DateBean (com.github.drbookings.ui.beans.DateBean)10 LocalDate (java.time.LocalDate)3 RoomBean (com.github.drbookings.ui.beans.RoomBean)2 YearMonth (java.time.YearMonth)2 DateRange (com.github.drbookings.DateRange)1 BookingBean (com.github.drbookings.model.data.BookingBean)1 SettingsManager (com.github.drbookings.model.settings.SettingsManager)1 BookingSelectionManager (com.github.drbookings.ui.selection.BookingSelectionManager)1 URL (java.net.URL)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 ResourceBundle (java.util.ResourceBundle)1 TreeMap (java.util.TreeMap)1 Callable (java.util.concurrent.Callable)1 Bindings (javafx.beans.binding.Bindings)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 FXML (javafx.fxml.FXML)1 Initializable (javafx.fxml.Initializable)1