Commit a3ebea01 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

lots of sync testing, debug view added

parent e97d5ebb
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="foam.mongoose"
android:versionCode="2"
android:versionCode="3"
android:versionName="1.0">
<application android:label="@string/app_name"
android:icon="@drawable/logo"
......
......@@ -431,6 +431,8 @@
(define (frame-layout-children t) (list-ref t 3))
(define (scroll-view id layout children)
(list "scroll-view" id layout children))
(define (scroll-view-vert id layout children)
(list "scroll-view-vert" id layout children))
(define (scroll-view-children t) (list-ref t 3))
(define (view-pager id layout fragment-list)
(list "view-pager" id layout fragment-list))
......
......@@ -213,41 +213,37 @@
(build-url-from-ktvlist (cadr e))))
;; spit all dirty entities to server
(define (spit-dirty db table)
(map
(lambda (e)
(http-request
(string-append "req-" (list-ref (car e) 1))
(build-url-from-entity table e)
(lambda (v)
(msg "spat" e v)
(if (or
(equal? (car v) "inserted")
(equal? (car v) "match"))
(begin
(msg "cleaning...")
(update-entity-clean db table (cadr v))
(list (toast (string-append "Uploaded " (car (car e))))))
(list (toast (string-append "Problem uploading " (car (car e)))))))))
(dirty-entities db table)))
;; spit all dirty entities to server
(define (spit-all db table)
(map
(lambda (e)
(msg "spit all" e)
(http-request
(string-append "req-" (list-ref (car e) 1))
(build-url-from-entity table e)
(lambda (v)
(msg "spat" e v)
(if (equal? (car v) "inserted")
(begin
(update-entity-clean db table (cadr v))
(toast (string-append "Uploaded " (car (car e)))))
(toast (string-append "Problem uploading " (car (car e))))))))
(dirty-and-all-entities db table)))
(define (spit db table entities)
(foldl
(lambda (e r)
(append
(list
(debug (string-append "Sending a " (car (car e)) " to Raspberry Pi"))
(http-request
(string-append "req-" (list-ref (car e) 1))
(build-url-from-entity table e)
(lambda (v)
(msg "spat" e v)
(cond
((or (equal? (car v) "inserted") (equal? (car v) "match"))
(update-entity-clean db table (cadr v))
(list
(debug (string-append "Uploaded " (car (car e))))))
((equal? (car v) "no change")
(list (debug (string-append "No change for " (car (car e))))))
((equal? (car v) "updated")
(update-entity-clean db table (cadr v))
(list (debug (string-append "Updated changed " (car (car e))))))
(else
(list (toast (string-append
"Problem uploading "
(car (car e)) " : " (car v)))
(debug (string-append
"Problem uploading "
(car (car e)) " : " (car v)))))))))
r))
'()
entities))
(define (suck-entity-from-server db table unique-id exists)
;; ask for the current version
......@@ -260,24 +256,25 @@
(let ((entity (list-ref data 0))
(ktvlist (list-ref data 1)))
(if (not exists)
(begin
(insert-entity-wholesale
db table
(list-ref entity 0) ;; entity-type
(list-ref entity 1) ;; unique-id
0 ;; dirty
(list-ref entity 2) ;; version
ktvlist))
(insert-entity-wholesale
db table
(list-ref entity 0) ;; entity-type
(list-ref entity 1) ;; unique-id
0 ;; dirty
(list-ref entity 2) ;; version
ktvlist)
(update-to-version
db table (get-entity-id db table unique-id)
(list-ref entity 4) ktvlist))
(list-ref entity 2) ktvlist))
(list
(update-widget 'text-view (get-id "sync-dirty") 'text (build-dirty))
(debug (string-append (if exists "Got new: " "Updated: ") (ktv-get ktvlist "name")))
(toast (string-append "Downloaded " (ktv-get ktvlist "name"))))))))
;; repeatedly read version and request updates
(define (suck-new db table)
(list
(debug "Requesting new entities")
(http-request
"new-entities-req"
(string-append url "fn=entity-versions&table=" table)
......@@ -300,8 +297,14 @@
'()
data)))
(if (null? r)
(cons (toast "All files up to date") r)
(cons (toast "Requesting " (length r) " entities") r)))))))
(append
(list
(debug "All files up to date")
(toast "All files up to date")) r)
(append
(list
(debug (string-append "Requesting " (number->string (length r)) " entities"))
(toast (string-append "Requesting " (number->string (length r)) " entities"))) r)))))))
(define (build-dirty)
(let ((sync (get-dirty-stats db "sync"))
......@@ -426,6 +429,12 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
(define (debug txt)
(set-current! 'debug-text (string-append txt "\n" (get-current 'debug-text "")))
(update-widget 'debug-text-view (get-id "sync-debug") 'text
(get-current 'debug-text "")))
(define (timer-cb)
(set-current!
'timer-seconds
......@@ -1536,22 +1545,27 @@
"network"
"mongoose-web"
(lambda (state)
(list
(update-widget 'text-view (get-id "sync-connect") 'text state)))))))
(list
(debug (string-append "Raspberry Pi connection state now: " state))
(update-widget 'text-view (get-id "sync-connect") 'text state)))))))
(mbutton2 "sync-syncall" "Push all"
(lambda ()
(let ((r (append
(spit-all db "sync")
(spit-all db "stream"))))
(spit db "sync" (dirty-and-all-entities db "sync"))
(spit db "stream" (dirty-and-all-entities db "stream")))))
(cons (toast "Uploading data...") r))))
(mbutton2 "sync-sync" "Push changes"
(lambda ()
(let ((r (append
(spit-dirty db "sync")
(spit-dirty db "stream"))))
(cons (if (> (length r) 0)
(toast "Uploading data...")
(toast "No data changed to upload")) r))))
(spit db "sync" (dirty-entities db "sync"))
(spit db "stream" (dirty-entities db "stream")))))
(append (if (> (length r) 0)
(list
(debug (string-append "Uploading " (number->string (/ (length r) 2)) " items..."))
(toast "Uploading data..."))
(list
(debug "No data changed to upload")
(toast "No data changed to upload"))) r))))
(mbutton2 "sync-pull" "Pull"
(lambda ()
(cons (toast "Downloading data...") (suck-new db "sync")))))
......@@ -1559,16 +1573,22 @@
(horiz
(mbutton2 "sync-download" "Download"
(lambda ()
(map
(lambda (e)
(http-download
(string-append "getting-" e)
(string-append url "fn=entity-csv&table=stream&type=" e)
(string-append "/sdcard/mongoose/" e ".csv")))
(foldl
(lambda (e r)
(append
(list
(debug (string-append "Downloading /sdcard/mongoose/" e ".csv"))
(http-download
(string-append "getting-" e)
(string-append url "fn=entity-csv&table=stream&type=" e)
(string-append "/sdcard/mongoose/" e ".csv")))
r))
'()
entity-types)))
(mbutton2 "sync-export" "Export"
(lambda ()
(list
(debug "Sending mail")
(send-mail
""
"From Mongoose2000" "Please find attached your mongoose data"
......@@ -1576,7 +1596,14 @@
(lambda (e)
(string-append "/sdcard/mongoose/" e ".csv"))
entity-types))))))
(spacer 10)
(mtitle "" "Debug")
(scroll-view-vert
0 (layout 'fill-parent 200 1 'left 0)
(list
(vert
(debug-text-view (make-id "sync-debug") "..." 15 (layout 'fill-parent 400 1 'left 0)))))
(spacer 10)
(mbutton2 "sync-send" "Done" (lambda () (list (finish-activity 2))))
......@@ -1586,8 +1613,8 @@
(activity-layout activity))
(lambda (activity arg)
(list
(update-widget 'debug-text-view (get-id "sync-debug") 'text (get-current 'debug-text ""))
(update-widget 'text-view (get-id "sync-dirty") 'text (build-dirty))
;;(update-widget 'text-view (get-id "sync-console") 'text (build-sync-debug db "sync"))
))
(lambda (activity) '())
(lambda (activity) '())
......
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:background="#000000"
android:textColor="#ffffff"
android:maxLines = "12"
/>
......@@ -69,6 +69,7 @@ import android.text.TextWatcher;
import android.text.Html;
import android.text.Editable;
import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.widget.DatePicker;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
......@@ -296,6 +297,19 @@ public class StarwispBuilder
return;
}
if (type.equals("scroll-view-vert")) {
ScrollView v = new ScrollView(ctx);
v.setId(arr.getInt(1));
v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
parent.addView(v);
JSONArray children = arr.getJSONArray(3);
for (int i=0; i<children.length(); i++) {
Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
}
return;
}
if (type.equals("view-pager")) {
ViewPager v = new ViewPager(ctx);
v.setId(arr.getInt(1));
......@@ -376,15 +390,19 @@ public class StarwispBuilder
}
if (type.equals("debug-text-view")) {
TextView v = new TextView(ctx);
TextView v = (TextView)ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
// v.setBackgroundResource(R.color.black);
v.setId(arr.getInt(1));
v.setText(Html.fromHtml(arr.getString(2)));
// v.setText(Html.fromHtml(arr.getString(2)));
// v.setTextColor(R.color.white);
v.setTextSize(arr.getInt(3));
v.setMovementMethod(LinkMovementMethod.getInstance());
v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
// v.setTextSize(arr.getInt(3));
// v.setMovementMethod(LinkMovementMethod.getInstance());
// v.setMaxLines(10);
// v.setVerticalScrollBarEnabled(true);
// v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
//v.setMovementMethod(new ScrollingMovementMethod());
/*
if (arr.length()>5) {
if (arr.getString(5).equals("left")) {
v.setGravity(Gravity.LEFT);
......@@ -398,7 +416,7 @@ public class StarwispBuilder
} else {
v.setGravity(Gravity.LEFT);
}
v.setTypeface(((StarwispActivity)ctx).m_Typeface);
v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
parent.addView(v);
}
......@@ -1078,6 +1096,9 @@ public class StarwispBuilder
Log.i("starwisp","text-view...");
TextView v = (TextView)vv;
if (token.equals("text")) {
if (type.equals("debug-text-view")) {
//v.setMovementMethod(new ScrollingMovementMethod());
}
v.setText(arr.getString(3));
}
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment