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();
}
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();
}
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));
}
}
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);
}
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);
}
}
Aggregations