From 75ef1653ffbf1aee8039032dc5ad9a41dd88576c Mon Sep 17 00:00:00 2001
From: tobias <tobias@thecodedev.de>
Date: Sun, 15 Sep 2019 21:11:30 +0200
Subject: [PATCH] Playout Log csv export group items by name

---
 .../src/main/resources/lang/_de.properties    |  2 +-
 .../playout/export/CsvPlayoutLogExport.scala  | 25 +++++++++++++------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/PlayWall/src/main/resources/lang/_de.properties b/PlayWall/src/main/resources/lang/_de.properties
index d3e6f30a..a334023f 100755
--- a/PlayWall/src/main/resources/lang/_de.properties
+++ b/PlayWall/src/main/resources/lang/_de.properties
@@ -223,7 +223,7 @@ MainLayout.Touch=Touchmodus
 Search.Button=Suchen
 Search.Placeholder=Suche
 Search.Alert.NoMatches.Header=Kachelsuche
-Search.Alert.NoMatches.Content=Keine weiteren Treffer zu '{}' gefunden.
+Search.Alert.NoMatches.Content=Keine weiteren Treffer zu '{}'. gefunden.
 
 # UI - Dialog - Page - Delete
 UI.Dialog.Page.Delete.Header=Seite l\u00F6schen
diff --git a/PlayWallPlugins/PlayWallPluginPlayoutLog/src/main/scala/de/tobias/playpad/plugin/playout/export/CsvPlayoutLogExport.scala b/PlayWallPlugins/PlayWallPluginPlayoutLog/src/main/scala/de/tobias/playpad/plugin/playout/export/CsvPlayoutLogExport.scala
index 25a1bb11..e45923c3 100644
--- a/PlayWallPlugins/PlayWallPluginPlayoutLog/src/main/scala/de/tobias/playpad/plugin/playout/export/CsvPlayoutLogExport.scala
+++ b/PlayWallPlugins/PlayWallPluginPlayoutLog/src/main/scala/de/tobias/playpad/plugin/playout/export/CsvPlayoutLogExport.scala
@@ -60,15 +60,26 @@ object CsvPlayoutLogExport {
 			.map(i => i.getPathUuid -> i.getTime)
 
 		items.foreach(item => {
-			val min: Long = timeMapping.filter(i => i._1 == item.id).minByOption(_._2).map(_._2).getOrElse(0)
-			val max: Long = timeMapping.filter(i => i._1 == item.id).maxByOption(_._2).map(_._2).getOrElse(0)
+			timeMapping.filter(i => i._1 == item.id).minByOption(_._2).map(_._2) match {
+				case Some(value) => item.firstTime = new Date(value)
+				case _ =>
+			}
 
-			if (min != 0)
-				item.firstTime = new Date(min)
-			if (max != 0)
-				item.lastTime = new Date(max)
+			timeMapping.filter(i => i._1 == item.id).maxByOption(_._2).map(_._2) match {
+				case Some(value) => item.lastTime = new Date(value)
+				case _ =>
+			}
 		})
 
-		items
+		items.groupBy(_.name).map((keyValue: (String, Array[CsvColumn])) => {
+			new CsvColumn(
+				null,
+				keyValue._1,
+				keyValue._2.map(i => i.count).sum,
+				keyValue._2.map(i => i.seasonCount).maxOption.getOrElse(0),
+				keyValue._2.map(i => i.firstTime).filter(_ != null).minOption.orNull,
+				keyValue._2.map(i => i.firstTime).filter(_ != null).minOption.orNull
+			)
+		}).toArray
 	}
 }
-- 
GitLab