Skip to content
Snippets Groups Projects
Commit bf024d3e authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

add new server code for clustering

parent 006637f1
No related branches found
No related tags found
No related merge requests found
......@@ -8,14 +8,17 @@ import sandbox.Point;
public class RecordCluster {
private ArrayList<Record> records;
private Point centroid;
private int individualCount;
public RecordCluster() {
records = new ArrayList<Record>();
centroid = new Point(0,0);
individualCount = 0;
}
public void addRecord(Record r) {
records.add(r);
individualCount++;
}
public Iterable<Record> records(){
......@@ -26,6 +29,10 @@ public class RecordCluster {
return records.size();
}
public int getCount() {
return records.size();
}
public Point centroid() {
double x = 0;
double y = 0;
......
......@@ -14,5 +14,6 @@
<url-pattern>/doBioLookup.do</url-pattern>
<url-pattern>/doHist.do</url-pattern>
<url-pattern>/doMap.do</url-pattern>
<url-pattern>/doCluster.do</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<%@ page import="java.util.*, data.Record, model.TrawlExpert, search.BST, search.BasicSearchResult,data.BioTree,data.TaxonNode,search.RecordCluster,sandbox.Point" %>
<%@page import="org.json.simple.JSONArray"%>
<%@page import="org.json.simple.JSONObject"%>
<%@page import="org.json.simple.parser.JSONParser"%>
<%
// Sample result data containing an iterable of records
TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl");
JSONParser parser = new JSONParser();
JSONObject req = (JSONObject) parser.parse(request.getReader().readLine());
Integer taxonId = (int) (long) req.get("taxId");
Integer yearLo = (int) (long) req.get("yearF");
Integer yearHi = (int) (long) req.get("yearT");
double area = (double) req.get("area");
BasicSearchResult result = te.rangeSearch(taxonId, yearLo, yearHi);
Iterable<RecordCluster> clusters = result.cluster(area);
// Initialize JSON Object and Arrays
JSONObject js = new JSONObject();
JSONArray longitude = new JSONArray();
JSONArray latitude = new JSONArray();
JSONArray count = new JSONArray();
// Update value of each JSON Object/Array at the same index as the corresponding Record in Result input
for (RecordCluster rc: clusters){
Point centroid = rc.centroid();
longitude.add(centroid.getX());
latitude.add(centroid.getY());
JSONObject dateobj = new JSONObject();
count.add(rc.getCount());
}
// Insert JSON Array and Objects into main Object
js.put("latitude", latitude);
js.put("longitude", longitude);
js.put("n", result.n());
js.put("individualCount", count);
js.put("time", result.time());
out.print(js.toJSONString());
%>
\ No newline at end of file
......@@ -42,7 +42,8 @@
js.put("longitude", longitude);
js.put("name", name);
js.put("date", date);
js.put("individual count", count);
js.put("n", result.n());
js.put("individualCount", count);
js.put("time", result.time());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment