Ejemplo n.º 1
0
 private void initializePredictionLookupTable(UtilizationKey utilizationKey) {
   queryFactory
       .insert(qPrediction)
       .set(qPrediction.facilityId, utilizationKey.facilityId)
       .set(qPrediction.capacityType, utilizationKey.capacityType)
       .set(qPrediction.usage, utilizationKey.usage)
       .execute();
 }
Ejemplo n.º 2
0
 @TransactionalRead
 @Override
 public List<PredictionBatch> getPredictionsByFacility(Long facilityId, DateTime time) {
   return queryFactory
       .from(qPrediction)
       .select(predictionMapping(time))
       .where(qPrediction.facilityId.eq(facilityId))
       .where(isWithinPredictionWindow(time))
       .fetch();
 }
Ejemplo n.º 3
0
 @TransactionalRead
 @Override
 public List<Prediction> getPredictionHistoryByPredictor(
     Long predictorId, DateTime start, DateTime end, int forecastDistanceInMinutes) {
   return queryFactory
       .from(qPredictionHistory)
       .select(historyToPredictionMapping())
       .where(
           qPredictionHistory.predictorId.eq(predictorId),
           qPredictionHistory.forecastDistanceInMinutes.eq(forecastDistanceInMinutes),
           qPredictionHistory.ts.between(start, end))
       .orderBy(qPredictionHistory.ts.asc())
       .fetch();
 }
Ejemplo n.º 4
0
 @TransactionalRead
 @Override
 public Optional<PredictionBatch> getPrediction(UtilizationKey utilizationKey, DateTime time) {
   return asOptional(
       queryFactory
           .from(qPrediction)
           .select(predictionMapping(time))
           .where(
               qPrediction.facilityId.eq(utilizationKey.facilityId),
               qPrediction.capacityType.eq(utilizationKey.capacityType),
               qPrediction.usage.eq(utilizationKey.usage))
           .where(isWithinPredictionWindow(time))
           .fetchOne());
 }
Ejemplo n.º 5
0
  private long maybeUpdatePredictionLookupTable(
      UtilizationKey utilizationKey, DateTime start, List<Prediction> predictions) {
    SQLUpdateClause update =
        queryFactory
            .update(qPrediction)
            .where(
                qPrediction.facilityId.eq(utilizationKey.facilityId),
                qPrediction.capacityType.eq(utilizationKey.capacityType),
                qPrediction.usage.eq(utilizationKey.usage))
            .set(qPrediction.start, start);
    predictions.forEach(p -> update.set(spacesAvailableAt(p.timestamp), p.spacesAvailable));

    return update.execute();
  }
Ejemplo n.º 6
0
 private void savePredictionHistory(
     Long predictorId, DateTime start, List<Prediction> predictions) {
   if (!predictions.isEmpty()) {
     final SQLInsertClause insert = queryFactory.insert(qPredictionHistory);
     predictions.forEach(
         p ->
             insert
                 .set(qPredictionHistory.predictorId, predictorId)
                 .set(
                     qPredictionHistory.forecastDistanceInMinutes,
                     ((int) new Duration(start, p.timestamp).getStandardMinutes()))
                 .set(qPredictionHistory.ts, p.timestamp)
                 .set(qPredictionHistory.spacesAvailable, p.spacesAvailable)
                 .addBatch());
     insert.execute();
   }
 }