Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
made jslint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
egorFiNE committed Jan 6, 2012
1 parent cea188b commit ad77b07
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 256 deletions.
36 changes: 21 additions & 15 deletions CandlesCalculator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
util = require('util');
/*jslint devel: false, node: true, sloppy: true, eqeq: true, es5: true, vars: true, white: true, nomen: true, plusplus: true, maxerr: 50, indent: 4 */

var
util = require('util'),
TickStorage = require('./TickStorage');

/**
Expand Down Expand Up @@ -50,7 +54,7 @@ function CandlesCalculator(tickStorage, periodSizeInMinutes) {
this._calculate();
}

CandlesCalculator.prototype._findOc = function(minute, openPos, closePos) {
CandlesCalculator.prototype._findOc = function(openPos, closePos) {
var i, tick;

var open=null, close=null, _openPos=null;
Expand Down Expand Up @@ -83,8 +87,8 @@ CandlesCalculator.prototype._findOc = function(minute, openPos, closePos) {
return {
o: open,
c: close
}
}
};
};

/**
Expand All @@ -100,7 +104,7 @@ CandlesCalculator.prototype.dumpMinutes = function(from, to) {
for (i=from;i<=to;i++) {
console.log("%d: %s", i, util.inspect(this._calculatedMinuteIndex[i]));
}
}
};

/**
Expand All @@ -116,7 +120,7 @@ CandlesCalculator.prototype.dumpCandles = function(from, to) {
for (i=from;i<=to;i+=this.periodSize) {
console.log("%d: %s", i, util.inspect(this.candles[i]));
}
}
};

/**
Expand All @@ -130,15 +134,15 @@ Get calculated candle.

CandlesCalculator.prototype.getCandle = function(minute) {
return this.candles[minute] || null;
}
};

CandlesCalculator.prototype._calculate = function() {
var i;
for(i=this.periodSize;i<=1440;i+=this.periodSize) {
this.candles[i] = this._calculatePeriod(i);
CandlesCalculator._setCandleHourMinute(this.candles[i], i);
}
}
};

CandlesCalculator.prototype._calculatePeriod = function(period) {
var open=0, close=0, high=Number.MIN_VALUE, low=Number.MAX_VALUE, volume=0, ticks=0;
Expand Down Expand Up @@ -169,11 +173,11 @@ CandlesCalculator.prototype._calculatePeriod = function(period) {
c: close,
v: volume,
t: ticks
}
};
} else {
return null;
}
}
};

CandlesCalculator.prototype._calculateMinutes = function() {
var _newMinuteIndex=[];
Expand All @@ -189,7 +193,7 @@ CandlesCalculator.prototype._calculateMinutes = function() {

var minute = this._tickStorage.minuteIndex.index[m];
if (minute) {
var oc = this._findOc(m, minute.o, minute.c);
var oc = this._findOc(minute.o, minute.c);
if (oc) {
_newMinuteIndex[m].h=minute.h;
_newMinuteIndex[m].l=minute.l;
Expand All @@ -202,7 +206,7 @@ CandlesCalculator.prototype._calculateMinutes = function() {
}

this._calculatedMinuteIndex = _newMinuteIndex;
}
};

CandlesCalculator._setCandleHourMinute = function(candle, minute) {
if (candle) {
Expand All @@ -213,7 +217,7 @@ CandlesCalculator._setCandleHourMinute = function(candle, minute) {
candle.minute = d.getMinutes();
candle.m = minute;
}
}
};

/**
Expand Down Expand Up @@ -256,7 +260,7 @@ CandlesCalculator.getCandlesOfTickStorage = function(tickStorage, period, from,
}

return _result;
}
};

/**
Expand All @@ -279,7 +283,9 @@ CandlesCalculator.getCandles = function(dbPath, symbol, daystamp, period, from,
}

return CandlesCalculator.getCandlesOfTickStorage(tickStorage, period, from, to);
}
};


module.exports = CandlesCalculator;


32 changes: 16 additions & 16 deletions ExtraDate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require('date-utils');

function _zeroStrip(s) {
return s.toString().replace(/^0+/, '');
}

/**
Various date methods useful for stock trading.
Expand All @@ -16,7 +20,7 @@ be specified both in string or integer and all the methods and functions must ac
// trick doc.js into thinking that we have declared the Date class.
/*
function Date() {
}
};
*/

