demands renamed to deliveries in scope of shortage prediction
This commit is contained in:
@@ -24,7 +24,7 @@ import static java.util.stream.Collectors.toMap;
|
||||
class ForecastORMProvider implements Forecasts {
|
||||
|
||||
private final WarehouseService stocks;
|
||||
private final DeliveryForecastDao demands;
|
||||
private final DeliveryForecastDao deliveries;
|
||||
private final ProductionOutputDao outputs;
|
||||
private final Clock clock;
|
||||
|
||||
@@ -34,15 +34,15 @@ class ForecastORMProvider implements Forecasts {
|
||||
Instant now = Instant.now(clock);
|
||||
LocalDateTime time = now.atZone(clock.getZone()).toLocalDateTime();
|
||||
|
||||
Map<LocalDateTime, Long> demands = this.demands
|
||||
Map<LocalDateTime, Long> deliveries = this.deliveries
|
||||
.findByRefNoAndTimeGreaterThanEqual(refNo.getRefNo(), time).stream()
|
||||
.collect(toMap(
|
||||
DeliveryForecastEntity::getTime,
|
||||
DeliveryForecastEntity::getLevel
|
||||
));
|
||||
SortedSet<LocalDateTime> deliveryTimes = new TreeSet<>(demands.keySet());
|
||||
SortedSet<LocalDateTime> deliveryTimes = new TreeSet<>(deliveries.keySet());
|
||||
|
||||
Demands demand = new Demands(demands);
|
||||
Deliveries demand = new Deliveries(deliveries);
|
||||
|
||||
ProductionOutputs outputs = new ProductionForecast(
|
||||
this.outputs.findByRefNoAndStartGreaterThanEqual(refNo.getRefNo(), time).stream()
|
||||
|
||||
7
app-monolith/src/test/resources/curl.txt
Normal file
7
app-monolith/src/test/resources/curl.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
curl http://localhost:8080
|
||||
|
||||
curl -X POST -H "Content-Type: application/json" \
|
||||
-d @app-monolith/src/test/resources/pl.com.bottega.factory.demand.forecasting.command/demand-adjustments.json \
|
||||
http://localhost:8080/demand-adjustments
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
{
|
||||
"note": "Customer moved demand for day earlier",
|
||||
"customerRepresentative": "Krysia z logistyki",
|
||||
"note": "Bo demo dla comarch-u",
|
||||
"customerRepresentative": "Koledzy z logistyki",
|
||||
"adjustment": {
|
||||
"refNo": "3009000",
|
||||
"adjustments": {
|
||||
"2017-12-11": {
|
||||
"2017-12-15": {
|
||||
"demand": {
|
||||
"level": 2800,
|
||||
"level": 1000,
|
||||
"schema": "AtDayStart"
|
||||
},
|
||||
"strong": true
|
||||
},
|
||||
"2017-12-12": {
|
||||
"2017-12-16": {
|
||||
"demand": {
|
||||
"level": 0,
|
||||
"level": 1000,
|
||||
"schema": "AtDayStart"
|
||||
},
|
||||
"strong": false
|
||||
|
||||
@@ -6,11 +6,11 @@ import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
@AllArgsConstructor
|
||||
class Demands {
|
||||
class Deliveries {
|
||||
|
||||
private final Map<LocalDateTime, Long> demands;
|
||||
private final Map<LocalDateTime, Long> forecast;
|
||||
|
||||
long get(LocalDateTime time) {
|
||||
return demands.getOrDefault(time, 0L);
|
||||
return forecast.getOrDefault(time, 0L);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class Forecast {
|
||||
private final SortedSet<LocalDateTime> deliveryTimes;
|
||||
private final Stock stock;
|
||||
private final ProductionOutputs outputs;
|
||||
private final Demands demands;
|
||||
private final Deliveries deliveries;
|
||||
|
||||
public Optional<Shortages> findShortages() {
|
||||
long level = stock.getLevel();
|
||||
@@ -23,7 +23,7 @@ public class Forecast {
|
||||
Shortages.Builder found = Shortages.builder(refNo, stock.getLocked(), created);
|
||||
LocalDateTime lastTime = created;
|
||||
for (LocalDateTime time : deliveryTimes) {
|
||||
long demand = demands.get(time);
|
||||
long demand = deliveries.get(time);
|
||||
long produced = outputs.getOutput(lastTime, time);
|
||||
|
||||
long levelOnDelivery = level + produced - demand;
|
||||
|
||||
@@ -13,7 +13,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(1000L),
|
||||
demands((now + 20.min): 500L),
|
||||
deliveries((now + 20.min): 500L),
|
||||
noProductions()
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0L, 1000L),
|
||||
demands((now + 20.min): 500L),
|
||||
deliveries((now + 20.min): 500L),
|
||||
noProductions()
|
||||
)
|
||||
|
||||
@@ -43,7 +43,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands((now + 20.min): 500L, (now + 1.day): 500L),
|
||||
deliveries((now + 20.min): 500L, (now + 1.day): 500L),
|
||||
noProductions()
|
||||
)
|
||||
|
||||
@@ -61,7 +61,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands((now): 500L),
|
||||
deliveries((now): 500L),
|
||||
noProductions()
|
||||
)
|
||||
|
||||
@@ -76,7 +76,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
noDemands(),
|
||||
noDeliveries(),
|
||||
noProductions()
|
||||
)
|
||||
|
||||
@@ -91,7 +91,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands((now + 5.h): 500L),
|
||||
deliveries((now + 5.h): 500L),
|
||||
plan([production(now, 50.min, 10)])
|
||||
)
|
||||
|
||||
@@ -106,7 +106,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands((now + 20.min): 500L),
|
||||
deliveries((now + 20.min): 500L),
|
||||
plan([production(now, 50.min, 10)])
|
||||
)
|
||||
|
||||
@@ -121,7 +121,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands((now): 500L),
|
||||
deliveries((now): 500L),
|
||||
plan([production(now + 1.h, 50.min, 10)])
|
||||
)
|
||||
|
||||
@@ -136,7 +136,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands((now + 30.min): 600L),
|
||||
deliveries((now + 30.min): 600L),
|
||||
plan([production(now, 50.min, 10), production(now, 50.min, 10)])
|
||||
)
|
||||
|
||||
@@ -151,7 +151,7 @@ class ShortagesCalculationAlgorithmSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(0),
|
||||
demands(
|
||||
deliveries(
|
||||
(now + 60.min): 500L, // first delivery
|
||||
(now + 1.day + 60.min): 500L + 100L), // second delivery
|
||||
plan([
|
||||
|
||||
@@ -12,12 +12,12 @@ trait ShortagesCalculationAssemblerTrait {
|
||||
String refNo = "3009000"
|
||||
SortedSet<LocalDateTime> times
|
||||
|
||||
Forecasts forecastProvider(Stock stock, Demands demands, ProductionOutputs outputs) {
|
||||
Forecasts forecastProvider(Stock stock, Deliveries demands, ProductionOutputs outputs) {
|
||||
def forecast = forecast(stock, demands, outputs)
|
||||
return { RefNoId refNo, int daysAhead -> forecast } as Forecasts
|
||||
}
|
||||
|
||||
Forecast forecast(Stock stock, Demands demands, ProductionOutputs outputs) {
|
||||
Forecast forecast(Stock stock, Deliveries demands, ProductionOutputs outputs) {
|
||||
new Forecast(refNo, now, times, stock, outputs, demands)
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ trait ShortagesCalculationAssemblerTrait {
|
||||
new ProductionForecast.Item(start, duration, partsPerMinute)
|
||||
}
|
||||
|
||||
Demands noDemands() {
|
||||
Deliveries noDeliveries() {
|
||||
times = Collections.emptySortedSet()
|
||||
new Demands([:])
|
||||
new Deliveries([:])
|
||||
}
|
||||
|
||||
Demands demands(Map<LocalDateTime, Long> demands) {
|
||||
Deliveries deliveries(Map<LocalDateTime, Long> demands) {
|
||||
times = new TreeSet<>(demands.keySet())
|
||||
new Demands(demands)
|
||||
new Deliveries(demands)
|
||||
}
|
||||
|
||||
Stock stock(long levels) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class ShortagesCalculationExamplesSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(7 * 500L),
|
||||
demands(
|
||||
deliveries(
|
||||
(now): 500L,
|
||||
(now + 1.day): 500L,
|
||||
(now + 2.day): 500L,
|
||||
@@ -36,7 +36,7 @@ class ShortagesCalculationExamplesSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(4 * 500L),
|
||||
demands(
|
||||
deliveries(
|
||||
(now): 500L,
|
||||
(now + 1.day): 500L,
|
||||
(now + 2.day): 500L,
|
||||
@@ -63,7 +63,7 @@ class ShortagesCalculationExamplesSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(6 * 500L),
|
||||
demands(
|
||||
deliveries(
|
||||
(now): 500L,
|
||||
(now + 1.day): 500L,
|
||||
(now + 2.day): 500L,
|
||||
@@ -86,7 +86,7 @@ class ShortagesCalculationExamplesSpec extends Specification
|
||||
given:
|
||||
def forecast = forecast(
|
||||
stock(500L),
|
||||
demands(
|
||||
deliveries(
|
||||
(now): 500L,
|
||||
(now + 1.day): 500L,
|
||||
(now + 2.day): 500L,
|
||||
|
||||
@@ -153,7 +153,7 @@ class ShortagePredictionProcessSpec extends Specification {
|
||||
Forecasts noShortagesWillBeFound() {
|
||||
forecastAssembler.forecastProvider(
|
||||
forecastAssembler.stock(1000),
|
||||
forecastAssembler.noDemands(),
|
||||
forecastAssembler.noDeliveries(),
|
||||
forecastAssembler.noProductions()
|
||||
)
|
||||
}
|
||||
@@ -161,7 +161,7 @@ class ShortagePredictionProcessSpec extends Specification {
|
||||
Forecasts willFindShortages(Map<LocalDateTime, Long> shortages) {
|
||||
forecastAssembler.forecastProvider(
|
||||
forecastAssembler.stock(0),
|
||||
forecastAssembler.demands(shortages),
|
||||
forecastAssembler.deliveries(shortages),
|
||||
forecastAssembler.noProductions()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user