Skip to content

Commit

Permalink
Merge pull request #11 from neomatrix369/dev-uk-2017
Browse files Browse the repository at this point in the history
Create api for archiving of ratings for all the accepted talks
  • Loading branch information
neomatrix369 authored Oct 26, 2017
2 parents 9e976c3 + b1cfc1f commit 79ec878
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/controllers/Attic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ object Attic extends SecureCFPController {
Redirect(routes.Attic.atticHome()).flashing(("success", s"All speakers archived (along with their Q&A)"))
}

def doArchiveRatings()= SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Rating.archiveTalkRatings()
Redirect(routes.Attic.atticHome()).flashing(("success", "Archived ratings (aka mobile votes) for all talks"))
}

def deleteInvitedSpeakers() = SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Invitation.deleteAll()
Expand Down Expand Up @@ -143,7 +149,7 @@ object Attic extends SecureCFPController {
// Mobile API
def deleteRatings()= SecuredAction(IsMemberOf("admin")) {
implicit request: SecuredRequest[play.api.mvc.AnyContent] =>
Rating.attic()
Rating.deleteAll()
Redirect(routes.Attic.atticHome()).flashing(("success", "Deleted mobile votes"))
}
}
40 changes: 39 additions & 1 deletion app/models/Rating.scala
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ object Rating {
BigDecimal(score).setScale(2,RoundingMode.HALF_EVEN).toDouble
}

def attic() = Redis.pool.withClient {
def deleteAll() = Redis.pool.withClient {
implicit client =>
client.del(RATING_KEY)

Expand All @@ -234,4 +234,42 @@ object Rating {
allKeys.foreach { key: String => tx.del(key) }
tx.exec()
}

def archiveTalkRatings(): Unit = Redis.pool.withClient {
val conferenceCode = ConferenceDescriptor.current().eventCode

val allAcceptedTalks = Proposal.allProposals().filter(_.state == ProposalState.ACCEPTED)
val allRatingsForTalks = allRatings()

implicit client =>
val allRatingsForTalksByTalkId = allAcceptedTalks.flatMap(
talk => client.hmget(RATING_KEY, client.smembers(s"$RATING_KEY:ByTalkId:${talk.id}"))
)

val tx = client.multi()

play.Logger.info(s"Attempting to archive summarised ratings (aka mobile votes) for all talks for $conferenceCode.")
allRatingsForTalks.foreach {
rating =>
tx.hset(s"Archived:$RATING_KEY", rating.id(), Json.toJson(rating).toString())
play.Logger.debug(s"Archived:$RATING_KEY:${rating.id()} => ${Json.toJson(rating).toString()}");
}
play.Logger.info(s"Finished archiving summarised ratings (aka mobile votes - (${allRatingsForTalks.size} of them) for all talks for $conferenceCode.")

play.Logger.info(s"Attempting to archive individual ratings for all talks for $conferenceCode.")

allRatingsForTalksByTalkId.foreach {
json => {
val rating = Json.parse(json).as[Rating]
tx.sadd(s"Archived:$RATING_KEY:ByTalkId:${rating.talkId}", rating.id())
play.Logger.debug(s"Archived:$RATING_KEY:ByTalkId:${rating.talkId} => ${rating.id()}");
}
}

play.Logger.info(s"Deleting summarised and individual talk ratings for all talks for $conferenceCode.")
deleteAll()

tx.exec()
play.Logger.debug(s"Finished archiving ratings (aka mobile votes - ${allRatingsForTalksByTalkId.size} of them) for all talks for ${conferenceCode}.")
}
}
5 changes: 5 additions & 0 deletions app/views/Attic/atticHome.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ <h3>Attic backoffice</h3>
<button type="submit" class="btn btn-primary">Archive all speakers (along with their Q&A)</button>
</form>

<form action="@routes.Attic.doArchiveRatings()" method="POST">
<input type="hidden" name="opType" value="prune"/>
<button type="submit" class="btn btn-primary">Archive ratings (aka mobile votes) of all talks</button>
</form>

<div class="clearfix"></div>

<div class="col-lg-12 col-md-12">
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ POST /cfpadmin/attic/deleteGoldenTickets
POST /cfpadmin/attic/deleteWishlisted controllers.Attic.deleteWishlist()
POST /cfpadmin/attic/deleteFav controllers.Attic.deleteFavoriteTalks()
POST /cfpadmin/attic/deleteRatings controllers.Attic.deleteRatings()
POST /cfpadmin/attic/doArchiveRatings controllers.Attic.doArchiveRatings()

# Golden ticket admin
GET /admin/goldenTickets controllers.GoldenTicketAdminController.showAll()
Expand Down

0 comments on commit 79ec878

Please sign in to comment.