/**
Expand All @@ -38,7 +42,7 @@ Date.parseDaystamp = function(daystamp) {

m--;
return new Date(y,m,d);
}
};

/**
Expand All @@ -50,7 +54,7 @@ Return daystamp representation of a Date.

Date.prototype.daystamp = function() {
return this.toFormat('YYYYMMDD');
}
};

/**
Expand All @@ -64,7 +68,7 @@ Parse unixtime into Date. It's a factory method.

Date.parseUnixtime = function(unixtime) {
return new Date(unixtime*1000);
}
};

/**
Expand All @@ -75,8 +79,8 @@ Return unixtime representation of a Date.
*/

Date.prototype.unixtime = function() {
return this.getTime()/1000 >> 0;
}
return parseInt(this.getTime()/1000);
};

/**
Expand All @@ -88,7 +92,7 @@ Return current unixtime.

Date.unixtime = function() {
return new Date().unixtime();
}
};

/**
Expand Down Expand Up @@ -142,7 +146,7 @@ Date.fillEmptyDays = function(from, to) {
}

return result;
}
};

/**
Expand All @@ -154,7 +158,7 @@ Get short human readable day name for given Date, like "Sun", "Mon", ...

Date.prototype.getDayName = function() {
return ['Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun'][this.getDay()];
}
};

/**
Expand All @@ -169,7 +173,7 @@ Date.prototype.setCurrentDayMinute = function(minute) {
var hours = Math.floor(minute/60);
var minutes = minute-hours*60;
this.setHours(hours, minutes, 0, 0);
}
};

/**
Expand All @@ -182,7 +186,7 @@ e.g. 570 for 9:30.

Date.prototype.getCurrentDayMinute = function() {
return this.getHours()*60 + this.getMinutes();
}
};

/**
Expand All @@ -203,9 +207,5 @@ Date.minuteToFormat = function(minute, format) {
var d = new Date();
d.setCurrentDayMinute(minute);
return d.toFormat(format);
}

function _zeroStrip(s) {
return s.toString().replace(/^0+/, '');
}
};

29 changes: 8 additions & 21 deletions ExtraLog.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
require('./ExtraNumber');
require('./ExtraDate');
var util = require('util');

/**
Actually it's a printf substitute with support for prices and unixtimes. Contains two functions.
*/

// trick doc.js into thinking that we have declared the class.
/*
function ExtraLog() {
}
*/

ExtraLog = {};
function ExtraLog() {}

var formatRegExp = /%[sdjpTD%]/g;

Expand All @@ -33,19 +28,11 @@ Example:
*/

ExtraLog.format = function(f) {
if (typeof f !== 'string') {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
}
return objects.join(' ');
}

var i = 1;
var i=1, x;
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function(x) {
if (i >= len) return x;
if (i >= len) { return x; }
switch (x) {
case '%D':return Date.parseUnixtime(args[i++]).toFormat('YYYYMMDD');
case '%T':return Date.parseUnixtime(args[i++]).toFormat('HH24:MI:SS');
Expand All @@ -58,15 +45,15 @@ ExtraLog.format = function(f) {
return x;
}
});
for (var x = args[i]; i < len; x = args[++i]) {
for (x = args[i]; i < len; x = args[++i]) {
if (x === null || typeof x !== 'object') {
str += ' ' + x;
} else {
str += ' ' + inspect(x);
str += ' ' + util.inspect(x);
}
}
return str;
}
};

/**
Expand All @@ -76,7 +63,7 @@ Similar to <code>console.log</code> but uses <code>ExtraLog.format()</code>.

ExtraLog.log = function() {
process.stdout.write(ExtraLog.format.apply(this, arguments) + '\n');
}
};

module.exports = {
format: ExtraLog.format,
Expand Down
10 changes: 5 additions & 5 deletions ExtraNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Example:
*/
Number.prototype.humanReadablePrice = function() {
return (this/10000).toFixed(2);
}
};

/**
Expand All @@ -47,8 +47,8 @@ Number.prototype.pad = function(length) {
return _num;
}

return (Array(length).join('0') + this).slice(-length);
}
return (new Array(length).join('0') + this).slice(-length);
};

/**
Expand All @@ -75,5 +75,5 @@ Number.prototype.humanReadableOrder = function() {
return (this/1000).toFixed(1)+'k';
}

return this+'';
}
return this.toString();
};
Loading

0 comments on commit ad77b07

Please sign in to comment.