@@ -47,6 +47,49 @@ function HbaseClient() {
47
47
HbaseClient . prototype = Object . create ( Hbase . prototype ) ;
48
48
HbaseClient . prototype . constructor = HbaseClient ;
49
49
50
+ /**
51
+ * getCapitalization
52
+ */
53
+
54
+ HbaseClient . prototype . getCapitalization = function ( options , callback ) {
55
+ var base = options . currency + '|' + options . issuer ;
56
+ var startRow = base + '|' + utils . formatTime ( options . start ) ;
57
+ var endRow = base + '|' + utils . formatTime ( options . end ) ;
58
+ var column ;
59
+
60
+ if ( options . adjustedChanges ) {
61
+ column = 'hotwallet_adj_balancesowed' ;
62
+ } else if ( options . changes ) {
63
+ column = 'issuer_balance_changes' ;
64
+ } else if ( options . adjusted ) {
65
+ column = 'cummulative_hotwallet_adj_balancesowed' ;
66
+ } else {
67
+ column = 'cummulative_issuer_balance_changes' ;
68
+ }
69
+
70
+ this . getScanWithMarker ( this , {
71
+ table : 'issuer_balance_snapshot' ,
72
+ startRow : startRow ,
73
+ stopRow : endRow ,
74
+ limit : options . limit || Infinity ,
75
+ descending : options . descending ,
76
+ marker : options . marker ,
77
+ columns : [ 'd:' + column ]
78
+ } , function ( err , resp ) {
79
+ if ( resp && resp . rows ) {
80
+ resp . rows . forEach ( function ( row , i ) {
81
+ var parts = row . rowkey . split ( '|' ) ;
82
+ resp . rows [ i ] = {
83
+ date : utils . unformatTime ( parts [ 2 ] ) . format ( ) ,
84
+ amount : 0 - Number ( row [ column ] )
85
+ } ;
86
+ } ) ;
87
+
88
+ callback ( err , resp ) ;
89
+ }
90
+ } ) ;
91
+ }
92
+
50
93
/**
51
94
* getStats
52
95
*/
@@ -192,26 +235,51 @@ HbaseClient.prototype.getStatsRow = function(options) {
192
235
*/
193
236
194
237
HbaseClient . prototype . getPayments = function ( options , callback ) {
195
- var table = 'payments' ;
196
- var startRow = utils . formatTime ( options . start ) ;
197
- var endRow = utils . formatTime ( options . end ) ;
198
238
var filters = [ ] ;
199
239
var filterString ;
240
+ var table ;
241
+ var startRow ;
242
+ var endRow ;
200
243
201
- if ( options . currency ) {
202
- filters . push ( {
203
- qualifier : 'currency' ,
204
- value : options . currency ,
205
- family : 'f' , comparator : '='
206
- } ) ;
207
- }
244
+ if ( options . interval ) {
245
+ table = 'agg_payments' ;
246
+ startRow = options . interval +
247
+ '|' + options . currency +
248
+ '|' + ( options . issuer || '' ) +
249
+ '|' + utils . formatTime ( options . start ) ;
250
+ endRow = options . interval +
251
+ '|' + options . currency +
252
+ '|' + ( options . issuer || '' ) +
253
+ '|' + utils . formatTime ( options . end ) ;
208
254
209
- if ( options . issuer ) {
210
- filters . push ( {
211
- qualifier : 'issuer' ,
212
- value : options . issuer ,
213
- family : 'f' , comparator : '='
214
- } ) ;
255
+ } else {
256
+ table = 'payments' ;
257
+ startRow = utils . formatTime ( options . start ) ;
258
+ endRow = utils . formatTime ( options . end ) ;
259
+
260
+ if ( options . currency ) {
261
+ filters . push ( {
262
+ qualifier : 'currency' ,
263
+ value : options . currency ,
264
+ family : 'f' , comparator : '='
265
+ } ) ;
266
+ }
267
+
268
+ if ( options . issuer ) {
269
+ filters . push ( {
270
+ qualifier : 'issuer' ,
271
+ value : options . issuer ,
272
+ family : 'f' , comparator : '='
273
+ } ) ;
274
+ }
275
+
276
+ if ( options . reduce ) {
277
+ options . columns = [
278
+ 'd:delivered_amount' ,
279
+ 'f:currency' ,
280
+ 'f:issuer'
281
+ ] ;
282
+ }
215
283
}
216
284
217
285
filterString = this . buildSingleColumnValueFilters ( filters ) ;
@@ -226,7 +294,40 @@ HbaseClient.prototype.getPayments = function(options, callback) {
226
294
filterString : filterString ,
227
295
columns : options . columns
228
296
} , function ( err , res ) {
229
- res . rows = formatPayments ( res . rows || [ ] ) ;
297
+ var amount ;
298
+
299
+ if ( options . interval ) {
300
+ if ( res && res . rows ) {
301
+ res . rows . forEach ( function ( row ) {
302
+ row . count = Number ( row . count ) ;
303
+ row . amount = Number ( row . amount ) ;
304
+ row . average = Number ( row . average ) ;
305
+ } ) ;
306
+ }
307
+
308
+ } else if ( options . reduce ) {
309
+ amount = 0 ;
310
+
311
+ if ( res && res . rows ) {
312
+ res . rows . forEach ( function ( row ) {
313
+ amount += Number ( row . delivered_amount ) ;
314
+ } ) ;
315
+
316
+ res = {
317
+ amount : amount ,
318
+ count : res . rows . length
319
+ } ;
320
+
321
+ } else {
322
+ res = {
323
+ amount : 0 ,
324
+ count : 0
325
+ } ;
326
+ }
327
+
328
+ } else {
329
+ res . rows = formatPayments ( res . rows || [ ] ) ;
330
+ }
230
331
callback ( err , res ) ;
231
332
} ) ;
232
333
@@ -474,6 +575,7 @@ HbaseClient.prototype.getAccountBalanceChanges = function (options, callback) {
474
575
stopRow : endRow ,
475
576
limit : options . limit ,
476
577
marker : options . marker ,
578
+ descending : options . descending ,
477
579
filterString : filterString
478
580
} , function ( err , res ) {
479
581
res . rows = formatChanges ( res . rows || [ ] ) ;
0 commit comments