Skip to content

Commit

Permalink
Data Download & processing works! :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanoux committed Apr 22, 2019
1 parent 998e38c commit 0d2cc8e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
23 changes: 19 additions & 4 deletions app/src/main/java/com/example/wifiology/AsyncHTTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class AsyncHTTPClient {
private static final String BASE_URL = "http://100.115.92.204:5000/api/1.0/";
//private static final String BASE_URL = "http://100.115.92.204:5000/api/1.0/";
//private static final String BASE_URL = "https://wifiology-pr-25.herokuapp.com/api/1.0/";
//private static final String BASE_URL = "https://wifiology.copesystems.com/api/1.0/";
private static final String BASE_URL = "https://wifiology.copesystems.com/api/1.0/";

private static RequestQueue queue;
private static Context context;
Expand All @@ -39,11 +40,25 @@ public static void setup(Context con){
public static void auth (String _userName, String _password, Response.Listener<String> responseHandler,Response.ErrorListener errorHandler){
username = _userName;
password = _password;
getString("users/",null,true,responseHandler,errorHandler);
getString("users/me/",null,true,responseHandler,errorHandler);
}

public static void getString(String url, final HashMap<String, String> data,final boolean useAuth , Response.Listener<String> responseHandler,Response.ErrorListener errorHandler) {
StringRequest getRequest = new StringRequest(Request.Method.GET, getAbsoluteUrl(url), responseHandler,errorHandler){
String uri = getAbsoluteUrl(url);
if (data != null && data.size() > 0) {
uri += "?";
String[] keys = new String[data.size()];
keys = data.keySet().toArray(keys);
for (int i = 0; i < keys.length; i++) {
String val = data.get(keys[i]);
uri += keys[i] + "=" + val;
if (i < keys.length - 1) {
uri += "&";
}
}
}
//Log.e("TESTING",uri);
StringRequest getRequest = new StringRequest(Request.Method.GET, uri, responseHandler,errorHandler){
@Override
protected Map<String, String> getParams()
{
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/com/example/wifiology/DataActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Date parseDate(String date, SimpleDateFormat form){
}

void getNodes(){
AsyncHTTPClient.getString("users/me/nodes", null, true, new Response.Listener<String>() {
AsyncHTTPClient.getString("nodes", null, true, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
Expand All @@ -147,11 +147,12 @@ public void onResponse(String response) {
for (int i = 0; i < array.length(); i++){
JSONObject ob = array.getJSONObject(i);
int nodeId = ob.getInt("nodeID");
String nodeLocation = ob.getString("nodeLocation");
boolean isLast = false;
if (i == array.length() - 1){
isLast = true;
}
getMeasurements(nodeId,isLast);
getMeasurements(nodeId,nodeLocation,isLast);
}
}catch (JSONException error){
Log.e("Wifiology","Error " + "" + ": " + error.toString());
Expand All @@ -166,17 +167,21 @@ public void onErrorResponse(VolleyError error) {
}

//for now: get service sets, avg number of stations on the service set, range of times of measurement
void getMeasurements(int nodeId, final boolean isLast){
//put stuff for last measurement id and shit here later maybe i dunno
AsyncHTTPClient.getString("nodes/" + nodeId + "/measurements", null, true, new Response.Listener<String>() {
void getMeasurements(int nodeId, final String location, final boolean isLast){
HashMap<String, String> params = new HashMap<String, String>();
//params.put("channel","10");
params.put("limit","20");
//params.put("lastPriorMeasurementID","potato");
AsyncHTTPClient.getString("nodes/" + nodeId + "/measurements", params, true, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//run this on its own thread later?
try {
JSONArray array = new JSONArray(response);
SimpleDateFormat dateForm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.000Z'", Locale.US);
SimpleDateFormat dateForm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
//Log.e("TEST",array.length() + "");

for (int i = 0; i < array.length(); i++){
for (int i = array.length()-1; i >= 0; i--){
JSONObject ob = array.getJSONObject(i);
JSONObject obM = ob.getJSONObject("measurement");

Expand All @@ -194,14 +199,15 @@ public void onResponse(String response) {
networksList.put(setId,newData);
}
}
if (i == array.length() - 1){
if (i == 0){
String end = obM.getString("measurementEndTime");
Date endDate = parseDate(end,dateForm);

Integer[] keys = new Integer[networksList.keySet().size()];
keys = networksList.keySet().toArray(keys);
for (int j = 0; j < keys.length; j++){
networksList.get(keys[j]).setLatestTime(endDate);
networksList.get(keys[j]).setLocation(location);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/example/wifiology/NetworkAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
String textEnd = "Time of last measurement: " + network.getLatestTime().toString();
holder.timeEnd.setText(textEnd);
}
if (network.getLocation() != null) {
String loc = "Measurement Location: " + network.getLocation();
holder.location.setText(loc);
}
boolean expanded = network.getExpanded();
holder.subLayout.setVisibility(expanded ? View.VISIBLE : View.GONE);

Expand All @@ -64,9 +68,7 @@ public int getItemCount(){

public class ViewHolder extends RecyclerView.ViewHolder{

public TextView ssidText;
public TextView timeBegin;
public TextView timeEnd;
public TextView ssidText,timeBegin,timeEnd,location;
public LinearLayout layout;
public LinearLayout subLayout;

Expand All @@ -76,6 +78,7 @@ public ViewHolder(@NonNull View itemView) {
ssidText = itemView.findViewById(R.id.networkSSIDText);
timeBegin = itemView.findViewById(R.id.timeBegin);
timeEnd = itemView.findViewById(R.id.timeEnd);
location = itemView.findViewById(R.id.location);
layout = itemView.findViewById(R.id.linearLayoutNetworks);
subLayout = itemView.findViewById(R.id.linearLayoutNetworksExpanded);
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/example/wifiology/NetworkData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class NetworkData {
private boolean expanded;
private Date earliestTime;
private Date latestTime;
private String location;

public NetworkData(String _ssid){
ssid = _ssid;
Expand Down Expand Up @@ -41,4 +42,12 @@ public Date getLatestTime(){
return latestTime;
}

public void setLocation(String loc){
location = loc;
}

public String getLocation(){
return location;
}

}
8 changes: 8 additions & 0 deletions app/src/main/res/layout/networks_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
android:layout_marginBottom="8dp"
android:text="Time of last measurement: "/>

<TextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginBottom="8dp"
android:text="Measurement Location: "/>


</LinearLayout>

Expand Down

0 comments on commit 0d2cc8e

Please sign in to comment.