コード例 #1
1
ファイル: ToDB.java プロジェクト: mmdk95/CityPark
  /**
   * Bereken de prijs die een ad-hoc klant moet betalen.
   *
   * @param intijd LocalDateTime
   * @param uittijd LocalDateTime
   * @return double
   */
  public double berekenPrijs(LocalDateTime intijd, LocalDateTime uittijd) {
    // haal de benodigde informatie op
    ArrayList<TijdTarief> tijdtarief = db.getTijdTarief();
    ArrayList<TariefCat> tariefcat = db.getTariefCat();

    // maak de variabelen voor het berekenen aan
    Duration deltatijd = Duration.between(intijd, uittijd);
    Duration minus = Duration.ofMinutes(30);
    Duration zeroDuration = Duration.ZERO;

    LocalTime per30min = LocalTime.from(uittijd);

    HashMap<TariefCat, HashMap<Integer, Double>> teBetalenPerCatPerDag = new HashMap<>();
    TariefCat tmpCat = null;

    do {
      DayOfWeek dag = uittijd.getDayOfWeek();
      setDagnr(dag.getValue());

      for (TijdTarief tijd : tijdtarief) {
        if (tijd.getDagbegin() <= getDagnr()
            && getDagnr() <= tijd.getDageind()
            && per30min.isAfter(tijd.getTijdstart())
            && per30min.isBefore(tijd.getTijdeind())) {
          setCatnr(tijd.getCategorie());
        }
      }

      for (TariefCat cat : tariefcat) {
        if (cat.getDatumbegin().getYear() == uittijd.toLocalDate().getYear()
            && cat.getDatumbegin().getMonthValue() <= uittijd.toLocalDate().getMonthValue()
            && cat.getCategorie() == getCatnr()) {
          tmpCat = cat;
        }
      }
      // update te betalen per categorie per dag
      HashMap<Integer, Double> totaal =
          teBetalenPerCatPerDag.getOrDefault(tmpCat, new HashMap<Integer, Double>());
      double dagTotaal = totaal.getOrDefault(getDagnr(), 0.0);
      dagTotaal += tmpCat.getTarief();
      totaal.put(getDagnr(), dagTotaal);
      teBetalenPerCatPerDag.put(tmpCat, totaal);

      uittijd = uittijd.minus(minus);
      deltatijd = deltatijd.minus(minus);
      per30min = LocalTime.from(uittijd);

    } while (deltatijd.compareTo(zeroDuration) == 1);

    double tebetalen = 0.0;
    for (Map.Entry<TariefCat, HashMap<Integer, Double>> dagEntry :
        teBetalenPerCatPerDag.entrySet()) {
      for (Map.Entry<Integer, Double> entry : dagEntry.getValue().entrySet()) {
        if (dagEntry.getKey().getMaxtarief() > entry.getValue().doubleValue())
          tebetalen += entry.getValue();
        else tebetalen += dagEntry.getKey().getMaxtarief();
      }
    }

    BigDecimal bd = new BigDecimal(tebetalen);
    bd = bd.setScale(2, RoundingMode.HALF_UP);

    return bd.doubleValue();
  }
コード例 #2
0
  @Override
  public String convert(LocalDateTime dateTime) {
    LocalDateTime now = LocalDateTime.now();
    Duration duration = Duration.between(dateTime, now);

    Period period = Period.between(dateTime.toLocalDate(), now.toLocalDate());

    if (duration.toMinutes() < 1) {
      return String.format("%s secs ago", duration.getSeconds());
    }

    if (duration.toHours() < 1) {
      return String.format("%s mins ago", duration.toMinutes());
    }

    if (duration.toDays() < 1) {
      return String.format("%s hrs ago", duration.toHours());
    }

    if (period.getYears() > 0) {
      return DateTimeFormatter.ISO_LOCAL_DATE.format(dateTime);
    }

    if (period.getMonths() > 0) {
      return String.format("%s months ago", period.getMonths());
    }

    return String.format("%s days ago", period.getDays());
  }
コード例 #3
0
  public static void main(String[] args) {
    LocalDateTime lDT = LocalDateTime.of(LocalDate.of(2016, 01, 17), LocalTime.of(23, 11, 25));

    System.out.println("The date and time is : " + lDT.toString());
    System.out.println("The strict date is :" + lDT.toLocalDate().toString());
    System.out.println("The strict time is :" + lDT.toLocalTime().toString());
  }
