Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding dependencies; refactoring support into dependcy

  • Loading branch information...
commit b39fffa8e38b72b369672b0b5086f331da6f84ee 1 parent 97f8320
@bingomanatee authored
Showing with 865 additions and 16 deletions.
  1. +0 −3  .gitmodules
  2. +1 −1  lib/Component/handler/Controller_dir.js
  3. +1 −1  lib/Component/index.js
  4. +1 −1  lib/Controller/index.js
  5. +2 −2 lib/Loader/index.js
  6. +1 −1  lib/framework/handler/Components.js
  7. +1 −1  lib/framework/index.js
  8. +1 −1  lib/utility/handler/Resources.js
  9. +0 −1  node_modules/node-support
  10. 0  node_modules/support/README
  11. +24 −0 node_modules/support/draw_canvas.js
  12. +89 −0 node_modules/support/gate.js
  13. +85 −0 node_modules/support/menu.js
  14. +165 −0 node_modules/support/mongoose_model/index.js
  15. +46 −0 node_modules/support/ondir.js
  16. +15 −0 node_modules/support/package.json
  17. +101 −0 node_modules/support/pipe.js
  18. +19 −0 node_modules/support/proper_path.js
  19. +147 −0 node_modules/support/simple_model.js
  20. +100 −0 node_modules/support/stat.js
  21. +56 −0 node_modules/support/wstat.js
  22. +7 −1 package.json
  23. +1 −1  test_resources/Mongoose_Model_test/app/resources/model/model_folks.js
  24. +1 −1  test_resources/REST_test/app/resources/model/model_folks.js
  25. +1 −1  test_resources/Resources_Test/app/resources/model/model_widgets.js
