Java Code Examples for org.codehaus.jettison.json.JSONObject#getDouble()

The following examples show how to use org.codehaus.jettison.json.JSONObject#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NycTaxiDataServer.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void processQuery(String queryStr)
{
  try {
    JSONObject query = new JSONObject(queryStr);
    JSONObject result = new JSONObject();
    double lat = query.getDouble("lat");
    double lon = query.getDouble("lon");
    Pair<String, String> zips = recommendZip(lat, lon);
    result.put("currentZip", zips.getLeft());
    result.put("driveToZip", zips.getRight());
    resultQueue.add(result.toString());
  } catch (JSONException e) {
    LOG.error("Unrecognized query: {}", queryStr);
  }
}
 
Example 2
Source File: ValidationRules.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
public ValidationRules(JSONObject jsonObject)  throws JSONException {
  if (jsonObject != null) {
    JSONArray jsonArray = jsonObject.getJSONArray("bannedVanderIds");

    for (int i = 0; i < jsonArray.length(); i++) {
      String bannedId = jsonArray.getString(i);
      LOG.info(" - Adding bannded venderId:" + bannedId);
      bannedVanderIdSet.add(bannedId);
    }

    thresholdInSpendDifferenceFromTodayFromPastMonthAverage = jsonObject.getDouble("thresholdInSpendDifferenceFromTodayFromPastMonthAverage");
  } else {
    LOG.warn("No Validation Rules Found in HBase");
  }
}
 
Example 3
Source File: UserEvent.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
public UserEvent(JSONObject jsonObject)  throws JSONException {
  userId = jsonObject.getString("userId");
  timeStamp = jsonObject.getLong("timeStamp");
  ipAddress = jsonObject.getString("ipAddress");
  countryCode = jsonObject.getString("countryCode");
  zipCode = jsonObject.getString("zipCode");
  itemCategory = jsonObject.getString("itemCategory");
  paymentAmount = jsonObject.getDouble("paymentAmount");
  vendorId = jsonObject.getString("vendorId");
  isCardPresent = jsonObject.getBoolean("isCardPresent");
}
 
Example 4
Source File: UserProfile.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
public UserProfile(JSONObject jsonObject)  throws JSONException {
  userId = jsonObject.getString("userId");
  historicAvgSingleDaySpend = jsonObject.getDouble("historicAvgSingleDaySpend");
  historicAvg90PercentSingleDaySpend = jsonObject.getDouble("historicAvg90PercentSingleDaySpend");
  todayMaxSpend = jsonObject.getDouble("todayMaxSpend");
  todayNumOfPurchases = jsonObject.getLong("todayNumOfPurchases");

  populateMapWithLong(jsonObject.getJSONObject("spendByLast100VenderId"), spendByLast100VenderId);
}
 
Example 5
Source File: TestRMWebServicesCapacitySched.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void verifySubQueue(JSONObject info, String q, 
    float parentAbsCapacity, float parentAbsMaxCapacity)
    throws JSONException, Exception {
  int numExpectedElements = 13;
  boolean isParentQueue = true;
  if (!info.has("queues")) {
    numExpectedElements = 25;
    isParentQueue = false;
  }
  assertEquals("incorrect number of elements", numExpectedElements, info.length());

  QueueInfo qi = isParentQueue ? new QueueInfo() : new LeafQueueInfo();
  qi.capacity = (float) info.getDouble("capacity");
  qi.usedCapacity = (float) info.getDouble("usedCapacity");
  qi.maxCapacity = (float) info.getDouble("maxCapacity");
  qi.absoluteCapacity = (float) info.getDouble("absoluteCapacity");
  qi.absoluteMaxCapacity = (float) info.getDouble("absoluteMaxCapacity");
  qi.absoluteUsedCapacity = (float) info.getDouble("absoluteUsedCapacity");
  qi.numApplications = info.getInt("numApplications");
  qi.queueName = info.getString("queueName");
  qi.state = info.getString("state");

  verifySubQueueGeneric(q, qi, parentAbsCapacity, parentAbsMaxCapacity);

  if (isParentQueue) {
    JSONArray arr = info.getJSONObject("queues").getJSONArray("queue");
    // test subqueues
    for (int i = 0; i < arr.length(); i++) {
      JSONObject obj = arr.getJSONObject(i);
      String q2 = q + "." + obj.getString("queueName");
      verifySubQueue(obj, q2, qi.absoluteCapacity, qi.absoluteMaxCapacity);
    }
  } else {
    LeafQueueInfo lqi = (LeafQueueInfo) qi;
    lqi.numActiveApplications = info.getInt("numActiveApplications");
    lqi.numPendingApplications = info.getInt("numPendingApplications");
    lqi.numContainers = info.getInt("numContainers");
    lqi.maxApplications = info.getInt("maxApplications");
    lqi.maxApplicationsPerUser = info.getInt("maxApplicationsPerUser");
    lqi.userLimit = info.getInt("userLimit");
    lqi.userLimitFactor = (float) info.getDouble("userLimitFactor");
    verifyLeafQueueGeneric(q, lqi);
    // resourcesUsed and users (per-user resources used) are checked in
    // testPerUserResource()
  }
}
 
Example 6
Source File: TestRMWebServicesCapacitySched.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void verifySubQueue(JSONObject info, String q, 
    float parentAbsCapacity, float parentAbsMaxCapacity)
    throws JSONException, Exception {
  int numExpectedElements = 13;
  boolean isParentQueue = true;
  if (!info.has("queues")) {
    numExpectedElements = 25;
    isParentQueue = false;
  }
  assertEquals("incorrect number of elements", numExpectedElements, info.length());

  QueueInfo qi = isParentQueue ? new QueueInfo() : new LeafQueueInfo();
  qi.capacity = (float) info.getDouble("capacity");
  qi.usedCapacity = (float) info.getDouble("usedCapacity");
  qi.maxCapacity = (float) info.getDouble("maxCapacity");
  qi.absoluteCapacity = (float) info.getDouble("absoluteCapacity");
  qi.absoluteMaxCapacity = (float) info.getDouble("absoluteMaxCapacity");
  qi.absoluteUsedCapacity = (float) info.getDouble("absoluteUsedCapacity");
  qi.numApplications = info.getInt("numApplications");
  qi.queueName = info.getString("queueName");
  qi.state = info.getString("state");

  verifySubQueueGeneric(q, qi, parentAbsCapacity, parentAbsMaxCapacity);

  if (isParentQueue) {
    JSONArray arr = info.getJSONObject("queues").getJSONArray("queue");
    // test subqueues
    for (int i = 0; i < arr.length(); i++) {
      JSONObject obj = arr.getJSONObject(i);
      String q2 = q + "." + obj.getString("queueName");
      verifySubQueue(obj, q2, qi.absoluteCapacity, qi.absoluteMaxCapacity);
    }
  } else {
    LeafQueueInfo lqi = (LeafQueueInfo) qi;
    lqi.numActiveApplications = info.getInt("numActiveApplications");
    lqi.numPendingApplications = info.getInt("numPendingApplications");
    lqi.numContainers = info.getInt("numContainers");
    lqi.maxApplications = info.getInt("maxApplications");
    lqi.maxApplicationsPerUser = info.getInt("maxApplicationsPerUser");
    lqi.userLimit = info.getInt("userLimit");
    lqi.userLimitFactor = (float) info.getDouble("userLimitFactor");
    verifyLeafQueueGeneric(q, lqi);
    // resourcesUsed and users (per-user resources used) are checked in
    // testPerUserResource()
  }
}