From 99ccb86756224e251679d06e3d8f208984e3ec20 Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Mon, 3 Oct 2016 03:20:30 +1300 Subject: [PATCH] Added Country with the most Outgoing FLights --- .../group9/GUI/RouteGraphController.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/seng202/group9/GUI/RouteGraphController.java b/src/main/java/seng202/group9/GUI/RouteGraphController.java index 5f01452..5eeaca1 100644 --- a/src/main/java/seng202/group9/GUI/RouteGraphController.java +++ b/src/main/java/seng202/group9/GUI/RouteGraphController.java @@ -91,6 +91,7 @@ public class RouteGraphController extends Controller{ loadDestGraph(); loadSourceGraph(); loadInCountryGraph(); + loadOutCountryGraph(); } public void loadAirlineGraph(){ @@ -232,7 +233,6 @@ public class RouteGraphController extends Controller{ } } } - System.out.println(countries.size()); int length = 10; if (countries.size() < 10){ length = countries.size(); @@ -253,6 +253,41 @@ public class RouteGraphController extends Controller{ inCountryGraph.getData().add(series); } + public void loadOutCountryGraph(){ + outCountryGraph.setTitle("Top 10 Countries Visited."); + outCountryXAxis.setLabel("Countries"); + XYChart.Series series = new XYChart.Series<>(); + series.setName("Number of Countries"); + LinkedHashMap countries = new LinkedHashMap<>(); + for (Route route: routesFiltered) { + Airport source = route.getSourceAirport(); + if (source != null){ + if (countries.containsKey(source.getCountryName())) { + countries.put(source.getCountryName(), countries.get(source.getCountryName()) + 1); + } else { + countries.put(source.getCountryName(), 1); + } + } + } + int length = 10; + if (countries.size() < 10){ + length = countries.size(); + } + for (int i = 0 ; i < length; i ++) { + int max = 0; + String maxCountry = null; + for (String country: countries.keySet()){ + if (countries.get(country) > max){ + maxCountry = country; + max = countries.get(country); + } + } + series.getData().add(new XYChart.Data(maxCountry, max)); + countries.remove(maxCountry); + } + outCountryGraph.getData().add(series); + } + public void goToRawData(){ replaceSceneContent(SceneCode.ROUTE_RAW_DATA); }