Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/disqualify-by-taken-date' into d…
Browse files Browse the repository at this point in the history
…isqualify-by-taken-date

# Conflicts:
#	scalawiki-core/src/main/scala/org/scalawiki/dto/Image.scala
  • Loading branch information
intracer committed Apr 3, 2024
2 parents 8c26d75 + 9d0e130 commit 69b94b2
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 18 deletions.
8 changes: 6 additions & 2 deletions scalawiki-core/src/main/scala/org/scalawiki/dto/Image.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ case class ImageMetadata(data: Map[String, String]) {

def date: Option[ZonedDateTime] =
data
.get("DateTime")
.flatMap(s => Try(LocalDateTime.parse(s, ImageMetadata.df).atZone(ZoneOffset.UTC)).toOption)
.get("DateTimeOriginal")
.flatMap { s =>
val parsed = Try(LocalDateTime.parse(s, ImageMetadata.df).atZone(ZoneOffset.UTC))
parsed.failed.foreach(println)
parsed.toOption
}
}

object ImageMetadata {
Expand Down
29 changes: 28 additions & 1 deletion scalawiki-core/src/test/scala/org/scalawiki/dto/ImageSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.scalawiki.dto

import org.scalawiki.dto.ImageSpec.{makeTemplate, withCategories, withSpecialNominations}
import org.scalawiki.dto.ImageSpec._
import org.scalawiki.dto.markup.Template
import org.specs2.mutable.Specification

Expand Down Expand Up @@ -86,6 +86,13 @@ class ImageSpec extends Specification {
.get

image2.specialNominations === Set.empty

val page3 = Page("File:Image.jpg").copy(revisions = Seq(Revision.one(withSpecialNomination2)))
val image3 = Image
.fromPageRevision(page3, Some("Monument"), Set("WLM2023-UA-interior"))
.get

image3.specialNominations === Set("WLM2023-UA-interior")
}

"resize" should {
Expand Down Expand Up @@ -172,4 +179,24 @@ object ImageSpec {
|[[Category:Bishop's house in Lutsk castle]]
|[[Category:Uploaded via Campaign:wlm-ua]]
|""".stripMargin

private val withSpecialNomination2 = """=={{int:filedesc}}==
|{{Information
||description={{uk|1=Прибутковий будинок, [[:uk:Дніпро (місто)|Дніпро]], вул. Троїцька (Червона), 8}}{{Monument Ukraine|12-101-0443}}[[Category:Wiki Loves Monuments in Ukraine 2023 - Quantity]]{{WLM2023-UA-interior}}
||date=2023-07-18 08:59:48
||source={{own}}
||author=[[User:Olebesedin|Olebesedin]]
||permission=
||other versions=
|}}
|{{Location|48.462144|35.042819}}
|
|=={{int:license-header}}==
|{{self|cc-by-sa-4.0}}
|
|{{Wiki Loves Monuments 2023|ua}}
|
|[[Category:8 Troitska Street, Dnipro]]
|[[Category:Uploaded via Campaign:wlm-ua]]
|""".stripMargin
}
2 changes: 1 addition & 1 deletion scalawiki-wlx/src/main/resources/wlm_ua.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"country": "Ukraine",

"year": 2016,
"year": 2023,

"campaign": "wlm-ua",

Expand Down
10 changes: 6 additions & 4 deletions scalawiki-wlx/src/main/scala/org/scalawiki/wlx/dto/Contest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ object Contest {
.find(country => country.name == countryStr || country.code == countryStr)
)
yield new Contest(
contestType,
country,
year,
contestType = contestType,
country = country,
year = year,
uploadConfigs = Seq(uploadConfig),
config = Some(config)
config = Some(config),
specialNominations = SpecialNomination.nominations
.filter(n => n.years.contains(year))
)
}

Expand Down
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,32 @@
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(s"${contest.year}-06-30T23:59:59Z")

override def name: String = "RecentlyTaken"

override def table: Table = {
val data = stat.currentYearImageDb
.map { db =>
val images = db.images.filter { i =>
i.metadata.exists(_.date.exists(_.isAfter(jun30))) &&
!i.specialNominations.contains(s"WLM${contest.year}-UA-interior")
}
images.map { i =>
List(
s"[[:${i.title}]]",
s"[[User:${i.author.getOrElse("")}|${i.author.getOrElse("")}]]",
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 69b94b2

Please sign in to comment.