Created
December 26, 2014 17:07
-
-
Save Noxville/fc8bd68925bd6e71227d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def longestStreak() { | |
Integer best = 0 | |
Map<String, Integer> currentStreaks = new HashMap<>() | |
Map<String, Date> startStreaks = new HashMap<>() | |
Mtch.list().sort { it.matchId }.each { Mtch m -> | |
def winner = m.winner.trim().toLowerCase() == "radiant" ? m.radiantTeam : m.direTeam | |
def loser = m.winner.trim().toLowerCase() == "radiant" ? m.direTeam : m.radiantTeam | |
// Winner first - can be the start of a streak | |
Integer currentStreak = currentStreaks.get(winner) | |
if (currentStreak) { | |
currentStreaks[winner] += 1 | |
} | |
else { | |
currentStreaks[winner] = 1 | |
startStreaks[winner] = m.date | |
} | |
// Loser next - can only be the end of a streak | |
currentStreak = currentStreaks.get(loser) | |
if (currentStreak > best) { | |
print "Team ${loser} has lost after winning ${currentStreak} in a row. They lost to ${winner} in " + | |
"${m.matchId} - (${m.event}). Their streak was from " + | |
"${startStreaks[loser].format("yyyy-MM-dd")} to ${m.date.format("yyyy-MM-dd")}" | |
best = currentStreak | |
} | |
currentStreaks.remove(loser) | |
startStreaks.remove(loser) | |
} | |
currentStreaks.entrySet().sort{ it.value }.each { | |
if (it.value > best) { | |
print "Team ${it.key} has not yet lost after winning ${it.value} in a row. Their " + | |
"streak was from ${startStreaks[it.key]} to ${new Date().format("yyyy-MM-dd")}" | |
best = it.value | |
} | |
} | |
[] | |
} | |
def longStreaks() { | |
final Integer THRESHOLD = 15 | |
Map<String, Integer> currentStreaks = new HashMap<>() | |
Map<String, Date> startStreaks = new HashMap<>() | |
Mtch.list().sort { it.matchId }.each { Mtch m -> | |
def winner = m.winner.trim().toLowerCase() == "radiant" ? m.radiantTeam : m.direTeam | |
def loser = m.winner.trim().toLowerCase() == "radiant" ? m.direTeam : m.radiantTeam | |
// Winner first - can be the start of a streak | |
Integer currentStreak = currentStreaks.get(winner) | |
if (currentStreak) { | |
currentStreaks[winner] += 1 | |
} | |
else { | |
currentStreaks[winner] = 1 | |
startStreaks[winner] = m.date | |
} | |
// Loser next - can only be the end of a streak | |
currentStreak = currentStreaks.get(loser) | |
if (currentStreak > THRESHOLD) { | |
print "Team ${loser} has lost after winning ${currentStreak} in a row. They lost to ${winner} in " + | |
"${m.matchId} - (${m.event}). Their streak was from " + | |
"${startStreaks[loser].format("yyyy-MM-dd")} to ${m.date.format("yyyy-MM-dd")}" | |
} | |
currentStreaks.remove(loser) | |
startStreaks.remove(loser) | |
} | |
currentStreaks.entrySet().sort{ it.value }.each { | |
if (it.value > THRESHOLD) { | |
print "Team ${it.key} has not yet lost, after winning ${it.value} in a row. Their " + | |
"streak was from ${startStreaks[it.key]} to ${new Date().format("yyyy-MM-dd")}" | |
} | |
} | |
[] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment