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

finish the new version of bioresult

parent efa4a885
No related branches found
No related tags found
No related merge requests found
...@@ -292,17 +292,24 @@ public class BioTree implements Serializable { ...@@ -292,17 +292,24 @@ public class BioTree implements Serializable {
public static Iterable<Integer> getNonEmptyChildren(int taxonId){ public static Iterable<Integer> getNonEmptyChildren(int taxonId){
ArrayList<Integer> result = new ArrayList<Integer>(); ArrayList<Integer> result = new ArrayList<Integer>();
getNonEmptyChildren(idNodes.get(taxonId), result); getAllChildren(idNodes.get(taxonId), result, false);
return result; return result;
}
public static Iterable<Integer> getAllChildren(int taxonId){
ArrayList<Integer> result = new ArrayList<Integer>();
getAllChildren(idNodes.get(taxonId), result, true);
return result;
} }
private static void getNonEmptyChildren(TaxonNode txNode, ArrayList<Integer> result) { private static void getAllChildren(TaxonNode txNode, ArrayList<Integer> result, boolean emptyAllowed) {
if (txNode == null) return; if (txNode == null) return;
if (txNode.getCount() > 0) result.add(txNode.getTaxonId()); if ((txNode.getCount() > 0) || emptyAllowed) result.add(txNode.getTaxonId());
for (TaxonNode tx: txNode.getChildren()) { for (TaxonNode tx: txNode.getChildren()) {
getNonEmptyChildren(tx, result); getAllChildren(tx, result, emptyAllowed);
} }
} }
......
package model; package model;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
...@@ -54,4 +55,13 @@ public class TrawlExpert { ...@@ -54,4 +55,13 @@ public class TrawlExpert {
} }
return null; return null;
} }
public Iterable<Integer> getNonEmptyChildren(int taxonId){
return BioTree.getNonEmptyChildren(taxonId);
}
public Iterable<Integer> getAllChildren(int taxonId){
return BioTree.getAllChildren(taxonId);
}
} }
package search;
public interface GeneralCompare<T> {
public int compare(Comparable<T> a1, Comparable<T> a2);
}
<%@page import="org.json.simple.JSONArray"%> <%@page import="org.json.simple.JSONArray"%>
<%@page import="sort.MergeSort"%> <%@page import="sort.MergeSort"%>
<%@page import="sort.GeneralCompare"%> <%@page import="sort.GeneralCompare"%>
<%@page import="search.RedBlackTree"%>
<%@page import="search.Field"%>
<%@page import="data.TaxonType"%>
<%@page import="org.json.simple.parser.JSONParser"%> <%@page import="org.json.simple.parser.JSONParser"%>
<%@ page import="java.util.*, data.Record, model.TrawlExpert, search.BST, search.BasicSearchResult, org.json.simple.JSONObject, data.TaxonNode" %> <%@ page import="java.util.*, data.Record, model.TrawlExpert, search.BST, search.BasicSearchResult, org.json.simple.JSONObject, data.TaxonNode" %>
<% <%
...@@ -10,27 +13,59 @@ ...@@ -10,27 +13,59 @@
Integer taxonId = (int) (long) req.get("taxId"); Integer taxonId = (int) (long) req.get("taxId");
//System.out.println(taxonId); //System.out.println(taxonId);
ArrayList<TaxonNode> txNodes = ((ArrayList<TaxonNode>) te.getTaxonRecord(taxonId).getChildren());
TaxonNode[] txNodesAr = txNodes.toArray(new TaxonNode[txNodes.size()]);
GeneralCompare<TaxonNode> gc = (tn0, tn1) -> ((TaxonNode) tn0).getName().compareTo(((TaxonNode) tn1).getName()); //get all children
MergeSort.sort(txNodesAr, 0, txNodesAr.length - 1, gc); ArrayList<Integer> txIds = ((ArrayList<Integer>) te.getAllChildren(taxonId));
//GeneralCompare<String> gc = (t0, t1) -> ((String) t0).compareTo((String)t1);
//Field<String, ArrayList<TaxonNode>> fld = tn -> ((ArrayList<TaxonNode>) tn).get(0).getName().toString().toLowerCase();
//RedBlackTree<String, ArrayList<TaxonNode>> tt = new RedBlackTree<String, ArrayList<TaxonNode>>(fld, gc);
BST<TaxonType, ArrayList<TaxonNode>> tt = new BST<TaxonType, ArrayList<TaxonNode>>();
//add to BST in bins
for (Integer txId: txIds){
TaxonNode txNode = te.getTaxonRecord(txId);
ArrayList<TaxonNode> txList = tt.get(txNode.getTaxonType());
if (txList == null){
txList = new ArrayList<TaxonNode>();
txList.add(txNode);
tt.put(txNode.getTaxonType(), txList);
} else{
txList.add(txNode);
}
}
//initialize JSON objects and arrays
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
JSONArray taxonIds = new JSONArray(); JSONArray taxonIds = new JSONArray();
JSONArray names = new JSONArray(); JSONArray names = new JSONArray();
taxonIds.add(-1); GeneralCompare<TaxonNode> gc = (tn0, tn1) -> ((TaxonNode) tn0).getName().compareTo(((TaxonNode) tn1).getName());
names.add("Any");
//iterate through all results
for (TaxonNode tx: txNodesAr){ for(TaxonType taxType: tt.keys()){
taxonIds.add(tx.getTaxonId()); String name = taxType.toString().toLowerCase();
names.add(tx.getName()); ArrayList<TaxonNode> al = tt.get(taxType);
TaxonNode[] txNodesAr = al.toArray(new TaxonNode[al.size()]);
//sort result
MergeSort.sort(txNodesAr, 0, txNodesAr.length - 1, gc);
taxonIds = new JSONArray();
names = new JSONArray();
taxonIds.add(-1);
names.add("Any");
for (TaxonNode tx: txNodesAr){
taxonIds.add(tx.getTaxonId());
names.add(tx.getName());
}
JSONObject inner = new JSONObject();
inner.put("taxonName", names);
inner.put("taxonId", taxonIds);
js.put(name, inner);
} }
js.put("taxonId", taxonIds);
js.put("taxonName", names);
out.print(js.toJSONString()); out.print(js.toJSONString());
%> %>
\ No newline at end of file
...@@ -10,7 +10,7 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range ...@@ -10,7 +10,7 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="insert, some, keywords"> <!--TODO--> <meta name="keywords" content="insert, some, keywords"> <!--TODO-->
<meta name="description" content="insert a description"> <!--TODO--> <meta name="description" content="insert a description"> <!--TODO-->
<title>TrawlTool</title> <title>TrawlExpert</title>
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<!--JQuery--> <!--JQuery-->
...@@ -30,7 +30,7 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range ...@@ -30,7 +30,7 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range
<body> <body>
<header> <header>
<div class="headerWrapper"> <div class="headerWrapper">
<a href="index.jsp" >TrawlTool</a> <a href="index.jsp" >TrawlExpert</a>
<span class="nav-bar"> <span class="nav-bar">
<a href="about.html">About</a> | <a href="about.html">About</a> |
<a href="index.html" target="_blank">Gitlab/Github Nonfunc!</a> <a href="index.html" target="_blank">Gitlab/Github Nonfunc!</a>
......
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