Skip to content

Commit

Permalink
recently taken reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
intracer committed Mar 17, 2024
1 parent 0b33d14 commit e7874f6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MonumentDbStat {
"article"
)

def getStat(monumentDbs: Seq[MonumentDB]) = {
def getStat(monumentDbs: Seq[MonumentDB]): String = {
val title =
monumentDbs.head.contest.contestType.name + " database statistics"

Expand Down Expand Up @@ -54,7 +54,7 @@ class MonumentDbStat {
)
}

val table = new Table(columns, data, title)
val table = Table(columns, data, title)

table.asWiki
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.scalawiki.wlx.stat.reports
import org.scalawiki.dto.markup.Table
import org.scalawiki.wlx.stat.ContestStat

import java.time.ZonedDateTime

class RecentlyTaken(val stat: ContestStat) extends Reporter {

private val jun30 = ZonedDateTime.parse("2023-06-30T23:59:59Z")

override def name: String = "RecentlyTaken"

override def table: Table = {
val data = stat.currentYearImageDb.map{ db =>
val images = db.images.filter(_.metadata.exists(_.date.exists(_.isAfter(jun30))))
images.map{ i =>
List(
s"[[File:${i.title}]]",
s"[[User:${i.author}|${i.author}]]",
i.metadata.flatMap(_.date.map(_.toString)).getOrElse("")
)

}
}.getOrElse(Nil)
Table(Seq("photo", "author", "date"), data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package org.scalawiki.wlx.stat.reports

import org.scalawiki.MwBot
import org.scalawiki.dto.markup.Table
import org.scalawiki.wlx.dto.Contest
import org.scalawiki.wlx.stat.ContestStat

import scala.concurrent.Future

trait Reporter {

def stat: ContestStat

def contest = stat.contest
def contest: Contest = stat.contest

def name: String

def category = contest.name
def category: String = contest.name

def page = s"Commons:$category/$name"

Expand All @@ -26,7 +29,7 @@ trait Reporter {
header + table.asWiki + categoryText
}

def updateWiki(bot: MwBot) = {
def updateWiki(bot: MwBot): Future[Any] = {
bot.page(page).edit(asText, Some("updating"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class ReporterRegistry(stat: ContestStat, cfg: StatConfig)(implicit

import org.scalawiki.wlx.stat.reports.{ReporterRegistry => RR}

val contest = stat.contest
val monumentDb = stat.monumentDb
val currentYearImageDb = stat.currentYearImageDb
val totalImageDb = stat.totalImageDb
val commons = MwBot.fromHost(MwBot.commons)
private val contest = stat.contest
private val monumentDb = stat.monumentDb
private val currentYearImageDb = stat.currentYearImageDb
private val totalImageDb = stat.totalImageDb
private val commons = MwBot.fromHost(MwBot.commons)

def monumentDbStat: Option[String] = stat.monumentDb.map(RR.monumentDbStat)

Expand All @@ -45,6 +45,7 @@ class ReporterRegistry(stat: ContestStat, cfg: StatConfig)(implicit
*/
def currentYear(): Unit = {
for (imageDb <- currentYearImageDb) {
new RecentlyTaken(stat).updateWiki(commons)

if (cfg.regionalGallery && stat.totalImageDb.isEmpty) {
Output.byRegion(monumentDb.get, imageDb)
Expand Down

0 comments on commit e7874f6

Please sign in to comment.