Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var t, e, n, r, a, s, i, o, c, l;
- c = 721, # Width of the graph
- e = 110, # Height of the graph
- l = [20, 0, 0, 20], # Only used for s/a/n/r below
- s = l[0], # Y offset of top of graph
- a = l[1], # Not used
- n = l[2], # Not used
- r = l[3], # X offset of top of graph
- t = 13, # Cell size
- i = 2, # Cell padding
- o = function(t) { # Calculates standard deviation(?) for outlier math
- var e, n, r, a, s;
- if (r = t.length, 1 > r)
- return 0 / 0;
- if (1 === r)
- return 0;
- for (n = d3.mean(t), e = -1, a = 0; ++e < r; )
- s = t[e] - n, a += s * s;
- return a / (r - 1)
- },
- $(document).on("graph:load", ".js-calendar-graph", function(n, a) {
- 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;
- for (
- l = $(this),
- f = l.attr("data-from"), # Set if we asked to hilight a specific date
- f && (f = C = moment(f).toDate()), # Turn that into a date if it exists
- A = l.attr("data-to"), # This never appears to be used
- A && (A = moment(A).toDate()), # Neither does this
- a || (a = []), # If we got no contrib data, give us an empty array
- a = a.map(function(t) { # Convert the points to [Date, Score] pairs, sorted by date
- return [new Date(t[0]), t[1]]
- }).sort(function(t, e) {
- return d3.ascending(t[0], e[0])
- }),
- u = 3.77972616981, # Magic number for finding outliers
- w = a.map(function(t) { # Array of just the scores
- return t[1]
- }),
- T = Math.sqrt(o(w)), # Square root of o() above, used for finding outliers
- b = d3.mean(w), # Mean of the scores
- _ = 3, # This is our loop max
- p = d3.max(w), # Max score
- L = p - b, # Max minus the mean
- (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
- x = 0 # Start the loop counter at 0
- ;
- _ > x; # Loop check
- )
- E = w.filter(function(t) { # Grab any outliers
- var e;
- return e = Math.abs((b - t) / T), e > u
- }),
- E.length > 0 ? # Did we find any outliers?
- (
- E = E[0], # If so, pop the first one
- w = w.filter(function(t) { # Now remove any instances of *that* number from the scores
- return t !== E
- }),
- 0 === x && (g = w) # If this is the first oulier, set g to the new list
- )
- :
- E = null, # If we have no outliers, null E
- x += 1; # Increment the loop counter and spin again
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement