예제 #1
0
  private void processInventory() {
    LocalDate crc = SystemDao.getCrc();
    if (isStockedOut) {
      Demand d = getDemand(SystemDao.getCrc());
      if (crc.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        d = getDemand(SystemDao.getReviewCycleStartDate());
      }
      int targetInv = (int) d.getRcAvgDemand() - inventory;

      setInventory(targetInv > 0 ? targetInv : (int) d.getRcAvgDemand());
      isStockedOut = false;
    }

    if (crc.getDayOfWeek() == DateTimeConstants.SUNDAY) {
      rcBopInv = inventory;
    }
    // daily inventory updates
    updateEpEopInv();
    epEopInv = inventory;
    rcInvOut += epInvOut;
    rcInvIn += epInvIn;
    ProductInventory p = getInventory(SystemDao.getReviewCycleStartDate());
    double beginOfPeriodEpAvgInv = 0;
    if (p != null) {
      beginOfPeriodEpAvgInv = p.getEpAvgInv();
    }
    double weight_5 = SystemDao.getWeight_5();
    epAvgInv =
        weight_5 * ((epEopInv >= 0) ? epEopInv : 0) + (((1 - weight_5) * beginOfPeriodEpAvgInv));
    epAvgInv = Math.max(0, epAvgInv);
  }
예제 #2
0
  private void performDailyLearning() {
    updateStatusCode();
    if (statusCd != STATUS_CD.LEARNING || disableLearning == true) {
      return;
    }
    if (onRange && (rcBopInv > 0 || hasSale == true || rcInvIn > 0)) {
      initLearningMetrics();
      // Daily learning only applies to RC_AVG_DEMAND and begins immediately when the PL comes on
      // range
      double lastWeekLift = getDemandUplift(SystemDao.getReviewCycleStartDate());
      double defaultWeight = SystemDao.getDefaultWeight();
      Demand beginOfRunCycleDemand = getDemand(SystemDao.getReviewCycleStartDate());
      double beginOfRunCycleRcAvgDemand = 0;
      if (beginOfRunCycleDemand != null) {
        beginOfRunCycleRcAvgDemand = beginOfRunCycleDemand.getRcAvgDemand();
      }

      if (onRange && !disableLearning) {
        rcAvgDemand =
            getWeightedWeight1(learningWeekCounter, defaultWeight) * rcDemand / lastWeekLift
                + (1 - getWeightedWeight1(learningWeekCounter, defaultWeight))
                    * beginOfRunCycleRcAvgDemand;
      }
    }
  }
예제 #3
0
  private String demandToString() {
    Iterator<Years> yrItr = demandMap.keySet().iterator();
    Map<LocalDate, Demand> currDemandMap;
    Years currYr;
    LocalDate currDate;
    Demand currDemand;

    StringBuffer epDemandBf = new StringBuffer();
    epDemandBf.append("epDemand|");

    StringBuffer rcActualDemandBf = new StringBuffer();
    rcActualDemandBf.append("rcActualDemand|");

    StringBuffer rcDemandBf = new StringBuffer();
    rcDemandBf.append("rcDemand|");

    StringBuffer rcAvgDemandBf = new StringBuffer();
    rcAvgDemandBf.append("rcAvgDemand|");

    StringBuffer rcAvgDemandActualBf = new StringBuffer();
    rcAvgDemandActualBf.append("rcAvgDemandActual|");

    while (yrItr.hasNext()) {
      currYr = yrItr.next();
      currDemandMap = demandMap.get(currYr);
      Iterator<LocalDate> itr = currDemandMap.keySet().iterator();
      while (itr.hasNext()) {
        currDate = itr.next();
        currDemand = currDemandMap.get(currDate);
        // ep demand
        epDemandBf.append(currDate);
        epDemandBf.append(":");
        epDemandBf.append(currDemand.getEpDemand());
        epDemandBf.append("|");
        // actual demand
        rcActualDemandBf.append(currDate);
        rcActualDemandBf.append(":");
        rcActualDemandBf.append(currDemand.getRcDemandActual());
        rcActualDemandBf.append("|");
        // rc demand
        rcDemandBf.append(currDate);
        rcDemandBf.append(":");
        rcDemandBf.append(currDemand.getRcDemand());
        rcDemandBf.append("|");
        // rc average demand
        rcAvgDemandBf.append(currDate);
        rcAvgDemandBf.append(":");
        rcAvgDemandBf.append(currDemand.getRcAvgDemand());
        rcAvgDemandBf.append("|");
        // rc average demand actual
        rcAvgDemandActualBf.append(currDate);
        rcAvgDemandActualBf.append(":");
        rcAvgDemandActualBf.append(currDemand.getRcAvgDemandActual());
        rcAvgDemandActualBf.append("|");
      }
    }
    rcActualDemandBf.append(";\n");
    epDemandBf.append(";\n");
    rcDemandBf.append(";\n");
    rcAvgDemandBf.append(";\n");
    rcAvgDemandActualBf.append(";\n");

    StringBuffer retBf = new StringBuffer();
    retBf.append(epDemandBf.toString());
    retBf.append(rcActualDemandBf.toString());
    retBf.append(rcDemandBf.toString());
    retBf.append(rcAvgDemandBf.toString());
    retBf.append(rcAvgDemandActualBf.toString());
    retBf.append("\n");

    return retBf.toString();
  }
