diff --git a/src/search/RecordCluster.java b/src/search/RecordCluster.java index 6bfe63086954c1f941215efb696b4cb6c0257326..ebccd096631c031e561e2cf9648d061e30eb7bbe 100644 --- a/src/search/RecordCluster.java +++ b/src/search/RecordCluster.java @@ -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; diff --git a/tomcat/webapps/Trawl/WEB-INF/web.xml b/tomcat/webapps/Trawl/WEB-INF/web.xml index 6b212a242070ce3bacf257925c8b9b5a99795ffa..dc7d6ca231cc2439744237d61062a4a5984953cf 100644 --- a/tomcat/webapps/Trawl/WEB-INF/web.xml +++ b/tomcat/webapps/Trawl/WEB-INF/web.xml @@ -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 diff --git a/tomcat/webapps/Trawl/cluster.jsp b/tomcat/webapps/Trawl/cluster.jsp new file mode 100644 index 0000000000000000000000000000000000000000..13c26d6fcadc83e8df02e8ab629e8a39b61ce42f --- /dev/null +++ b/tomcat/webapps/Trawl/cluster.jsp @@ -0,0 +1,49 @@ +<%@ 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 diff --git a/tomcat/webapps/Trawl/map.jsp b/tomcat/webapps/Trawl/map.jsp index 6681bdb2b42985714f5769ba926aca4148048cb7..79cd8c76ec763c5f003a5ae5e47fbd6e2bb88ebe 100644 --- a/tomcat/webapps/Trawl/map.jsp +++ b/tomcat/webapps/Trawl/map.jsp @@ -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());