Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. var t, e, n, r, a, s, i, o, c, l;
  2. c = 721, # Width of the graph
  3. e = 110, # Height of the graph
  4. l = [20, 0, 0, 20], # Only used for s/a/n/r below
  5. s = l[0], # Y offset of top of graph
  6. a = l[1], # Not used
  7. n = l[2], # Not used
  8. r = l[3], # X offset of top of graph
  9. t = 13, # Cell size
  10. i = 2, # Cell padding
  11. o = function(t) { # Calculates standard deviation(?) for outlier math
  12. var e, n, r, a, s;
  13. if (r = t.length, 1 > r)
  14. return 0 / 0;
  15. if (1 === r)
  16. return 0;
  17. for (n = d3.mean(t), e = -1, a = 0; ++e < r; )
  18. s = t[e] - n, a += s * s;
  19. return a / (r - 1)
  20. },
  21. $(document).on("graph:load", ".js-calendar-graph", function(n, a) {
  22. var l, u, d, h, f, m, p, g, v, b, y, j, w, x, C, k, S, _, T, D, P, A, L, E, M, B, I, O, q, F;
  23. for (
  24. l = $(this),
  25. f = l.attr("data-from"), # Set if we asked to hilight a specific date
  26. f && (f = C = moment(f).toDate()), # Turn that into a date if it exists
  27. A = l.attr("data-to"), # This never appears to be used
  28. A && (A = moment(A).toDate()), # Neither does this
  29. a || (a = []), # If we got no contrib data, give us an empty array
  30. a = a.map(function(t) { # Convert the points to [Date, Score] pairs, sorted by date
  31. return [new Date(t[0]), t[1]]
  32. }).sort(function(t, e) {
  33. return d3.ascending(t[0], e[0])
  34. }),
  35. u = 3.77972616981, # Magic number for finding outliers
  36. w = a.map(function(t) { # Array of just the scores
  37. return t[1]
  38. }),
  39. T = Math.sqrt(o(w)), # Square root of o() above, used for finding outliers
  40. b = d3.mean(w), # Mean of the scores
  41. _ = 3, # This is our loop max
  42. p = d3.max(w), # Max score
  43. L = p - b, # Max minus the mean
  44. (6 > L || 15 > p) && (_ = 1), # If (max-mean) is greater than 5 or the max is greater than 15, drop the loop max to 1
  45. x = 0 # Start the loop counter at 0
  46. ;
  47. _ > x; # Loop check
  48. )
  49. E = w.filter(function(t) { # Grab any outliers
  50. var e;
  51. return e = Math.abs((b - t) / T), e > u
  52. }),
  53. E.length > 0 ? # Did we find any outliers?
  54. (
  55. E = E[0], # If so, pop the first one
  56. w = w.filter(function(t) { # Now remove any instances of *that* number from the scores
  57. return t !== E
  58. }),
  59. 0 === x && (g = w) # If this is the first oulier, set g to the new list
  60. )
  61. :
  62. E = null, # If we have no outliers, null E
  63. x += 1; # Increment the loop counter and spin again
  64. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement