Example usage for org.joda.time Period toStandardSeconds

List of usage examples for org.joda.time Period toStandardSeconds

Introduction

In this page you can find the example usage for org.joda.time Period toStandardSeconds.

Prototype

public Seconds toStandardSeconds() 

Source Link

Document

Converts this period to a period in seconds assuming a 7 day week, 24 hour day, 60 minute hour and 60 second minute.

Usage

From source file:fr.inria.wimmics.prissma.selection.entities.ContextUnit.java

License:Open Source License

/**
 * Retrieves the specified property value from the context unit.
 * Used by GEO and TIME context units./*from  www  .  j  a  va2 s  .co  m*/
 * @param prop
 * @return
 * @throws ContextUnitException
 */
public double getComplexCtxUnitProp(Property prop) throws ContextUnitException {

    if (!instance.isResource())
        throw new ContextUnitException();

    if (this.type != CtxUnitType.GEO && this.type != CtxUnitType.TIME && instance.isResource())
        throw new ContextUnitException();
    else {
        Statement stat = ((Resource) instance).getProperty(prop);
        if (stat == null)
            throw new ContextUnitException();

        // TIME conversions
        if (prop.equals(PrissmaProperties.pStart)) {
            String timeStr = stat.getLiteral().getString();
            DateTimeFormatter dtf = ISODateTimeFormat.timeParser();
            DateTime startTime = dtf.withZone(DateTimeZone.UTC).parseDateTime(timeStr); // UTC by default
            long millis = startTime.getMillis();
            long seconds = millis / 1000;
            return seconds;
        } else if (prop.equals(PrissmaProperties.pDuration)) {
            String durationStr = stat.getLiteral().getString();
            PeriodFormatter pf = ISOPeriodFormat.standard();
            Period period = pf.parsePeriod(durationStr);
            int seconds = period.toStandardSeconds().getSeconds();
            return seconds;
        }
        return stat.getLiteral().getDouble();
    }
}

From source file:free.rm.skytube.businessobjects.YouTube.POJOs.YouTubeVideo.java

License:Open Source License

public void setDurationInSeconds(String durationInSeconds) {
    PeriodFormatter formatter = ISOPeriodFormat.standard();
    Period p = formatter.parsePeriod(durationInSeconds);
    this.durationInSeconds = p.toStandardSeconds().getSeconds();
}

From source file:org.apache.eagle.alert.engine.publisher.dedup.DefaultDeduplicator.java

License:Apache License

@Override
public void setDedupIntervalMin(String newDedupIntervalMin) {
    if (newDedupIntervalMin == null || newDedupIntervalMin.isEmpty()) {
        dedupIntervalSec = 0;/*  ww w. ja  v  a  2s  .  c  o m*/
        return;
    }
    try {
        Period period = Period.parse(newDedupIntervalMin);
        this.dedupIntervalSec = period.toStandardSeconds().getSeconds();
    } catch (Exception e) {
        LOG.warn("Fail to pares deDupIntervalMin, will disable deduplication instead", e);
        this.dedupIntervalSec = 0;
    }
}

From source file:org.apache.eagle.alert.utils.TimePeriodUtils.java

License:Apache License

public static long formatSecondsByPeriod(long seconds, Period period) {
    return seconds - (seconds % Int.int2long(period.toStandardSeconds().getSeconds()));
}

From source file:org.apache.eagle.alert.utils.TimePeriodUtils.java

License:Apache License

public static int getSecondsOfPeriod(Period period) {
    return period.toStandardSeconds().getSeconds();
}

From source file:org.ednovo.gooru.application.util.ResourceImageUtil.java

License:Open Source License

