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

3
client/src/types/segment.ts

@ -2,6 +2,7 @@ export type SegmentId = string;
export enum SegmentType {
LABEL = 'Label',
ANTI_LABEL = 'AntiLabel',
DETECTION = 'Detection'
}
@ -50,7 +51,7 @@ export class Segment {
id: this.id,
from: this.from,
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
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum SegmentType {
Detection = 0,
Label = 1,
Detection = 2,
AntiLabel = 2
}
impl SegmentType {
fn from(u: u64) -> SegmentType {
if u == 1 {
SegmentType::Label
} else if u == 2 {
SegmentType::AntiLabel
} else {
SegmentType::Detection
}
@ -28,8 +31,10 @@ impl SegmentType {
fn to_integer(&self) -> u64 {
if *self == SegmentType::Label {
1
} else {
} else if *self == SegmentType::AntiLabel {
2
} else {
0
}
}
}
@ -125,9 +130,9 @@ impl SegmentsService {
let mut stmt = conn.prepare(
"SELECT id, start, end, segment_type
FROM segment
WHERE (start <= ?1 and ?1 <= end) OR
WHERE (start <= ?1 and ?1 <= 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) ",
)?;

Loading…
Cancel
Save