示例#1
0
  private void storeWeeklyMetrics(LocalDate crc) {
    // Store weekly demand metrics
    Years yr = Years.years(crc.getYear());
    Map<LocalDate, Demand> currDemandMap = demandMap.get(yr);
    if (currDemandMap == null) {
      currDemandMap = new TreeMap<LocalDate, Demand>();
    }
    Demand d = currDemandMap.get(crc);
    if (d == null) {
      d = new Demand();
    }
    d.setRcAvgDemand(rcAvgDemand);
    d.setRcAvgDemandActual(rcAvgDemandActual);
    currDemandMap.put(crc, d);
    demandMap.put(yr, currDemandMap);

    // Store weekly sales metrics
    Map<LocalDate, Sales> currSalesMap = salesMap.get(yr);
    if (currSalesMap == null) {
      currSalesMap = new TreeMap<LocalDate, Sales>();
    }
    Sales s = currSalesMap.get(crc);
    if (s == null) {
      s = new Sales();
    }
    s.setRcAvgSalesActual(rcAvgSalesActual);
    s.setRcAvgSales(rcAvgSales);
    currSalesMap.put(crc, s);
    salesMap.put(yr, currSalesMap);
  }
  /**
   * Defines the magnitudes that can be added to the timestamp
   *
   * @param token token of form "[number][magnitude]" (ex. "1d")
   * @return integer indicating the magnitude of the date for the calendar system
   */
  public static ReadablePeriod getTimePeriod(String token) {
    String valString = token.substring(0, token.length() - 1);
    int value = Integer.parseInt(valString);
    char mag = token.charAt(token.length() - 1);

    ReadablePeriod period;

    switch (mag) {
      case 's':
        period = Seconds.seconds(value);
        break;
      case 'm':
        period = Minutes.minutes(value);
        break;
      case 'h':
        period = Hours.hours(value);
        break;
      case 'd':
        period = Days.days(value);
        break;
      case 'M':
        period = Months.months(value);
        break;
      case 'y':
        period = Years.years(value);
        break;
      default:
        logger.warn("Invalid date magnitude: {}. Defaulting to seconds.", mag);
        period = Seconds.seconds(value);
        break;
    }

    return period;
  }
示例#3
0
 private double getDemandUplift(LocalDate dt) {
   Map<LocalDate, List<Event>> currEventMap = eventsMap.get(Years.years(dt.getYear()));
   if (currEventMap == null) {
     return 1.0;
   }
   List<Event> events = currEventMap.get(dt);
   return Event.calculateDemandUplift(events);
 }
示例#4
0
 public void setTempOnHold(LocalDate dt, Boolean val) {
   Years yr = Years.years(dt.getYear());
   Map<LocalDate, Boolean> map = tempOnHoldMap.get(yr);
   if (map == null) {
     map = new TreeMap<LocalDate, Boolean>();
   }
   map.put(dt, val);
   tempOnHoldMap.put(yr, map);
 }
  @Test
  public void serializesCreditCardWithOutIdAndWithAppropriateMontshAndYears() throws Exception {

    CreditCard creditCard =
        new CreditCard(
            new CreditCardNumber("1234123412341234"),
            "Oliver Gierke",
            Months.ELEVEN,
            Years.years(2013));
    assertThat(mapper.writeValueAsString(creditCard), is(REFERENCE));
  }
示例#6
0
  public void addEvent(LocalDate dt, Event e) {
    Years yr = Years.years(dt.getYear());
    Map<LocalDate, List<Event>> currEventMap = eventsMap.get(yr);
    if (currEventMap == null) {
      currEventMap = new TreeMap<LocalDate, List<Event>>();
    }

    List<Event> eventList = currEventMap.get(dt);
    if (eventList == null) {
      eventList = new ArrayList<Event>();
    }
    eventList.add(e);
    currEventMap.put(dt, eventList);
    eventsMap.put(yr, currEventMap);
  }
