Skip to content

Commit

Permalink
#13[1h]. Add bonuses. Add default check period.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Kanivets committed Nov 20, 2017
1 parent fca976d commit 69697b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import acmp.AcmpClient
import firebase.FirebaseClient
import model.Bonus
import model.Student
import org.apache.log4j.BasicConfigurator
import org.apache.log4j.Level
Expand All @@ -20,6 +21,8 @@ fun main(args: Array<String>) {
BasicConfigurator.configure()
Logger.getRootLogger().level = Level.ERROR

val checkPeriod = if (args.size == 1) args[0].toLong() else 600000

val timer = Timer()
timer.schedule(object : TimerTask() {
override fun run() {
Expand All @@ -29,7 +32,7 @@ fun main(args: Array<String>) {
}
}
}
}, 0, args[0].toLong())
}, 0, checkPeriod)
}

fun fetchStudents(failure: (reason: String) -> Unit = {}, success: (students: Array<Student>) -> Unit) {
Expand All @@ -44,7 +47,10 @@ fun fetchStudents(failure: (reason: String) -> Unit = {}, success: (students: Ar
if (student.startRating == -1) {
student.startRating = student.currentRating
}

student.bonusRating = 0
student.bonuses.forEach { student.bonusRating += it.value }

student.contestRating = student.currentRating - student.startRating + student.bonusRating
student.solvedTasks = acmpUser.solvedTasks.toList()
student.notSolvedTasks = acmpUser.notSolvedTasks.toList()
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/firebase/FirebaseClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class FirebaseClient {
updates.put("${it.id}/currentRating", it.currentRating)
updates.put("${it.id}/bonusRating", it.bonusRating)
updates.put("${it.id}/contestRating", it.contestRating)
updates.put("${it.id}/bonuses", it.bonuses.toList())
updates.put("${it.id}/solvedTasks", it.solvedTasks.toList())
updates.put("${it.id}/notSolvedTasks", it.notSolvedTasks.toList())
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/model/Student.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ data class Student(var id: String = "",
var currentRating: Int = -1,
var bonusRating: Int = 0,
var contestRating: Int = -1,
var solvedTasks: List<String> = listOf<String>(),
var notSolvedTasks: List<String> = listOf<String>())
var bonuses: List<Bonus> = listOf(),
var solvedTasks: List<String> = listOf(),
var notSolvedTasks: List<String> = listOf())

data class Bonus(val description: String = "",
val value: Int = 0)

0 comments on commit 69697b2

Please sign in to comment.