From 1034ee6731ac3e24c795f0efc3c0be6a8a0440ef Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Mon, 3 Oct 2016 03:31:49 +1300 Subject: [PATCH] Added most similar Routes Graph --- .../group9/GUI/RouteGraphController.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/main/java/seng202/group9/GUI/RouteGraphController.java b/src/main/java/seng202/group9/GUI/RouteGraphController.java index e4710d1..a10984d 100644 --- a/src/main/java/seng202/group9/GUI/RouteGraphController.java +++ b/src/main/java/seng202/group9/GUI/RouteGraphController.java @@ -94,6 +94,7 @@ public class RouteGraphController extends Controller{ loadInCountryGraph(); loadOutCountryGraph(); loadEquipGraph(); + loadSimilarGraph(); } public void loadAirlineGraph(){ @@ -327,6 +328,78 @@ public class RouteGraphController extends Controller{ equipGraph.getData().add(series); } + + public void loadSimilarGraph(){ + similarGraph.setTitle("Top 10 Most Similar Routes"); + similarXAxis.setLabel("Routes"); + XYChart.Series series = new XYChart.Series<>(); + series.setName("Number of Routes"); + HashMap routes = new HashMap<>();//equipment, count + for (Route route: routesFiltered){ + String key = route.getDepartureAirport() + " to " + route.getArrivalAirport(); + if (routes.containsKey(key)){ + routes.put(key, routes.get(key) + 1); + }else{ + routes.put(key, 1); + } + } + + int length = 10; + if (routes.size() < 10){ + length = routes.size(); + } + for (int i = 0 ; i < length; i ++) { + int max = 0; + String maxRoute = ""; + for (String route: routes.keySet()){ + if (routes.get(route) > max){ + max = routes.get(route); + maxRoute = route; + } + } + series.getData().add(new XYChart.Data(maxRoute, max)); + routes.remove(maxRoute); + } + + similarGraph.getData().add(series); + } + + /*public void loadStopsGraph(){ + stopsGraph.setTitle("Top 10 Equipment used by Routes"); + XYChart.Series series = new XYChart.Series<>(); + series.setName("Number of Equipment"); + HashMap equipmentList = new HashMap<>();//equipment, count + for (Route route: routesFiltered){ + String equipment[] = route.getEquipment().split(" "); + for (String equip : equipment){ + if (equipmentList.containsKey(equip)){ + equipmentList.put(equip, equipmentList.get(equip) + 1); + }else{ + equipmentList.put(equip, 1); + } + } + } + + int length = 10; + if (equipmentList.size() < 10){ + length = equipmentList.size(); + } + for (int i = 0 ; i < length; i ++) { + int max = 0; + String maxEquip = ""; + for (String equip: equipmentList.keySet()){ + if (equipmentList.get(equip) > max){ + max = equipmentList.get(equip); + maxEquip = equip; + } + } + series.getData().add(new XYChart.Data(maxEquip, max)); + equipmentList.remove(maxEquip); + } + + equipGraph.getData().add(series); + }*/ + public void goToRawData(){ replaceSceneContent(SceneCode.ROUTE_RAW_DATA); }