Changeset 134
- Timestamp:
- 02/10/09 16:05:05 (10 months ago)
- Location:
- trunk/rapidandroid/org.rapidandroid
- Files:
-
- 4 added
- 10 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/rapidandroid/org.rapidandroid/AndroidManifest.xml
r98 r134 6 6 7 7 8 <application android: icon="@drawable/icon" android:label="@string/app_name" android:name="RapidAndroidApplication">8 <application android:label="@string/app_name" android:name="RapidAndroidApplication" android:icon="@drawable/rapidandroid"> 9 9 <provider android:authorities="org.rapidandroid.provider.RapidSms" android:name=".content.RapidSmsContentProvider"> 10 10 </provider> … … 63 63 </intent-filter> 64 64 </receiver> 65 <activity android:name=".activity.GlobalSettings"></activity> 65 66 </application> 66 67 -
trunk/rapidandroid/org.rapidandroid/assets/definitions/fields.json
r64 r134 1 [{"pk": 1, "model": "rapidandroid.field", "fields": {"fieldtype": 1, "prompt": "Location of distribution center", "name": "Location", "form": 1, "sequence": 1}}, {"pk": 2, "model": "rapidandroid.field", "fields": {"fieldtype": 2, "prompt": "Number of bednets received", "name": "received", "form": 1, "sequence": 2}}, {"pk": 3, "model": "rapidandroid.field", "fields": {"fieldtype": 2, "prompt": "Number of bednets that have been handed out", "name": "given", "form": 1, "sequence": 3}}, {"pk": 4, "model": "rapidandroid.field", "fields": {"fieldtype": 2, "prompt": "Number of bednets that remain in balance", "name": "balance", "form": 1, "sequence": 4}}, {"pk": 5, "model": "rapidandroid.field", "fields": {"fieldtype": 1, "prompt": "Child Identifier (6 digits)", "name": "child_id", "form": 2, "sequence": 1}}, {"pk": 6, "model": "rapidandroid.field", "fields": {"fieldtype": 3, "prompt": "weight", "name": "weight", "form": 2, "sequence": 2}}, {"pk": 7, "model": "rapidandroid.field", "fields": {"fieldtype": 4, "prompt": "height", "name": "height", "form": 2, "sequence": 3}}, {"pk": 8, "model": "rapidandroid.field", "fields": {"fieldtype": 5, "prompt": "ratio", "name": "ratio", "form": 2, "sequence": 4}}, {"pk": 9, "model": "rapidandroid.field", "fields": {"fieldtype": 6, "prompt": "muac", "name": "muac", "form": 2, "sequence": 5}}, {"pk": 10, "model": "rapidandroid.field", "fields": {"fieldtype": 7, "prompt": "Does child suffer from oedema", "name": "oedema", "form": 2, "sequence": 6}}, {"pk": 11, "model": "rapidandroid.field", "fields": {"fieldtype": 7, "prompt": "does the child suffer from diarrhoea", "name": "diarrhoea", "form": 2, "sequence": 7}}] 1 [{"pk": 1, "model": "rapidandroid.field", 2 "fields": {"fieldtype": 1, "prompt": "Distribution site location", "name": "Location", "form": 1, "sequence": 1}}, 3 {"pk": 2, "model": "rapidandroid.field", 4 "fields": {"fieldtype": 2, "prompt": "Number of bednets received", "name": "received", "form": 1, "sequence": 2}}, 5 {"pk": 3, "model": "rapidandroid.field", 6 "fields": {"fieldtype": 2, "prompt": "Number of bednets handed out", "name": "given", "form": 1, "sequence": 3}}, 7 {"pk": 4, "model": "rapidandroid.field", 8 "fields": {"fieldtype": 2, "prompt": "Number of bednets in inventory", "name": "balance", "form": 1, "sequence": 4}}, 9 {"pk": 5, "model": "rapidandroid.field", 10 "fields": {"fieldtype": 1, "prompt": "Child Identifier (6 digits)", "name": "child_id", "form": 2, "sequence": 1}}, 11 {"pk": 6, "model": "rapidandroid.field", 12 "fields": {"fieldtype": 3, "prompt": "weight", "name": "weight", "form": 2, "sequence": 2}}, 13 {"pk": 7, "model": "rapidandroid.field", 14 "fields": {"fieldtype": 4, "prompt": "height", "name": "height", "form": 2, "sequence": 3}}, 15 {"pk": 8, "model": "rapidandroid.field", 16 "fields": {"fieldtype": 5, "prompt": "ratio", "name": "ratio", "form": 2, "sequence": 4}}, 17 {"pk": 9, "model": "rapidandroid.field", 18 "fields": {"fieldtype": 6, "prompt": "muac", "name": "muac", "form": 2, "sequence": 5}}, 19 {"pk": 10, "model": "rapidandroid.field", 20 "fields": {"fieldtype": 7, "prompt": "Does child suffer from oedema", "name": "oedema", "form": 2, "sequence": 6}}, 21 {"pk": 11, "model": "rapidandroid.field", 22 "fields": {"fieldtype": 7, "prompt": "does the child suffer from diarrhoea", "name": "diarrhoea", "form": 2, "sequence": 7}}] 23 -
trunk/rapidandroid/org.rapidandroid/res/values/strings.xml
r109 r134 48 48 <string name="rad_last500">Last 500</string> 49 49 <string name="rad_all">All</string> 50 <string name="glbsettings_parse_ack">Successful Parse Reply</string> 51 <string name="glbsettings_noparse_ack">Failed Parse Reply</string> 52 <string name="glb_chk_noparse_text">Reply on failed parses</string> 53 <string name="glb_chk_parse_text">Reply on successful parses</string> 54 <string name="glbsettings_heading">Global reply settings</string> 50 55 </resources> -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/RapidAndroidApplication.java
r133 r134 37 37 super.onCreate(); 38 38 // Debug.startMethodTracing("rapidandroid_application"); 39 40 ApplicationGlobals.checkGlobals(this.getApplicationContext()); 39 41 ModelBootstrap.InitApplicationDatabase(this.getApplicationContext()); 40 42 -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/Dashboard.java
r133 r134 71 71 * @created Jan 9, 2009 72 72 * 73 *74 *75 73 */ 76 74 public class Dashboard extends Activity { … … 116 114 // private static final int ACTIVITY_DATERANGE = 2; 117 115 private static final int ACTIVITY_CHARTS = 3; // this and ACTIVITY_CHARTS 116 private static final int ACTIVITY_GLOBALSETTINGS = 4; 118 117 119 118 private static final int MENU_CREATE_ID = Menu.FIRST; … … 121 120 private static final int MENU_CHANGE_DATERANGE = Menu.FIRST + 2; 122 121 private static final int MENU_CHARTS_ID = Menu.FIRST + 3; 122 private static final int MENU_GLOBAL_SETTINGS = Menu.FIRST + 4; 123 123 // private static final int MENU_SHOW_REPORTS = Menu.FIRST + 3; 124 124 // private static final int MENU_EXIT = Menu.FIRST + 3; //waitaminute, we … … 402 402 beginListViewReload(); 403 403 break; 404 case ACTIVITY_GLOBALSETTINGS: 405 resetCursor = true; 406 beginListViewReload(); 407 break; 404 408 // case ACTIVITY_DATERANGE: 405 409 // if (extras != null) { … … 426 430 // R.string.chart_menu_change_parameters.setIcon(android.R.drawable.ic_menu_recent_history); 427 431 menu.add(0, MENU_CHARTS_ID, 0, R.string.dashboard_menu_view).setIcon(android.R.drawable.ic_menu_sort_by_size); 432 menu.add(0, MENU_GLOBAL_SETTINGS, 0, "Change Settings").setIcon(android.R.drawable.ic_menu_preferences); 428 433 // menu.add(0, MENU_SHOW_REPORTS, 0, 429 434 // R.string.dashboard_menu_show_reports); … … 449 454 startActivityChart(); 450 455 return true; 456 case MENU_GLOBAL_SETTINGS: 457 startActivityGlobalSettings(); 458 return true; 451 459 } 452 460 return true; 453 461 } 462 463 454 464 455 465 @Override … … 518 528 } 519 529 530 /** 531 * 532 */ 533 private void startActivityGlobalSettings() { 534 Intent i; 535 i = new Intent(this, GlobalSettings.class); 536 startActivityForResult(i, ACTIVITY_GLOBALSETTINGS); 537 538 } 539 520 540 // Start the form edit/create activity 521 541 private void startActivityFormReview() { -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/FormCreator.java
r133 r134 253 253 } 254 254 } while (checkForFields); 255 fin.close(); 255 256 f.delete(); 256 257 } -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/activity/FormReviewer.java
r133 r134 22 22 package org.rapidandroid.activity; 23 23 24 import java.io.BufferedReader; 24 25 import java.io.File; 26 import java.io.IOException; 27 import java.io.InputStream; 28 import java.io.StringReader; 29 import java.text.ParseException; 25 30 import java.util.Calendar; 26 31 import java.util.Date; 27 32 import java.util.Random; 33 import java.util.StringTokenizer; 28 34 import java.util.Vector; 29 35 … … 158 164 menu.add(0, MENU_DUMP_CSV, 0, R.string.formreview_dump_csv).setIcon(android.R.drawable.ic_menu_save); 159 165 160 menu.add(0, MENU_HTTP_UPLOAD, 0, R.string.formreview_upload_csv).setIcon(android.R.drawable.ic_menu_upload);161 162 menu.add(0, MENU_INJECT_DEBUG, 0, "Generate Data").setIcon(android.R.drawable.ic_menu_manage);166 // menu.add(0, MENU_HTTP_UPLOAD, 0, R.string.formreview_upload_csv).setIcon(android.R.drawable.ic_menu_upload); 167 168 //menu.add(0, MENU_INJECT_DEBUG, 0, "Generate Data").setIcon(android.R.drawable.ic_menu_manage); 163 169 return true; 164 170 } … … 344 350 @Override 345 351 public void run() { 346 doInjection(); 352 if(mForm.getFormName().toLowerCase().equals("bednets")) { 353 doCsvDirectBednetsInjection(); 354 } else { 355 doRandomizedInjection(); 356 } 347 357 mDebugHandler.post(mUpdateResults); 348 358 } … … 351 361 } 352 362 353 private void doInjection() { 363 364 private void doCsvDirectBednetsInjection() { 365 String rawMessageText = ""; 366 367 try { 368 InputStream is = this.getAssets().open("testdata/rawdata.csv"); 369 370 int size = is.available(); 371 372 // Read the entire asset into a local byte buffer. 373 byte[] buffer = new byte[size]; 374 is.read(buffer); 375 is.close(); 376 377 // Convert the buffer into a Java string. 378 String text = new String(buffer); 379 380 rawMessageText = text; 381 382 } catch (IOException e) { 383 // Should never happen! 384 throw new RuntimeException(e); 385 } 386 387 388 StringReader sr = new StringReader(rawMessageText); 389 BufferedReader bufRdr = new BufferedReader(sr); 390 391 String line = null; 392 int row = 0; 393 int col = 0; 394 Vector<String[]> lines = new Vector<String[]>(); 395 // read each line of text file 396 try { 397 while ((line = bufRdr.readLine()) != null) { 398 StringTokenizer st = new StringTokenizer(line, ","); 399 int tokCount = st.countTokens(); 400 401 String[] tokenizedLine = new String[tokCount]; 402 int toki = 0; 403 while (st.hasMoreTokens()) { 404 tokenizedLine[toki] = st.nextToken(); 405 toki++; 406 } 407 lines.add(tokenizedLine); 408 } 409 } catch (IOException e) { 410 // TODO Auto-generated catch block 411 e.printStackTrace(); 412 } finally { 413 414 try { 415 sr.close(); 416 bufRdr.close(); 417 } catch (IOException e) { 418 // TODO Auto-generated catch block 419 e.printStackTrace(); 420 } 421 } 422 int len = lines.size(); 423 424 for (int i = 0; i < len; i++) { 425 String[] csvline = lines.get(i); 426 427 String datestr = csvline[0]; 428 429 Date dateval = new Date(); 430 try { 431 dateval = Message.SQLDateFormatter.parse(datestr); 432 } catch (ParseException e) { 433 // TODO Auto-generated catch block 434 e.printStackTrace(); 435 436 } 437 String sender = csvline[1]; 438 String text = csvline[2]; 439 440 Monitor monitor = MessageTranslator.GetMonitorAndInsertIfNew(this, sender); 441 442 ContentValues messageValues = new ContentValues(); 443 messageValues.put(RapidSmsDBConstants.Message.MESSAGE, text); 444 messageValues.put(RapidSmsDBConstants.Message.MONITOR, monitor.getID()); 445 446 messageValues.put(RapidSmsDBConstants.Message.TIME, Message.SQLDateFormatter.format(getRandomDate())); 447 messageValues.put(RapidSmsDBConstants.Message.RECEIVE_TIME, Message.SQLDateFormatter.format(dateval)); 448 messageValues.put(RapidSmsDBConstants.Message.IS_OUTGOING, false); 449 450 Uri msgUri = null; 451 452 msgUri = this.getContentResolver().insert(RapidSmsDBConstants.Message.CONTENT_URI, messageValues); 453 Vector<IParseResult> results = ParsingService.ParseMessage(mForm, text); 454 ParsedDataTranslator.InsertFormData(this, mForm, Integer.valueOf(msgUri.getPathSegments().get(1)) 455 .intValue(), results); 456 } 457 458 459 460 } 461 462 private void doRandomizedInjection() { 354 463 Random r = new Random(); 355 464 -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/data/controller/ParsedDataReporter.java
r133 r134 141 141 142 142 Cursor cr = mHelper.getReadableDatabase().rawQuery(query.toString(), null); 143 144 File sdcard = Environment.getExternalStorageDirectory();145 File destinationdir = new File(sdcard, "rapidandroid/exports");146 destinationdir.mkdir();147 Date now = new Date();148 File destinationfile = new File(destinationdir, "formdata_" + f.getPrefix() + now.getYear() + now.getMonth()149 + now.getDate() + "-" + now.getHours() + now.getMinutes() + ".csv");150 143 FileOutputStream fOut = null; 144 151 145 try { 146 147 File sdcard = Environment.getExternalStorageDirectory(); 148 File destinationdir = new File(sdcard, "rapidandroid/exports"); 149 destinationdir.mkdir(); 150 Date now = new Date(); 151 File destinationfile = new File(destinationdir, "formdata_" + f.getPrefix() + now.getYear() 152 + now.getMonth() + now.getDate() + "-" + now.getHours() + now.getMinutes() + ".csv"); 153 154 152 155 destinationfile.createNewFile(); 153 156 fOut = new FileOutputStream(destinationfile); -
trunk/rapidandroid/org.rapidandroid/src/org/rapidandroid/receiver/SmsParseReceiver.java
r133 r134 24 24 import java.util.Vector; 25 25 26 import org.json.JSONException; 27 import org.json.JSONObject; 28 import org.rapidandroid.ApplicationGlobals; 26 29 import org.rapidandroid.content.translation.MessageTranslator; 27 30 import org.rapidandroid.content.translation.ModelTranslator; 28 31 import org.rapidandroid.content.translation.ParsedDataTranslator; 29 30 32 import org.rapidsms.java.core.model.Form; 31 33 import org.rapidsms.java.core.model.Monitor; … … 51 53 private static String[] prefixes = null; 52 54 private static Form[] forms = null; 55 56 57 private static boolean globalsLoaded = false; 58 private static boolean mReplyParse = true; 59 private static boolean mReplyFail = true; 60 61 private static String mReplyParseText = ""; 62 private static String mReplyFailText = ""; 63 64 65 public static void initGlobals(Context context) { 66 if(!globalsLoaded) { 67 JSONObject globals = ApplicationGlobals.loadSettingsFromFile(context); 68 try { 69 mReplyParse = globals.getBoolean(ApplicationGlobals.KEY_PARSE_REPLY); 70 mReplyFail = globals.getBoolean(ApplicationGlobals.KEY_FAILED_REPLY); 71 mReplyParseText = globals.getString(ApplicationGlobals.KEY_PARSE_REPLY_TEXT); 72 mReplyFailText = globals.getString(ApplicationGlobals.KEY_FAILED_REPLY_TEXT); 73 globalsLoaded = true; 74 } catch (JSONException e) { 75 // TODO Auto-generated catch block 76 e.printStackTrace(); 77 } 78 } 79 } 53 80 54 81 // private Context mContext = null; … … 79 106 @Override 80 107 public void onReceive(Context context, Intent intent) { 81 // if (mContext == null) { 82 // mContext = context; 83 // } 108 initGlobals(context); 109 84 110 if (prefixes == null) { 85 111 initFormCache(); // profiler shows us that this is being called … … 98 124 Form form = determineForm(body); 99 125 if (form == null) { 100 Intent broadcast = new Intent("org.rapidandroid.intents.SMS_REPLY"); 101 broadcast.putExtra(SmsReplyReceiver.KEY_DESTINATION_PHONE, intent.getStringExtra("from")); 102 broadcast.putExtra(SmsReplyReceiver.KEY_MESSAGE, "Your message could not be parsed"); 103 context.sendBroadcast(broadcast); 126 127 128 if (mReplyFail) { 129 Intent broadcast = new Intent("org.rapidandroid.intents.SMS_REPLY"); 130 broadcast.putExtra(SmsReplyReceiver.KEY_DESTINATION_PHONE, intent.getStringExtra("from")); 131 broadcast.putExtra(SmsReplyReceiver.KEY_MESSAGE, mReplyFailText); 132 context.sendBroadcast(broadcast); 133 } 104 134 return; 105 135 } else { 106 136 Monitor mon = MessageTranslator.GetMonitorAndInsertIfNew(context, intent.getStringExtra("from")); 107 137 // if(mon.getReplyPreference()) { 108 // if(true) { 109 // //for debug purposes, we'll just ack every time. 110 // Intent broadcast = new 111 // Intent("org.rapidandroid.intents.SMS_REPLY"); 112 // broadcast.putExtra(SmsReplyReceiver.KEY_DESTINATION_PHONE, 113 // intent.getStringExtra("from")); 114 // broadcast.putExtra(SmsReplyReceiver.KEY_MESSAGE, 115 // "Message parse successful, thank you!"); 116 // context.sendBroadcast(broadcast); 117 // } 118 138 if (mReplyParse) { 139 // for debug purposes, we'll just ack every time. 140 Intent broadcast = new Intent("org.rapidandroid.intents.SMS_REPLY"); 141 broadcast.putExtra(SmsReplyReceiver.KEY_DESTINATION_PHONE, intent.getStringExtra("from")); 142 broadcast.putExtra(SmsReplyReceiver.KEY_MESSAGE, mReplyParseText); 143 context.sendBroadcast(broadcast); 144 } 119 145 Vector<IParseResult> results = ParsingService.ParseMessage(form, body); 120 146 ParsedDataTranslator.InsertFormData(context, form, msgid, results); 121 122 147 } 123 148 } -
trunk/rapidandroid/org.rapidandroid/unittests/org/rapidandroid/tests/MessageCorpusTests.java
r133 r134 65 65 for (int i = 0; i < forms.length; i++) { 66 66 prefixes[i] = forms[i].getPrefix(); 67 getContext().getContentResolver().delete( 68 Uri.parse(RapidSmsDBConstants.FormData.CONTENT_URI_PREFIX 67 getContext().getContentResolver().delete(Uri.parse(RapidSmsDBConstants.FormData.CONTENT_URI_PREFIX 69 68 + forms[i].getFormId()), null, null); 70 69