public static ResourceMetadataCo getYoutubeResourceFeeds(String url, ResourceMetadataCo resourceFeeds) {
    if (resourceFeeds == null) {
        resourceFeeds = new ResourceMetadataCo();
    }/* w  ww.ja v  a  2s  .  c  o m*/
    int status = 404;
    resourceFeeds.setUrlStatus(status);
    long start = System.currentTimeMillis();
    String videoId = getYoutubeVideoId(url);
    if (videoId != null) {
        String requestURL = "https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&key="
                + ConfigProperties.getGoogleApiKey() + "&part=snippet,contentDetails,statistics,status";
        try {
            ClientResource clientResource = new ClientResource(requestURL);
            Representation representation = new ClientResource(requestURL).get();
            Map<String, Object> data = JsonDeserializer.deserialize(representation.getText(),
                    new TypeReference<Map<String, Object>>() {
                    });
            Map<String, Object> pageInfo = (Map<String, Object>) data.get(PAGE_INFO);
            Integer totalResults = (Integer) pageInfo.get(TOTAL_RESULTS);
            if (totalResults > 0) {
                status = 200;
            }
            if (status == 200) {
                LOGGER.info("youtube api response code: " + status);
                List<Map<String, Object>> items = (List<Map<String, Object>>) data.get(ITEMS);
                Map<String, Object> item = items.get(0);
                Map<String, Object> snippet = (Map<String, Object>) item.get(SNIPPET);
                resourceFeeds.setTitle((String) snippet.get(TITLE));
                resourceFeeds.setDescription((String) snippet.get(DESCRIPTION));
                if (item.get(STATISTICS) != null) {
                    Map<String, Object> statistics = (Map<String, Object>) item.get(STATISTICS);
                    resourceFeeds.setFavoriteCount(Long.parseLong((String) statistics.get(FAVORITE_COUNT)));
                    resourceFeeds.setViewCount(Long.parseLong((String) statistics.get(VIEW_COUNT)));
                }

                if (item.get(CONTENT_DETAILS) != null) {
                    Map<String, Object> contentDetails = (Map<String, Object>) item.get(CONTENT_DETAILS);
                    PeriodFormatter formatter = ISOPeriodFormat.standard();
                    Period period = formatter.parsePeriod((String) contentDetails.get(DURATION));
                    Seconds seconds = period.toStandardSeconds();
                    resourceFeeds.setDuration((long) seconds.getSeconds());
                }
                resourceFeeds.setUrlStatus(status);
                return resourceFeeds;
            }
        } catch (Exception ex) {
            LOGGER.error("getYoutubeResourceFeeds: " + ex);
            LOGGER.error("Total time for get youtube api data :" + (System.currentTimeMillis() - start));
        }
    }
    return resourceFeeds;
}

From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.GeneratorStatistics.java

License:Open Source License

public void addTimeseriesData(final Period timestep, final LocalTime timestamp, final Interval dateRange) {
    if (timestep != null) {
        if (timestep.toStandardSeconds().getSeconds() < m_smallestTimestep.toPeriod().toStandardSeconds()
                .getSeconds())/*  w  ww  .ja  v  a 2s  .c o  m*/
            m_smallestTimestep = timestep;
    }

    if (timestamp != null) {
        final Integer number = m_timestamps.get(timestamp);
        if (number != null)
            m_timestamps.put(timestamp, new Integer(number.intValue() + 1));
        else
            m_timestamps.put(timestamp, new Integer(1));
    }

    if (dateRange != null) {
        if (m_validityRange == null)
            m_validityRange = dateRange;
        else
            m_validityRange = m_validityRange.overlap(dateRange);
    }
}

From source file:org.kalypso.ui.rrm.internal.timeseries.view.imports.ValidateTimestepsVisitor.java

License:Open Source License

public ValidateTimestepsVisitor(final Period timestep) {
    m_duration = new Duration(timestep.toStandardSeconds().getSeconds() * 1000);
}

From source file:org.kalypso.ui.rrm.internal.utils.featureTree.TreeNodeLabelComparator.java

License:Open Source License

private int comparteTimeseries(final ITimeseries t1, final ITimeseries t2) {
    final Period s1 = t1.getTimestep();
    final Period s2 = t2.getTimestep();
    if (Objects.allNotNull(s1, s2)) {
        final Seconds sec1 = s1.toStandardSeconds();
        final Seconds sec2 = s2.toStandardSeconds();

        final int compared = sec1.compareTo(sec2);
        if (compared != 0)
            return compared;
    }//from  w ww  .j a  v  a2 s .co  m

    final String q1 = Objects.firstNonNull(t1.getQuality(), StringUtils.EMPTY);
    final String q2 = Objects.firstNonNull(t2.getQuality(), StringUtils.EMPTY);

    return q1.compareTo(q2);
}

From source file:org.kalypso.zml.ui.chart.layer.themes.ZmlBarLayerRangeHandler.java

License:Open Source License

private Date doAdjustMax(final IObservation observation, final Date max) {
    final Period timestep = MetadataHelper.getTimestep(observation.getMetadataList());
    if (Objects.isNull(timestep))
        return max;

    final long ms = Double.valueOf(timestep.toStandardSeconds().getSeconds() * 1000.0).longValue();

    return new Date(max.getTime() + ms);
}