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

big refactor started

parent 260db9ab
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="foam.symbai"
android:versionCode="4"
android:versionCode="7"
android:versionName="1.0">
<application android:label="@string/app_name"
android:icon="@drawable/logo"
......@@ -33,6 +33,7 @@
<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.MoveActivity" android:configChanges="orientation"></activity>
<activity android:name="foam.symbai.VillagesActivity" android:configChanges="orientation"></activity>
</application>
......
......@@ -81,7 +81,7 @@
'entity-values
(ktv-set
(get-current 'entity-values '())
(ktv-create key type value))))
(ktv key type value))))
(define (entity-set! ktv-list)
(set-current! 'entity-values ktv-list))
......@@ -128,11 +128,11 @@
(let ((values
(append
(list
(ktv-create "user" "varchar" (get-current 'user-id "none"))
(ktv-create "time" "varchar" (date-time->string (date-time)))
(ktv-create "lat" "real" (car (get-current 'location '(0 0))))
(ktv-create "lon" "real" (cadr (get-current 'location '(0 0))))
(ktv-create "deleted" "int" 0))
(ktv "user" "varchar" (get-current 'user-id "none"))
(ktv "time" "varchar" (date-time->string (date-time)))
(ktv "lat" "real" (car (get-current 'location '(0 0))))
(ktv "lon" "real" (cadr (get-current 'location '(0 0))))
(ktv "deleted" "int" 0))
ktv-list)))
(let ((r (insert-entity/get-unique
db table entity-type (get-current 'user-id "no id")
......@@ -176,7 +176,7 @@
(define url "http://192.168.2.1:8889/symbai?")
(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)
(foldl
......@@ -282,8 +282,8 @@
(ktvlist (list-ref data 1))
(unique-id (list-ref entity 1))
(exists (entity-exists? db table unique-id)))
;;(msg "from server...:")
;;(msg ktvlist)
(msg "from server...:")
(msg ktvlist)
;; need to check exists again here, due to delays back and forth
(if (not exists)
(insert-entity-wholesale
......@@ -702,12 +702,14 @@
;; pull db data into list of button widgets
(define (update-list-widget db table entity-type edit-activity parent)
(msg "ulw")
(let ((search-results
(if parent
(db-filter-only db table entity-type
(list (list "parent" "varchar" "=" parent))
(list (list "name" "varchar")))
(db-all db table entity-type))))
(msg "ulw search results " search-results)
(update-widget
'linear-layout
(get-id (string-append entity-type "-list"))
......@@ -750,6 +752,13 @@
(list)
(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 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 @@
(choose
(list
(list
(ktv-create "name" "varchar"
(ktv "name" "varchar"
(string-append "Abe-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "abe.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "abe.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Akira-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "akira.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "akira.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Apu-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "apu.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "apu.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Barney-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "barney.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "barney.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Bart-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "bartsimpson.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "bartsimpson.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Billy-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "billy.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "billy.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Carl-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "carl.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "carl.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Cletus-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "cletus.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "cletus.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "ComicBookGuy-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "comicbookguy.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "comicbookguy.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Homer-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "homersimpson.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "homersimpson.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Jasper-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "jasper.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "jasper.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Kent-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "kentbrockman.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "kentbrockman.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Kodos-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "kodos.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "kodos.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Lenny-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "lenny.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "lenny.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Lisa-" (number->string n)))
(ktv-create "gender" "varchar" "female")
(ktv-create "photo" "file" "lisasimpson.jpg"))
(ktv "gender" "varchar" "female")
(ktv "photo" "file" "lisasimpson.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Marge-" (number->string n)))
(ktv-create "gender" "varchar" "female")
(ktv-create "photo" "file" "margesimpson.jpg"))
(ktv "gender" "varchar" "female")
(ktv "photo" "file" "margesimpson.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Martin-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "martinprince.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "martinprince.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Milhouse-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "milhouse.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "milhouse.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "MrBurns-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "mrburns.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "mrburns.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Ned-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "nedflanders.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "nedflanders.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Nelson-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "nelson.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "nelson.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Otto-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "otto.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "otto.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Ralph-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "ralphwiggum.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "ralphwiggum.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "Santaslittlehelper-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "santaslittlehelper.jpg"))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "santaslittlehelper.jpg"))
(list
(ktv-create
(ktv
"name" "varchar" (string-append "SideshowBob-" (number->string n)))
(ktv-create "gender" "varchar" "male")
(ktv-create "photo" "file" "sideshowbob.jpg")))))))))
(ktv "gender" "varchar" "male")
(ktv "photo" "file" "sideshowbob.jpg")))))))))
(define (looper! n fn)
(when (not (zero? n))
......
......@@ -202,6 +202,8 @@
;; don't make dirty or update version here
(define (update-value-from-sync db table entity-id ktv)
;;(msg "update-value-from-sync")
;;(msg entity-id ktv)
(let ((s (select-first
db (string-append
"select value from " table "_value_" (ktv-type ktv) " where entity_id = ? and attribute_id = ?")
......@@ -534,6 +536,7 @@
ktvlist)
(for-each
(lambda (ktv)
;;(msg ktv)
(when (not (equal? (ktv-key ktv) "unique_id"))
(if dirty
(update-value db table entity-id ktv)
......@@ -613,12 +616,12 @@
db (string-append
"select entity_id, entity_type, unique_id, dirty, version from "
table "_entity where dirty=1 limit 5;"))))
(msg de)
;;(msg de)
(if (null? de)
'()
(map
(lambda (i)
(msg "dirty:" (vector-ref i 2))
;;(msg "dirty:" (vector-ref i 2))
(list
;; build according to url ([table] entity-type unique-id dirty version)
(cdr (vector->list i))
......
......@@ -569,7 +569,10 @@
; r)))
(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)
;;(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, ,,
times-married, How many times married, ,,
change-spouse, Change/add spouse, ,,
children-living, Living, ,,
children-dead, Dead, ,,
children-together, Living together, ,,
children-apart, Living apart, ,,
residence-after-marriage, Residence after marriage, ,,
birthplace, Birthplace, ,,
spouse-village, Spouses natal village, ,,
num-siblings, Number of living siblings of the same sex born from same mother, ,,
birth-order, Birth order amoung currently living same sex siblings born from same mother, ,,
length-time, Length of time lived in this village (years), ,,
place-of-birth, Place of birth, ,,
num-residence-changes, Number of time place of residence changed since birth, ,,
village-visits-month, Number of times you have visited another village in the last month, ,,
village-visits-year, Number of times you have visited another village in the last year (i.e. betwen last summer and this summer), ,,
occupation, Occupation, ,,
occupation, Occupation, ,,
agriculture, Agriculture, ,,
gathering, Gathering, ,,
labour, Labour, ,,
cows, Cows, ,,
fishing, Fishing, ,,
num-people-in-house, People living in house, ,,
contribute, Contribute to family earnings?, ,,
own-land, Own land?, ,,
rent-land, Rent out your land?, ,,
hire-land, Hire land?, ,,
crops, Crops, ,,
unit, Unit, ,,
quantity, Quantity, ,,
used-or-eaten, Used/Eaten, ,,
sold, Sold, ,,
seed, Seed (hybrid/local), ,,
house-type, House type, ,,
concrete, Concrete, ,,
tin, Tin, ,,
thatched, Thatched, ,,
loan, Outstanding loans, ,,
earning, One day's earnings, ,,
in-the-home, In the home, ,,
radio, Radio, ,,
tv, TV, ,,
mobile, Mobile phone, ,,
visit-market, Tribal market visits, ,,
town-sell, Town or city visits, ,,
default-crop-name, A crop, ,,
crop-name, Crop name, ,,
crop-unit, Crop unit, ,,
crop-used, Used or eaten, ,,
crop-sold, Sold, ,,
crop-seed, Seed, ,,
mother, Mother, ,,
father, Father, ,,
change-mother, Change mother, ,,
change-father, Change father, ,,
alive, Alive, ,,
sex, Sex, ,,
social-type, Type, ,,
friendship, Friendship, ,,
knowledge, Knowledge, ,,
prestige, Prestige, ,,
social-one, One, ,,
social-two, Two, ,,
social-three, Three, ,,
social-four, Four, ,,
social-five, Five, ,,
social-relationship, Relationship, ,,
social-residence, Residence, ,,
social-strength, Strength, ,,
mother, Mother, ,,
father, Father, ,,
sister, Sister, ,,
brother, Brother, ,,
spouse, Spouse, ,,
children, Children, ,,
co-wife, Co-wife, ,,
spouse-mother, Spouse's mother, ,,
spouse-father, Spouse's father, ,,
spouse-brother-wife, Spouse's brother's wife, ,,
spouse-sister-husband, Spouse's sister's husband, ,,
friend, Friend, ,,
neighbour, Neighbour, ,,
same, Same, ,,
daily, Daily, ,,
weekly, Weekly, ,,
monthly, Monthly, ,,
less, Less, ,,
......@@ -2,8 +2,8 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<gradient android:endColor="#eeffa276"
android:startColor="#eeefa276" android:angle="270" />
<gradient android:endColor="#eea276ff"
android:startColor="#eea276ef" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
......@@ -11,8 +11,8 @@
</item>
<item android:state_pressed="true">
<shape>
<gradient android:endColor="#77ffa276"
android:startColor="#77efa276" android:angle="270" />
<gradient android:endColor="#77a276ff"
android:startColor="#77a276ef" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
......@@ -20,8 +20,8 @@
</item>
<item android:state_focused="true">
<shape>
<gradient android:endColor="#ffffa276"
android:startColor="#ffefa276" android:angle="270" />
<gradient android:endColor="#ffa276ff"
android:startColor="#ffa276ef" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
......@@ -29,8 +29,8 @@
</item>
<item>
<shape>
<gradient android:endColor="#ffff8256"
android:startColor="#ffefa276" android:angle="270" />
<gradient android:endColor="#888256ff"
android:startColor="#88a276ef" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
......