Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Session
- @DNF: -1
- solves = []
- solves: -> solves
- length: -> solves.length
- reset: -> solves = []
- add: (solve) ->
- solves[solves.length] = solve
- delete: (index) ->
- solves.splice index, 1
- current_average: (n) ->
- average(solves.length - n, n)
- trim_count = (n) ->
- Math.ceil n / 20.0
- average = (index, length) ->
- return Session.DNF if (length - index) < 3
- trim = trim_count length
- copy = solves.slice index, index + length
- copy.sort session_sort
- copy.splice(0, trim)
- copy.splice(copy.length - trim, trim)
- return Session.DNF if copy[copy.length - 1]['DNF']
- sum = copy.reduce ((a, b) -> a + b['time']), 0
- sum / (length - (2 * trim))
- mean = ->
- return Session.DNF if solves.length < 1
- dnfs = 0
- sum = solves.reduce ((t, s) ->
- t + if s['DNF'] then ++dnfs; 0 else s['time']), 0
- return Session.DNF if solves.length == dnfs
- sum / (solves.length - dnfs)
- session_sort = (a, b) ->
- return 1 if a['DNF']
- return -1 if b['DNF']
- return a['time'] - b['time']
- @Session = Session
Add Comment
Please, Sign In to add comment