simple (and broken) sort on progress %

This commit is contained in:
Radek Stepan 2014-10-20 20:25:48 -07:00
parent 367f26e517
commit 796904f226
9 changed files with 180 additions and 58 deletions

View File

@ -47,6 +47,7 @@ module.exports = (grunt) ->
'vendor/d3-tip/index.js'
'vendor/marked/lib/marked.js'
'vendor/director/build/director.js'
'vendor/sorted-index-compare/index.js'
]
dest: 'public/js/vendor.js'
options:

View File

@ -16,6 +16,7 @@
"ractive": "~0.6.0",
"ractive-ractive": "rstacruz/ractive-ractive",
"ractive-transitions-fade": "~0.1.2",
"sorted-index-compare": "6wunderkinder/sortedindex-compare",
"superagent": "~0.19.0"
}
}

File diff suppressed because one or more lines are too long

View File

@ -38827,4 +38827,55 @@ Router.prototype.mount = function(routes, path) {
}(typeof exports === "object" ? exports : window));
}(typeof exports === "object" ? exports : window));;(function(root) {
/**
* Uses a binary search to determine the smallest index at which a value
* should be inserted into a given sorted array in order to maintain the sort
* order of the array. The sort ranking is calculated internally by comparing
* an element of the array with the given value. The compare function should return
* a positive number larger than 0 if the second argument has a higher sort ranking than first,
* 0 if the first and the second argument have the same sort raking,
* and a negative number if the the second argument has a smaller sort ranking than the first.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to inspect.
* @param {*} value The value to evaluate.
* @param {Function} [compare] The function to compare elements.
Received to arguments that it should return a number for as described above.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
*/
function sortedIndex(array, value, compare) {
var low = 0,
high = array ? array.length : low;
while (low < high) {
var mid = (low + high) >>> 1;
(compare(array[mid],value) > 0)
? low = mid + 1
: high = mid;
}
return low;
}
//export for amd, commonjs and traditional global scope
if (typeof define === 'function' && define.amd) {
define('sortedindex-compare', [], function() {
return sortedIndex;
});
}
else if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = sortedIndex;
}
exports.sortedIndex = sortedIndex;
}
else {
root.sortedIndex = sortedIndex;
}
})(this);

View File

@ -1,4 +1,4 @@
{ _, lscache } = require '../modules/vendor.coffee'
{ _, lscache, sortedIndexCmp } = require '../modules/vendor.coffee'
config = require '../models/config.coffee'
mediator = require '../modules/mediator.coffee'
@ -15,6 +15,22 @@ module.exports = new Model
'data':
'sortBy': 'priority'
# Return a sort order comparator.
comparator: ->
switch @data.sortBy
# Priority comparator from most delayed in days.
when 'priority' then ([ i, j ], b) =>
# Convert existing index into actual proejct milestone.
a = @data.list[i].milestones[j]
# By progress points.
$ = { 'progress': { 'points': 0 } }
a.stats ?= $ ; b.progress ?= $
a.stats.progress.points - b.stats.progress.points
# Whatever sort order...
else -> 0
find: (project) ->
_.find @data.list, project
@ -61,11 +77,13 @@ module.exports = new Model
# Get or initialize the index.
index = @data.index or []
for p in @data.list
for p, i in @data.list
continue unless p.milestones?
for m in p.milestones
for m, j in p.milestones
# Run a comparator here inserting into index.
console.log @data.sortBy, m
idx = sortedIndexCmp index, m, do @comparator
# Log.
index.splice idx, 0, [ i, j ]
# Save the index.
@set 'index', index
@ -86,7 +104,7 @@ module.exports = new Model
, 'init': no
# Reset our index and re-sort.
@observe 'sortKey', ->
@observe 'sortBy', ->
# Use pop as Ractive is glitchy.
( @pop 'index' while @data.index.length ) if @data.index?
# Run the sort again.

View File

@ -1,3 +1,5 @@
{ moment } = require './vendor.coffee'
# Progress in %.
progress = (a, b) -> 100 * (a / (b + a))
@ -17,9 +19,11 @@ module.exports = (milestone) ->
# Progress in time.
time = progress b - a, c - b
isOnTime = points > time
# How many days is 1% of the time?
days = (moment(a).diff(moment(b), 'days')) / 100
{
'isOnTime': isOnTime
'isOnTime': points > time
'progress': { points, time }
'days': days
}

View File

@ -11,4 +11,5 @@ module.exports =
'marked': window.marked
'director':
'Router': window.Router
'lscache': window.lscache
'lscache': window.lscache
'sortedIndexCmp': window.sortedIndex

View File

@ -5,35 +5,45 @@
</div>
<table>
{{#projects.list}}
{{#if errors}}
<tr>
<td colspan="3" class="repo">
<div class="project">{{owner}}/{{name}} <span class="error" title="{{errors.join('\n')}}"><Icons icon="attention"/></span></div>
</td>
</tr>
{{else}}
{{#milestones}}
<tr>
<td class="repo">
<a class="project" href="#{{owner}}/{{name}}">{{owner}}/{{name}}</a>
</td>
<td>
<a class="milestone" href="#{{owner}}/{{name}}/{{number}}">{{ title }}</a>
</td>
<td style="width:1%">
<div class="progress">
<span class="percent">{{Math.floor(stats.progress.points)}}%</span>
<span class="due">{{{ format.due(due_on) }}}</span>
<div class="outer bar">
<div class="inner bar {{(stats.isOnTime) ? 'green' : 'red'}}" style="width:{{stats.progress.points}}%"></div>
</div>
</div>
</td>
</tr>
{{/milestones}}
{{/if}}
{{/projects.list}}
{{#projects.index}}
{{# { index: this } }}
{{# { project: projects.list[index[0]] } }}
{{#with project}}
{{#if errors}}
<tr>
<td colspan="3" class="repo">
<div class="project">{{owner}}/{{name}} <span class="error" title="{{errors.join('\n')}}"><Icons icon="attention"/></span></div>
</td>
</tr>
{{else}}
{{# { milestone: project.milestones[index[1]] } }}
<tr>
<td class="repo">
<a class="project" href="#{{owner}}/{{name}}">{{owner}}/{{name}}</a>
</td>
<td>
<a class="milestone" href="#{{owner}}/{{name}}/{{milestone.number}}">{{ title }}</a>
</td>
<td style="width:1%">
<div class="progress">
<span class="percent">{{Math.floor(milestone.stats.progress.points)}}%</span>
<span class="due">{{{ format.due(due_on) }}}</span>
<div class="outer bar">
<div class="inner bar {{(milestone.stats.isOnTime) ? 'green' : 'red'}}" style="width:{{milestone.stats.progress.points}}%"></div>
</div>
</div>
</td>
</tr>
{{/}}
{{/if}}
{{/with}}
{{/}}
{{/}}
{{/projects.index}}
</table>
<div class="footer">

View File

@ -3,6 +3,7 @@
mediator = require '../../modules/mediator.coffee'
format = require '../../utils/format.coffee'
Icons = require '../icons.coffee'
projects = require '../../models/projects.coffee'
module.exports = Ractive.extend