Skip to content

Commit

Permalink
EC Plate counting working
Browse files Browse the repository at this point in the history
  • Loading branch information
grassick committed Aug 7, 2013
1 parent 8346538 commit a92ab1b
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 24 deletions.
26 changes: 26 additions & 0 deletions app/js/forms/ECPlates.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Module that handles calling EC Compact Dry Plate automatic counting

exports.isAvailable = (success, error) ->
if window.OpenCVActivity?
window.OpenCVActivity.processList (list) =>
if _.contains(list, "ec-plate")
success(true)
else
success(false)
else
success(false)


exports.processImage = (imgUrl, success, error) ->
console.log "Processing image url: #{imgUrl}"
window.resolveLocalFileSystemURI imgUrl, (fileEntry) =>
fullPath = fileEntry.fullPath

# Handle bug in Cordova fullPath
if fullPath.match /^file:\/\//
fullPath = fullPath.substring(7)

console.log "Got image fullPath: #{fullPath}"
OpenCVActivity.process "ec-plate", [fullPath], "EC Compact Dry Plate Counter", (args) ->
success(args)
, @error
1 change: 1 addition & 0 deletions app/js/forms/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports.SourceQuestion = require './SourceQuestion'
exports.ImageQuestion = require './ImageQuestion'
exports.ImagesQuestion = require './ImagesQuestion'
exports.Instructions = require './Instructions'
exports.ECPlates = require './ECPlates'

# Must be created with model (backbone model) and contents (array of views)
exports.FormView = class FormView extends Backbone.View
Expand Down
20 changes: 19 additions & 1 deletion app/js/pages/SettingsPage.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Page = require "../Page"
ECPlates = require '../forms/ECPlates'

class SettingsPage extends Page
events:
"click #reset_db" : "resetDb"
"click #crash" : "crash"
"click #request_source_codes": "requestSourceCodes"

"click #test_ecplates" : "testECPlates"

activate: ->
@setTitle "Settings"
Expand All @@ -17,6 +18,12 @@ class SettingsPage extends Page
)
@$("#crash").toggle(@login? and @login.user == "admin")

# Show EC plates test if available
@$("#test_ecplates").hide()
ECPlates.isAvailable (available) =>
@$("#test_ecplates").show()
, @error

resetDb: ->
if confirm("Completely discard local data, logout and lose unsubmitted changes?")
localStorage.clear()
Expand All @@ -36,4 +43,15 @@ class SettingsPage extends Page
, ->
alert("Unable to contact server")

testECPlates: ->
# Get camera image
navigator.camera.getPicture (imgUrl) ->
ECPlates.processImage imgUrl, (args) =>
if args.error
res = "Error: " + args.error
else
res = "E.Coli: " + args.ecoli + "\nTC: " + args.tc + "\nAlgorithm: " + args.algorithm
alert res
, @error

module.exports = SettingsPage
6 changes: 5 additions & 1 deletion app/templates/pages/SettingsPage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@

<div>
<button id="crash" class="btn btn-danger" type="button">Crash!</button>
</div>
</div>

<div>
<button id="test_ecplates" class="btn" type="button">Test EC Compact Dry Plate Counter</button>
</div>
4 changes: 2 additions & 2 deletions forms/Aquagenx100PA/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "Aquagenx 100 mL Presence / Absence Bag Test",
"desc": "100 mL presence / absence test for E. coli",
"code": "Aquagenx100PA",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:49.869Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:09.862Z",
"on": "2013-08-07T02:46:09.198Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/ArsenicGeneric/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "Arsenic (generic method)",
"desc": "Any method for measuring arsenic in water",
"code": "ArsenicGeneric",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:50.050Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:10.514Z",
"on": "2013-08-07T02:46:10.180Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/ColilertMPN/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "Colilert MPN tube",
"desc": "10 mL presence / absence test for E. coli and total coliform",
"code": "ColilertMPN",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:50.289Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:11.134Z",
"on": "2013-08-07T02:46:11.454Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/CompactDryEC/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "Compact Dry EC Plate",
"desc": "1 mL direct count plate method for E. coli and total coliform",
"code": "CompactDryEC",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:50.508Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:11.733Z",
"on": "2013-08-07T02:46:12.249Z",
"by": "admin"
},
"user": "admin"
Expand Down
38 changes: 38 additions & 0 deletions forms/CompactDryEC/views/edit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,44 @@ questions.push new forms.ImageQuestion
prompt: "Photo"
ctx: options.ctx

class AutoCounter extends Backbone.View
events:
'click #auto_count' : 'autoCount'

