-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Stats type, so values exist for all members even when populated…
… by a sparse result
- Loading branch information
1 parent
4b909a3
commit 16c1515
Showing
5 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var Stats = (function() { | ||
|
||
function MessageCount(values) { | ||
this.count = (values && values.count) || 0; | ||
this.data = (values && values.data) || 0; | ||
} | ||
|
||
function ResourceCount(values) { | ||
this.peak = (values && values.peak) || 0; | ||
this.min = (values && values.min) || 0; | ||
this.mean = (values && values.mean) || 0; | ||
this.opened = (values && values.opened) || 0; | ||
this.refused = (values && values.refused) || 0; | ||
} | ||
|
||
function RequestCount(values) { | ||
this.succeeded = (values && values.succeeded) || 0; | ||
this.failed = (values && values.failed) || 0; | ||
this.refused = (values && values.refused) || 0; | ||
} | ||
|
||
function ConnectionTypes(values) { | ||
this.plain = new ResourceCount(values && values.plain); | ||
this.tls = new ResourceCount(values && values.tls); | ||
this.all = new ResourceCount(values && values.all); | ||
} | ||
|
||
function MessageTypes(values) { | ||
this.messages = new MessageCount(values && values.messages); | ||
this.presence = new MessageCount(values && values.presence); | ||
this.all = new MessageCount(values && values.all); | ||
} | ||
|
||
function MessageTraffic(values) { | ||
this.realtime = new MessageTypes(values && values.realtime); | ||
this.rest = new MessageTypes(values && values.rest); | ||
this.webhook = new MessageTypes(values && values.webhook); | ||
this.all = new MessageTypes(values && values.all); | ||
} | ||
|
||
function Stats(values) { | ||
this.all = new MessageTypes(values && values.all); | ||
this.inbound = new MessageTraffic(values && values.inbound); | ||
this.outbound = new MessageTraffic(values && values.outbound); | ||
this.persisted = new MessageTypes(values && values.persisted); | ||
this.connections = new ConnectionTypes(values && values.connections); | ||
this.channels = new ResourceCount(values && values.channels); | ||
this.apiRequests = new RequestCount(values && values.apiRequests); | ||
this.tokenRequests = new RequestCount(values && values.tokenRequests); | ||
this.inProgress = (values && values.inProgress) || undefined; | ||
this.intervalId = (values && values.intervalId) || undefined; | ||
} | ||
|
||
Stats.fromValues = function(values) { | ||
return new Stats(values); | ||
}; | ||
|
||
return Stats; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16c1515
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks @paddybyers