List of usage examples for org.joda.time Duration standardDays
public static Duration standardDays(long days)
From source file:com.sg.infrastructure.AuthTokenServiceImpl.java
private Duration getDurationForTokenType(TokenType type) { switch (type) { case WEB_SESSION_TOKEN: return Duration.standardHours(1l); case REGISTRATION_CONFIRMATION_TOKEN: return Duration.standardDays(60l); case PASWORD_RESET_TOKEN: return Duration.standardDays(1l); }/* www.j a va 2s. c o m*/ return null; }
From source file:com.sojanddesign.boxes.domain.model.user.DomainBoxesUserActivateSteps.java
License:Open Source License
@Given("$email of inactive user account created previously 4 days ago") public void givenEmailOfInactiveUserAccountCreatedPreviouslyFoorDaysAgo(String email) { this.email = email; try {//w w w . ja v a2 s .co m User mockUser = new User(new UserId("4")); mockUser.setActive(false); Duration foorDays = Duration.standardDays(4); Instant fourDaysAgo = Instant.now().minus(foorDays); mockUser.setAccountSettings(new AccountSettings(email, null, null, fourDaysAgo.toDate())); when(mockUserRepository.findByEmail(email)).thenReturn(mockUser); } catch (DomainException e) { exception = e; e.printStackTrace(); } }
From source file:com.tomtom.speedtools.metrics.MetricsCollector.java
License:Apache License
@Nonnull public static MetricsCollector create(@Nonnull final Period interval) { assert interval != null; switch (interval) { case LAST_MONTH: return new MetricsCollector(Duration.standardDays(30), 30); case LAST_WEEK: return new MetricsCollector(Duration.standardDays(7), 24 * 7); case LAST_DAY: return new MetricsCollector(Duration.standardDays(1), 48); case LAST_HOUR: return new MetricsCollector(Duration.standardHours(1), 60); case LAST_MINUTE: return new MetricsCollector(Duration.standardMinutes(1), 30); }/*from www .j a v a2 s. com*/ assert false; throw new IllegalStateException(); }
From source file:domains.donuts.config.DonutsRegistryConfig.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j a va 2s .c o m * * <p>Thirty days makes a sane default, because it's highly unlikely we'll ever need to generate a * deposit older than that. And if we do, we could always bring up a separate App Engine instance * and replay the commit logs off GCS. */ @Override public Duration getCommitLogDatastoreRetention() { return Duration.standardDays(30); }
From source file:domains.donuts.config.DonutsRegistryConfig.java
License:Open Source License
@Override public Duration getSingletonCachePersistDuration() { return Duration.standardDays(365); }
From source file:edu.indiana.soic.ts.streaming.dataflow.StockAnalysisPipeline1.java
License:Apache License
public static void main(String[] args) throws IOException { final SymbolEncoder symbolEncoder = new SymbolEncoder(); StockAnalysisPipelineOptions options = PipelineOptionsFactory.fromArgs(args) .as(StockAnalysisPipelineOptions.class); Pipeline pipeline = Pipeline.create(options); //Reading and time stamping the stock prices PCollection<KV<Integer, StockPricePoint>> stockPrices = pipeline .apply(TextIO.Read.named("Reading Input File").from(options.getInputFilePath())) .apply(ParDo.named("Timestamping").of(new DoFn<String, KV<Integer, StockPricePoint>>() { @Override//from w ww. ja v a2s. c o m public void processElement(ProcessContext c) throws Exception { try { String[] fields = c.element().split(","); StockPricePoint stockPoint = new StockPricePoint(); stockPoint.setId(fields[0]); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); stockPoint.setDate(sdf.parse(fields[1].trim())); stockPoint.setSymbol(fields[2]); stockPoint.setPrice(Double.parseDouble(fields[5].trim())); stockPoint.setCap(Double.parseDouble(fields[6].trim())); Instant instant = new Instant(stockPoint.getDate().getTime()); //debugging - we cannot handle large amounts of data when using local runner //int index = symbolEncoder.getSymbolIndex(stockPoint.getSymbol()); //if(index > 1000 && index < 1100) c.outputWithTimestamp( KV.of(symbolEncoder.getSymbolIndex(stockPoint.getSymbol()), stockPoint), instant); } catch (Exception ex) { //input format issue } } })); //creating the sliding windows PCollection<KV<Integer, StockPricePoint>> slidingWindowStockPrices = stockPrices .apply(Window.named("Windowing").<KV<Integer, StockPricePoint>>into(SlidingWindows .of(Duration.standardDays(WINDOW_LENGTH)).every(Duration.standardDays(SLIDING_INTERVAL)))); //combining stock prices per company per window PCollection<KV<Integer, List<StockPricePoint>>> stockPricesPerCompanyPerWindow = slidingWindowStockPrices .apply(GroupByKey.create()).apply(ParDo.named("Combining By Company") .of(new DoFn<KV<Integer, Iterable<StockPricePoint>>, KV<Integer, List<StockPricePoint>>>() { @Override public void processElement(ProcessContext c) throws Exception { Integer key = c.element().getKey(); Iterator<StockPricePoint> iterator = c.element().getValue().iterator(); List<StockPricePoint> stockPricePoints = new ArrayList<>(); while (iterator.hasNext()) { stockPricePoints.add(iterator.next()); } c.output(KV.of(key, stockPricePoints)); } })); //accumulating companies per window PCollectionView<Set<Integer>> companiesPerWindow = slidingWindowStockPrices.apply( Combine.globally(new Combine.CombineFn<KV<Integer, StockPricePoint>, Set<Integer>, Set<Integer>>() { @Override public Set<Integer> createAccumulator() { return new HashSet<>(); } @Override public Set<Integer> addInput(Set<Integer> indices, KV<Integer, StockPricePoint> integerStockPricePointKV) { indices.add(integerStockPricePointKV.getKey()); return indices; } @Override public Set<Integer> mergeAccumulators(Iterable<Set<Integer>> iterable) { HashSet<Integer> indices = new HashSet<>(); Iterator<Set<Integer>> iterator = iterable.iterator(); while (iterator.hasNext()) { indices.addAll(iterator.next()); } return indices; } @Override public Set<Integer> extractOutput(Set<Integer> indices) { return indices; } }).named("Combine By Window").asSingletonView()); //duplicate the company entries in each window to create distance matrix entries PCollection<KV<String, List<StockPricePoint>>> explodedEntries = stockPricesPerCompanyPerWindow .apply(ParDo.named("Duplicating Entries").withSideInputs(companiesPerWindow) .of(new DoFn<KV<Integer, List<StockPricePoint>>, KV<String, List<StockPricePoint>>>() { @Override public void processElement(ProcessContext c) throws Exception { Set<Integer> indices = c.sideInput(companiesPerWindow); Integer key = c.element().getKey(); List<StockPricePoint> stockPricePoints = c.element().getValue(); Iterator<Integer> iterator = indices.iterator(); while (iterator.hasNext()) { Integer temp = iterator.next(); // we generate only the lower half. The distance matrix is symmetric if (key > temp) { c.output(KV.of(key + "_" + temp, stockPricePoints)); } else if (temp > key) { c.output(KV.of(temp + "_" + key, stockPricePoints)); } } } })); //grouping two entries to create a distance entry in the matrix and calculating the distance PCollection<KV<String, Double>> distances = explodedEntries.apply(GroupByKey.create()) .apply(ParDo.named("Calculate Distances") .of(new DoFn<KV<String, Iterable<List<StockPricePoint>>>, KV<String, Double>>() { @Override public void processElement(ProcessContext processContext) throws Exception { Integer keyX = Integer.parseInt(processContext.element().getKey().split("_")[0]); Integer keyY = Integer.parseInt(processContext.element().getKey().split("_")[1]); Iterator<List<StockPricePoint>> iterator = processContext.element().getValue() .iterator(); List<StockPricePoint> stockPricesX = iterator.next(); List<StockPricePoint> stockPricesY = iterator.next(); //TODO calculate distance processContext.output(KV.of(keyX + "_" + keyY, 0.0)); } })); //formulate the distance matrix PCollection<DistanceMatrix> distanceMatrix = distances.apply( Combine.globally(new Combine.CombineFn<KV<String, Double>, DistanceMatrix, DistanceMatrix>() { @Override public DistanceMatrix createAccumulator() { return new DistanceMatrix(); } @Override public DistanceMatrix addInput(DistanceMatrix distanceMatrix, KV<String, Double> stringDoubleKV) { distanceMatrix.addPoint(Integer.parseInt(stringDoubleKV.getKey().split("_")[0]), Integer.parseInt(stringDoubleKV.getKey().split("_")[1]), stringDoubleKV.getValue()); return distanceMatrix; } @Override public DistanceMatrix mergeAccumulators(Iterable<DistanceMatrix> iterable) { DistanceMatrix distanceMatrix = new DistanceMatrix(); Iterator<DistanceMatrix> iterator = iterable.iterator(); while (iterator.hasNext()) { distanceMatrix.merge(iterator.next()); } return distanceMatrix; } @Override public DistanceMatrix extractOutput(DistanceMatrix distanceMatrix) { return distanceMatrix; } }).named("Combine Distance Matrix").withoutDefaults()); //write to file distanceMatrix.apply(ParDo.named("Matrix to String").of(new DoFn<DistanceMatrix, String>() { @Override public void processElement(ProcessContext processContext) throws Exception { String temp = "<distance-matrix-entry>\n" + processContext.timestamp() + "\n"; temp += processContext.element().getDistanceValues().toString() + "\n"; temp += processContext.element().getRow().toString() + "\n"; temp += processContext.element().getColumn().toString() + "\n"; temp += "</distance-matrix-entry>\n"; processContext.output(temp); } })).apply(TextIO.Write.named("Writing Output File").to(options.getOutputFilePath())); pipeline.run(); System.exit(0); }
From source file:edu.indiana.soic.ts.streaming.dataflow.StockAnalysisPipeline2.java
License:Apache License
public static void main(String[] args) throws IOException { final SymbolEncoder symbolEncoder = new SymbolEncoder(); StockAnalysisPipelineOptions options = PipelineOptionsFactory.fromArgs(args) .as(StockAnalysisPipelineOptions.class); Pipeline pipeline = Pipeline.create(options); //Reading and time stamping the stock prices PCollection<KV<Integer, StockPricePoint>> stockPrices = pipeline .apply(TextIO.Read.named("Reading Input File").from(options.getInputFilePath())) .apply(ParDo.named("Timestamping").of(new DoFn<String, KV<Integer, StockPricePoint>>() { @Override/*from w w w. jav a 2 s .co m*/ public void processElement(ProcessContext c) throws Exception { try { String[] fields = c.element().split(","); StockPricePoint stockPoint = new StockPricePoint(); stockPoint.setId(fields[0]); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); stockPoint.setDate(sdf.parse(fields[1].trim())); stockPoint.setSymbol(fields[2]); stockPoint.setPrice(Double.parseDouble(fields[5].trim())); stockPoint.setCap(Double.parseDouble(fields[6].trim())); Instant instant = new Instant(stockPoint.getDate().getTime()); //debugging - we cannot handle large amounts of data when using local runner //int index = symbolEncoder.getSymbolIndex(stockPoint.getSymbol()); //if(index > 1000 && index < 1100) c.outputWithTimestamp( KV.of(symbolEncoder.getSymbolIndex(stockPoint.getSymbol()), stockPoint), instant); } catch (Exception ex) { //input format issue } } })); //creating the sliding windows PCollection<KV<Integer, StockPricePoint>> slidingWindowStockPrices = stockPrices .apply(Window.named("Windowing").<KV<Integer, StockPricePoint>>into(SlidingWindows .of(Duration.standardDays(WINDOW_LENGTH)).every(Duration.standardDays(SLIDING_INTERVAL)))); //stock prices of each company within a single window PCollection<KV<Integer, List<StockPricePoint>>> stockPricesOfCompany = slidingWindowStockPrices .apply(GroupByKey.create()).apply(ParDo.named("Combine By Company") .of(new DoFn<KV<Integer, Iterable<StockPricePoint>>, KV<Integer, List<StockPricePoint>>>() { @Override public void processElement(ProcessContext processContext) throws Exception { Integer key = processContext.element().getKey(); Iterator<StockPricePoint> iterator = processContext.element().getValue().iterator(); ArrayList<StockPricePoint> stockPricePoints = new ArrayList<>(250); while (iterator.hasNext()) { stockPricePoints.add(iterator.next()); } processContext.output(KV.of(key, stockPricePoints)); } })); //complete stock prices vector as a view PCollectionView<Map<Integer, List<StockPricePoint>>> stockPriceVectorView = stockPricesOfCompany .apply(Combine.globally( new Combine.CombineFn<KV<Integer, List<StockPricePoint>>, Map<Integer, List<StockPricePoint>>, Map<Integer, List<StockPricePoint>>>() { @Override public Map<Integer, List<StockPricePoint>> createAccumulator() { return new HashMap<>(); } @Override public Map<Integer, List<StockPricePoint>> addInput( Map<Integer, List<StockPricePoint>> stockPricesMap, KV<Integer, List<StockPricePoint>> stockPricePointKV) { if (stockPricesMap.get(stockPricePointKV.getKey()) != null) { stockPricesMap.get(stockPricePointKV.getKey()) .addAll(stockPricePointKV.getValue()); } else { ArrayList<StockPricePoint> stockPricePoints = new ArrayList<>(); stockPricePoints.addAll(stockPricePointKV.getValue()); stockPricesMap.put(stockPricePointKV.getKey(), stockPricePoints); } return stockPricesMap; } @Override public Map<Integer, List<StockPricePoint>> mergeAccumulators( Iterable<Map<Integer, List<StockPricePoint>>> iterable) { Map<Integer, List<StockPricePoint>> stockPricesMap = new HashMap<>(); Iterator<Map<Integer, List<StockPricePoint>>> iterator = iterable.iterator(); while (iterator.hasNext()) { for (Map.Entry<Integer, List<StockPricePoint>> entry : iterator.next() .entrySet()) { if (stockPricesMap.get(entry.getKey()) != null) { stockPricesMap.get(entry.getKey()).addAll(entry.getValue()); } else { ArrayList<StockPricePoint> stockPricePoints = new ArrayList<>(); stockPricePoints.addAll(entry.getValue()); stockPricesMap.put(entry.getKey(), stockPricePoints); } } } return stockPricesMap; } @Override public Map<Integer, List<StockPricePoint>> extractOutput( Map<Integer, List<StockPricePoint>> stockPricesMap) { return stockPricesMap; } }).named("Combine By Window").asSingletonView()); //calculating distance between companies within window PCollection<KV<String, Double>> distances = stockPricesOfCompany .apply(ParDo.withSideInputs(stockPriceVectorView).named("Calculate Distances") .of(new DoFn<KV<Integer, List<StockPricePoint>>, KV<String, Double>>() { @Override public void processElement(ProcessContext processContext) throws Exception { Map<Integer, List<StockPricePoint>> stockPricesVector = processContext .sideInput(stockPriceVectorView); Integer keyX = processContext.element().getKey(); List<StockPricePoint> stockPricesX = processContext.element().getValue(); for (Map.Entry<Integer, List<StockPricePoint>> entry : stockPricesVector .entrySet()) { //calculate only the bottom triangle (matrix is symmetric) Integer keyY = entry.getKey(); if (keyY < keyX) { List<StockPricePoint> stockPricesY = entry.getValue(); //TODO calculate distance processContext.output(KV.of(keyX + "_" + keyY, 0.0)); } } } })); //formulate the distance matrix PCollection<DistanceMatrix> distanceMatrix = distances.apply( Combine.globally(new Combine.CombineFn<KV<String, Double>, DistanceMatrix, DistanceMatrix>() { @Override public DistanceMatrix createAccumulator() { return new DistanceMatrix(); } @Override public DistanceMatrix addInput(DistanceMatrix distanceMatrix, KV<String, Double> stringDoubleKV) { distanceMatrix.addPoint(Integer.parseInt(stringDoubleKV.getKey().split("_")[0]), Integer.parseInt(stringDoubleKV.getKey().split("_")[1]), stringDoubleKV.getValue()); return distanceMatrix; } @Override public DistanceMatrix mergeAccumulators(Iterable<DistanceMatrix> iterable) { DistanceMatrix distanceMatrix = new DistanceMatrix(); Iterator<DistanceMatrix> iterator = iterable.iterator(); while (iterator.hasNext()) { distanceMatrix.merge(iterator.next()); } return distanceMatrix; } @Override public DistanceMatrix extractOutput(DistanceMatrix distanceMatrix) { return distanceMatrix; } }).named("Combine Distance Matrix").withoutDefaults()); //write to file distanceMatrix.apply(ParDo.named("Matrix to String").of(new DoFn<DistanceMatrix, String>() { @Override public void processElement(ProcessContext processContext) throws Exception { String temp = "<distance-matrix-entry>\n" + processContext.timestamp() + "\n"; temp += processContext.element().getDistanceValues().toString() + "\n"; temp += processContext.element().getRow().toString() + "\n"; temp += processContext.element().getColumn().toString() + "\n"; temp += "</distance-matrix-entry>\n"; processContext.output(temp); } })).apply(TextIO.Write.to(options.getOutputFilePath()).named("Writing Output File")); pipeline.run(); System.exit(0); }
From source file:es.usc.citius.servando.calendula.jobs.CheckDatabaseUpdatesJob.java
License:Open Source License
@Override public JobRequest getRequest() { return new JobRequest.Builder(getTag()).setPeriodic(Duration.standardDays(PERIOD_DAYS).getMillis()) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED).setRequirementsEnforced(true) .setPersisted(true).build(); }
From source file:eu.esdihumboldt.hale.common.headless.transform.TransformationWorkspace.java
License:Open Source License
/** * Create a new transformation workspace with a lease duration of one day. * /*from w w w .jav a 2 s .c o m*/ * @throws IllegalStateException if the {@link WorkspaceService} is not * available */ public TransformationWorkspace() { this(Duration.standardDays(1)); }
From source file:google.registry.config.ConfigModule.java
License:Open Source License
/** * Amount of time between BRDA deposits. * * @see google.registry.rde.PendingDepositChecker *///from w w w . j av a 2 s .c o m @Provides @Config("brdaInterval") public static Duration provideBrdaInterval() { return Duration.standardDays(7); }