コード例 #4
0
ファイル: JclFactoryTest.java プロジェクト: peter-mount/Job
  @Test
  public void timeout() {
    Jcl jcl =
        JclFactory.compileJcl(
            JOB
                + "## run at 2016-2-10 18:24 timeout 1 minute\n"
                + "## run at 2016/2/10 18:24 timeout 1 hour\n"
                + "## run every minute timeout minute\n"
                + "## run every 10 minutes timeout 5 minutes\n");
    test(jcl);

    System.out.println(jcl.getSchedule().replace("><", ">\n<"));

    assertSame(JclType.SCHEDULABLE, jcl.getType());

    LocalDateTime dt = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
    String now = dt.toLocalDate().toString() + " " + dt.toLocalTime().toString();

    assertEquals(
        "Schedule",
        "<schedule>"
            + "<once at=\"2016-02-10 18:24\" timeout=\"1 minute\"/>"
            + "<once at=\"2016-02-10 18:24\" timeout=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 minute\" timeout=\"1 minute\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"10 minute\" timeout=\"5 minute\"/>"
            + "</schedule>",
        jcl.getSchedule());
  }
コード例 #5
0
  public List<Timespan> split() {
    if (!end.toLocalDate().equals(start.toLocalDate())) {
      List<Timespan> dates = new ArrayList<>();
      Timespan firstDay = new Timespan(start, start.toLocalDate().atTime(23, 59, 59));
      long diffDays = end.getLong(ChronoField.EPOCH_DAY) - start.getLong(ChronoField.EPOCH_DAY);

      dates.add(firstDay);
      for (int i = 0; i < diffDays - 1; i++) {
        LocalDateTime currDateTime = dates.get(i).getEnd().plusSeconds(1);
        dates.add(new Timespan(currDateTime, currDateTime.toLocalDate().atTime(23, 59, 59)));
      }
      Timespan lastDay = new Timespan(end.toLocalDate().atStartOfDay(), end);
      dates.add(lastDay);

      return Collections.unmodifiableList(dates);
    }
    return Arrays.asList(this);
  }
コード例 #6
0
 @Test
 public void testAsLocalDateTime() {
   LocalDateTime dateTime = LocalDateTime.now();
   long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime());
   LocalDateTime upacked = asLocalDateTime(packed);
   assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear());
   assertEquals(dateTime.getHour(), upacked.getHour());
   assertEquals(dateTime.getMinute(), upacked.getMinute());
   assertEquals(dateTime.getSecond(), upacked.getSecond());
 }
コード例 #7
0
  /**
   * Track dsa bids performance
   *
   * @throws Exception
   */
  public void start(IDsaTrackerUserConfiguration userConfig) throws Exception {
    Map<String, Account> accounts = sourceManager.loadSources(userConfig);

    Map<Long, AdGroupPerformance> baseReport = initializeBaseReport(userConfig, accounts);
    Map<Long, AdGroupPerformance> report = baseReport;
    do {
      modifyBids(userConfig, accounts, baseReport, report);

      // update adGroups bids
      if (!userConfig.getIdleMode()) {
        adGroupBidUploaderService.uploadBids(
            userConfig,
            accounts
                .values()
                .stream()
                .flatMap(accountData -> accountData.getCampaigns().values().stream())
                .flatMap(campaignData -> campaignData.getAdGroups().values().stream()));
      }

      if (configuration.dsaTracker.singleRunMod) {
        return;
      }

      LOGGER.info(
          "Wait for data to accumulate (waitTime = "
              + userConfig.getDsaTracker().waitTime
              + " sec)...");
      Thread.sleep(userConfig.getDsaTracker().waitTime * 1000);

      LocalDateTime dateOne = now();
      LocalDateTime dateTwo = dateOne.minusDays(REPORT_DAYS);
      report =
          performanceDataLoader.downloadPerformanceData(
              accounts, dateTwo.toLocalDate(), dateOne.toLocalDate());
    } while (!Thread.interrupted());
  }
