enhance(backend): improve chart engine
This commit is contained in:
parent
d95fafb5b3
commit
0be4e10462
36 changed files with 604 additions and 248 deletions
|
|
@ -1,69 +0,0 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
import Chart, { Obj, DeepPartial } from '../../core';
|
||||
import { SchemaType } from '@/misc/schema';
|
||||
import { name, schema } from '../schemas/test';
|
||||
|
||||
type TestLog = SchemaType<typeof schema>;
|
||||
|
||||
export default class TestChart extends Chart<TestLog> {
|
||||
public total = 0; // publicにするのはテストのため
|
||||
|
||||
constructor() {
|
||||
super(name, schema);
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected genNewLog(latest: TestLog): DeepPartial<TestLog> {
|
||||
return {
|
||||
foo: {
|
||||
total: latest.foo.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected aggregate(logs: TestLog[]): TestLog {
|
||||
return {
|
||||
foo: {
|
||||
total: logs[0].foo.total,
|
||||
inc: logs.reduce((a, b) => a + b.foo.inc, 0),
|
||||
dec: logs.reduce((a, b) => a + b.foo.dec, 0),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
protected async fetchActual(): Promise<DeepPartial<TestLog>> {
|
||||
return {
|
||||
foo: {
|
||||
total: this.total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async increment() {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = 1;
|
||||
update.inc = 1;
|
||||
this.total++;
|
||||
|
||||
await this.inc({
|
||||
foo: update,
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
public async decrement() {
|
||||
const update: Obj = {};
|
||||
|
||||
update.total = -1;
|
||||
update.dec = 1;
|
||||
this.total--;
|
||||
|
||||
await this.inc({
|
||||
foo: update,
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue