dasf-web
Version:
Web frontend components for the data analytics software framework (DASF)
89 lines (72 loc) • 2.25 kB
text/typescript
import { JsonProperty, JsonObject } from "json2typescript";
import { DateConverter, VersionConverter } from "./JsonSerializeHelper";
("DateValuePair")
export class DateValuePair {
("date", DateConverter)
public date: Date = new Date();
("field", Number)
public field: Number = -1;
public constructor(date?: Date, field?: Number) {
this.date = date || new Date();
this.field = field || 0;
}
}
("Header")
export class Header {
("name", String)
public name: string;
("unit", String)
public unit: string;
public constructor(name?: string, unit?: string) {
this.name = name || "";
this.unit = unit || "";
}
}
("Timeseries")
export class Timeseries {
("gid", Number, true)
public gid: number = 0;
("data", [DateValuePair])
public data: DateValuePair[] = [];
("header", Header)
public header: Header = new Header();
("version", VersionConverter)
public version: string = "0";
/**
* Returns the minimum and maximum value of this time-series
*/
public getValueBounds(): [number, number] {
let min = Number.MAX_VALUE;
let max = -Number.MAX_VALUE;
for (let pair of this.data) {
min = Math.min(pair.field.valueOf(), min);
max = Math.max(pair.field.valueOf(), max);
}
return [min, max];
}
/**
* Return the minimum and maximum date of the time-series
*/
public getDateBounds(): [Date, Date] {
let min = this.data[0].date;
let max = min;
for (let pair of this.data) {
if (min > pair.date) {
min = pair.date;
}
if (max < pair.date) {
max = pair.date;
}
}
return [min, max];
}
public getSubsection(startDate: Date, endDate: Date): DateValuePair[] {
let slice: DateValuePair[] = [];
for (let e of this.data) {
if (e.date >= startDate && e.date <= endDate) {
slice.push(e);
}
}
return slice;
}
}