Browse Source

antilabel begin

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
532e6b5bb1
  1. 54
      client/src/components/hastic_pod/index.ts
  2. 3
      client/src/types/segment.ts
  3. 13
      server/src/services/segments_service.rs

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

@ -19,9 +19,11 @@ export class HasticPod extends LinePod {
private _csc: CreateSegmentCallback; private _csc: CreateSegmentCallback;
private _dsc: DeleteSegmentCallback; private _dsc: DeleteSegmentCallback;
private _ctrlKeyIsDown: boolean; private _aKeyIsDown: boolean;
private _sKeyIsDown: boolean;
private _dKeyIsDown: boolean; private _dKeyIsDown: boolean;
private _labelBrush: boolean; private _labelBrush: boolean;
private _antiLabelBrush: boolean;
private _deleteBrush: boolean; private _deleteBrush: boolean;
protected segmentsContainer; protected segmentsContainer;
@ -52,20 +54,31 @@ export class HasticPod extends LinePod {
this._csc = csc; this._csc = csc;
this._dsc = dsc; this._dsc = dsc;
this._ctrlKeyIsDown = false;
this._sKeyIsDown = false;
this._aKeyIsDown = false;
this._dKeyIsDown = false;
this._labelBrush = false; this._labelBrush = false;
this._antiLabelBrush = false;
window.addEventListener("keydown", e => { window.addEventListener("keydown", e => {
if(e.code == "ControlLeft") { if(e.code == "KeyA") {
this._ctrlKeyIsDown = true; this._aKeyIsDown = true;
}
if(e.code == "KeyS") {
this._sKeyIsDown = true;
} }
if(e.code == 'KeyD') { if(e.code == 'KeyD') {
this._dKeyIsDown = true; this._dKeyIsDown = true;
} }
}); });
window.addEventListener("keyup", (e) => { window.addEventListener("keyup", (e) => {
if(e.code == "ControlLeft") { if(e.code == "KeyA") {
this._ctrlKeyIsDown = false; this._aKeyIsDown = false;
}
if(e.code == "KeyS") {
this._sKeyIsDown = false;
} }
if(e.code == 'KeyD') { if(e.code == 'KeyD') {
this._dKeyIsDown = false; this._dKeyIsDown = false;
@ -114,14 +127,18 @@ export class HasticPod extends LinePod {
} }
protected onBrushStart(): void { protected onBrushStart(): void {
if(this._ctrlKeyIsDown) { if(this._sKeyIsDown) {
this._labelBrush = true; this._labelBrush = true;
this.svg.select('.selection') this.svg.select('.selection')
.attr('fill', 'red') .attr('fill', 'red');
} else if (this._aKeyIsDown) {
this._antiLabelBrush = true;
this.svg.select('.selection')
.attr('fill', 'blue');
} else if (this._dKeyIsDown) { } else if (this._dKeyIsDown) {
this._deleteBrush = true; this._deleteBrush = true;
this.svg.select('.selection') this.svg.select('.selection')
.attr('fill', 'blue') .attr('fill', 'darkgreen');
} }
// TODO: move to state // TODO: move to state
@ -134,7 +151,7 @@ export class HasticPod extends LinePod {
} }
protected onBrushEnd(): void { protected onBrushEnd(): void {
if(!this._labelBrush && !this._deleteBrush) { if(!this._labelBrush && !this._antiLabelBrush && !this._deleteBrush) {
super.onBrushEnd(); super.onBrushEnd();
} else { } else {
const extent = this.d3.event.selection; const extent = this.d3.event.selection;
@ -149,9 +166,13 @@ export class HasticPod extends LinePod {
const endTimestamp = this.xScale.invert(extent[1]); const endTimestamp = this.xScale.invert(extent[1]);
if(this._labelBrush) { if(this._labelBrush) {
this.addSegment(startTimestamp, endTimestamp); this.addSegment(startTimestamp, endTimestamp, SegmentType.LABEL);
this._labelBrush = false; this._labelBrush = false;
} }
if(this._antiLabelBrush) {
this.addSegment(startTimestamp, endTimestamp, SegmentType.ANTI_LABEL);
this._antiLabelBrush = false;
}
if(this._deleteBrush) { if(this._deleteBrush) {
this.deleteSegment(startTimestamp, endTimestamp); this.deleteSegment(startTimestamp, endTimestamp);
this._deleteBrush = false; this._deleteBrush = false;
@ -159,7 +180,7 @@ export class HasticPod extends LinePod {
} }
} }
protected async addSegment(from: number, to: number): Promise<void> { protected async addSegment(from: number, to: number, type: SegmentType): Promise<void> {
const id = this.getNewTempSegmentId(); const id = this.getNewTempSegmentId();
from = Math.floor(from); from = Math.floor(from);
to = Math.ceil(to); to = Math.ceil(to);
@ -170,7 +191,7 @@ export class HasticPod extends LinePod {
to = t; to = t;
} }
const segment = new Segment(id, from, to); const segment = new Segment(id, from, to, type);
//const storedId = //const storedId =
await this._csc(segment); await this._csc(segment);
this.fetchData(); this.fetchData();
@ -224,10 +245,13 @@ export class HasticPod extends LinePod {
.attr('fill', ANALYTIC_UNIT_COLORS[0]) .attr('fill', ANALYTIC_UNIT_COLORS[0])
.attr('opacity', '0.8') .attr('opacity', '0.8')
.attr('pointer-events', 'none') .attr('pointer-events', 'none')
if(segment.segmentType == SegmentType.LABEL) { if(segment.segmentType == SegmentType.LABEL || segment.segmentType == SegmentType.ANTI_LABEL) {
r.attr('style', 'stroke:rgb(0,0,0); stroke-width:2') r.attr('style', 'stroke:rgb(0,0,0); stroke-width:2')
} }
if(segment.segmentType == SegmentType.ANTI_LABEL) {
r.attr('fill', ANALYTIC_UNIT_COLORS[1])
}
} }
private async _updateRange(range: AxisRange[]) { private async _updateRange(range: AxisRange[]) {

3
client/src/types/segment.ts

@ -2,6 +2,7 @@ export type SegmentId = string;
export enum SegmentType { export enum SegmentType {
LABEL = 'Label', LABEL = 'Label',
ANTI_LABEL = 'AntiLabel',
DETECTION = 'Detection' DETECTION = 'Detection'
} }
@ -50,7 +51,7 @@ export class Segment {
id: this.id, id: this.id,
from: this.from, from: this.from,
to: this.to, to: this.to,
segment_type: 'Label' segment_type: this.segmentType
} }
} }

13
server/src/services/segments_service.rs

@ -12,14 +12,17 @@ pub type SegmentId = String;
// TODO: make logic with this enum shorter // TODO: make logic with this enum shorter
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum SegmentType { pub enum SegmentType {
Detection = 0,
Label = 1, Label = 1,
Detection = 2, AntiLabel = 2
} }
impl SegmentType { impl SegmentType {
fn from(u: u64) -> SegmentType { fn from(u: u64) -> SegmentType {
if u == 1 { if u == 1 {
SegmentType::Label SegmentType::Label
} else if u == 2 {
SegmentType::AntiLabel
} else { } else {
SegmentType::Detection SegmentType::Detection
} }
@ -28,8 +31,10 @@ impl SegmentType {
fn to_integer(&self) -> u64 { fn to_integer(&self) -> u64 {
if *self == SegmentType::Label { if *self == SegmentType::Label {
1 1
} else { } else if *self == SegmentType::AntiLabel {
2 2
} else {
0
} }
} }
} }
@ -125,9 +130,9 @@ impl SegmentsService {
let mut stmt = conn.prepare( let mut stmt = conn.prepare(
"SELECT id, start, end, segment_type "SELECT id, start, end, segment_type
FROM segment FROM segment
WHERE (start <= ?1 and ?1 <= end) OR WHERE (start <= ?1 and ?1 <= end) OR
(start <= ?2 AND ?2 <= end) OR (start <= ?2 AND ?2 <= end) OR
(?1 <= start AND start <= ?2) OR (?1 <= start AND start <= ?2) OR
(?1 <= end AND end <= ?2) ", (?1 <= end AND end <= ?2) ",
)?; )?;

Loading…
Cancel
Save