From bd70806586079628ea063a87eccf9f7e5aa93c8e Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Mon, 3 Jul 2017 18:16:50 +0200 Subject: [PATCH] Implemented first visualization of table Signed-off-by: Jim Martens --- 07/src/de/dis2017/MainAnalysis.java | 59 ++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/07/src/de/dis2017/MainAnalysis.java b/07/src/de/dis2017/MainAnalysis.java index c4bc14c..8b5dbd6 100644 --- a/07/src/de/dis2017/MainAnalysis.java +++ b/07/src/de/dis2017/MainAnalysis.java @@ -2,6 +2,11 @@ package de.dis2017; import de.dis2017.data.db.ORM; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + public class MainAnalysis { private static ORM _orm; @@ -10,6 +15,58 @@ public class MainAnalysis { */ public static void main(String[] args) { _orm = new ORM(); - _orm.getSalesCrossTable(2017); + Map>> sales = _orm.getSalesCrossTable(2017); + List articleNames = new ArrayList<>(sales.get("total").get("total").keySet()); + Collections.sort(articleNames); + System.out.print("City | Time | Sales | "); + int chars = 27; + for (String article : articleNames) { + if (article.equals("total")) continue; + System.out.print(article + " | "); + chars += article.length() + 3; + } + System.out.println("total"); + System.out.println(new String(new char[chars]).replace('\0', '-')); + + // cities + List cityNames = new ArrayList<>(sales.keySet()); + Collections.sort(cityNames); + for (String city : cityNames) { + if (city.equals("total")) continue; + Map> timeMap = sales.get(city); + List times = new ArrayList<>(timeMap.keySet()); + Collections.sort(times); + + for (String time : times) { + if (time.equals("total")) continue; + Map productMap = timeMap.get(time); + System.out.print(city + " | " + time + " | " ); + for (String article : articleNames) { + if (article.equals("total")) continue; + System.out.print(productMap.get(article) + " | "); + } + System.out.println(productMap.get("total")); + System.out.println(new String(new char[chars]).replace('\0', '-')); + } + Map productMap = timeMap.get("total"); + System.out.print(city + " | total | " ); + for (String article : articleNames) { + if (article.equals("total")) continue; + System.out.print(productMap.get(article) + " | "); + } + System.out.println(productMap.get("total")); + System.out.println(new String(new char[chars]).replace('\0', '-')); + } + + System.out.println(new String(new char[chars]).replace('\0', '-')); + + Map> timeMap = sales.get("total"); + Map productMap = timeMap.get("total"); + System.out.print("total | total | "); + for (String article : articleNames) { + if (article.equals("total")) continue; + System.out.print(productMap.get(article) + " | "); + } + System.out.println(productMap.get("total")); } }