Browse Source

analytic unit begin

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
5dbb372aea
  1. 19565
      client/package-lock.json
  2. 27
      client/src/components/hastic_pod/index.ts
  3. 49
      server/src/analytic_unit.rs
  4. 1
      server/src/main.rs

19565
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

27
client/src/components/hastic_pod/index.ts

@ -1,5 +1,6 @@
import { AxisRange } from "@chartwerk/core/dist/types";
import { LinePod, LineTimeSerie } from "@chartwerk/line-pod";
import { AxisRange } from "@chartwerk/core/dist/types";
import { BrushOrientation } from "@chartwerk/core";
import { SegmentsSet } from "@/types/segment_set";
import { ANALYTIC_UNIT_COLORS } from "@/types/colors"
import { Segment, SegmentId } from "@/types/segment";
@ -34,6 +35,14 @@ export class HasticPod extends LinePod {
) {
super(el, undefined, {
renderLegend: false,
zoomEvents: {
mouse: {
zoom: {
isActive: true,
orientation: BrushOrientation.HORIZONTAL
}
}
},
eventsCallbacks: {
zoomIn: range => { this._updateRange(range) },
zoomOut: ({x, y}) => { this._zoomOut({x, y}) },
@ -41,6 +50,8 @@ export class HasticPod extends LinePod {
}
});
console.log( BrushOrientation.VERTICAL);
this._csc = csc;
this._dsc = dsc;
this._ctrlKeyIsDown = false;
@ -73,7 +84,7 @@ export class HasticPod extends LinePod {
console.log('render my metrics');
}
protected fetchData() {
protected fetchData(): void {
let to = Math.floor(Date.now() / 1000);
let from = to - 5000; // -5000 seconds
@ -150,7 +161,7 @@ export class HasticPod extends LinePod {
}
}
protected async addSegment(from: number, to: number) {
protected async addSegment(from: number, to: number): Promise<void> {
const id = this.getNewTempSegmentId();
from = Math.floor(from);
to = Math.ceil(to);
@ -171,7 +182,7 @@ export class HasticPod extends LinePod {
// this.renderSegment(segment);
}
protected async deleteSegment(from: number, to: number) {
protected async deleteSegment(from: number, to: number): Promise<void> {
from = Math.floor(from);
to = Math.ceil(to);
@ -186,7 +197,7 @@ export class HasticPod extends LinePod {
}
protected renderSegments() {
protected renderSegments(): void {
const segments = this._segmentSet.getSegments();
this.segmentsContainer = this.metricContainer
.append('g')
@ -196,7 +207,7 @@ export class HasticPod extends LinePod {
}
}
protected renderSegment(segment: Segment) {
protected renderSegment(segment: Segment): void {
const x = this.xScale(segment.from);
const y = 0;
const w = this.xScale(segment.to) - x;
@ -220,11 +231,11 @@ export class HasticPod extends LinePod {
this.fetchData();
}
private _zoomOut({x, y}) {
private _zoomOut({x, y}): void {
this.fetchData();
}
protected updateSegments(segments: Segment[]) {
protected updateSegments(segments: Segment[]): void {
this._segmentSet.clear();
this._segmentSet.setSegments(segments);
this.renderSegments();

49
server/src/analytic_unit.rs

@ -0,0 +1,49 @@
use hastic::config::Config;
use hastic::services::data_service::Segment;
use hastic::services::metric_service::MetricService;
use anyhow;
use subbeat::metric::{Metric, MetricResult};
struct AnalyticUnit {
metric_service: MetricService
}
impl AnalyticUnit {
fn new(config: &Config) -> AnalyticUnit {
AnalyticUnit{
metric_service: MetricService::new(
&config.prom_url,
&config.query
)
}
}
pub async fn get_detections(&self, from: u64, to: u64) -> anyhow::Result<Vec<Segment>> {
let prom = self.metric_service.get_prom();
let mr = prom.query(from, to, 10).await?;
let key = mr.data.keys().nth(0).unwrap();
let ts = &mr.data[key];
let mut result = Vec::<Segment>::new();
let mut from: Option<u64> = None;
for (t, v) in ts {
if *v > 100.0 {
if from.is_some() {
continue;
} else {
from = Some(*t);
}
} else {
if from.is_some() {
result.push(Segment{ id: None, from: from.unwrap(), to: *t });
from = None;
}
}
}
Ok(result)
}
}

1
server/src/main.rs

@ -1,6 +1,7 @@
use anyhow;
mod api;
mod analytic_unit;
#[tokio::main]
async fn main() -> anyhow::Result<()> {

Loading…
Cancel
Save