Skip to content

Commit

Permalink
added life history
Browse files Browse the repository at this point in the history
  • Loading branch information
nebogeo committed Feb 22, 2018
1 parent 084a8fe commit cb7d2b5
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -35,3 +35,5 @@ output.json
obj/
.externalNativeBuild
*.so

*.csv
111 changes: 111 additions & 0 deletions android/app/src/main/assets/life-history.scm
@@ -0,0 +1,111 @@
(msg "life-history happened")

(define list-pack-lifehist
(list
(list 'endgrp "End of pack")
(list 'lgrp "Last seen")
(list 'fgrp "First seen")))

(define list-litter-lifehist
(list
(list 'unsuccessful "Unsuccessful")
(list 'short-lived "Short lived")
(list 'successful "Successful")))

(define list-individual-lifehist
(list
(list 'adied "Assumed died")
(list 'died "Died")
(list 'lseen "Last seen")
(list 'fseen "First seen")
(list 'stev "Start eviction")
(list 'endev "End eviction")
(list 'leave "Leave")
(list 'return "Return")
(list 'imm "Immigrate")
(list 'emm "Emmigrate")))

(define list-female-lifehist
(list
(list 'fpreg "First pregnant")
(list 'abort "Abort")
(list 'birth "Birth")))

(define (lifehist-types type)
(cond
((eq? type 'pack) list-pack-lifehist)
((eq? type 'litter) list-litter-lifehist)
((eq? type 'male) list-individual-lifehist)
(else (append list-individual-lifehist list-female-lifehist))))

(define (lifehist-text type)
(cond
((eq? type 'pack) "pack")
((eq? type 'litter) "litter")
((eq? type 'male) "male")
(else "female")))

(define (init-lifehist db)
(entity-init! db "stream" "lifehist-event"
(list
(ktv "date" "varchar" (date-time->string (date-time)))
(ktv "type" "varchar" "none")
(ktv "code" "varchar" "none")
(ktv "entity-uid" "varchar" "none")
(ktv "entity-name" "varchar" "none"))))


(define (build-lifehist type)
(linear-layout
(make-id "") 'vertical fillwrap lh-bgcol
(list
(text-view 0 (string-append "New life history event for this " (lifehist-text type)) 30 fillwrap)
(horiz
(vert
(horiz
(mtext 0 "Date:")
(mtext "lifehist-date-view" (date->string (date-time))))
(mbutton-large "lifehist-date" "Set date"
(lambda ()
(list (date-picker-dialog
"lifehist-date"
(lambda (day month year)
(let ((datestring (date-time->string (list year (+ month 1) day))))
(set-current! 'entity-type "lifehist-event")
(entity-set-value! "date" "varchar" datestring)
(list
(update-widget
'text-view
(get-id "lifehist-date-view") 'text datestring)))))))))
(vert
(mtext 0 "Code")
(mspinner "lifehist-type"
(lifehist-types type)
(lambda (v)
(set-current! 'entity-type "lifehist-event")
(entity-set-value!
"code" "varchar"
(spinner-choice (lifehist-types type) v))
'())))
(vert
(mtext 0 "")
(mcolour-button-large
"lifehist-record" "Record"
lh-col
(lambda ()
(set-current! 'entity-type "lifehist-event")
(entity-set-value! "entity-uid" "varchar" (get-current 'focal-id ""))
(list
(alert-dialog
"lifehist-check"
"Recording life history event: are you sure?"
(lambda (v)
(cond
((eqv? v 1)
(entity-record-values!)
'())
(else
(list)))))))))))))



9 changes: 9 additions & 0 deletions android/app/src/main/assets/mongoose.scm
Expand Up @@ -50,6 +50,7 @@
"preg-focal-aggr"
"preg-focal-affil"

"lifehist-event"
))

(define pup-focal-export
Expand Down Expand Up @@ -186,6 +187,7 @@
(define gc-col (list 164 82 9 255))
(define of-col (list 82 102 204 255))
(define prf-col (list 255 81 81 255))
(define lh-col (list 255 81 255 255))

;(define of-col (list 51 204 51 255))
;(define prf-col (list 255 51 51 255))
Expand All @@ -196,6 +198,7 @@
(define gc-bgcol (list 164 82 9 127))
(define of-bgcol (list 102 204 102 127))
(define prf-bgcol (list 255 102 51 127))
(define lh-bgcol (list 255 204 255 127))

;(define pf-col (list 22 19 178 127))
;(define gp-col (list 255 97 0 127))
Expand Down Expand Up @@ -249,9 +252,15 @@
(define (mbutton id title fn)
(button (make-id id) title 20 (layout 'fill-parent 'wrap-content 1 'centre 5) fn))

(define (mbutton-large id title fn)
(button (make-id id) title 30 (layout 'fill-parent 'wrap-content 1 'centre 5) fn))

(define (mcolour-button id title col fn)
(colour-button (make-id id) title 20 (layout 'fill-parent 'wrap-content 1 'centre 5) col fn))

(define (mcolour-button-large id title col fn)
(colour-button (make-id id) title 30 (layout 'fill-parent 'wrap-content 1 'centre 5) col fn))

(define (mbutton2 id title fn)
(button (make-id id) title 20 (layout 150 100 1 'centre 5) fn))

Expand Down
10 changes: 7 additions & 3 deletions android/app/src/main/assets/starwisp.scm
Expand Up @@ -533,11 +533,10 @@
(activity
"manage-individual"
(vert
(text-view (make-id "title") "Manage individuals" 40 fillwrap)
(text-view (make-id "title") "Update pack" 40 fillwrap)
(text-view (make-id "manage-individual-pack-name") "Pack:" 30 fillwrap)
(build-grid-selector "manage-individuals-list" "button" "Choose individual")
(horiz
(mbutton2 "choose-obs-back" "Back" (lambda () (list (finish-activity 1))))
(mbutton2 "manage-individuals-new" "New individual" (lambda () (list (start-activity "new-individual" 2 ""))))
(mbutton2 "manage-individuals-delete" "Delete pack"
(lambda ()
Expand All @@ -555,14 +554,19 @@
(lambda (v)
(cond
((eqv? v 1)
(set-current! 'entity-type "pack")
(entity-update-single-value! (ktv "deleted" "int" 1))
(list (finish-activity 1)))
(else
(list)))))))
(else (list))))))))))
(else (list)))))))))
(build-lifehist 'pack)
(mbutton2 "choose-obs-back" "Back" (lambda () (list (finish-activity 1))))
)
(lambda (activity arg)
(activity-layout activity))
(lambda (activity arg)
(init-lifehist db)
(entity-init! db "sync" "pack" (get-current 'pack #f))
(list
(populate-grid-selector
Expand Down
12 changes: 12 additions & 0 deletions android/app/src/main/java/foam/starwisp/starwisp.java
Expand Up @@ -47,6 +47,7 @@
import android.text.Editable;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;

import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -115,6 +116,7 @@ public void onCreate(Bundle savedInstanceState)
m_Scheme.Load("eavdb/eavdb.ss");
m_Scheme.Load("dbsync.scm");
m_Scheme.Load("mongoose.scm");
m_Scheme.Load("life-history.scm");
m_Scheme.Load("pup-focal.scm");
m_Scheme.Load("oestrus-focal.scm");
m_Scheme.Load("preg-focal.scm");
Expand Down Expand Up @@ -147,6 +149,16 @@ public void onCreate(Bundle savedInstanceState)
"(define timezone-offset-mins "+timezone_offset_mins+")"+
"(define app-version "+version+")");

// also updated in StarwispActivity::onCreate()
String ori = "'portrait";
if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE) {
ori = "'landscape";
}
m_Scheme.eval("(define screen-orientation "+ori+")");

// pass in a bunch of useful stuff
DeclareSensors();

Log.i("starwisp","started, now running starwisp.scm...");
m_Scheme.eval(m_Scheme.readRawTextFile(this, "starwisp.scm"));

Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/jni/app.cpp
Expand Up @@ -38,7 +38,7 @@ void appInit()
FILE *log_file=stdout;
scheme_set_input_port_file(sc, stdin);
#else
FILE *log_file=fopen("/sdcard/jellyfish-log.txt","w");
FILE *log_file=fopen("/sdcard/mongoose-log.txt","w");
#endif
#endif
if (log_file!=NULL) scheme_set_output_port_file(sc, log_file);
Expand Down

0 comments on commit cb7d2b5

Please sign in to comment.