Permalink
Browse files

made jslint happy

  • Loading branch information...
egorFiNE committed Jan 6, 2012
1 parent cea188b commit ad77b07a8e84679bf6658e9df72e34e66d0e2080
View
@@ -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');
/**
@@ -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;
@@ -83,8 +87,8 @@ CandlesCalculator.prototype._findOc = function(minute, openPos, closePos) {
return {
o: open,
c: close
- }
-}
+ };
+};
/**
@@ -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]));
}
-}
+};
/**
@@ -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]));
}
-}
+};
/**
@@ -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;
@@ -169,11 +173,11 @@ CandlesCalculator.prototype._calculatePeriod = function(period) {
c: close,
v: volume,
t: ticks
- }
+ };
} else {
return null;
}
-}
+};
CandlesCalculator.prototype._calculateMinutes = function() {
var _newMinuteIndex=[];
@@ -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;
@@ -202,7 +206,7 @@ CandlesCalculator.prototype._calculateMinutes = function() {
}
this._calculatedMinuteIndex = _newMinuteIndex;
-}
+};
CandlesCalculator._setCandleHourMinute = function(candle, minute) {
if (candle) {
@@ -213,7 +217,7 @@ CandlesCalculator._setCandleHourMinute = function(candle, minute) {
candle.minute = d.getMinutes();
candle.m = minute;
}
-}
+};
/**
@@ -256,7 +260,7 @@ CandlesCalculator.getCandlesOfTickStorage = function(tickStorage, period, from,
}
return _result;
-}
+};
/**
@@ -279,7 +283,9 @@ CandlesCalculator.getCandles = function(dbPath, symbol, daystamp, period, from,
}
return CandlesCalculator.getCandlesOfTickStorage(tickStorage, period, from, to);
-}
+};
module.exports = CandlesCalculator;
+
+
View
@@ -1,5 +1,9 @@
require('date-utils');
+function _zeroStrip(s) {
+ return s.toString().replace(/^0+/, '');
+}
+
/**
Various date methods useful for stock trading.
@@ -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() {
-}
+};
*/
/**
@@ -38,7 +42,7 @@ Date.parseDaystamp = function(daystamp) {
m--;
return new Date(y,m,d);
-}
+};
/**
@@ -50,7 +54,7 @@ Return daystamp representation of a Date.
Date.prototype.daystamp = function() {
return this.toFormat('YYYYMMDD');
-}
+};
/**
@@ -64,7 +68,7 @@ Parse unixtime into Date. It's a factory method.
Date.parseUnixtime = function(unixtime) {
return new Date(unixtime*1000);
-}
+};
/**
@@ -75,8 +79,8 @@ Return unixtime representation of a Date.
*/
Date.prototype.unixtime = function() {
- return this.getTime()/1000 >> 0;
-}
+ return parseInt(this.getTime()/1000);
+};
/**
@@ -88,7 +92,7 @@ Return current unixtime.
Date.unixtime = function() {
return new Date().unixtime();
-}
+};
/**
@@ -142,7 +146,7 @@ Date.fillEmptyDays = function(from, to) {
}
return result;
-}
+};
/**
@@ -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()];
-}
+};
/**
@@ -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);
-}
+};
/**
@@ -182,7 +186,7 @@ e.g. 570 for 9:30.
Date.prototype.getCurrentDayMinute = function() {
return this.getHours()*60 + this.getMinutes();
-}
+};
/**
@@ -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+/, '');
-}
+};
View
@@ -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;
@@ -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');
@@ -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;
-}
+};
/**
@@ -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,
View
@@ -25,7 +25,7 @@ Example:
*/
Number.prototype.humanReadablePrice = function() {
return (this/10000).toFixed(2);
-}
+};
/**
@@ -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);
+};
/**
@@ -75,5 +75,5 @@ Number.prototype.humanReadableOrder = function() {
return (this/1000).toFixed(1)+'k';
}
- return this+'';
-}
+ return this.toString();
+};
Oops, something went wrong.

0 comments on commit ad77b07

Please sign in to comment.