mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
utility method to calculate average time between entries
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user