Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions Java/API/src/edu/uml/cs/isense/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public ArrayList<RProject> getProjects(int page, int perPage,
proj.project_id = inner.getInt("id");
proj.name = inner.getString("name");
proj.url = inner.getString("url");
proj.hidden = inner.getBoolean("hidden");
proj.featured = inner.getBoolean("featured");
proj.like_count = inner.getInt("likeCount");
proj.timecreated = inner.getString("createdAt");
Expand Down Expand Up @@ -236,7 +235,6 @@ public RProject getProject(int projectId) {
proj.project_id = j.getInt("id");
proj.name = j.getString("name");
proj.url = j.getString("url");
proj.hidden = j.getBoolean("hidden");
proj.featured = j.getBoolean("featured");
proj.like_count = j.getInt("likeCount");
proj.timecreated = j.getString("createdAt");
Expand Down Expand Up @@ -437,7 +435,6 @@ public ArrayList<RDataSet> getDataSets(int projectId) {
JSONObject inner = dataSets.getJSONObject(i);
rds.ds_id = inner.getInt("id");
rds.name = inner.getString("name");
rds.hidden = inner.getBoolean("hidden");
rds.url = inner.getString("url");
rds.timecreated = inner.getString("createdAt");
rds.fieldCount = inner.getInt("fieldCount");
Expand All @@ -450,6 +447,76 @@ public ArrayList<RDataSet> getDataSets(int projectId) {
return result;
}

/**
* Gets all the data sets associated with a project The data sets returned
* by this function DO have their data field filled.
*
* @param projectId
* The project ID whose data sets you want
* @return An ArrayList of Data Set objects
*/
public ArrayList<RDataSet> getFilledDataSets(int projectId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not lined up correctly. The first half of the function is indented way more than the second half. Check your editor's settings.

ArrayList<RDataSet> result = new ArrayList<RDataSet>();
try {
String reqResult = makeRequest(baseURL, "projects/" + projectId,
"recur=true", "GET", null);
JSONObject j = new JSONObject(reqResult);
JSONArray dataSets = j.getJSONArray("dataSets");
for (int i = 0; i < dataSets.length(); i++) {
RDataSet rds = new RDataSet();
JSONObject inner = dataSets.getJSONObject(i);
rds.ds_id = inner.getInt("id");
rds.name = inner.getString("name");
rds.url = inner.getString("url");
rds.timecreated = inner.getString("createdAt");
rds.fieldCount = inner.getInt("fieldCount");
rds.datapointCount = inner.getInt("datapointCount");
JSONObject jo = new JSONObject();
jo.put("data", inner.getJSONArray("data"));
rds.data = rowsToCols(jo);
rds.project_id = projectId;
result.add(rds);
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

/**
*
* Gets all datasets associated with a project by field.
* @param projectId The project ID whose datasets you're looking for
* @param field The field we care about
*
* @return An ArrayList of Strings containing the appropriate data
*/
public ArrayList<String> getDataSetsByField(int ProjectID, String field) {
String FieldID = null;
ArrayList<RDataSet> rdata = getFilledDataSets(ProjectID);
ArrayList<RProjectField> projectFields = getProjectFields(ProjectID);
ArrayList<String> fdata = new ArrayList<String>();
for (RProjectField f : projectFields) {
if (f.name.equals(field)) {
FieldID = f.field_id + "";
break;
}
}
for (RDataSet r : rdata) {
try {
System.out.println("iSENSE: fdata:" + r.data.getString(FieldID));
JSONArray jadata = new JSONArray();
jadata = r.data.getJSONArray(FieldID);
for (int i = 0; i < jadata.length(); i++) {
fdata.add(jadata.getString(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return fdata;
}

/**
* Upload a dataset to iSENSE while logged in
*
Expand Down