View
3  .gitmodules
@@ -1,3 +0,0 @@
-[submodule "node_modules/node-support"]
- path = node_modules/node-support
- url = git@github.com:bingomanatee/node-support.git
View
2  lib/Component/handler/Controller_dir.js
@@ -1,6 +1,6 @@
var Path_Handler = require('./../../Loader/Path_Handler');
var fs = require('fs');
-var Gate = require('node-support/gate');
+var Gate = require('support/gate');
var _DEBUG = false;
View
2  lib/Component/index.js
@@ -12,7 +12,7 @@ var controller_handler = require('./handler/Controller');
var controller_dir_loader = require('./handler/Controller_dir');
var heritage = require('./../utility/heritage');
var digest_config = require('./../utility/digest_config');
-var Gate = require('node-support/gate');
+var Gate = require('support/gate');
var log = require('./../utility/log');
var ensure_name = require('./../utility/ensure_name');
/**
View
2  lib/Controller/index.js
@@ -9,7 +9,7 @@ var config_handler = require('./../utility/handler/Config');
var ress_handler = require('./../utility/handler/resources');
var heritage = require('./../utility/heritage');
var digest_config = require('./../utility/digest_config');
-var Gate = require('node-support/gate');
+var Gate = require('support/gate');
var ensure_name = require('./../utility/ensure_name');
function Controller(config) {
View
4 lib/Loader/index.js
@@ -4,8 +4,8 @@ var path = require('path');
var fs = require('fs');
var _ = require('./../../node_modules/underscore');
-var proper_path = require('./../../node_modules/node-support/proper_path');
-var Gate = require('node-support/gate');
+var proper_path = require('./../../node_modules/support/proper_path');
+var Gate = require('support/gate');
var _DEBUG = false;
var _DEBUG_WORK = false;
View
2  lib/framework/handler/Components.js
@@ -1,5 +1,5 @@
var Path_Handler = require('./../../Loader/Path_Handler');
-var Gate = require('node-support/gate')
+var Gate = require('support/gate')
var fs = require('fs');
var Component = require('./../../Component');
View
2  lib/framework/index.js
@@ -8,7 +8,7 @@ var con_handler = require('./../Component/handler/Controller');
var controller_dir_loader = require('./../Component/handler/Controller_dir');
var ress_handler = require('./../utility/handler/resources');
var path = require('path');
-var Gate = require('node-support/gate');
+var Gate = require('support/gate');
var log = require('./../utility/log');
var _DEBUG = false;
View
2  lib/utility/handler/Resources.js
@@ -3,7 +3,7 @@ var Resource = require('./../../Resource');
var util = require('util');
var path = require('path');
var fs = require('fs');
-var Gate = require('node-support/gate');
+var Gate = require('support/gate');
var _ = require('underscore');
var known_types = ['action_helper', 'view_helper', 'express_helper', 'mixin', 'model', 'resource'];
1  node_modules/node-support
@@ -1 +0,0 @@
-Subproject commit ca5d2fd12059ad93ac44afd7ea9a98c8102024bb
View
0  node_modules/support/README
No changes.
View
24 node_modules/support/draw_canvas.js
@@ -0,0 +1,24 @@
+var fs = require('fs');
+
+function draw_canvas(canvas, c_path, cb) {
+ console.log('drawing canvas to %s: %s w x %s h', c_path, canvas.width, canvas.height);
+
+ var stream = canvas.createPNGStream();
+ var out = fs.createWriteStream(c_path);
+
+ stream.on('data', function (c) {
+ out.write(c);
+ });
+
+ stream.on('end', function () {
+ out.close();
+ if (cb){
+ cb(null, c_path);
+ } else {
+ console.log('done writing to %s', c_path);
+ }
+ })
+
+}
+
+module.exports = draw_canvas;
View
89 node_modules/support/gate.js
@@ -0,0 +1,89 @@
+/**
+ * This module allows you to track aggregate activity and
+ * execute one or more callbacks when your tasks clear.
+ * It is not necessary to identify individual tasks as
+ * the only thing this class cares about is the quantity of tasks in the queue.
+ *
+ * However for future proofing, tasks are identified and optionally removed by name.
+ */
+var _ = require('./../../node_modules/underscore');
+
+module.exports = function (callback) {
+ this._tasks = [];
+ this._start = false;
+ this.debug = false;
+ this._callback = callback;
+}
+
+module.exports.prototype.start = function () {
+ this._start = true;
+ var self = this;
+ if (this.debug) {
+ console.log(__filename + ':: start starting with ' + this._tasks.length + ' tasks');
+ }
+ this._check_status();
+}
+
+module.exports.prototype.task_start = function (task) {
+ if (!task) {
+ task = this._tasks.length
+ }
+ this._tasks.push(task);
+ if (this.debug) {
+ console.log('gate task start');
+ }
+}
+
+
+/**
+ * @id scalar (optional)
+ * returns either the designated task
+ * or the last task in the queue.
+ */
+module.exports.prototype.task_done = function () {
+ var done_task = this._tasks.pop();
+
+ if (this.debug) {
+ console.log('gate task done');
+ }
+
+ this._check_status();
+}
+
+/**
+ * returns a callback that, when called, acknowledges
+ * that a task has been completed.
+ * @param start_task
+ */
+module.exports.prototype.task_done_callback = function (start_task) {
+ var my_gate = this;
+ return function () {
+ my_gate.task_done();
+ }
+ if (start_task) {
+ // acknowledge that a task has been begun.
+ this.task_start();
+ }
+}
+
+module.exports.prototype._check_status = function () {
+ var self = this;
+
+ if (this._start) {
+ if (this._tasks.length < 1) {
+ this._start = false;
+ if (this.debug) {
+ console.log(__filename + ':: _check_status: done with gate');
+ }
+ this._callback(self);
+ } else {
+ if (this.debug) {
+ console.log('task done; ', this._tasks.length, ' tasks left');
+ }
+ }
+ } else {
+ if (this.debug) {
+ console.log('task done; ', this._tasks.length, ' tasks left - STILL NOT STARTED');
+ }
+ }
+}
View
85 node_modules/support/menu.js
@@ -0,0 +1,85 @@
+var _ = require('./../../node_modules/underscore');
+var util = require('util');
+
+function Menu(config) {
+ this._init(config);
+}
+
+var menu_id = 0;
+Menu.prototype = {
+ _init:function (config) {
+ _.extend(this, config);
+ this._menu_id = ++menu_id;
+
+ if (this.children && _.isArray(this.children)){
+ for (var i = 0; i < this.children.length; ++i){
+ this.children[i] = new Menu(this.children[i]);
+ }
+ }
+ },
+ title:'',
+ link:'',
+ visible:function (env) {
+ return true;
+ },
+ active:function (env) {
+ return false;
+ },
+ children:[],
+ template:'<div class="menu"><a href="%s" class="menu_item%s">%s</a>%s</div>',
+ children_template:'<div class="menu_children">%s</div>',
+
+ render:function (env) {
+ // console.log('rendering #%s:%s', this._menu_id, this.title);
+
+ if (!this.visible(env)) {
+ return '';
+ }
+ var ctx_class = this.active(env) ? ' active' : '';
+ // console.log(' ---------- rendering %s children of #%s: %s', this.children.length, this._menu_id, this.title);
+ var children_rendered = this._render_children(env);
+ return util.format(this.template, this.link, ctx_class, this.title, children_rendered);
+ },
+
+ add_child:function (child) {
+ var menu = new Menu(child);
+ // console.log('adding child #%s:%s to %s:%s', menu._menu_id, menu.title, this._menu_id, this.title);
+ this.children.push(menu);
+ },
+
+ _render_children:function (env) {
+ if (!this.children.length) {
+ return '';
+ }
+ var menu = this;
+ var child_items = [];
+
+ this.children.forEach(function (child, i) {
+ try {
+ if (child.visible(env)) {
+ // console.log('rendering child %s of #%s:%s - #%s:%s', i, menu._menu_id, menu.title, child._menu_id, child.title);
+ child_items.push(child.render(env));
+ }
+ } catch (e) {
+ console.log('err: %s', util.inspect(e));
+ }
+ });
+
+ if (child_items.length > 0) {
+ var ci = child_items.join("\n");
+ // console.log('ci: %s', ci);
+ return util.format(this.children_template, ci);
+ } else {
+ return '';
+ }
+ }
+}
+
+
+module.exports = {
+ Menu:Menu,
+
+ create:function (config) {
+ return new Menu(config);
+ }
+}
View
165 node_modules/support/mongoose_model/index.js
@@ -0,0 +1,165 @@
+var _ = require('underscore');
+var mongoose = require('mongoose');
+var util = require('util');
+
+/**
+ * Mongoose Model is, for the most part, a wrapper for the mongoose schema.
+ * There are a few reasons for its existence:
+ *
+ * 1) its generally considered good practice to have a layer between
+ * your custom model class and the retrieval class
+ *
+ * 2) I wanted a more REST-ish API for models, one that while it allows for
+ * mongoosey options, also allows for a more streamlined use of traditional
+ * rest methods a la MyModel.get(3, function(err, my_model)).
+ *
+ * That being said, the MongooseModel returns Mongoose Documents, not instances
+ * of itself or any other custom record .. by default.
+ *
+ * @param model
+ * @param config
+ */
+
+function MongooseModel(model, config) {
+
+ if (config) {
+ _.extend(this, config);
+ }
+
+ this.model = model;
+
+}
+
+MongooseModel.prototype = {
+
+ force_oid:true,
+
+ get:function (id, fields, options, callback) {
+ return this.model.findById(id, fields, options, callback);
+ },
+
+ put:function (doc, options, callback) {
+ if (typeof options == 'function') {
+ callback = options;
+ options = {};
+ }
+
+ var doc_obj;
+ if (doc instanceof mongoose.Document) {
+ doc_obj = doc;
+ } else {
+ doc_obj = new this.model(doc);
+ }
+ console.log('putting %s', util.inspect(doc_obj));
+
+ var self = this;
+ var _callback;
+
+ if (this.post_save) {
+ _callback = function (err, doc) {
+ if (err) {
+ console.log('err on save - skipping post_save');
+ callback(err);
+ } else {
+ console.log('doing post save');
+ self.post_save(doc, callback);
+ }
+ }
+ } else {
+ _callback = callback;
+ }
+
+ if (this.pre_save) {
+ this.pre_save(doc_obj, function (err, doc_obj) {
+ if (err) {
+ _callback(err);
+ } else {
+ doc_obj.save(function (err) {
+ if (err) {
+ callback(err);
+ } else {
+ callback(null, doc_obj);
+ }
+ });
+ }
+ })
+ } else {
+ doc_obj.save(function (err) {
+ if (err) {
+ callback(err);
+ } else {
+ callback(null, doc_obj);
+ }
+ });
+ }
+
+ },
+
+ post:function (doc, options, callback) {
+ this.put(doc, options, callback);
+ },
+
+ all:function (callback, max, skip) {
+ if (!skip) {
+ skip = 0;
+ }
+ if (!max) {
+ max = 500;
+ }
+ ;
+ try {
+ this.model.find({}).sort('_id', 1).slice(skip, max).run(callback);
+ } catch (err) {
+ callback(err);
+ }
+ },
+
+ delete:function (id, callback) {
+ this.find(get, function (err, doc) {
+ if (doc) {
+ doc.remove(callback);
+ } else {
+ callback(new Error('Cannot find that document'));
+ }
+ })
+ },
+
+ find:function (crit, field, options, callback) {
+ return this.model.find(crit, field, options, callback);
+ },
+
+ find_one:function (crit, field, options, callback) {
+ return this.model.findOne(crit, field, options, callback);
+ },
+
+ model:null,
+
+ count:function (crit, cb) {
+ return this.model.count(crit, cb);
+ },
+
+ validation_errors:function (err) {
+ var req_re = /Validator "required" failed for path .*/;
+
+ function _filter_error(error) {
+ if (req_re.test(error)) {
+ return 'required';
+ }
+ return error;
+ }
+
+ var list = [];
+ for (var field in err.errors) {
+ list.push(_filter_error(field + ': ' + err.errors[field].message));
+ }
+ return list.join(',');
+ }
+
+}
+
+module.exports = {
+ MongooseModel:MongooseModel,
+ create:function (model, config) {
+ return new MongooseModel(model, config);
+ }
+}
View
46 node_modules/support/ondir.js
@@ -0,0 +1,46 @@
+var fs = require('fs');
+var path = require('path');
+var util = require('util');
+var Gate = require('./gate');
+
+/**
+ * executes across all files/dirs in a directory - non recursive.
+ * Note that the main callback is not called until either all the file/dir items have executed
+ * (assuming the path is good).
+ *
+ * @param root_path :string - an absolute directory path
+ * @param if_file(done_callback): :function - executes on all files. Passed full path to file.
+ * @param if_dir(done_callback): :function - executes on all directories. Passed full path to file.
+ * @param if_nopath(callback) :function - executes if root path does not exist; otherwise error thrown.
+ */
+module.exports = function(root_path, callback, if_file, if_dir, if_nopath) {
+ root_path = root_path.replace(/\/$/, '');
+ if (!path.existsSync(root_path)) {
+ // console.log('no path ', root_path);
+
+ if (if_nopath) {
+ // console.log('handling no path ', root_path);
+ if_nopath(root_path, callback);
+ } else {
+ callback(new Error(util.format('%s: cannot find path "%s"', __dirname, root_path)));
+ }
+
+ } else {
+
+ var items = fs.readdirSync(root_path);
+ var gate = new Gate(callback);
+
+ items.forEach(function(item) {
+ var full_path = root_path + '/' + item;
+ var s = fs.statSync(full_path);
+ if (s.isDirectory() && if_dir) {
+ if_dir(full_path, gate.task_done_callback(true));
+ } else if (s.isFile() && if_file){
+ if_file(full_path, gate.task_done_callback(true));
+ }
+ })
+
+ gate.start();
+ }
+
+}
View
15 node_modules/support/package.json
@@ -0,0 +1,15 @@
+{
+ "author": "Dave Edelhart <dave@wonderlandlabs.com> (http://www.wonderlandlabs.com)",
+ "name": "support",
+ "description": "A toolkit for node.js",
+ "version": "1.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/bingomanatee/support.git"
+ },
+ "engines": {
+ "node": "~0.6.14"
+ },
+ "dependencies": {},
+ "devDependencies": {}
+}
View
101 node_modules/support/pipe.js
@@ -0,0 +1,101 @@
+/**
+ * Pipe calls the same function with different parameters;
+ * it allows for asynchronous but single threaded activity.
+ *
+ * action has a profile:
+ * action(param_array_element, this.static_params, this._act_done_callback, this._pipe_done_callback);
+ *
+ * note that the last two parameters are functions PRODUCED by local functions.
+ */
+
+function Pipe(callback, action, param_array, static_params) {
+ this.callback = callback;
+
+ if (typeof action != 'function') {
+ throw new Error(__filename + ': non function passed as action');
+ }
+
+ if (typeof callback != 'function') {
+ throw new Error(__filename + ': non function passed as callback');
+ }
+
+ this.action = action;
+ this.param_array = param_array ? param_array : [];
+ this.stop_on_end_of_param_array = false;
+ this.static_params = static_params ? static_params : false;
+ this.idle = true;
+ this.done = false;
+ this.iv = null;
+}
+
+module.exports = Pipe;
+
+Pipe.prototype = {
+
+ _iv: function() {
+ var self = this;
+ return function() {
+ self.check_pipe();
+ };
+ },
+
+ start: function() {
+ var self = this;
+ this._pipe_done_callback = function() {
+ // console.log('pipe done callback called');
+ self.finish();
+ };
+ this._act_done_callback = function(){
+ // console.log('act done callback called');
+ self.act();
+ }
+ this.act();
+ },
+
+ check_pipe: function() {
+ if (this.idle) {
+ this.idle = false;
+ // console.log('acting');
+ this.act();
+ }
+ },
+
+ /**
+ * Pipe allows for an array of changing parameters,passed in param_array
+ * -- howver they are optional.
+ * The param_array running out of params
+ * doesn't trigger finish unless stop_on_end_of_param_array is set to true.
+ * If not, then stopping the loop has to be done inside action
+ * by calling pipe.finish(); this is why pipe is the first parameter
+ * of action.
+ */
+
+ act: function() {
+
+ if (this.param_array.length) {
+ var params = this.param_array.shift();
+ } else if (this.stop_on_end_of_param_array) {
+ // console.log('out of params - finishing');
+ return this.finish();
+ } else {
+ params = false;
+ }
+
+ // console.log('acting on ', params, this.static_params);
+ this.action(params, this.static_params, this._act_done_callback, this._pipe_done_callback);
+ },
+
+ _act_done_callback: false,
+ _pipe_done_callback: false,
+
+ /**
+ * Finish will prevent further functions from being launched.
+ * It won't abort the execution of a function being executied.
+ */
+
+ finish: function() {
+ this.callback(this);
+ this.done = true;
+ }
+
+}
View
19 node_modules/support/proper_path.js
@@ -0,0 +1,19 @@
+module.exports = function (resource_path) {
+ // console.log('proper_path - pathing %s', resource_path);
+ if ((resource_path == '') || (resource_path == '/')){
+ // console.log('root %s returning "/"', resource_path);
+ return '/';
+ }
+ if (resource_path.substring(0, 1) != '/') { // insisting on first "/" being present
+ resource_path = '/' + resource_path;
+ }
+
+ if (resource_path.substr(-1) == '/') { // insisting on NOT ending in "/";
+ // console.log('removing trailing "/" from %s', resource_path);
+ resource_path = resource_path.substring(0, resource_path.length - 1);
+ }
+
+ // console.log('proper_path - pathing returning %s', resource_path);
+
+ return resource_path;
+}
View
147 node_modules/support/simple_model.js
@@ -0,0 +1,147 @@
+var _ = require('underscore');
+var util = require('util');
+
+/**
+ * This model is intending for testing server systems before the remote repo is added,
+ * or for unit testing.
+ * @param config
+ * @param data
+ * @constructor
+ */
+function MockModel(config, data) {
+ var self = this;
+
+ if (config) {
+ _.extend(self, config);
+ }
+
+ this.repo = [];
+ this.index = {};
+
+ if (data) {
+ data.forEach(function (item) {
+ self.put(item, function () {
+ });
+ });
+ }
+
+}
+
+MockModel.prototype = {
+
+ all:function (callback) {
+ callback(null, this.repo.slice(0));
+ },
+
+ count:function (callback) {
+ // console.log('counting records');
+ callback(null, this.repo.length);
+ },
+
+ del:function (id, callback) {
+ var self = this;
+ if (self.index.hasOwnProperty(id)) {
+ var outed = self.index[id];
+ delete self.index[id];
+ self.repo = _.reject(self.repo, function (n) {
+ var nid = n[self.key];
+
+ // console.log('test: key %s == %s', nid, id);
+ return nid == id;
+ });
+
+ // console.log('repo afer del: %s', util.inspect(this.repo));
+
+ callback(null, outed);
+ } else {
+ callback(new Error('cannot delete ' + id + '; no record found'));
+ }
+ },
+
+ get:function (id, callback) {
+ if (this.index.hasOwnProperty(id)) {
+ callback(null, this.index[id]);
+ } else {
+ callback(new Error('cannot find key ' + id));
+ }
+ },
+
+ find:function (what, callback, sort) {
+ var self = this;
+ var out = [];
+ if (typeof what == 'function') {
+ f = what;
+ } else {
+ f = function (n) {
+ for (p in what) {
+ var pvalue = what[p];
+
+ if (!n.hasOwnProperty(p)) {
+ return false;
+ } else if (n[p] != pvalue) {
+ return false;
+ }
+
+ }
+ return true;
+ }
+ }
+
+ out = _.filter(self.repo, f);
+ if (sort) {
+ return _.sortBy(out, sort);
+ } else {
+ return out;
+ }
+ },
+
+ key:'id',
+
+ next_key:function () {
+ var self = this;
+ var id = 0;
+
+
+ this.repo.forEach(function (obj) {
+ var oid = obj[self.key];
+ // console.log('next_key == %s', oid);
+ if (oid > id) {
+ id = oid;
+ }
+ });
+
+ // console.log('next_key: returning %s', id);
+ return id + 1;
+ },
+
+ put:function (obj, callback) {
+ var self = this;
+
+ if (_.isObject(obj)) {
+ if (obj.hasOwnProperty(self.key)) {
+ obj[self.key] = parseInt(obj[self.key]);
+ self.repo = _.reject(self.repo, function (item) {
+ if (!item.hasOwnProperty(self.key)) {
+ return false;
+ }
+
+ return item[self.key] == obj[self.key]
+ })// done cleaning out old object
+ } else {
+ obj[self.key] = self.next_key();
+ }
+
+ self.repo.push(obj);
+ self.index[obj[self.key]] = obj;
+
+ if (callback) {
+ callback(null, obj);
+ }
+
+ }
+
+ }
+
+}
+
+module.exports = MockModel;
View
100 node_modules/support/stat.js
@@ -0,0 +1,100 @@
+var _ = require('underscore');
+var util = require('util');
+
+module.exports = function (numbers) {
+ this.numArr = numbers;
+}
+
+module.exports.prototype = {
+ _dec:function (num, numOfDec) {
+ var pow10s = Math.pow(10, numOfDec || 0);
+ return (numOfDec) ? Math.round(pow10s * num) / pow10s : num;
+ },
+
+ set_data:function (d) {
+ this.numArr = d;
+ },
+
+ avg:function (numOfDec) {
+ if (!_.isArray(this.numArr)) {
+ return false;
+ }
+ var i = this.numArr.length,
+ sum = 0;
+ while (i--) {
+ sum += this.numArr[i];
+ }
+
+ var avg = (sum / this.numArr.length);
+ return arguments.length ? this._dec(avg, numOfDec) : avg;
+ },
+
+ variance:function (numOfDec) {
+ if (!_.isArray(this.numArr)) {
+ return false;
+ }
+ var avg = this.avg(numOfDec),
+ i = this.numArr.length,
+ v = 0;
+
+ while (i--) {
+ v += Math.pow((this.numArr[i] - avg), 2);
+ }
+
+ v /= this.numArr.length;
+ return arguments.length ? this._dec(v, numOfDec) : v;
+ },
+
+ std_dev:function (numOfDec) {
+ var stdDev = Math.sqrt(this.variance(numOfDec));
+ return arguments.length ? this._dec(stdDev, numOfDec) : stdDev;
+ },
+
+ med_ratio:function (ratio) {
+ var end_count = Math.max(1, Math.ceil(this.numArr.length * ratio));
+
+ var dists = [];
+ var last_dist = false;
+ var dist;
+ var sorted = _.sortBy(this.numArr, function (v) {
+ return v;
+ });
+
+ // console.log('sorted dists: %s', util.inspect(sorted));
+
+ sorted.forEach(function (v) {
+ dists.push({value:v, last_gap: -1, next_gap: -1});
+ })
+
+ dists.forEach(function(dist, i){
+ if (i > 0){
+ var last_dist = dists[i - 1];
+ last_dist.next_gap = dist.value - last_dist.value;
+ dist.last_gap = last_dist.next_gap;
+ }
+ })
+
+ dists.forEach(function (dist) {
+ if (dist.last_gap == -1){
+ dist.gap = 2 * dist.next_gap;
+ } else if (dist.next_gap == -1){
+ dist.gap = 2 * dist.last_gap;
+ } else {
+ dist.gap = (dist.last_gap + dist.next_gap);
+ }
+ })
+
+ dists = _.sortBy(dists, function (dist) {
+ return dist.gap;
+ });
+
+ var sum = 0;
+
+ var slice = dists.slice(0, end_count);
+ // console.log('gap rated dists: %s', util.inspect(slice));
+ slice.forEach(function(d){ sum += d.value;});
+
+
+ return sum / (1.0 * end_count);
+ }
+}
View
56 node_modules/support/wstat.js
@@ -0,0 +1,56 @@
+var _ = require('underscore');
+var util = require('util');
+
+function Wstat(params){
+ this.weight = 'weight';
+ this.value = 'value';
+ _.extend(this, params);
+ _.defaults(this, {values: []});
+}
+
+module.exports = Wstat;
+
+Wstat.prototype = {
+
+ w_avg: function(){
+
+ var weights = 0;
+ var sum = 0;
+ var self = this;
+
+ this.values.forEach(function(item){
+ var value = 0;
+ var weight = 1;
+ if (item.hasOwnProperty(self.value)){
+ value = item[self.value];
+ };
+
+ if (item.hasOwnProperty(self.weight)){
+ weight = item[self.weight];
+ }
+
+ if (isNaN(value) || isNaN(weight) || (!isFinite(value)) || (!isFinite(weight))){
+ return;
+ }
+
+ if (weight <= 0){
+ return;
+ }
+
+ weights += weight;
+ sum += value * weight;
+ });
+
+ if (weights <= 0){
+ return 0;
+ }
+ var out = sum / weights;
+ if (isNaN(out) || (!isFinite(out))){
+ console.log('w_avg isNaN: %s', util.inspect(this.values));
+ return 0;
+ }
+ return out;
+ }
+
+
+}
View
8 package.json
@@ -20,7 +20,13 @@
"engines": {
"node": ">=0.6.0"
},
- "dependencies": {},
+ "dependencies": {
+ "ejs": "~3.0.0",
+ "mongoose": "~2.6.0",
+ "request": "~2.9.202",
+ "underscore": ">=1.2.3",
+ "support": ">=1.0.0"
+ },
"devDependencies": {},
"homepage": "https://github.com/bingomanatee/nuby-express/wiki",
"scripts": {
View
2  test_resources/Mongoose_Model_test/app/resources/model/model_folks.js
@@ -1,4 +1,4 @@
-var Mongoose_Model = require("node-support/mongoose_model");
+var Mongoose_Model = require("support/mongoose_model");
var NE = require('./../../../../../lib');
var util = require('util');
var _ = require('underscore');
View
2  test_resources/REST_test/app/resources/model/model_folks.js
@@ -1,4 +1,4 @@
-var Mongoose_Model = require("node-support/mongoose_model");
+var Mongoose_Model = require("support/mongoose_model");
var NE = require('./../../../../../lib');
var util = require('util');
var _ = require('underscore');
View
2  test_resources/Resources_Test/app/resources/model/model_widgets.js
@@ -1,4 +1,4 @@
-var Simple_Model = require("node-support/simple_model");
+var Simple_Model = require("support/simple_model");
var NE = require('./../../../../../lib');
var util = require('util');
var _ = require('underscore');
Please sign in to comment.
Something went wrong with that request. Please try again.