|
@@ -16,6 +16,7 @@ import scala.collection.{immutable, mutable}
|
16
|
16
|
import scala.concurrent.Await
|
17
|
17
|
import scala.concurrent.duration.DurationInt
|
18
|
18
|
import scala.language.postfixOps
|
|
19
|
+import scala.util.Try
|
19
|
20
|
|
20
|
21
|
|
21
|
22
|
@Component
|
|
@@ -40,11 +41,6 @@ class MovieQueryService extends MovieServiceTrait {
|
40
|
41
|
.via(CsvToMap.toMapAsStringsCombineAll(headerPlaceholder = Option.empty))
|
41
|
42
|
}
|
42
|
43
|
|
43
|
|
-
|
44
|
|
- val res = getSeriesTitle(titleEpisodeResource)
|
45
|
|
- val r = getTitleByIds(titleBasicsResource, res)
|
46
|
|
- println(r)
|
47
|
|
-
|
48
|
44
|
override def principalsForMovieName(name: String): List[Principal] = {
|
49
|
45
|
|
50
|
46
|
val titleId: String = getIdOfTitle(titleBasicsResource, name)
|
|
@@ -53,8 +49,11 @@ class MovieQueryService extends MovieServiceTrait {
|
53
|
49
|
personsList
|
54
|
50
|
}
|
55
|
51
|
|
56
|
|
- override def tvSeriesWithGreatestNumberOfEpisodes(): List[TvSeries] = ???
|
57
|
|
- //val personsIdList: List[String] = getSeriestitle(titleEpisodeResource)
|
|
52
|
+ override def tvSeriesWithGreatestNumberOfEpisodes(): List[TvSeries] = {
|
|
53
|
+ val seriesTitleMap = getSeriesTitle(titleEpisodeResource)
|
|
54
|
+ val titleListMaxEpisode = getTitleByIds(titleBasicsResource, seriesTitleMap)
|
|
55
|
+ titleListMaxEpisode
|
|
56
|
+ }
|
58
|
57
|
|
59
|
58
|
|
60
|
59
|
|
|
@@ -76,25 +75,22 @@ class MovieQueryService extends MovieServiceTrait {
|
76
|
75
|
result.value.get.get.get
|
77
|
76
|
}
|
78
|
77
|
|
79
|
|
- def getTitleByIds(file: File, titleIdMap: mutable.Map[String, Int]): Seq[Option[String]] = {
|
80
|
|
- val result = fileSource(file)
|
81
|
|
- .mapAsync(50) {
|
82
|
|
- res =>
|
83
|
|
- Source.single(res)
|
84
|
|
- .via(lineParser)
|
85
|
|
- .filter(row => titleIdMap.contains(row.getOrElse("tconst", "")))
|
86
|
|
- .map(a => a.get("primaryTitle"))
|
87
|
|
- .withAttributes(supervisionStrategy(resumingDecider))
|
88
|
|
- .runWith(Sink.collection)
|
89
|
|
- }
|
90
|
|
- .withAttributes(supervisionStrategy(resumingDecider))
|
91
|
|
- .runWith(Sink.head)
|
|
78
|
+ def getTitleByIds(file: File, titleIdMap: mutable.Map[String, Int]): List[TvSeries] = {
|
|
79
|
+ val result = Source.single(file)
|
|
80
|
+ .flatMapConcat(f => FileIO.fromPath(Paths.get(f.getPath), 1 * 1024 * 1024))
|
|
81
|
+ .via(Compression.gunzip())
|
|
82
|
+ .via(CsvParsing.lineScanner(CsvParsing.Tab, CsvParsing.DoubleQuote, CsvParsing.DoubleQuote))
|
|
83
|
+ .via(CsvToMap.toMapAsStringsCombineAll(StandardCharsets.UTF_8, Option.empty))
|
|
84
|
+ .filter(row => titleIdMap.keySet.toList.contains(row.getOrElse("tconst", "")))
|
|
85
|
+ .map(a => TvSeries(a("originalTitle"), Try(a.getOrElse("startYear","").toInt).getOrElse(0), a.getOrElse("endYear","").toIntOption, a.get("genres").toList))
|
|
86
|
+ .runWith(Sink.collection)
|
92
|
87
|
|
93
|
88
|
Await.result(result, 5 minutes)
|
94
|
89
|
result.value.get.get.toList
|
95
|
90
|
}
|
|
91
|
+
|
96
|
92
|
def getIdOfPersons(file: File, titleId: String): immutable.Iterable[Option[String]] = {
|
97
|
|
- val te = fileSource(file)
|
|
93
|
+ val result = fileSource(file)
|
98
|
94
|
.mapAsync(50) {
|
99
|
95
|
res =>
|
100
|
96
|
Source.single(res)
|
|
@@ -107,7 +103,7 @@ class MovieQueryService extends MovieServiceTrait {
|
107
|
103
|
.withAttributes(supervisionStrategy(resumingDecider))
|
108
|
104
|
.runWith(Sink.head)
|
109
|
105
|
|
110
|
|
- Await.result(te, 5 minutes)
|
|
106
|
+ Await.result(result, 5 minutes)
|
111
|
107
|
}
|
112
|
108
|
|
113
|
109
|
|
|
@@ -118,7 +114,7 @@ class MovieQueryService extends MovieServiceTrait {
|
118
|
114
|
.via(CsvParsing.lineScanner(CsvParsing.Tab, CsvParsing.DoubleQuote, CsvParsing.DoubleQuote))
|
119
|
115
|
.via(CsvToMap.toMapAsStringsCombineAll(StandardCharsets.UTF_8, Option.empty))
|
120
|
116
|
.filter(row => personsIdList.contains(row.getOrElse("nconst", "")))
|
121
|
|
- .map(a => Principal(a("primaryName"), a("birthYear").toInt, a("deathYear").toIntOption, a.get("primaryProfession").toList))
|
|
117
|
+ .map(a => Principal(a("primaryName"), Try(a("birthYear").toInt).getOrElse(0), a("deathYear").toIntOption, a.get("primaryProfession").toList))
|
122
|
118
|
.runWith(Sink.collection)
|
123
|
119
|
|
124
|
120
|
Await.result(result, 5 minutes)
|