in football/src/main/scala/com/gu/mobile/notifications/football/lib/FootballData.scala [70:102]
def matchIdsInProgress(dateTime: ZonedDateTime): Future[List[MatchDay]] = {
def inProgress(m: MatchDay): Boolean =
m.date.minusMinutes(5).isBefore(dateTime) && m.date.plusHours(4).isAfter(dateTime)
// unfortunately PA provide 00:00 as start date when they don't have the start date
// so we can't do anything with these matches
def isMidnight(matchDay: MatchDay): Boolean = {
val localDate = matchDay.date.toLocalTime
localDate.getHour() == 0 && localDate.getMinute() == 0
}
//Theres some stuff that PA don't provide data for and we want to supress alerts for these matches
def paProvideAlerts(matchDay: MatchDay) : Boolean = {
matchDay.competition.map {
c => c.id match {
//International friendly: Must involve at least one of a whitelisted set of teams
case "721" if matchDay.isUncoveredInternationalFriendly => false
//FA cup qualifying rounds not covererd before round 3
case "303" if matchDay.isEarlyQualifyingRound => false
case _ => true
}
}.getOrElse(false) //Shouldn't ever happen
}
logger.info(s"Retrieving matches on or around $dateTime from PA")
val matches = paClient.aroundToday(dateTime)
matches.map(
_.filter(inProgress)
.filter(paProvideAlerts)
.filterNot(isMidnight)
)
}