utility method to calculate average time between entries

This commit is contained in:
Athou
2013-05-19 12:54:15 +02:00
parent 65a32c8cdd
commit df52dcd748
3 changed files with 27 additions and 7 deletions

11
pom.xml
View File

@@ -214,6 +214,11 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
@@ -489,9 +494,9 @@
</execution>
</executions>
<configuration>
<targetGroups>all</targetGroups>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
<destinationFolder>${basedir}/target/generated-sources/wro4j/</destinationFolder>
<targetGroups>all</targetGroups>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
<destinationFolder>${basedir}/target/generated-sources/wro4j/</destinationFolder>
</configuration>
</plugin>
<plugin>

View File

@@ -1,12 +1,17 @@
package com.commafeed.backend.feeds;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document.OutputSettings;
import org.jsoup.nodes.Entities.EscapeMode;
import org.jsoup.safety.Whitelist;
import org.mozilla.universalchardet.UniversalDetector;
import com.commafeed.backend.model.FeedEntry;
public class FeedUtils {
public static String guessEncoding(byte[] bytes) {
@@ -95,4 +100,14 @@ public class FeedUtils {
}
return sb.toString();
}
public static long average(List<FeedEntry> entries) {
SummaryStatistics stats = new SummaryStatistics();
for (int i = 0; i < entries.size() - 1; i++) {
long diff = Math.abs(entries.get(i).getUpdated().getTime()
- entries.get(i + 1).getUpdated().getTime());
stats.addValue(diff);
}
return (long) stats.getMean();
}
}

View File

@@ -1,7 +1,7 @@
package com.commafeed.backend.feeds;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedEntry;
@@ -10,7 +10,7 @@ import com.google.api.client.util.Lists;
public class FetchedFeed {
private Feed feed = new Feed();
private Collection<FeedEntry> entries = Lists.newArrayList();
private List<FeedEntry> entries = Lists.newArrayList();
private String title;
private long fetchDuration;
@@ -24,11 +24,11 @@ public class FetchedFeed {
this.feed = feed;
}
public Collection<FeedEntry> getEntries() {
public List<FeedEntry> getEntries() {
return entries;
}
public void setEntries(Collection<FeedEntry> entries) {
public void setEntries(List<FeedEntry> entries) {
this.entries = entries;
}