Skip to content

Commit

Permalink
Added the ability to clear away measurements without changing the mea…
Browse files Browse the repository at this point in the history
…sure or calibrate status.
  • Loading branch information
cfreeman committed May 9, 2018
1 parent 4331579 commit a1f53b6
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 40 deletions.
56 changes: 35 additions & 21 deletions controllers/scout.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,40 @@ func GetScout(db *sql.DB, c echo.Context) error {
return c.JSON(http.StatusOK, s)
}

func ClearMeasurements(db *sql.DB, c echo.Context) error {
s, err := models.GetScoutByUUID(db, c.Param("uuid"))
if err != nil {
return err
}

err = models.DeleteScoutHealths(db, s.UUID)
if err != nil {
return err
}

err = models.DeleteScoutInteractions(db, s.UUID)
if err != nil {
return err
}

err = models.DeleteScoutLogs(db, s.UUID)
if err != nil {
return err
}

ss, err := models.GetScoutSummaryByUUID(db, s.UUID)
if err != nil {
return err
}

err = ss.Clear(db)
if err != nil {
return err
}

return c.JSON(http.StatusOK, s)
}

func UpdateScout(db *sql.DB, c echo.Context, deltaC chan models.Command) error {
body, err := ioutil.ReadAll(c.Request().Body)
if err != nil {
Expand All @@ -164,27 +198,7 @@ func UpdateScout(db *sql.DB, c echo.Context, deltaC chan models.Command) error {
if !ns.Authorised {
ns.State = models.IDLE

err = models.DeleteScoutHealths(db, ns.UUID)
if err != nil {
return err
}

err = models.DeleteScoutInteractions(db, ns.UUID)
if err != nil {
return err
}

err = models.DeleteScoutLogs(db, ns.UUID)
if err != nil {
return err
}

ss, err := models.GetScoutSummaryByUUID(db, ns.UUID)
if err != nil {
return err
}

err = ss.Clear(db)
err = ClearMeasurements(db, c)
if err != nil {
return err
}
Expand Down
24 changes: 22 additions & 2 deletions frontend/src/components/primaryActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"use strict;"

import React from 'react';
import { UpdateActiveLocation, ActiveLocation } from '../reducers/index.js';
import { UpdateActiveLocation, ActiveLocation, ClearMeasurements } from '../reducers/index.js';

var DeactivateAction = React.createClass({
handleDeactivate: function() {
Expand Down Expand Up @@ -137,17 +137,37 @@ SettingsAction.contextTypes = {
store: React.PropTypes.object
};

var ClearAction = React.createClass({
handleClear: function() {
const { store } = this.context;
ClearMeasurements(store);
//store.dispatch({ type:'CLEAR_MEASUREMENTS' });
},

render: function() {
return (
<a id="settings" href="#" className="warning" onClick={this.handleClear}>[<i className="fa fa-times"></i> clear measurements]</a>
);
}
});
ClearAction.contextTypes = {
store: React.PropTypes.object
};

var PrimaryActions = React.createClass({
render: function() {
const { store } = this.context;
console.log(ActiveLocation(store).authorised);
console.log(ActiveLocation(store).state);
var onOff = (ActiveLocation(store).authorised ? <DeactivateAction /> : <ActivateAction />);
var calibrate = ((ActiveLocation(store).authorised && (ActiveLocation(store).state == 'idle' || ActiveLocation(store).state == 'calibrated')) ? <CalibrateAction /> : "");
var measure = ((ActiveLocation(store).authorised && ActiveLocation(store).state == 'calibrated') ? <MeasureAction /> : "");
var edit = (store.getState().editLocation ? <SaveAction /> : <EditAction />);
var settings = <SettingsAction />;
var clearMeasurements = ((ActiveLocation(store).authorised && ActiveLocation(store).state == 'measuring') ? <ClearAction /> : "");

return (
<p className="location-meta">{onOff} {calibrate} {measure} {edit} {settings}</p>
<p className="location-meta">{onOff} {calibrate} {measure} {clearMeasurements} {edit} {settings}</p>
);
}
});
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ function GetLocations(store) {
}
}

function ClearMeasurements(store) {
var state = store.getState();
var l = Object.assign({}, state.locations[state.active]);

var httpreq = new XMLHttpRequest();
httpreq.open("GET", "http://"+window.location.host+"/scouts/"+l.uuid+"/clearMeasurements", true);
httpreq.send(null);
httpreq.onreadystatechange = function() {
if (httpreq.readyState == 4 && httpreq.status == 200) {
var locations = JSON.parse(httpreq.responseText)
store.dispatch({ type:'UPDATE_LOCATIONS', locations:locations})
}
}
}

function SaveActiveLocation(store) {
var state = store.getState();

Expand Down Expand Up @@ -125,4 +140,4 @@ function Mothership(state, action) {
}
}

export { Mothership, GetLocations, ActiveLocation, UpdateActiveLocation, SaveActiveLocation }
export { Mothership, GetLocations, ActiveLocation, UpdateActiveLocation, ClearMeasurements, SaveActiveLocation }
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func main() {
return controllers.UpdateScout(db, c, deltaC)
})

e.GET("/scouts/:uuid/clearMeasurements", func(c echo.Context) error {
log.Printf("clearing meaasurements")
return controllers.ClearMeasurements(db, c)
})

e.GET("/download.zip", func(c echo.Context) error {
return controllers.DownloadData(db, c)
})
Expand Down
37 changes: 21 additions & 16 deletions processes/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func measure(db *sql.DB, deltaC chan models.Command, videoFile string, debug boo
calFile := C.CString("calibrationFrame.jpg")

success := C.startMeasure(srcFile, calFile,
C.int(configuration.FrameW), C.int(configuration.FrameH),
C.int(s.MogHistoryLength), C.double(s.MogThreshold), C.int(s.MogDetectShadows))
C.int(configuration.FrameW), C.int(configuration.FrameH),
C.int(s.MogHistoryLength), C.double(s.MogThreshold), C.int(s.MogDetectShadows))

C.free(unsafe.Pointer(srcFile))
C.free(unsafe.Pointer(calFile))
Expand All @@ -145,7 +145,6 @@ func measure(db *sql.DB, deltaC chan models.Command, videoFile string, debug boo
log.Printf("ERROR: Unable to get video source")
return
}
defer C.stopMeasure()

// Make sure we release the camera when the operating system crushes us.
c := make(chan os.Signal, 1)
Expand All @@ -159,8 +158,6 @@ func measure(db *sql.DB, deltaC chan models.Command, videoFile string, debug boo

scene := models.InitScene(s)

// Current frame counter.
//frame := int64(0)
measuring := true

// Start monitoring from the camera.
Expand All @@ -171,6 +168,13 @@ func measure(db *sql.DB, deltaC chan models.Command, videoFile string, debug boo
switch {
case c == models.STOP_MEASURE:
log.Printf("INFO: Stopping measure")

// Delete the hidden file to indicate that measuring has stopped across reboots.
err := os.Remove(".mtf-measure")
if err != nil && os.IsNotExist(err) {
log.Printf("ERROR: Unable to remove .mtf-measure file")
log.Print(err)
}
measuring = false
}

Expand All @@ -180,21 +184,21 @@ func measure(db *sql.DB, deltaC chan models.Command, videoFile string, debug boo

numObjects := C.int(0)
objects := C.grabFrame(&numObjects,
C._Bool(debug),
C.double(s.GaussianSmooth),
C.double(s.ForegroundThresh),
C.int(s.DilationIterations),
C.double(s.MinArea),
C.double(s.MaxArea))
o := (*[1<<30]C.int)(unsafe.Pointer(objects))
C._Bool(debug),
C.double(s.GaussianSmooth),
C.double(s.ForegroundThresh),
C.int(s.DilationIterations),
C.double(s.MinArea),
C.double(s.MaxArea))
o := (*[1 << 30]C.int)(unsafe.Pointer(objects))

var detectedObjects []models.Waypoint
for i := C.int(0); i < numObjects; i = i + 4 {
detectedObjects = append(detectedObjects,
models.Waypoint{int(o[i]),
int(o[i + 1]),
int(o[i + 2]),
int(o[i + 3]), 0.0})
models.Waypoint{int(o[i]),
int(o[i+1]),
int(o[i+2]),
int(o[i+3]), 0.0})
}

C.free(unsafe.Pointer(objects))
Expand Down Expand Up @@ -245,4 +249,5 @@ func measure(db *sql.DB, deltaC chan models.Command, videoFile string, debug boo

log.Printf("INFO: Finished measure")
scene.Close(db)
C.stopMeasure()
}

0 comments on commit a1f53b6

Please sign in to comment.