@lightningkite/ktor-batteries
Version:
127 lines • 5 kB
JavaScript
"use strict";
// Package: com.lightningkite.ktordb
// Generated by Khrysalis - this file will be overwritten.
Object.defineProperty(exports, "__esModule", { value: true });
exports.xSequenceAggregate = exports.StandardDeviationPopulationAggregator = exports.StandardDeviationSampleAggregator = exports.AverageAggregator = exports.SumAggregator = exports.xAggregateAggregator = exports.Aggregate = void 0;
//! Declares com.lightningkite.ktordb.Aggregate
class Aggregate {
constructor(name, jsonName) {
this.name = name;
this.jsonName = jsonName;
}
static values() { return Aggregate._values; }
static valueOf(name) { return Aggregate[name]; }
toString() { return this.name; }
toJSON() { return this.jsonName; }
static fromJSON(key) { return Aggregate._values.find(x => x.jsonName.toLowerCase() === key.toLowerCase()); }
}
exports.Aggregate = Aggregate;
Aggregate.Sum = new Aggregate("Sum", "Sum");
Aggregate.Average = new Aggregate("Average", "Average");
Aggregate.StandardDeviationSample = new Aggregate("StandardDeviationSample", "StandardDeviationSample");
Aggregate.StandardDeviationPopulation = new Aggregate("StandardDeviationPopulation", "StandardDeviationPopulation");
Aggregate._values = [Aggregate.Sum, Aggregate.Average, Aggregate.StandardDeviationSample, Aggregate.StandardDeviationPopulation];
//! Declares com.lightningkite.ktordb.aggregator>com.lightningkite.ktordb.Aggregate
function xAggregateAggregator(this_) {
return (() => {
switch (this_) {
case Aggregate.Sum: {
return new SumAggregator();
}
case Aggregate.Average: {
return new AverageAggregator();
}
case Aggregate.StandardDeviationSample: {
return new StandardDeviationSampleAggregator();
}
case Aggregate.StandardDeviationPopulation: {
return new StandardDeviationPopulationAggregator();
}
default:
throw new Error("Exhaustive when turned out to not be so exhaustive.");
}
})();
}
exports.xAggregateAggregator = xAggregateAggregator;
//! Declares com.lightningkite.ktordb.SumAggregator
class SumAggregator {
constructor() {
this.current = 0.0;
this.anyFound = false;
}
consume(value) {
this.anyFound = true;
this.current = this.current + value;
}
complete() {
return this.anyFound ? this.current : null;
}
}
exports.SumAggregator = SumAggregator;
SumAggregator.implementsAggregator = true;
//! Declares com.lightningkite.ktordb.AverageAggregator
class AverageAggregator {
constructor() {
this.count = 0;
this.current = 0.0;
}
consume(value) {
this.count = this.count + 1;
this.current = this.current + (value - this.current) / this.count;
}
complete() {
return this.count === 0 ? null : this.current;
}
}
exports.AverageAggregator = AverageAggregator;
AverageAggregator.implementsAggregator = true;
//! Declares com.lightningkite.ktordb.StandardDeviationSampleAggregator
class StandardDeviationSampleAggregator {
constructor() {
this.count = 0;
this.mean = 0.0;
this.m2 = 0.0;
}
consume(value) {
this.count = this.count + 1;
const delta1 = value - this.mean;
this.mean = this.mean + (delta1) / this.count;
const delta2 = value - this.mean;
this.m2 = this.m2 + delta1 * delta2;
}
complete() {
return this.count < 2 ? null : Math.sqrt(this.m2 / (this.count - 1));
}
}
exports.StandardDeviationSampleAggregator = StandardDeviationSampleAggregator;
StandardDeviationSampleAggregator.implementsAggregator = true;
//! Declares com.lightningkite.ktordb.StandardDeviationPopulationAggregator
class StandardDeviationPopulationAggregator {
constructor() {
this.count = 0;
this.mean = 0.0;
this.m2 = 0.0;
}
consume(value) {
this.count = this.count + 1;
const delta1 = value - this.mean;
this.mean = this.mean + (delta1) / this.count;
const delta2 = value - this.mean;
this.m2 = this.m2 + delta1 * delta2;
}
complete() {
return this.count === 0 ? null : Math.sqrt(this.m2 / this.count);
}
}
exports.StandardDeviationPopulationAggregator = StandardDeviationPopulationAggregator;
StandardDeviationPopulationAggregator.implementsAggregator = true;
//! Declares com.lightningkite.ktordb.aggregate>kotlin.sequences.Sequencekotlin.Double
function xSequenceAggregate(this_, aggregate) {
const aggregator = xAggregateAggregator(aggregate);
for (const item of this_) {
aggregator.consume(item);
}
return aggregator.complete();
}
exports.xSequenceAggregate = xSequenceAggregate;
//# sourceMappingURL=Aggregate.js.map