예제 #4
0
  private void processWeeklyMetrics() {
    // On the end of the review cycle (Sat night) the rcAvgDemand does not undergo weekly learning
    // For this exercise we do not have time granulity  so weekly processing is done Sunday for the
    // prior week

    LocalDate crc = SystemDao.getCrc();
    LocalDate prevCRCStartDate = SystemDao.getReviewCycleStartDate(); // getPreviousCRCStartDate();
    Sales salesData = getSales(crc);

    Sales beginOfPeriodSalesData = getSales(prevCRCStartDate);
    double beginOfPeriodRcAvgSales = 0;
    double beginOfPeriodRcActualAvgSales = 0;
    if (beginOfPeriodSalesData != null) {
      beginOfPeriodRcAvgSales = beginOfPeriodSalesData.getRcAvgSales();
      beginOfPeriodRcActualAvgSales = beginOfPeriodSalesData.getRcAvgSalesActual();
    }

    Demand demandData = getDemand(crc);
    Demand beginOfPeriodDemandData = getDemand(prevCRCStartDate);
    double beginOfPeriodRcAvgDemand = 0;
    double beginOfPeriodRcAvgActualDemand = 0;
    if (beginOfPeriodDemandData != null) {
      beginOfPeriodRcAvgDemand = beginOfPeriodDemandData.getRcAvgDemand();
      beginOfPeriodRcAvgActualDemand = beginOfPeriodDemandData.getRcAvgDemandActual();
    }
    double defaultWeight = SystemDao.getDefaultWeight();

    double lastWeekLift = getDemandUplift(prevCRCStartDate);
    double weight = 1.0;
    if (statusCd == STATUS_CD.LEARNING) {
      weight = getWeightedWeight1(learningWeekCounter, defaultWeight);
    } else if (statusCd == STATUS_CD.ACTIVE) {
      weight = getWeight1(learningWeekCounter);
    }

    rcAvgSalesActual =
        (weight * (salesData.getRcSalesActual() / lastWeekLift))
            + ((1 - weight) * beginOfPeriodRcActualAvgSales);
    rcAvgSales =
        (weight * (salesData.getRcSales() / lastWeekLift))
            + ((1 - weight) * beginOfPeriodRcAvgSales);
    rcAvgDemand =
        (weight * (demandData.getRcDemand() / lastWeekLift))
            + ((1 - weight) * beginOfPeriodRcAvgDemand);
    rcAvgDemandActual =
        (weight * (demandData.getRcDemandActual() / lastWeekLift))
            + ((1 - weight) * beginOfPeriodRcAvgActualDemand);

    // error checking
    if (rcAvgDemand == 0 && statusCd != STATUS_CD.INACTIVE) {
      System.out.println("Error: 0 demand when product status is not inactive");
    }
    if (rcAvgDemand >= 4 * rcAvgSales) {
      rcAvgSales = 4 * rcAvgSalesActual;
      System.out.println("Error: RC Actual Sales greater then 4 times RC Average Sales");
    }
    if (rcAvgDemand >= 3 * rcAvgSalesActual) {
      rcAvgSales = 3 * rcAvgSalesActual;
      System.out.println("Error: RC Actual Sales greater then 3 times RC Actual Average Sales");
    }

    storeWeeklyMetrics(crc);
    this.learningWeekCounter++;
    // this is the end of the review cycle reset hasBeenOffRange
    if (hasBeenOffRange) {
      hasBeenOffRange = false;
    }
    resetRcAccumulators();
  }