Beispiel #1
0
 @Override
 public String getLastEntry() throws PDCDatabaseException {
   StreamDbHelper streamDbHelper = new StreamDbHelper(_app.getApplicationContext());
   Response response = streamDbHelper.getLastSurveyResponse();
   Campaign campaign = streamDbHelper.getCampaign(response.campaignUrn);
   JSONObject responseJson = new JSONObject();
   if (response != null) {
     try {
       responseJson.put("header_c", campaign.NAME);
       responseJson.put("header_u", response.username);
       responseJson.put("header_ci", "android");
       responseJson.put("date", response.date);
       responseJson.put("time", response.time);
       responseJson.put("timezone", response.timezone);
       responseJson.put("location_status", response.locationStatus);
       if (!response.locationStatus.equals(SurveyGeotagService.LOCATION_UNAVAILABLE)) {
         JSONObject locationJson = new JSONObject();
         locationJson.put("latitude", response.locationLatitude);
         locationJson.put("longitude", response.locationLongitude);
         locationJson.put("provider", response.locationProvider);
         locationJson.put("accuracy", response.locationAccuracy);
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String locationTimestamp = dateFormat.format(new Date(response.locationTime));
         locationJson.put("timestamp", locationTimestamp);
         responseJson.put("location", locationJson);
       }
       responseJson.put("survey_id", response.surveyId);
       responseJson.put("survey_launch_context", new JSONObject(response.surveyLaunchContext));
       responseJson.put("responses", new JSONArray(response.response));
     } catch (JSONException e) {
       throw new RuntimeException(e);
     }
   }
   return responseJson.toString();
 }
Beispiel #2
0
 @Override
 public List<String> getRangeIds(String start, String end) throws PDCDatabaseException {
   StreamDbHelper streamDbHelper = new StreamDbHelper(_app.getApplicationContext());
   List<Response> responses;
   if (start != null && end != null) {
     responses =
         streamDbHelper.getRangeSurveyResponse(Integer.parseInt(start), Integer.parseInt(end));
   } else if (start != null) {
     responses = streamDbHelper.getRangeSurveyResponse(Integer.parseInt(start), -1);
   } else {
     responses = streamDbHelper.getRangeSurveyResponse(-1, -1);
   }
   Campaign campaign = streamDbHelper.getCampaign(Response.CAMPAIGN_URN);
   ArrayList<String> responseStrArr = new ArrayList<String>();
   for (Response response : responses) {
     try {
       JSONObject responseJson = new JSONObject();
       responseJson.put("header_c", campaign.NAME);
       responseJson.put("header_u", response.username);
       responseJson.put("header_ci", "android");
       responseJson.put("date", response.date);
       responseJson.put("time", response.time);
       responseJson.put("timezone", response.timezone);
       responseJson.put("location_status", response.locationStatus);
       if (!response.locationStatus.equals(SurveyGeotagService.LOCATION_UNAVAILABLE)) {
         JSONObject locationJson = new JSONObject();
         locationJson.put("latitude", response.locationLatitude);
         locationJson.put("longitude", response.locationLongitude);
         locationJson.put("provider", response.locationProvider);
         locationJson.put("accuracy", response.locationAccuracy);
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String locationTimestamp = dateFormat.format(new Date(response.locationTime));
         locationJson.put("timestamp", locationTimestamp);
         responseJson.put("location", locationJson);
       }
       responseJson.put("survey_id", response.surveyId);
       responseJson.put("survey_launch_context", new JSONObject(response.surveyLaunchContext));
       responseJson.put("responses", new JSONArray(response.response));
       responseStrArr.add(responseJson.toString());
     } catch (JSONException e) {
       throw new RuntimeException(e);
     }
   }
   if (responses.isEmpty()) {
     throw new PDCDatabaseException("Could not find data record");
   }
   return responseStrArr;
 }
Beispiel #3
0
 @Override
 /*
  * parameters:
  * id : Id of the record which differs from stream to stream
  */
 public DataRecord getRecord(String id) throws PDCDatabaseException {
   StreamDbHelper streamDbHelper = new StreamDbHelper(_app.getApplicationContext());
   Response response = streamDbHelper.getSurveyResponse(Integer.parseInt(id));
   Campaign campaign = streamDbHelper.getCampaign(response.campaignUrn);
   HashMap<String, String> responseJson = new HashMap<String, String>();
   if (response != null) {
     try {
       responseJson.put("header_c", campaign.NAME);
       responseJson.put("header_u", response.username);
       responseJson.put("header_ci", "android");
       responseJson.put("date", response.date);
       responseJson.put("time", response.time + "");
       responseJson.put("timezone", response.timezone);
       responseJson.put("location_status", response.locationStatus);
       if (!response.locationStatus.equals(SurveyGeotagService.LOCATION_UNAVAILABLE)) {
         JSONObject locationJson = new JSONObject();
         locationJson.put("latitude", response.locationLatitude);
         locationJson.put("longitude", response.locationLongitude);
         locationJson.put("provider", response.locationProvider);
         locationJson.put("accuracy", response.locationAccuracy);
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String locationTimestamp = dateFormat.format(new Date(response.locationTime));
         locationJson.put("timestamp", locationTimestamp);
         responseJson.put("location", locationJson.toString());
       }
       responseJson.put("survey_id", response.surveyId);
       // responseJson.put("survey_launch_context", new JSONObject(
       //		response.surveyLaunchContext));
       // responseJson.put("responses", new JSONArray(response.response));
     } catch (JSONException e) {
       throw new RuntimeException(e);
     }
   }
   DataRecord dr = new DataRecord();
   dr.putAll(responseJson);
   return dr;
 }