Esempio n. 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);
  }
Esempio n. 2
0
  private void initLearningMetrics() {
    if (learningMetricsInitialized) {
      return;
    }
    double defaultWeight = SystemDao.getDefaultWeight();
    double lastWeekLift = getDemandUplift(SystemDao.getReviewCycleStartDate());
    Sales beginOfRunCycleSales = getSales(SystemDao.getReviewCycleStartDate());
    double beginOfRunCycleRcAvgSales = 0;
    if (beginOfRunCycleSales != null) {
      beginOfRunCycleRcAvgSales = beginOfRunCycleSales.getRcAvgSales();
    }

    rcAvgSales =
        getWeightedWeight1(learningWeekCounter, defaultWeight) * epSales / lastWeekLift
            + (1 - getWeightedWeight1(learningWeekCounter, defaultWeight))
                * beginOfRunCycleRcAvgSales;

    // Tim's documentation states:
    // Its important sales metrics are initialized to AVG_WEEKLY_SALES based on the initialization
    // logic.
    // This estimates initial values based on different combinations of the PLs product and location
    // hierarchies dependent on the specific situation for that PL
    rcAvgSalesActual = rcAvgSales;
    rcAvgDemand = rcAvgSales;
    rcOldAvgDemand = rcAvgSales;
    rcAvgDemandActual = rcAvgSales;
    epAvgInv = rcAvgSales;
    rcWass2 = Math.pow(rcAvgSales, 2);
    learningMetricsInitialized = true;
  }
Esempio n. 3
0
  @Test(dependsOnMethods = "read")
  public void update() throws Exception {

    Sales role = repository.findOne(id);
    Sales newrole = new Sales.Builder(role.getSalesDate()).copy(role).build();
    // SAVE UPDATED ROLE
    repository.save(newrole);

    // GET THE SAVED ROLE

    Assert.assertEquals(newrole.getPrice(), 22.00);
  }
Esempio n. 4
0
 @Test
 public void create() throws Exception {
   Beekeeper beekeepers = BeekeeperFactory.create("karl", "otto", "*****@*****.**");
   Location locations = LocationFactory.create("Darling", beekeepers);
   SubLocation subLocations = SubLocationFactory.create("Fossil", locations);
   Harvest harvests = HarvestFactory.create("Fossil", 66.00, subLocations);
   Customer customers = CustomerFactory.create("", "", "");
   Bucket buckets = BucketFactory.create(66.00, harvests);
   Sales role = SalesFactory.create("date", 22.00, buckets, customers);
   repository.save(role);
   id = role.getId();
   Assert.assertNotNull(role);
 }
 private Object assertQueryGeneratesSql(String query, String sql) {
   Sales sales = getSales();
   Connection oldConnection = sales.getConnection();
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   Connection newConnection = createTracingConnection(oldConnection, pw);
   sales.setConnection(newConnection);
   Object o;
   try {
     o = runQuery(query);
     pw.flush();
     String s = sw.toString();
     assertTrue(s, s.indexOf(sql) >= 0);
   } finally {
     sales.setConnection(oldConnection);
   }
   return o;
 }
Esempio n. 6
0
  private String salesToString() {
    StringBuffer epSalesActualBf = new StringBuffer();
    epSalesActualBf.append("epSalesActual|");

    StringBuffer epSalesBf = new StringBuffer();
    epSalesBf.append("epSales|");

    StringBuffer rcSalesBf = new StringBuffer();
    rcSalesBf.append("rcSales|");

    StringBuffer rcAvgSalesBf = new StringBuffer();
    rcAvgSalesBf.append("rcAvgSales|");

    StringBuffer rcSalesActualBf = new StringBuffer();
    rcSalesActualBf.append("rcSalesActual|");

    StringBuffer rcAvgSalesActualBf = new StringBuffer();
    rcAvgSalesActualBf.append("rcAvgSalesActual|");

    Iterator<Years> yrItr = salesMap.keySet().iterator();
    Map<LocalDate, Sales> currSalesMap;
    LocalDate currDate;
    Years currYr;
    Sales currSale;
    // Populate Sale buffers
    while (yrItr.hasNext()) {
      currYr = yrItr.next();
      currSalesMap = salesMap.get(currYr);
      Iterator<LocalDate> itr = currSalesMap.keySet().iterator();
      while (itr.hasNext()) {
        currDate = itr.next();
        currSale = currSalesMap.get(currDate);
        // epSaleActual
        epSalesActualBf.append(currDate);
        epSalesActualBf.append(":");
        epSalesActualBf.append(currSale.getEpSalesActual());
        epSalesActualBf.append("|");
        // epSale
        epSalesBf.append(currDate);
        epSalesBf.append(":");
        epSalesBf.append(currSale.getEpSales());
        epSalesBf.append("|");
        // rc sales actual
        rcSalesActualBf.append(currDate);
        rcSalesActualBf.append(":");
        rcSalesActualBf.append(currSale.getRcSalesActual());
        rcSalesActualBf.append("|");
        // rc average sales actual
        rcAvgSalesActualBf.append(currDate);
        rcAvgSalesActualBf.append(":");
        rcAvgSalesActualBf.append(currSale.getRcAvgSalesActual());
        rcAvgSalesActualBf.append("|");
        // rc sales
        rcSalesBf.append(currDate);
        rcSalesBf.append(":");
        rcSalesBf.append(currSale.getRcSales());
        rcSalesBf.append("|");
        // rc sales average
        rcAvgSalesBf.append(currDate);
        rcAvgSalesBf.append(":");
        rcAvgSalesBf.append(currSale.getRcAvgSales());
        rcAvgSalesBf.append("|");
      }
    }
    epSalesActualBf.append(";\n");
    epSalesBf.append(";\n");
    rcSalesActualBf.append(";\n");
    rcAvgSalesActualBf.append(";\n");
    rcSalesBf.append(";\n");
    rcAvgSalesBf.append(";\n");

    StringBuffer retBf = new StringBuffer();
    retBf.append(epSalesActualBf.toString());
    retBf.append(epSalesBf.toString());
    retBf.append(rcSalesActualBf.toString());
    retBf.append(rcAvgSalesActualBf.toString());
    retBf.append(rcSalesBf.toString());
    retBf.append(rcAvgSalesBf.toString());
    retBf.append("\n");

    return retBf.toString();
  }
Esempio n. 7
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();
  }
Esempio n. 8
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();
  }
Esempio n. 9
0
 @Override
 public double valueAt(final int time) {
   return sales.valueAt(time) - (incrementalCosts.valueAt(time) + fixedCosts.valueAt(time));
 }