Skip to content

Instantly share code, notes, and snippets.

@CaptainZidgel
Created August 24, 2020 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaptainZidgel/6d8ef54d925136f753015bee701176aa to your computer and use it in GitHub Desktop.
Save CaptainZidgel/6d8ef54d925136f753015bee701176aa to your computer and use it in GitHub Desktop.
Non comprehensive definition of logs.tf logs for kotlin
//This class is nonexhaustive, as I didn't want to spend an hour creating a bunch of useless subclasses.
class Log(
val version: Int,
val success: Boolean,
val info: Info,
val players: HashMap<String, pInfo>
) {
data class pInfo(
val team: String,
val class_stats: List<class_stats>,
val kills: Int,
val deaths: Int,
val assists: Int,
val kapd: String,
val kpd: String,
val dmg: Int,
val hr: Int,
@Json(name = "as") // as is a reserved word in Kotlin, this annotation lets us get past that (all value names must match their appearance in the json or use this annotation)
val AS: Int,
@Json(name = "dapm") // Logs.tf records _da_mage per minute as pm
val dpm: Int,
val ubers: Int,
val drops: Int,
val headshots: Int,
val heal: Int,
val cpc: Int
)
data class class_stats(
val type: String,
val kills: Int,
val assists: Int,
val deaths: Int,
val dmg: Int,
val total_time: Int
)
data class Info(
val map: String,
val total_length: Int,
val hasRealDamage: Boolean,
val hasWeaponDamage: Boolean,
val hasAccuracy: Boolean,
val hasHP: Boolean,
val hasHP_real: Boolean,
val hasAS: Boolean,
val date: Int
)
}
/*
val result = Klaxon().parse<Log>(logstring)
for ((id, player) in result!!.players) {
println("$id had ${player?.dpm} DPM")
}
*PRODUCES*
[U:1:*] had 153 DPM
[U:1:*] had 123 DPM
[U:1:*] had 116 DPM
[U:1:*] had 321 DPM
[U:1:*] had 93 DPM
[U:1:*] had 254 DPM
[U:1:*] had 408 DPM
***IDs removed to protect the innocent
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment