Ammonite/Статистика відвідувань вікісторінок: відмінності між версіями
Вилучено вміст Додано вміст
Ilya (обговорення | внесок) |
Ilya (обговорення | внесок) |
||
Рядок 312:
import scala.io.Source
val monthStr = (if (month < 10) "0" else "") + month▼
def getMonthlyViews(project: String, year: Int, month: Int): List[PageViews] = {
val url = s"https://wikimedia.org/api/rest_v1/metrics/pageviews/top/$project/all-access/$year/$monthStr/all-days" ▼
def url: String = {
▲ val monthStr = (if (month < 10) "0" else "") + month
▲
}
val text = Source.fromURL(url).mkString
val doc = parse(text).getOrElse(Json.Null)
val articles = root.items.each.articles.each.article.string.getAll(doc)
val views = root.items.each.articles.each.views.int.getAll(doc)
articles.zip(views).map{ case (name, views) => new PageViews(name, views) }
}
val monthly = (1 to 12).map(month => getMonthlyViews("uk.wikibooks.org", 2016, month))
val groupedByArticle = monthly.flatten.groupBy
val articleToViews = groupedByArticle.mapValues
val yearlyByBookSeq = articleToViews.toSeq.map
val groupedByBook = yearlyByBookSeq.groupBy
val bookToViews = groupedByBook.mapValues
val orderedBookViews = bookToViews.toSeq.sortBy
</source>
|