initialize: ->
forms.ECPlates.isAvailable (avail) =>
if avail
# Re-render based on model changes
@model.on("change", @render, @)
@render()
, @options.ctx.error

render: ->
@$el.html('<button id="auto_count" class="btn btn-info">Perform Automatic Count</button><div id="hint" class="muted"></div>')

# Disable based on photo
if not @model.get('photo')
@$('button').attr("disabled", true)
@$('#hint').text("To enable automatic counting, first take a photo of the plate by tapping the camera icon.")

autoCount: ->
@options.ctx.imageManager.getImageUrl @model.get('photo').id, (imgUrl) =>
forms.ECPlates.processImage imgUrl, (args) =>
if args.error
alert("Automatic count failed: " + args.error)
else
if confirm("E.Coli: #{args.ecoli} TC: #{args.tc}. Save counts?")
@model.set {
ecoli_count: args.ecoli
ecoli_tntc: false
tc_count: args.tc
tc_tntc: false
}
, @options.ctx.error
, @options.ctx.error

questions.push new AutoCounter({ model: model, ctx: options.ctx })

questions.push new forms.TextQuestion
id: 'notes'
model: model
Expand Down
4 changes: 2 additions & 2 deletions forms/FluorideGeneric/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "Fluoride (generic method)",
"desc": "Any method for measuring fluoride in water",
"code": "FluorideGeneric",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:50.726Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:12.362Z",
"on": "2013-08-07T02:46:12.857Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/PetrifilmEcoliColiform/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "3M Petrifilm E. coli/coliform",
"desc": "1 mL direct count method for E. coli and total coliform",
"code": "PetrifilmEcoliColiform",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:50.949Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:12.895Z",
"on": "2013-08-07T02:46:13.379Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/Sample/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"type": "Survey",
"name": "Sample Survey",
"code": "Sample",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:51.789Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:13.533Z",
"on": "2013-08-07T02:46:14.194Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/SenSafeFreeChlorine/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "SenSafe Free Chlorine Water Check",
"desc": "US EPA approved test strip for free chlorine (manufactured by ITS)",
"code": "SenSafeFreeChlorine",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:51.219Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:14.174Z",
"on": "2013-08-07T02:46:14.936Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 2 additions & 2 deletions forms/USAIDTzWaterUserSurvey/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"name": "USAID Tanzania Water User Survey",
"code": "USAIDTzWaterUserSurvey",
"_id": "08e98c800e2844acb7a0ca8dbaeb750b",
"_rev": 9,
"_rev": 13,
"created": {
"on": "2013-07-18T15:36:36.419Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:14.888Z",
"on": "2013-08-07T02:46:15.643Z",
"by": "admin"
},
"user": "admin",
Expand Down
4 changes: 2 additions & 2 deletions forms/WaterWorksNitrateNitrite/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"name": "WaterWorks Nitrate / Nitrite Nitrogen",
"desc": "Test strip for nitrate (NO3) and nitrite (NO2) (manufactured by ITS)",
"code": "WaterWorksNitrateNitrite",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:51.479Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:15.673Z",
"on": "2013-08-07T02:46:16.257Z",
"by": "admin"
},
"user": "admin"
Expand Down
4 changes: 4 additions & 0 deletions forms/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
require('mobile-behavior').setup($('body'));
var formsModule =require('forms');

formsModule.ECPlates.isAvailable = function(success, error) {
success(true);
}

_.each(forms, function(form) {
$('#formlist').append($("<br/>"));
_.each(_.keys(form.views), function(viewName){
Expand Down
4 changes: 2 additions & 2 deletions forms/who-sanitary/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"type": "Survey",
"name": "WHO UNICEF Sanitary Inspection and Pollution Risk Assessment",
"code": "WHOSIPRA",
"_rev": 10,
"_rev": 14,
"created": {
"on": "2013-07-17T14:03:52.439Z",
"by": "admin"
},
"modified": {
"on": "2013-08-06T14:09:16.656Z",
"on": "2013-08-07T02:46:17.250Z",
"by": "admin"
},
"user": "admin"
Expand Down
1 change: 1 addition & 0 deletions setup_cordova.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.g
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
cordova plugin add https://github.com/mWater/cordova-plugin-camera-foreground.git
cordova plugin add https://github.com/mWater/OpenCVActivityPlugin.git
rm platforms/android/res/drawable-hdpi/icon.png
rm platforms/android/res/drawable-ldpi/icon.png
rm platforms/android/res/drawable-mdpi/icon.png
Expand Down

0 comments on commit a92ab1b

Please sign in to comment.