forked from Archives/Athou_commafeed
utility method to calculate average time between entries
This commit is contained in:
11
pom.xml
11
pom.xml
@@ -214,6 +214,11 @@
|
|||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
<version>2.6</version>
|
<version>2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-math</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-fileupload</groupId>
|
<groupId>commons-fileupload</groupId>
|
||||||
<artifactId>commons-fileupload</artifactId>
|
<artifactId>commons-fileupload</artifactId>
|
||||||
@@ -489,9 +494,9 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetGroups>all</targetGroups>
|
<targetGroups>all</targetGroups>
|
||||||
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
|
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
|
||||||
<destinationFolder>${basedir}/target/generated-sources/wro4j/</destinationFolder>
|
<destinationFolder>${basedir}/target/generated-sources/wro4j/</destinationFolder>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package com.commafeed.backend.feeds;
|
package com.commafeed.backend.feeds;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document.OutputSettings;
|
import org.jsoup.nodes.Document.OutputSettings;
|
||||||
import org.jsoup.nodes.Entities.EscapeMode;
|
import org.jsoup.nodes.Entities.EscapeMode;
|
||||||
import org.jsoup.safety.Whitelist;
|
import org.jsoup.safety.Whitelist;
|
||||||
import org.mozilla.universalchardet.UniversalDetector;
|
import org.mozilla.universalchardet.UniversalDetector;
|
||||||
|
|
||||||
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
|
|
||||||
public class FeedUtils {
|
public class FeedUtils {
|
||||||
|
|
||||||
public static String guessEncoding(byte[] bytes) {
|
public static String guessEncoding(byte[] bytes) {
|
||||||
@@ -95,4 +100,14 @@ public class FeedUtils {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.commafeed.backend.feeds;
|
package com.commafeed.backend.feeds;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
@@ -10,7 +10,7 @@ import com.google.api.client.util.Lists;
|
|||||||
public class FetchedFeed {
|
public class FetchedFeed {
|
||||||
|
|
||||||
private Feed feed = new Feed();
|
private Feed feed = new Feed();
|
||||||
private Collection<FeedEntry> entries = Lists.newArrayList();
|
private List<FeedEntry> entries = Lists.newArrayList();
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private long fetchDuration;
|
private long fetchDuration;
|
||||||
@@ -24,11 +24,11 @@ public class FetchedFeed {
|
|||||||
this.feed = feed;
|
this.feed = feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<FeedEntry> getEntries() {
|
public List<FeedEntry> getEntries() {
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEntries(Collection<FeedEntry> entries) {
|
public void setEntries(List<FeedEntry> entries) {
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user