コード例 #8
0
 /**
  * Check time zones on the IANA time and zone database
  *
  * @param args
  */
 public static void main(String[] args) {
   ZoneId casaZone = ZoneId.of("Africa/Casablanca");
   ZoneId defaultZone = TimeZone.getDefault().toZoneId();
   LocalDate rightNow = LocalDate.now();
   ZonedDateTime zoneDateTime = rightNow.atStartOfDay(casaZone);
   ZoneId parisZone = ZoneId.of("Europe/Paris");
   LocalDateTime rightNowInTime = LocalDateTime.now();
   ZonedDateTime rightNowInTimeInParis = rightNowInTime.atZone(parisZone);
   Instant thisMoment = Instant.now();
   ZonedDateTime thisMomentInCasa = thisMoment.atZone(casaZone);
   ZoneId tokyoZone = ZoneId.of("Asia/Tokyo");
   LocalDate thisInstantInTokyo = rightNowInTime.toLocalDate();
   LocalDateTime timeFromThisMomentInTokyo = LocalDateTime.ofInstant(thisMoment, tokyoZone);
   System.out.println(
       String.format("In Tokyo right now is %s", timeFromThisMomentInTokyo.toString()));
 }
コード例 #9
0
  private static void useLocalDate() {
    LocalDate date = LocalDate.of(2014, 3, 18);
    int year = date.getYear(); // 2014
    Month month = date.getMonth(); // MARCH
    int day = date.getDayOfMonth(); // 18
    DayOfWeek dow = date.getDayOfWeek(); // TUESDAY
    int len = date.lengthOfMonth(); // 31 (days in March)
    boolean leap = date.isLeapYear(); // false (not a leap year)
    System.out.println(date);

    int y = date.get(ChronoField.YEAR);
    int m = date.get(ChronoField.MONTH_OF_YEAR);
    int d = date.get(ChronoField.DAY_OF_MONTH);

    LocalTime time = LocalTime.of(13, 45, 20); // 13:45:20
    int hour = time.getHour(); // 13
    int minute = time.getMinute(); // 45
    int second = time.getSecond(); // 20
    System.out.println(time);

    LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); // 2014-03-18T13:45
    LocalDateTime dt2 = LocalDateTime.of(date, time);
    LocalDateTime dt3 = date.atTime(13, 45, 20);
    LocalDateTime dt4 = date.atTime(time);
    LocalDateTime dt5 = time.atDate(date);
    System.out.println(dt1);

    LocalDate date1 = dt1.toLocalDate();
    System.out.println(date1);
    LocalTime time1 = dt1.toLocalTime();
    System.out.println(time1);

    Instant instant = Instant.ofEpochSecond(44 * 365 * 86400);
    Instant now = Instant.now();

    Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time);
    Duration d2 = Duration.between(instant, now);
    System.out.println(d1.getSeconds());
    System.out.println(d2.getSeconds());

    Duration threeMinutes = Duration.of(3, ChronoUnit.MINUTES);
    System.out.println(threeMinutes);

    JapaneseDate japaneseDate = JapaneseDate.from(date);
    System.out.println(japaneseDate);
  }
コード例 #10
0
 /** TimePointを生成します。 */
 public static TimePoint now(Clock clock) {
   LocalDateTime now = LocalDateTime.now(clock);
   return of(now.toLocalDate(), now);
 }
