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

add clustering to command line, fixed clustering distance calculation.

parent 1911e9b2
No related branches found
No related tags found
No related merge requests found
public class HelloWorld {
// Abbreviated Print line Function
private static void println(String line) {
System.out.println(line);
}
public static void main(String[] args) {
System.out.println("I really want a monkey!");
}
}
......@@ -112,7 +112,7 @@ public class Main {
System.out.println("Found " + result.n() + " records in " + result.time() + " seconds.");
while(true) {
System.out.println("Available commands: list, histogram, sum, exit");
System.out.println("Available commands: list, histogram, sum, cluster (area), exit");
System.out.print("> ");
Scanner s = new Scanner(System.in);
......@@ -126,7 +126,15 @@ public class Main {
return;
else if (command.equals("sum")) {
System.out.println(result.sum());
}
} else if (command.startsWith("cluster")) {
String[] strSpl = command.split(" ");
try {
doCluster(result.cluster(Double.parseDouble(strSpl[1])));
} catch (NumberFormatException e) {
}
} else
System.out.println("Invalid command " + command);
}
}
......@@ -181,4 +189,46 @@ public class Main {
}
System.out.format("Scale: one = is %d individuals.\n", max / scale);
}
/**
* Prints a histogram based on a BST of records
*
* @param record -An BST of records
*/
public static void doCluster(ArrayList<RecordCluster> clusters) {
System.out.println("Found " + clusters.size() + " clusters.");
String format = "|%1$-15s|%2$-15s|%3$-15s|%4$-15s|%5$-15s\n";
System.out.format(format, "Cluster #", "Latitude", "Longitude", "Record Count", "Individual Count");
for(int i = 0; i < clusters.size(); i++)
System.out.format(format, (i+1), String.format("%.5f", clusters.get(i).centroid().getY()), String.format("%.5f", clusters.get(i).centroid().getX()), clusters.get(i).N(), clusters.get(i).getCount());
while(true) {
System.out.println("Available commands: list (cluster #), clusters, exit");
Scanner s = new Scanner(System.in);
String command = s.nextLine();
if (command.startsWith("list")){
String[] strSpl = command.split(" ");
int clusterNum = 0;
try {
clusterNum = Integer.parseInt(strSpl[1]);
} catch (Exception e) {
System.out.println("Invalid command.");
continue;
}
try {
printRecords(clusters.get(clusterNum-1).records());
} catch (Exception e) {
System.out.println("Invalid cluster #");
}
} else if (command.equals("exit"))
return;
else if (command.equals("clusters")) {
doCluster(clusters);
return;
} else
System.out.println("Invalid command.");
}
}
}
......@@ -68,7 +68,7 @@ public class FileProcessor {
fr.close();
}
catch (IOException e) {
e.printStackTrace();
System.out.println("Fatal Error: Cannot find dataset at " + path + ".");
}
}
......
......@@ -76,10 +76,10 @@ public class Cluster {
}
private static double lngRange(double dist, double lat){
return dist/(Math.cos(lat)*222);
return dist/(Math.cos(Math.toRadians(lat))*222);
}
private static double latRange(double dist){
return (dist/111)/2;
return (dist/222);
}
}
......@@ -26,10 +26,10 @@ public class TrawlExpert {
public TrawlExpert() {
//load data
try {
//try loading from disc, otherwise load from dataset
BioTree.init("data/biotree/");
DataStore.records = new KDT<Record>("data/records.kdtree");
} catch (Exception e0) {
e0.printStackTrace();
try {
BioTree.init();
FileProcessor.initProcessing();
......
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