示例#7
0
  /** Outlier filtering has been done prior to processing daily metrics * */
  private void processDailyMetrics() {
    LocalDate crc = SystemDao.getCrc();
    double lostSales = getLostSales();

    rcSalesActual = rcSalesActual + epSalesActual;
    // rcSales is outlier filtered sales and has been calculated in outlier processing
    rcSales = rcSales + epSales;

    Years yr = Years.years(crc.getYear());
    Map<LocalDate, Sales> currSalesMap = salesMap.get(yr);
    if (currSalesMap == null) {
      currSalesMap = new TreeMap<LocalDate, Sales>();
    }
    Sales s = currSalesMap.get(crc);
    if (s == null) {
      s = new Sales();
    }
    s.setEpSalesActual(epSalesActual);
    s.setEpSales(epSales);
    s.setRcSales(rcSales);
    s.setRcSalesActual(rcSalesActual);
    s.setLostSales(lostSales);

    currSalesMap.put(crc, s);
    salesMap.put(yr, currSalesMap);

    /** * Daily Demand Calculations **** */
    // daily demand
    epDemand = getEpDemand();
    // demand = sales + lostsales
    // outlier filtered sales used for rcDemand
    rcDemand = rcSales + lostSales;
    rcDemandActual += (epSalesActual + lostSales);

    Map<LocalDate, Demand> currDemandMap = demandMap.get(yr);
    if (currDemandMap == null) {
      currDemandMap = new TreeMap<LocalDate, Demand>();
    }
    Demand d = currDemandMap.get(crc);
    if (d == null) {
      d = new Demand();
    }
    d.setEpDemand(epDemand);
    d.setRcDemand(rcDemand);
    d.setRcDemandActual(rcDemandActual);
    currDemandMap.put(crc, d);
    demandMap.put(yr, currDemandMap);

    /** **** Daily Inventory Calculations ****** */
    processInventory();

    if (epSales > rcMaxSales) {
      rcMaxSales = epSales;
      weekSinceMaxSales = 0;
    }

    if (epEopInv > demoStock) {
      daysSinceWalk = daysSinceWalk + 1;
    } else {
      daysSinceWalk = 0;
    }

    if (epSalesActual == 0) {
      daysSinceSale = daysSinceSale + 1;
    } else {
      daysSinceSale = 0;
    }

    Map<LocalDate, ProductInventory> currInventoryMap = inventoryMap.get(yr);
    if (currInventoryMap == null) {
      currInventoryMap = new TreeMap<LocalDate, ProductInventory>();
    }
    ProductInventory inv = currInventoryMap.get(crc);
    if (inv == null) {
      inv = new ProductInventory();
    }
    inv.setEpAvgInv(epAvgInv);
    inv.setEpEopInv(epEopInv);
    inv.setEpInvOut(epInvOut);
    inv.setEpInvIn(epInvIn);
    inv.setRcBopInv(rcBopInv);
    inv.setRcBopInv(rcBopInv);
    inv.setRcInvIn(rcInvIn);
    inv.setRcInvOut(rcInvOut);
    inv.setInventory(inventory);

    currInventoryMap.put(crc, inv);
    inventoryMap.put(yr, currInventoryMap);

    if (statusCd == STATUS_CD.LEARNING) {
      performDailyLearning();
    }
    resetEpAccumulators();
  }
示例#8
0
 private ProductInventory getInventory(LocalDate dt) {
   return inventoryMap.get(Years.years(dt.getYear())) == null
       ? null
       : inventoryMap.get(Years.years(dt.getYear())).get(dt);
 }
示例#9
0
 private Demand getDemand(LocalDate dt) {
   return demandMap.get(Years.years(dt.getYear())) == null
       ? null
       : demandMap.get(Years.years(dt.getYear())).get(dt);
 }
示例#10
0
 private Sales getSales(LocalDate dt) {
   return salesMap.get(Years.years(dt.getYear())) == null
       ? null
       : salesMap.get(Years.years(dt.getYear())).get(dt);
 }