Commit 0611b540 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

big refactor started

parent 260db9ab
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="foam.symbai" package="foam.symbai"
android:versionCode="4" android:versionCode="7"
android:versionName="1.0"> android:versionName="1.0">
<application android:label="@string/app_name" <application android:label="@string/app_name"
android:icon="@drawable/logo" android:icon="@drawable/logo"
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<activity android:name="foam.symbai.CropActivity" android:configChanges="orientation"></activity> <activity android:name="foam.symbai.CropActivity" android:configChanges="orientation"></activity>
<activity android:name="foam.symbai.ChildActivity" android:configChanges="orientation"></activity> <activity android:name="foam.symbai.ChildActivity" android:configChanges="orientation"></activity>
<activity android:name="foam.symbai.MoveActivity" android:configChanges="orientation"></activity> <activity android:name="foam.symbai.MoveActivity" android:configChanges="orientation"></activity>
<activity android:name="foam.symbai.VillagesActivity" android:configChanges="orientation"></activity>
</application> </application>
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
'entity-values 'entity-values
(ktv-set (ktv-set
(get-current 'entity-values '()) (get-current 'entity-values '())
(ktv-create key type value)))) (ktv key type value))))
(define (entity-set! ktv-list) (define (entity-set! ktv-list)
(set-current! 'entity-values ktv-list)) (set-current! 'entity-values ktv-list))
...@@ -128,11 +128,11 @@ ...@@ -128,11 +128,11 @@
(let ((values (let ((values
(append (append
(list (list
(ktv-create "user" "varchar" (get-current 'user-id "none")) (ktv "user" "varchar" (get-current 'user-id "none"))
(ktv-create "time" "varchar" (date-time->string (date-time))) (ktv "time" "varchar" (date-time->string (date-time)))
(ktv-create "lat" "real" (car (get-current 'location '(0 0)))) (ktv "lat" "real" (car (get-current 'location '(0 0))))
(ktv-create "lon" "real" (cadr (get-current 'location '(0 0)))) (ktv "lon" "real" (cadr (get-current 'location '(0 0))))
(ktv-create "deleted" "int" 0)) (ktv "deleted" "int" 0))
ktv-list))) ktv-list)))
(let ((r (insert-entity/get-unique (let ((r (insert-entity/get-unique
db table entity-type (get-current 'user-id "no id") db table entity-type (get-current 'user-id "no id")
...@@ -176,7 +176,7 @@ ...@@ -176,7 +176,7 @@
(define url "http://192.168.2.1:8889/symbai?") (define url "http://192.168.2.1:8889/symbai?")
(define (build-url-from-ktv ktv) (define (build-url-from-ktv ktv)
(string-append "&" (ktv-key ktv) ":" (ktv-type ktv) ":" (number->string (ktv-version ktv)) "=" (stringify-value-url ktv))) (string-append "&" (ktv-key ktv) ":" (ktv-type ktv) "=" (stringify-value-url ktv)))
(define (build-url-from-ktvlist ktvlist) (define (build-url-from-ktvlist ktvlist)
(foldl (foldl
...@@ -282,8 +282,8 @@ ...@@ -282,8 +282,8 @@
(ktvlist (list-ref data 1)) (ktvlist (list-ref data 1))
(unique-id (list-ref entity 1)) (unique-id (list-ref entity 1))
(exists (entity-exists? db table unique-id))) (exists (entity-exists? db table unique-id)))
;;(msg "from server...:") (msg "from server...:")
;;(msg ktvlist) (msg ktvlist)
;; need to check exists again here, due to delays back and forth ;; need to check exists again here, due to delays back and forth
(if (not exists) (if (not exists)
(insert-entity-wholesale (insert-entity-wholesale
...@@ -702,12 +702,14 @@ ...@@ -702,12 +702,14 @@
;; pull db data into list of button widgets ;; pull db data into list of button widgets
(define (update-list-widget db table entity-type edit-activity parent) (define (update-list-widget db table entity-type edit-activity parent)
(msg "ulw")
(let ((search-results (let ((search-results
(if parent (if parent
(db-filter-only db table entity-type (db-filter-only db table entity-type
(list (list "parent" "varchar" "=" parent)) (list (list "parent" "varchar" "=" parent))
(list (list "name" "varchar"))) (list (list "name" "varchar")))
(db-all db table entity-type)))) (db-all db table entity-type))))
(msg "ulw search results " search-results)
(update-widget (update-widget
'linear-layout 'linear-layout
(get-id (string-append entity-type "-list")) (get-id (string-append entity-type "-list"))
...@@ -750,6 +752,13 @@ ...@@ -750,6 +752,13 @@
(list) (list)
(list (list "name" "varchar"))))) (list (list "name" "varchar")))))
(define (find-index-from-name-array arr unique-id)
(define (_ l i)
(cond
((null? l) #f)
((equal? unique-id (cadr (car l))) i)
(else (_ (cdr l) (+ i 1)))))
(_ arr 0))
(define vowel (map symbol->string (list 'a 'e 'i 'o 'u))) (define vowel (map symbol->string (list 'a 'e 'i 'o 'u)))
(define consonant (map symbol->string (list 'b 'c 'd 'f 'g 'h 'j 'k 'l 'm 'n 'p 'q 'r 's 't 'v 'w 'x 'y 'z))) (define consonant (map symbol->string (list 'b 'c 'd 'f 'g 'h 'j 'k 'l 'm 'n 'p 'q 'r 's 't 'v 'w 'x 'y 'z)))
...@@ -795,130 +804,130 @@ ...@@ -795,130 +804,130 @@
(choose (choose
(list (list
(list (list
(ktv-create "name" "varchar" (ktv "name" "varchar"
(string-append "Abe-" (number->string n))) (string-append "Abe-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "abe.jpg")) (ktv "photo" "file" "abe.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Akira-" (number->string n))) "name" "varchar" (string-append "Akira-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "akira.jpg")) (ktv "photo" "file" "akira.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Apu-" (number->string n))) "name" "varchar" (string-append "Apu-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "apu.jpg")) (ktv "photo" "file" "apu.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Barney-" (number->string n))) "name" "varchar" (string-append "Barney-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "barney.jpg")) (ktv "photo" "file" "barney.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Bart-" (number->string n))) "name" "varchar" (string-append "Bart-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "bartsimpson.jpg")) (ktv "photo" "file" "bartsimpson.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Billy-" (number->string n))) "name" "varchar" (string-append "Billy-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "billy.jpg")) (ktv "photo" "file" "billy.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Carl-" (number->string n))) "name" "varchar" (string-append "Carl-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "carl.jpg")) (ktv "photo" "file" "carl.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Cletus-" (number->string n))) "name" "varchar" (string-append "Cletus-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "cletus.jpg")) (ktv "photo" "file" "cletus.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "ComicBookGuy-" (number->string n))) "name" "varchar" (string-append "ComicBookGuy-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "comicbookguy.jpg")) (ktv "photo" "file" "comicbookguy.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Homer-" (number->string n))) "name" "varchar" (string-append "Homer-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "homersimpson.jpg")) (ktv "photo" "file" "homersimpson.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Jasper-" (number->string n))) "name" "varchar" (string-append "Jasper-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "jasper.jpg")) (ktv "photo" "file" "jasper.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Kent-" (number->string n))) "name" "varchar" (string-append "Kent-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "kentbrockman.jpg")) (ktv "photo" "file" "kentbrockman.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Kodos-" (number->string n))) "name" "varchar" (string-append "Kodos-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "kodos.jpg")) (ktv "photo" "file" "kodos.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Lenny-" (number->string n))) "name" "varchar" (string-append "Lenny-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "lenny.jpg")) (ktv "photo" "file" "lenny.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Lisa-" (number->string n))) "name" "varchar" (string-append "Lisa-" (number->string n)))
(ktv-create "gender" "varchar" "female") (ktv "gender" "varchar" "female")
(ktv-create "photo" "file" "lisasimpson.jpg")) (ktv "photo" "file" "lisasimpson.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Marge-" (number->string n))) "name" "varchar" (string-append "Marge-" (number->string n)))
(ktv-create "gender" "varchar" "female") (ktv "gender" "varchar" "female")
(ktv-create "photo" "file" "margesimpson.jpg")) (ktv "photo" "file" "margesimpson.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Martin-" (number->string n))) "name" "varchar" (string-append "Martin-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "martinprince.jpg")) (ktv "photo" "file" "martinprince.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Milhouse-" (number->string n))) "name" "varchar" (string-append "Milhouse-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "milhouse.jpg")) (ktv "photo" "file" "milhouse.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "MrBurns-" (number->string n))) "name" "varchar" (string-append "MrBurns-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "mrburns.jpg")) (ktv "photo" "file" "mrburns.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Ned-" (number->string n))) "name" "varchar" (string-append "Ned-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "nedflanders.jpg")) (ktv "photo" "file" "nedflanders.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Nelson-" (number->string n))) "name" "varchar" (string-append "Nelson-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "nelson.jpg")) (ktv "photo" "file" "nelson.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Otto-" (number->string n))) "name" "varchar" (string-append "Otto-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "otto.jpg")) (ktv "photo" "file" "otto.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Ralph-" (number->string n))) "name" "varchar" (string-append "Ralph-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "ralphwiggum.jpg")) (ktv "photo" "file" "ralphwiggum.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "Santaslittlehelper-" (number->string n))) "name" "varchar" (string-append "Santaslittlehelper-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "santaslittlehelper.jpg")) (ktv "photo" "file" "santaslittlehelper.jpg"))
(list (list
(ktv-create (ktv
"name" "varchar" (string-append "SideshowBob-" (number->string n))) "name" "varchar" (string-append "SideshowBob-" (number->string n)))
(ktv-create "gender" "varchar" "male") (ktv "gender" "varchar" "male")
(ktv-create "photo" "file" "sideshowbob.jpg"))))))))) (ktv "photo" "file" "sideshowbob.jpg")))))))))
(define (looper! n fn) (define (looper! n fn)
(when (not (zero? n)) (when (not (zero? n))
......
...@@ -202,6 +202,8 @@ ...@@ -202,6 +202,8 @@
;; don't make dirty or update version here ;; don't make dirty or update version here
(define (update-value-from-sync db table entity-id ktv) (define (update-value-from-sync db table entity-id ktv)
;;(msg "update-value-from-sync")
;;(msg entity-id ktv)
(let ((s (select-first (let ((s (select-first
db (string-append db (string-append
"select value from " table "_value_" (ktv-type ktv) " where entity_id = ? and attribute_id = ?") "select value from " table "_value_" (ktv-type ktv) " where entity_id = ? and attribute_id = ?")
...@@ -534,6 +536,7 @@ ...@@ -534,6 +536,7 @@
ktvlist) ktvlist)
(for-each (for-each
(lambda (ktv) (lambda (ktv)
;;(msg ktv)
(when (not (equal? (ktv-key ktv) "unique_id")) (when (not (equal? (ktv-key ktv) "unique_id"))
(if dirty (if dirty
(update-value db table entity-id ktv) (update-value db table entity-id ktv)
...@@ -613,12 +616,12 @@ ...@@ -613,12 +616,12 @@
db (string-append db (string-append
"select entity_id, entity_type, unique_id, dirty, version from " "select entity_id, entity_type, unique_id, dirty, version from "
table "_entity where dirty=1 limit 5;")))) table "_entity where dirty=1 limit 5;"))))
(msg de) ;;(msg de)
(if (null? de) (if (null? de)
'() '()
(map (map
(lambda (i) (lambda (i)
(msg "dirty:" (vector-ref i 2)) ;;(msg "dirty:" (vector-ref i 2))
(list (list
;; build according to url ([table] entity-type unique-id dirty version) ;; build according to url ([table] entity-type unique-id dirty version)
(cdr (vector->list i)) (cdr (vector->list i))
......
...@@ -569,7 +569,10 @@ ...@@ -569,7 +569,10 @@
; r))) ; r)))
(define (get-id name) (define (get-id name)
(id-map-get name)) (let ((r (id-map-get name)))
(cond
((zero? r) (msg "no id found for" name) 0)
(else r))))
(define (make-id name) (define (make-id name)
;;(msg "making id for" name) ;;(msg "making id for" name)
......
(define lang #f)
(define scheme #f)
(define racket #f)
(define (planet n) #f)
(define jaymccarthy/sqlite:5:1/sqlite #f)
(define (require . args) #f)
(define (provide . args) #f)
(define (all-defined-out) #f)
(define (make-semaphore n) #f)
(define (semaphore-wait n) #f)
;; tinyscheme
(define db-select db-exec)
;; helper to return first instance from a select
(define (select-first db str . args)
(let ((s (apply db-select (append (list db str) args))))
(if (or (null? s) (eq? s #t))
'()
(vector-ref (cadr s) 0))))
;; get a unique hash for this user (used for all the unique-ids)
(define (get-unique user)
(let ((t (time)))
(string-append
user "-" (number->string (car t)) ":" (number->string (cadr t)))))
This diff is collapsed.
test-num,1,1,1,
test-text, I am test text, I am test text, I am test text,
one, one, ,,
two, two, ,,
three, three, ,,
village, Village, ,,
household, Household, ,,
households, Households, ,,
individual, Individual, ,,
individuals, Individuals, ,,
add-item-to-list,0, ,,
default-village-name, New village, ,,
title, Symbai, Symbai, Symbai,
sync, Sync, Sync, Sync,
languages, Choose language, Choose language, Choose language,
english, English, English, English,
khasi, Khasi, Khasi, Khasi,
hindi, Hindi, Hindi, Hindi,
user-id, Your user ID, User ID, User ID,
save, Save, Save, Save,
back, Back, Back, Back,
off, Off, Off, Off,
villages, Villages, Villages, Villages,
list-empty, List empty, ,,
delete, Delete, ,,
delete-are-you-sure, Are you sure you want to delete this?, ,,
save-are-you-sure, Are you sure you want to save changes?, ,,
quick-name, New person name, ,,
quick-add, Quick add, ,,
find-individual, Find individual, ,,
filter, Filter, ,,
off, Off, Off, Off,
name, Name, ,,
sync-all, Sync me!, ,,
sync-syncall, Sync everything, ,,
export-data, Exporting data, ,,
sync-download, Download main DB, ,,
sync-export, Email main DB, ,,
email-local, Email local DB, ,,
debug, Debug, ,,
sync-back, Back, ,,
sync-prof, Profile, ,,
village-name, Village name, Village name, Village name,
block, Block, Block, Block,
district, District, District, District,
car, Accessible by car, ,,
household-list, Household list, ,,
amenities, Amenities, ,,
school, School, ,,
present, Present, ,,
closest-access, Closest place of access, ,,
house-gps, GPS, ,,
toilet-gps, GPS, ,,
school, School, ,,
school-closest-access, Access, ,,
school-gps, GPS, ,,
hospital, Hospital/Health care centre, ,,
hospital-closest-access, Access, ,,
hospital-gps, GPS, ,,
post-office, Post Office, ,,
post-office-closest-access, Access, ,,
post-office-gps, GPS, ,,
railway-station, Railway station, ,,
railway-station-closest-access, Access, ,,
railway-station-gps, GPS, ,,
state-bus-service, Inter-state bus service, ,,
state-bus-service-closest-access, Access, ,,
state-bus-service-gps, GPS, ,,
district-bus-service, Inter-village/district bus service, ,,
district-bus-service-closest-access, Access, ,,
district-bus-service-gps, GPS, ,,
panchayat, Village Panchayat Office, ,,
panchayat-closest-access, Access, ,,
panchayat-gps, GPS, ,,
NGO, Presence of NGO's working with them, ,,
NGO-closest-access, Access, ,,
NGO-gps, GPS, ,,
market, Market, ,,
market-closest-access, Access, ,,
market-gps, GPS, ,,
household-name, Household name, ,,
default-household-name, A household, ,,
location, House location, ,,
elevation, Elevation, ,,
toilet-location, Toilet location, ,,
children, Children, ,,
male, Male, ,,
female, Female, ,,
num-pots, Number of pots, ,,
adults, Adults, ,,
add-individual, Add individual, ,,
default-individual-name, A person, ,,
default-family-name, A family, ,,
default-photo-id, ???, ,,
name-display, Name, ,,
photo-id-display, Photo ID, ,,
family-display, Family, ,,
details-button, Details, ,,
family-button, Family, ,,
migration-button, Migration, ,,
income-button, Income, ,,
geneaology-button, Geneaology, ,,
social-button, Social, ,,
agreement-button, Agreement, ,,
is-a-child, Child, ,,
change-photo, Change photo, ,,
details-name, Name, ,,
details-photo-id, Photo ID, ,,
details-family, Family, ,,
tribe, Tribe, ,,
sub-tribe, Sub tribe, ,,
khasi, Khasi, ,,
khynriam, Khynriam, ,,
pnar, Pnar, ,,
bhoi, Bhoi, ,,
war, War, ,,
other, Other, ,,
age, Age, ,,
gender, Gender, ,,
education, Education, ,,
illiterate, Illiterate, ,,
literate, Literate, ,,
primary, Primary 1-5, ,,
middle, Middle 6-8, ,,
high, High 9-10, ,,
secondary, Higher Secondary, ,,
university, University, ,,
spouse, Spouse, ,,
change-id, Change, ,,
head-of-house, Head of house, ,,
marital-status, Marital status, ,,
ever-married, Ever married, ,,
currently-married, Currently married, ,,
currently-single, Currently single, ,,
seperated, Seperated/divorced, ,,