List of usage examples for org.joda.time Period toStandardSeconds
public Seconds toStandardSeconds()
From source file:org.kalypso.zml.ui.chart.layer.themes.ZmlBarLayerRangeHandler.java
License:Open Source License
private Date doAdjustMin(final IObservation observation, final Date min) { final Period timestep = MetadataHelper.getTimestep(observation.getMetadataList()); if (Objects.isNull(timestep)) return min; final long ms = Double.valueOf(timestep.toStandardSeconds().getSeconds() * 1000.0).longValue(); return new Date(min.getTime() - ms); }
From source file:org.n52.sos.ds.hibernate.SosCacheFeederDAO.java
License:Open Source License
private void logCacheLoadTime(long startTime) { Period cacheLoadPeriod = new Period(startTime, System.currentTimeMillis()); LOGGER.info("Cache load finished in {} ({} seconds)", PeriodFormat.getDefault().print(cacheLoadPeriod.normalizedStandard()), cacheLoadPeriod.toStandardSeconds()); }
From source file:org.wisdom.executors.scheduler.Job.java
License:Apache License
/** * Translates the given (Joda) Period to duration in seconds. * * @param period the period/* w ww. ja va2 s. c o m*/ * @return the duration representing the same amount of time in seconds */ public static long toDuration(Period period) { return period.toStandardSeconds().getSeconds(); }
From source file:propel.core.validation.propertyMetadata.PeriodPropertyMetadata.java
License:Open Source License
protected void checkBounds(Period value) throws ValidationException { // check conditions if (value.toStandardSeconds().getSeconds() > getMaxValue().toStandardSeconds().getSeconds()) throw new ValidationException( String.format(BoundedValueTypePropertyMetadata.SHOULD_NOT_BE_GREATER_THAN, getName()) + getMaxValue()); if (value.toStandardSeconds().getSeconds() < getMinValue().toStandardSeconds().getSeconds()) throw new ValidationException( String.format(BoundedValueTypePropertyMetadata.SHOULD_NOT_BE_LESS_THAN, getName()) + getMinValue()); }
From source file:uk.ac.imperial.lsds.seep.infrastructure.monitor.policy.evaluate.PolicyRuleEvaluator.java
License:Open Source License
/** * Prune old readings from the queue of readings required to evaluate all the * triggers associated to the scaling rule bound to this evaluator. * //from w w w . j a v a2 s.c o m * @param maximumAge Maximum age for metric readings in the queue. Any readings * which have a timestamp older than this age can be safely discarded as they * are no longer needed to evaluate the state of the rule triggers. */ private void pruneOldReadings(Period maximumAge) { boolean done = false; MetricReading reading = pastReadings.peek(); while ((reading != null) && !done) { Period readingAge = new Period(reading.getTimestamp(), Instant.now()); // Once we find a reading with an age less than the maximum age, we // stop prunning as readings in the queue are sorted. An evaluator // works based on the assumption that metrics readings are offered // with always increasing timestamps. if (readingAge.toStandardSeconds().isLessThan(maximumAge.toStandardSeconds()) || readingAge.toStandardSeconds().equals(maximumAge.toStandardSeconds())) { done = true; } else { pastReadings.poll(); // Get the next element in the queue and continue pruning reading = pastReadings.peek(); } } }
From source file:uk.ac.imperial.lsds.seep.infrastructure.monitor.policy.evaluate.PolicyRuleEvaluator.java
License:Open Source License
/** * Given all the triggers associated to the scaling rule, it finds the one * with the longest time threshold (longest horizon). The evaluator needs to * be aware of this as this is the cut-off for metric readings, any readings * older than the maximum time threshold can safely be discarded. *//* w ww . j a v a 2 s. c o m*/ private void calcMaxAgeForReadings() { PolicyRule rule = getEvalSubject(); maximumAge = null; for (ActionTrigger trigger : rule.getTriggers()) { Period triggerAge = trigger.getTimeThreshold().toPeriod(); if (maximumAge == null) { maximumAge = triggerAge; } else { if (triggerAge.toStandardSeconds().isGreaterThan(maximumAge.toStandardSeconds())) { maximumAge = triggerAge; } } } }
From source file:uk.ac.imperial.lsds.seep.infrastructure.monitor.policy.threshold.TimeThreshold.java
License:Open Source License
/** * Evaluates the threshold with respect to a certain period of time. * @param period period of time to evaluate (usually a period ending at the * current time and spanning for X seconds/minutes into the past). * @return True if the time length of period is below the threshold. *///from ww w . j av a2 s . c o m @Override public boolean evaluate(Period period) { boolean result = false; if ((period != null) && (period.toStandardSeconds() != null)) { result = period.toStandardSeconds().isLessThan(threshold.toStandardSeconds()); } logger.debug("Evaluating threshold[" + threshold.toString() + "] period[" + period.toString() + "] result[" + result + "]"); return result; }
From source file:uk.ac.imperial.lsds.seep.infrastructure.monitor.policy.trigger.ActionTrigger.java
License:Open Source License
/** * Evaluates the state of the trigger. Both the value and the time threshold * need to evaluate to true in order for the trigger state to change from * non-fired to fired./*from w w w .jav a2 s.c o m*/ * @param readings metric readings to evaluate (all those that are within the * time threshold need to evaluate to true in terms of their value). */ public void evaluate(List<MetricReading> readings, TimeReference time) { logger.info( "Evaluating trigger for " + metricName.toString() + " - " + readings.size() + " readings provided"); logger.debug("value threshold: " + valueThreshold.toString()); logger.debug("time threshold: " + timeThreshold.toString()); // Determine the new state of the trigger depending on the result of // evaluating boh thresholds. Need to mark flag if state changes. ActionTriggerState pastTriggerState = triggerState; boolean enoughReadings = true; // Check that we have enough readings to cover the entire time threshold if ((readings != null) && (readings.size() > 0)) { MetricReading mostRecentReading = readings.get(readings.size() - 1); MetricReading leastRecentReading = readings.get(0); logger.info("Most recent reading [" + mostRecentReading.getTimestamp() + "]"); logger.info("Least recent reading [" + leastRecentReading.getTimestamp() + "]"); Period readingsPeriod = new Period(leastRecentReading.getTimestamp(), mostRecentReading.getTimestamp()); int toleranceSeconds = new Double(0.1 * timeThreshold.toPeriod().toStandardSeconds().getSeconds()) .intValue(); if (readingsPeriod.toStandardSeconds() .isLessThan(timeThreshold.toPeriod().toStandardSeconds().minus(toleranceSeconds))) { logger.info("Not enough readings, only for last period[" + readingsPeriod + "]"); enoughReadings = false; } } // If we have enough readings, then we evaluate in detail if (enoughReadings) { int i = 0; for (MetricReading r : readings) { Period metricPeriod = new Period(r.getTimestamp(), time.now()); MetricValue metricValue = r.getValues().get(metricName); logger.info("Evaluating reading[" + i + "] value[" + metricValue.toString() + "] period[" + metricPeriod.toString() + "]"); // We evaluate the time threshold first, simple optimisation to be // able to abort the iteration sooner (readings are guaranteed to be // sorted by time of reception, from most recent to least recent). if (timeThreshold.evaluate(metricPeriod)) { triggerState = valueThreshold.evaluate(metricValue) ? ActionTriggerState.FIRED : ActionTriggerState.NON_FIRED; // If there is a reading within the time threshold for which // the value evaluates to false (trigger is non-fired), then // we can break from the evaluation loop. if (triggerState.equals(ActionTriggerState.NON_FIRED)) { break; } } i++; } } stateChanged = (triggerState != pastTriggerState); logger.info("New trigger state is [" + triggerState.toString() + "] changed[" + stateChanged + "]"); }
From source file:youtube.YoutubeApiClient.java
/** * //from w w w . ja va 2s . c o m * @param response * gets the detailed informations JSON produced eariler, * containing all informations about a sinlge video * @param youtubeTemp * is a reference to the youtube object we try to fill in the for * loop * * the method iterates over the details JSON and fills all fields * @throws java.text.ParseException */ private YoutubeMetaData processingDetailedResults(JSONObject response, YoutubeMetaData youtubeTemp) { JSONArray responseItems = (JSONArray) response.get("items"); JSONObject responseItemsEntry = (JSONObject) responseItems.get(0); JSONObject responseSnippet = (JSONObject) responseItemsEntry.get("snippet"); JSONObject responseStatus = (JSONObject) responseItemsEntry.get("status"); System.out.println("channelId " + responseSnippet.get("channelId").toString()); youtubeTemp.setChannelID(responseSnippet.get("channelId").toString()); youtubeTemp.setTitle(responseSnippet.get("title").toString()); System.out.println("title: " + responseSnippet.get("title").toString()); String tempDate = responseSnippet.get("publishedAt").toString(); DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss"); Date date = null; try { date = formatter.parse(tempDate); } catch (java.text.ParseException e) { e.printStackTrace(); return null; } youtubeTemp.setPublishedAt(date); System.out.println("publishedAt: " + youtubeTemp.getPublishedAt()); JSONObject responseContentDetails = (JSONObject) responseItemsEntry.get("contentDetails"); youtubeTemp.setDuration(responseContentDetails.get("duration").toString()); PeriodFormatter pf = ISOPeriodFormat.standard(); Period p = pf.parsePeriod(responseContentDetails.get("duration").toString()); Seconds s = p.toStandardSeconds(); System.out.println("durationInSecond: " + s.getSeconds()); youtubeTemp.setDurationInSeconds(s.getSeconds()); System.out.println("duration " + responseContentDetails.get("duration").toString()); JSONObject responseStatistics = (JSONObject) responseItemsEntry.get("statistics"); youtubeTemp.setViewCount(responseStatistics.get("viewCount").toString()); System.out.println("viewCount" + responseStatistics.get("viewCount").toString()); youtubeTemp.setLikeCount(responseStatistics.get("likeCount").toString()); System.out.println("likeCount" + responseStatistics.get("likeCount").toString()); youtubeTemp.setDislikeCount(responseStatistics.get("dislikeCount").toString()); System.out.println("dislikeCount" + responseStatistics.get("dislikeCount").toString()); youtubeTemp.setCommentCount(responseStatistics.get("commentCount").toString()); System.out.println("commentCount" + responseStatistics.get("commentCount").toString()); boolean isCreativeCommon = false; if (responseStatus.get("license").toString() == "creativeCommon") isCreativeCommon = true; youtubeTemp.setCreativeCommon(isCreativeCommon); System.out.println("creativeCommon: " + youtubeTemp.isCreativeCommon()); System.out.println("------------------------------"); return youtubeTemp; }