コード例 #11
0
  private Map<Long, AdGroupPerformance> initializeBaseReport(
      IDsaTrackerUserConfiguration userConfig, final Map<String, Account> accounts)
      throws Exception {
    if (userConfig.getDsaTracker().reinitializeBaseReport) {
      File baseReportFile = fsUtils.getResultFile(userConfig, "DsaBaseReport");
      LOGGER.info("Reinitialize base report");

      // update adGroups bids
      if (!userConfig.getIdleMode()) {
        adGroupBidUploaderService.uploadBids(
            userConfig,
            accounts
                .values()
                .stream()
                .flatMap(accountData -> accountData.getCampaigns().values().stream())
                .flatMap(campaignData -> campaignData.getAdGroups().values().stream()));
      }

      if (!configuration.dsaTracker.singleRunMod) {
        LOGGER.info(
            "Wait for data to accumulate (waitTime = "
                + userConfig.getDsaTracker().waitTime
                + " sec)...");
        Thread.sleep(userConfig.getDsaTracker().waitTime * 1000);
      }

      LocalDateTime dateOne = now();
      LocalDateTime dateTwo = dateOne.minusDays(REPORT_DAYS);
      Map<Long, AdGroupPerformance> baseReport =
          performanceDataLoader.downloadPerformanceData(
              accounts, dateTwo.toLocalDate(), dateOne.toLocalDate());

      for (Long key : baseReport.keySet()) {
        if (baseReport.get(key).adGroup == null) baseReport.remove(key);
      }

      for (Account account : accounts.values()) {
        for (Campaign campaign : account.getCampaigns().values()) {
          for (AdGroup adGroup : campaign.getAdGroups().values()) {
            if (baseReport.get(adGroup.getAdGroupId()) != null) continue;
            AdGroupPerformance adGroupPerformance = new AdGroupPerformance();
            Long campaignId = campaign.getCampaignId();
            Long adGroupId = adGroup.getAdGroupId();
            adGroupPerformance.adGroup =
                new AdGroupImpl(
                    new CampaignImpl(new AccountImpl(account.getAccountId()), campaignId),
                    adGroupId);
            adGroupPerformance.adGroup.setMetrics(
                new DsaMetrics() {
                  {
                    setMaxBid(0.0);
                  }
                });
            adGroupPerformance.hasConversions = false;
            adGroupPerformance.averageCpc = 0;
            adGroupPerformance.averagePosition = 0;
            adGroupPerformance.clicks = 0;
            adGroupPerformance.cost = 0;
            adGroupPerformance.impressions = 0;

            baseReport.put(adGroupId, adGroupPerformance);
          }
        }
      }

      baseReport
          .values()
          .forEach(
              r -> {
                DsaMetrics metrics = (DsaMetrics) r.adGroup.getMetrics();
                r.maxBaseCpc =
                    metrics.getMaxBid() * (1 + userConfig.getDsaTracker().maxCpcBidChange);
                r.minBaseCpc =
                    metrics.getMaxBid() * (1 - userConfig.getDsaTracker().maxCpcBidChange);
              });

      dsaTrackerUtils.saveBaseReport(baseReportFile, baseReport);
      ((DsaTrackerUserConfiguration) userConfig).baseReportFilePath =
          baseReportFile.getAbsolutePath();

      return baseReport;
    } else {
      LOGGER.info("Load base report from previous launch");
      File baseReportFile = new File(((DsaTrackerUserConfiguration) userConfig).baseReportFilePath);
      if (!baseReportFile.exists()) {
        throw new FileNotFoundException("Basic landscape report file does not exist");
      }

      return dsaTrackerUtils.loadBaseReport(baseReportFile, accounts);
    }
  }
コード例 #12
0
ファイル: JclFactoryTest.java プロジェクト: peter-mount/Job
  @Test
  public void runEvery() {
    Jcl jcl =
        JclFactory.compileJcl(
            JOB
                + "## run every minute\n"
                + "## run every 10 minutes\n"
                + "## run every hour\n"
                + "## run every 3 hours\n"
                + "## run every day\n"
                + "## run every 2 days\n"
                + "## run every 2 day\n"
                // retry on failure after 1 hour
                + "## run every day retry 1 hour\n"
                + "## run every day retry 1 hour maximum 3 times\n"
                + "## run every day retry every 1 hour\n"
                + "## run every day retry every 1 hour maximum 3\n"
                // Between
                + "## run every hour between 00:00 and 06:00\n"
                + "## run every hour between 00:00 and 06:00 retry 10 minutes maximum 3 times\n"
                + "## run every hour between 21:00 and 03:00\n"
                + "## run every hour between 21:00 and 03:00 retry 10 minutes maximum 3 times\n");
    test(jcl);

    System.out.println(jcl.getSchedule().replace("><", ">\n<"));

    assertSame(JclType.SCHEDULABLE, jcl.getType());

    LocalDateTime dt = LocalDateTime.now().truncatedTo(ChronoUnit.MINUTES);
    String now = dt.toLocalDate().toString() + " " + dt.toLocalTime().toString();

    assertEquals(
        "Schedule",
        "<schedule>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 minute\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"10 minute\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"3 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"2 day\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"2 day\"/>"
            // retry on failure after 1 hour
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\" max=\"3\"/>"
            // same but with every keyword
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 day\" retry=\"1 hour\" max=\"3\"/>"
            // Between
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" between=\"00:00-06:00\"/>"
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" retry=\"10 minute\" max=\"3\" between=\"00:00-06:00\"/>"
            // Between 2100-0300 crossing midnight
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" between=\"21:00-03:00\"/>"
            // Between 2100-0300 crossing midnight retry 10 minutes max 3
            + "<repeat next=\""
            + now
            + "\" step=\"1 hour\" retry=\"10 minute\" max=\"3\" between=\"21:00-03:00\"/>"
            + "</schedule>",
        jcl.getSchedule());
  }