Commit df68a9fdcc44bce10a158df2905bf566f2245627

Authored by lsagona
1 parent 93534e6934
Exists in master and in 1 other branch dev

refactor graph minor optimization

Showing 5 changed files with 211 additions and 183 deletions Inline Diff

src/main/kotlin/application/controller/DataPanelController.kt View file @ df68a9f
package application.controller 1 1 package application.controller
2 2
import application.model.* 3 3 import application.model.*
import javafx.collections.FXCollections 4 4 import javafx.collections.FXCollections
import javafx.collections.ObservableList 5 5 import javafx.collections.ObservableList
import javafx.fxml.FXML 6 6 import javafx.fxml.FXML
import javafx.fxml.Initializable 7 7 import javafx.fxml.Initializable
import javafx.scene.control.ListCell 8 8 import javafx.scene.control.ListCell
import javafx.scene.control.ListView 9 9 import javafx.scene.control.ListView
import kotlinx.coroutines.GlobalScope 10 10 import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch 11 11 import kotlinx.coroutines.launch
import org.charts.dataviewer.api.config.DataViewerConfiguration 12 12 import org.charts.dataviewer.api.config.DataViewerConfiguration
import org.charts.dataviewer.api.data.PlotData 13 13 import org.charts.dataviewer.api.data.PlotData
import org.charts.dataviewer.api.trace.ScatterTrace 14 14 import org.charts.dataviewer.api.trace.ScatterTrace
import org.charts.dataviewer.javafx.JavaFxDataViewer 15 15 import org.charts.dataviewer.javafx.JavaFxDataViewer
import org.charts.dataviewer.utils.TraceColour 16 16 import org.charts.dataviewer.utils.TraceColour
import org.charts.dataviewer.utils.TraceVisibility 17 17 import org.charts.dataviewer.utils.TraceVisibility
import java.net.URL 18 18 import java.net.URL
import java.util.* 19 19 import java.util.*
20 20
21 21
class DataPanelController : Initializable, SelectedVesselListener { 22 22 class DataPanelController : Initializable, SelectedVesselListener {
private var dataList: ObservableList<Pair<String, ArrayList<MessageData?>>> = FXCollections.observableArrayList() 23 23 private var dataList: ObservableList<String> = FXCollections.observableArrayList()
private lateinit var timeData: ArrayList<MessageData?> 24 24 private lateinit var timeData: ArrayList<String>
25 25
private val latitude: ArrayList<MessageData?> = arrayListOf() 26 26 private val latitude: ArrayList<Double> = arrayListOf()
private val longitude: ArrayList<MessageData?> = arrayListOf() 27 27 private val longitude: ArrayList<Double> = arrayListOf()
private val speedOverGround: ArrayList<MessageData?> = arrayListOf() 28 28 private val speedOverGround: ArrayList<Double> = arrayListOf()
private val courseOverGround: ArrayList<MessageData?> = arrayListOf() 29 29 private val courseOverGround: ArrayList<Double> = arrayListOf()
private val heading: ArrayList<MessageData?> = arrayListOf() 30 30 private val heading: ArrayList<Double> = arrayListOf()
private val vesselName: ArrayList<MessageData?> = arrayListOf() 31 31 private val vesselName: ArrayList<String> = arrayListOf()
private val imo: ArrayList<MessageData?> = arrayListOf() 32 32 private val imo: ArrayList<String> = arrayListOf()
private val callSign: ArrayList<MessageData?> = arrayListOf() 33 33 private val callSign: ArrayList<String> = arrayListOf()
private val vesselType: ArrayList<MessageData?> = arrayListOf() 34 34 private val vesselType: ArrayList<Double> = arrayListOf()
private val status: ArrayList<MessageData?> = arrayListOf() 35 35 private val status: ArrayList<String> = arrayListOf()
private val length: ArrayList<MessageData?> = arrayListOf() 36 36 private val length: ArrayList<Double> = arrayListOf()
private val width: ArrayList<MessageData?> = arrayListOf() 37 37 private val width: ArrayList<Double> = arrayListOf()
private val draft: ArrayList<MessageData?> = arrayListOf() 38 38 private val draft: ArrayList<Double> = arrayListOf()
private val cargo: ArrayList<MessageData?> = arrayListOf() 39 39 private val cargo: ArrayList<Double> = arrayListOf()
40 40
private var selectedItem: Pair<String, ArrayList<MessageData?>>? = null 41 41 private var selectedItem: String? = null
42 42
@FXML 43 43 @FXML
var dataListView = ListView<Pair<String, ArrayList<MessageData?>>>() 44 44 var dataListView = ListView<String>()
45 45
@FXML 46 46 @FXML
var dataViewer = JavaFxDataViewer() 47 47 var dataViewer = JavaFxDataViewer()
48 48
private val plotData = PlotData() 49 49 private val plotData = PlotData()
private val config = DataViewerConfiguration() 50 50 private val config = DataViewerConfiguration()
51
override fun initialize(location: URL?, resources: ResourceBundle?) { 52 51 override fun initialize(location: URL?, resources: ResourceBundle?) {
setObservableSelectedVesselListener() 53 52 setObservableSelectedVesselListener()
dataListView.items = dataList 54 53 dataListView.items = dataList
55 54
56 55
57 56
config.showLegend(false) 58 57 config.showLegend(false)
config.setLegendInsidePlot(false) 59 58 config.setLegendInsidePlot(false)
60 59
setObservableCurrentTimeListener() 61 60 setObservableCurrentTimeListener()
62 61
dataListView.setCellFactory { 63 62 dataListView.setCellFactory {
object : ListCell<Pair<String, ArrayList<MessageData?>>?>() { 64 63 object : ListCell<String?>() {
override fun updateItem(item: Pair<String, ArrayList<MessageData?>>?, empty: Boolean) { 65 64 override fun updateItem(item: String?, empty: Boolean) {
super.updateItem(item, empty) 66 65 super.updateItem(item, empty)
text = if (empty) { 67 66 text = if (empty) {
null 68 67 null
} else { 69 68 } else {
item?.first 70 69 item
} 71 70 }
} 72 71 }
} 73 72 }
} 74 73 }
75 74
dataListView.selectionModel.selectedItemProperty().addListener { _, _, newValue -> 76 75 dataListView.selectionModel.selectedItemProperty().addListener { _, _, newValue ->
selectedItem = newValue 77 76 selectedItem = newValue
updateDataList(observableSelectedVessel.value) 78 77 updateDataList(observableSelectedVessel.value)
plot(newValue) 79 78 plot(newValue)
} 80 79 }
81 80
plotData.allTraces.clear() 82 81 plotData.allTraces.clear()
config.setxAxisTitle("") 83 82 config.setxAxisTitle("")
config.setyAxisTitle("") 84 83 config.setyAxisTitle("")
config.plotTitle = "" 85 84 config.plotTitle = ""
dataViewer.updateConfiguration(config) 86 85 dataViewer.updateConfiguration(config)
dataViewer.updatePlot(plotData) 87 86 dataViewer.updatePlot(plotData)
initDataList() 88 87 initDataList()
89 88
90 89
} 91 90 }
92 91
private fun plot() { 93 92 private fun plot() {
if (selectedItem != null && observableSelectedVessel.value.messages.size != 0) { 94 93 if (selectedItem != null && observableSelectedVessel.value.messages.size != 0) {
GlobalScope.launch { 95 94 GlobalScope.launch {
plot(selectedItem) 96 95 plot(selectedItem)
} 97 96 }
} 98 97 }
} 99 98 }
100 99
private fun plot(data: Pair<String, ArrayList<MessageData?>>?) { 101 100
101
102 private fun plot(data: String?) {
if (data == null) { 102 103 if (data == null) {
plotData.allTraces.clear() 103 104 plotData.allTraces.clear()
config.setxAxisTitle("") 104 105 config.setxAxisTitle("")
config.setyAxisTitle("") 105 106 config.setyAxisTitle("")
dataViewer.updateConfiguration(config) 106 107 dataViewer.updateConfiguration(config)
107 108
dataViewer.resetPlot() 108 109 dataViewer.resetPlot()
109 110
return 110 111 return
}else if (data.second.size < timeData.size) return 111
112
val getValueVisitorX = GetValueVisitor() 113
val getValueVisitorY = GetValueVisitor() 114
115
val arrayListStringX = arrayListOf<String>() 116
// val arrayListDoubleX = arrayListOf<Double>() 117
val arrayListStringY = arrayListOf<String>() 118
val arrayListDoubleY = arrayListOf<Double>() 119
120
for (x in 0 until timeData.size) { 121
timeData[x]?.accept(getValueVisitorX) 122
data.second[x]?.accept(getValueVisitorY) 123
124
if (getValueVisitorY.value.toDoubleOrNull() == null) { 125
arrayListStringX.add(getValueVisitorX.value) 126
arrayListStringY.add(getValueVisitorY.value) 127
} else { 128
arrayListStringX.add(getValueVisitorX.value) 129
arrayListDoubleY.add(getValueVisitorY.value.toDouble()) 130
} 131
} 132 112 }
133 113
val scatterTrace = ScatterTrace<Any>() 134 114 val scatterTrace = ScatterTrace<Any>()
scatterTrace.traceColour = TraceColour.RED 135 115 scatterTrace.traceColour = TraceColour.RED
scatterTrace.traceVisibility = TraceVisibility.TRUE 136 116 scatterTrace.traceVisibility = TraceVisibility.TRUE
137 117
val serieStringX: Array<String> = arrayListStringX.toTypedArray() 138 118 val serieStringX: Array<String> = timeData.toTypedArray()
// val serieDoubleX: Array<Double> = arrayListDoubleX.toTypedArray() 139 119 // val serieDoubleX: Array<Double> = arrayListDoubleX.toTypedArray()
val serieStringY: Array<String> = arrayListStringY.toTypedArray() 140 120 var serieStringY: Array<String> = arrayOf()
val serieDoubleY: Array<Double> = arrayListDoubleY.toTypedArray() 141 121 var serieDoubleY: Array<Double> = arrayOf()
122 when (data) {
123 "Latitude" -> {
124 serieDoubleY = latitude.toTypedArray()
125 }
126 "Longitude" -> {
127 serieDoubleY = longitude.toTypedArray()
128 }
129 "Speed Over Ground" -> {
130 serieDoubleY = speedOverGround.toTypedArray()
131 }
132 "Course Over Ground" -> {
133 serieDoubleY = courseOverGround.toTypedArray()
134 }
135 "Heading" -> {
136 serieDoubleY = heading.toTypedArray()
137 }
138 "Vessel Name" -> {
139 serieStringY = vesselName.toTypedArray()
140 }
141 "IMO" -> {
142 serieStringY = imo.toTypedArray()
143 }
144 "Call Sign" -> {
145 serieStringY = callSign.toTypedArray()
146 }
147 "Vessel Type" -> {
148 serieDoubleY = vesselType.toTypedArray()
149 }
150 "Status" -> {
151 serieStringY = status.toTypedArray()
152 }
153 "Length" -> {
154 serieDoubleY = length.toTypedArray()
155 }
156 "Width" -> {
157 serieDoubleY = width.toTypedArray()
158 }
159 "Draft" -> {
160 serieDoubleY = draft.toTypedArray()
161 }
162 "Cargo" -> {
163 serieDoubleY = cargo.toTypedArray()
164 }
165 }
142 166
if (getValueVisitorY.value.toDoubleOrNull() == null) { 143 167 if (serieStringY.isNotEmpty()) {
scatterTrace.setxArray(serieStringX) 144 168 scatterTrace.setxArray(serieStringX)
scatterTrace.setyArray(serieStringY) 145 169 scatterTrace.setyArray(serieStringY)
} else { 146 170 } else {
scatterTrace.setxArray(serieStringX) 147 171 scatterTrace.setxArray(serieStringX)
scatterTrace.setyArray(serieDoubleY) 148 172 scatterTrace.setyArray(serieDoubleY)
} 149 173 }
150 174
config.plotTitle = "" 151 175 config.plotTitle = ""
config.setxAxisTitle("Time (s)") 152 176 config.setxAxisTitle("Time (s)")
config.setyAxisTitle(data.first) 153 177 config.setyAxisTitle(data)
dataViewer.resetPlot() 154 178 dataViewer.resetPlot()
plotData.allTraces.clear() 155 179 plotData.allTraces.clear()
plotData.addTrace(scatterTrace) 156 180 plotData.addTrace(scatterTrace)
dataViewer.updateConfiguration(config) 157 181 dataViewer.updateConfiguration(config)
dataViewer.updatePlot(plotData) 158 182 dataViewer.updatePlot(plotData)
159 183
} 160 184 }
161 185
162
private fun setObservableSelectedVesselListener() { 163 186 private fun setObservableSelectedVesselListener() {
observableSelectedVessel.listeners.add(this) 164 187 observableSelectedVessel.listeners.add(this)
} 165 188 }
166 189
private fun populateTime(vessel: Vessel): ArrayList<MessageData?> { 167 190 private fun populateTime(vessel: Vessel): ArrayList<String> {
return if (observableIsReplayState.value) { 168 191 return if (observableIsReplayState.value) {
vessel.getAllTimeBeforeSelectedTime() 169 192 vessel.getAllTimeBeforeSelectedTime()
} else { 170 193 } else {
vessel.getAllTime() 171 194 vessel.getAllTime()
} 172 195 }
} 173 196 }
174 197
175 198 private fun populateLatitude(vessel: Vessel): ArrayList<Double> {
private fun populateLatitude(vessel: Vessel): ArrayList<MessageData?> { 176
return if (observableIsReplayState.value) { 177 199 return if (observableIsReplayState.value) {
vessel.getAllLatitudeBeforeSelectedTime() 178 200 vessel.getAllLatitudeBeforeSelectedTime()
} else { 179 201 } else {
vessel.getAllLatitude() 180 202 vessel.getAllLatitude()
} 181 203 }
} 182 204 }
183 205
private fun populateLongitude(vessel: Vessel): ArrayList<MessageData?> { 184 206 private fun populateLongitude(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 185 207 return if (observableIsReplayState.value) {
vessel.getAllLongitudeBeforeSelectedTime() 186 208 vessel.getAllLongitudeBeforeSelectedTime()
} else { 187 209 } else {
vessel.getAllLongitude() 188 210 vessel.getAllLongitude()
} 189 211 }
} 190 212 }
191 213
private fun populateSpeedOverGround(vessel: Vessel): ArrayList<MessageData?> { 192 214 private fun populateSpeedOverGround(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 193 215 return if (observableIsReplayState.value) {
vessel.getAllSpeedOverGroundBeforeSelectedTime() 194 216 vessel.getAllSpeedOverGroundBeforeSelectedTime()
} else { 195 217 } else {
vessel.getAllSpeedOverGround() 196 218 vessel.getAllSpeedOverGround()
} 197 219 }
} 198 220 }
199 221
private fun populateCourseOverGround(vessel: Vessel): ArrayList<MessageData?> { 200 222 private fun populateCourseOverGround(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 201 223 return if (observableIsReplayState.value) {
vessel.getAllCourseOverGroundBeforeSelectedTime() 202 224 vessel.getAllCourseOverGroundBeforeSelectedTime()
} else { 203 225 } else {
vessel.getAllCourseOverGround() 204 226 vessel.getAllCourseOverGround()
} 205 227 }
} 206 228 }
207 229
private fun populateHeading(vessel: Vessel): ArrayList<MessageData?> { 208 230 private fun populateHeading(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 209 231 return if (observableIsReplayState.value) {
vessel.getAllHeadingBeforeSelectedTime() 210 232 vessel.getAllHeadingBeforeSelectedTime()
} else { 211 233 } else {
vessel.getAllHeading() 212 234 vessel.getAllHeading()
} 213 235 }
} 214 236 }
215 237
private fun populateVesselName(vessel: Vessel): ArrayList<MessageData?> { 216 238 private fun populateVesselName(vessel: Vessel): ArrayList<String> {
return if (observableIsReplayState.value) { 217 239 return if (observableIsReplayState.value) {
vessel.getAllVesselNameBeforeSelectedTime() 218 240 vessel.getAllVesselNameBeforeSelectedTime()
} else { 219 241 } else {
vessel.getAllVesselName() 220 242 vessel.getAllVesselName()
} 221 243 }
} 222 244 }
223 245
private fun populateIMO(vessel: Vessel): ArrayList<MessageData?> { 224 246 private fun populateIMO(vessel: Vessel): ArrayList<String> {
return if (observableIsReplayState.value) { 225 247 return if (observableIsReplayState.value) {
vessel.getAllIMOBeforeSelectedTime() 226 248 vessel.getAllIMOBeforeSelectedTime()
} else { 227 249 } else {
vessel.getAllIMO() 228 250 vessel.getAllIMO()
} 229 251 }
} 230 252 }
231 253
private fun populateCallSign(vessel: Vessel): ArrayList<MessageData?> { 232 254 private fun populateCallSign(vessel: Vessel): ArrayList<String> {
return if (observableIsReplayState.value) { 233 255 return if (observableIsReplayState.value) {
vessel.getAllCallSignBeforeSelectedTime() 234 256 vessel.getAllCallSignBeforeSelectedTime()
} else { 235 257 } else {
vessel.getAllCallSign() 236 258 vessel.getAllCallSign()
} 237 259 }
} 238 260 }
239 261
private fun populateVesselType(vessel: Vessel): ArrayList<MessageData?> { 240 262 private fun populateVesselType(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 241 263 return if (observableIsReplayState.value) {
vessel.getAllVesselTypeBeforeSelectedTime() 242 264 vessel.getAllVesselTypeBeforeSelectedTime()
} else { 243 265 } else {
vessel.getAllVesselType() 244 266 vessel.getAllVesselType()
} 245 267 }
} 246 268 }
247 269
private fun populateStatus(vessel: Vessel): ArrayList<MessageData?> { 248 270 private fun populateStatus(vessel: Vessel): ArrayList<String> {
return if (observableIsReplayState.value) { 249 271 return if (observableIsReplayState.value) {
vessel.getAllStatusBeforeSelectedTime() 250 272 vessel.getAllStatusBeforeSelectedTime()
} else { 251 273 } else {
vessel.getAllStatus() 252 274 vessel.getAllStatus()
} 253 275 }
} 254 276 }
255 277
private fun populateLength(vessel: Vessel): ArrayList<MessageData?> { 256 278 private fun populateLength(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 257 279 return if (observableIsReplayState.value) {
vessel.getAllLengthBeforeSelectedTime() 258 280 vessel.getAllLengthBeforeSelectedTime()
} else { 259 281 } else {
vessel.getAllLength() 260 282 vessel.getAllLength()
} 261 283 }
} 262 284 }
263 285
private fun populateWidth(vessel: Vessel): ArrayList<MessageData?> { 264 286 private fun populateWidth(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 265 287 return if (observableIsReplayState.value) {
vessel.getAllWidthBeforeSelectedTime() 266 288 vessel.getAllWidthBeforeSelectedTime()
} else { 267 289 } else {
vessel.getAllWidth() 268 290 vessel.getAllWidth()
} 269 291 }
} 270 292 }
271 293
private fun populateDraft(vessel: Vessel): ArrayList<MessageData?> { 272 294 private fun populateDraft(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 273 295 return if (observableIsReplayState.value) {
vessel.getAllDraftBeforeSelectedTime() 274 296 vessel.getAllDraftBeforeSelectedTime()
} else { 275 297 } else {
vessel.getAllDraft() 276 298 vessel.getAllDraft()
} 277 299 }
} 278 300 }
279 301
private fun populateCargo(vessel: Vessel): ArrayList<MessageData?> { 280 302 private fun populateCargo(vessel: Vessel): ArrayList<Double> {
return if (observableIsReplayState.value) { 281 303 return if (observableIsReplayState.value) {
vessel.getAllCargoBeforeSelectedTime() 282 304 vessel.getAllCargoBeforeSelectedTime()
} else { 283 305 } else {
vessel.getAllCargo() 284 306 vessel.getAllCargo()
} 285 307 }
} 286 308 }
287 309
private fun initDataList() { 288 310 private fun initDataList() {
val data = arrayListOf<Pair<String, ArrayList<MessageData?>>>() 289 311 val data = arrayListOf<String>()
290 312
data.add(Pair("Latitude", latitude)) 291 313 data.add("Latitude")
data.add(Pair("Longitude", longitude)) 292 314 data.add("Longitude")
data.add(Pair("Speed Over Ground", speedOverGround)) 293 315 data.add("Speed Over Ground")
data.add(Pair("Course Over Ground", courseOverGround)) 294 316 data.add("Course Over Ground")
data.add(Pair("Heading", heading)) 295 317 data.add("Heading")
data.add(Pair("Vessel Name", vesselName)) 296 318 data.add("Vessel Name")
data.add(Pair("IMO", imo)) 297 319 data.add("IMO")
data.add(Pair("Call Sign", callSign)) 298 320 data.add("Call Sign")
data.add(Pair("Vessel Type", vesselType)) 299 321 data.add("Vessel Type")
data.add(Pair("Status", status)) 300 322 data.add("Status")
data.add(Pair("Length", length)) 301 323 data.add("Length")
data.add(Pair("Width", width)) 302 324 data.add("Width")
data.add(Pair("Draft", draft)) 303 325 data.add("Draft")
data.add(Pair("Cargo", cargo)) 304 326 data.add("Cargo")
305 327
dataList.addAll(data) 306 328 dataList.addAll(data)
} 307 329 }
308 330
private fun updateDataList(vessel: Vessel) { 309 331 private fun updateDataList(vessel: Vessel) {
timeData = populateTime(vessel) 310 332 timeData = populateTime(vessel)
311 333
if(dataListView.selectionModel.selectedItem == null) return 312 334 if (dataListView.selectionModel.selectedItem == null) return
313 335 //NOTE: Ajouter les nouvelles donnรฉe ร  la fin
when (dataListView.selectionModel.selectedItem.first) { 314 336 when (dataListView.selectionModel.selectedItem) {
"Latitude" -> { 315 337 "Latitude" -> {
latitude.clear() 316 338 latitude.clear()
latitude.addAll(populateLatitude(vessel)) 317 339 latitude.addAll(populateLatitude(vessel))
} 318 340 }
"Longitude" -> { 319 341 "Longitude" -> {
longitude.clear() 320 342 longitude.clear()
longitude.addAll(populateLongitude(vessel)) 321 343 longitude.addAll(populateLongitude(vessel))
} 322 344 }
"Speed Over Ground" -> { 323 345 "Speed Over Ground" -> {
speedOverGround.clear() 324 346 speedOverGround.clear()
speedOverGround.addAll(populateSpeedOverGround(vessel)) 325 347 speedOverGround.addAll(populateSpeedOverGround(vessel))
} 326 348 }
"Course Over Ground" -> { 327 349 "Course Over Ground" -> {
courseOverGround.clear() 328 350 courseOverGround.clear()
courseOverGround.addAll(populateCourseOverGround(vessel)) 329 351 courseOverGround.addAll(populateCourseOverGround(vessel))
} 330 352 }
"Heading" -> { 331 353 "Heading" -> {
heading.clear() 332 354 heading.clear()
heading.addAll(populateHeading(vessel)) 333 355 heading.addAll(populateHeading(vessel))
} 334 356 }
"Vessel Name" -> { 335 357 "Vessel Name" -> {
vesselName.clear() 336 358 vesselName.clear()
vesselName.addAll(populateVesselName(vessel)) 337 359 vesselName.addAll(populateVesselName(vessel))
} 338 360 }
"IMO" -> { 339 361 "IMO" -> {
imo.clear() 340 362 imo.clear()
imo.addAll(populateIMO(vessel)) 341 363 imo.addAll(populateIMO(vessel))
} 342 364 }
"Call Sign" -> { 343 365 "Call Sign" -> {
callSign.clear() 344 366 callSign.clear()
callSign.addAll(populateCallSign(vessel)) 345 367 callSign.addAll(populateCallSign(vessel))
} 346 368 }
"Vessel Type" -> { 347 369 "Vessel Type" -> {
vesselType.clear() 348 370 vesselType.clear()
vesselType.addAll(populateVesselType(vessel)) 349 371 vesselType.addAll(populateVesselType(vessel))
} 350 372 }
"Status" -> { 351 373 "Status" -> {
status.clear() 352 374 status.clear()
status.addAll(populateStatus(vessel)) 353 375 status.addAll(populateStatus(vessel))
} 354 376 }
"Length" -> { 355 377 "Length" -> {
length.clear() 356 378 length.clear()
length.addAll(populateLength(vessel)) 357 379 length.addAll(populateLength(vessel))
} 358 380 }
"Width" -> { 359 381 "Width" -> {
width.clear() 360 382 width.clear()
width.addAll(populateWidth(vessel)) 361 383 width.addAll(populateWidth(vessel))
} 362 384 }
"Draft" -> { 363 385 "Draft" -> {
draft.clear() 364 386 draft.clear()
draft.addAll(populateDraft(vessel)) 365 387 draft.addAll(populateDraft(vessel))
} 366 388 }
"Cargo" -> { 367 389 "Cargo" -> {
cargo.clear() 368 390 cargo.clear()
cargo.addAll(populateCargo(vessel)) 369 391 cargo.addAll(populateCargo(vessel))
} 370 392 }
} 371 393 }
} 372 394 }
373 395
private fun setObservableCurrentTimeListener() { 374 396 private fun setObservableCurrentTimeListener() {
observableCurrentTime.listeners.add(object : CurrentTime { 375 397 observableCurrentTime.listeners.add(object : CurrentTime {
override fun onValueChanged(newValue: Int) { 376 398 override fun onValueChanged(newValue: Int) {
updateDataList(observableSelectedVessel.value) 377 399 updateDataList(observableSelectedVessel.value)
plot() 378 400 plot()
} 379 401 }
}) 380 402 })
} 381 403 }
382 404
override fun onValueChanged(newValue: Vessel) { 383 405 override fun onValueChanged(newValue: Vessel) {
updateDataList(newValue) 384 406 updateDataList(newValue)
plot() 385 407 plot()
} 386 408 }
387 409
} 388 410 }
389 411
390 412
src/main/kotlin/application/model/Message.kt View file @ df68a9f
package application.model 1 1 package application.model
2 2
import java.time.LocalDateTime 3 3 import java.time.LocalDateTime
4 4
class Message(split: List<String>) { 5 5 class Message(split: List<String>) {
val mmsi = MMSI(if (split[0] == "") null else split[0]) 6 6 val mmsi = MMSI(if (split[0] == "") null else split[0])
val time = Time(LocalDateTime.parse(split[1])) 7 7 val time = Time(LocalDateTime.parse(split[1]))
val latitude = Latitude(split[2].toDoubleOrNull()) 8 8 val latitude = Latitude(split[2].toDoubleOrNull())
val longitude = Longitude(split[3].toDoubleOrNull()) 9 9 val longitude = Longitude(split[3].toDoubleOrNull())
val speedOverGround = SpeedOverGround(split[4].toDoubleOrNull()) 10 10 val speedOverGround = SpeedOverGround(split[4].toDoubleOrNull())
val courseOverGround = CourseOverGround(split[5].toDoubleOrNull()) 11 11 val courseOverGround = CourseOverGround(split[5].toDoubleOrNull())
val heading = Heading(split[6].toDoubleOrNull()) 12 12 val heading = Heading(split[6].toDoubleOrNull())
val vesselName = VesselName(if (split[7] == "") null else split[7]) 13 13 val vesselName = VesselName(if (split[7] == "") null else split[7])
val imo = IMO(if (split[8] == "") null else split[8]) 14 14 val imo = IMO(if (split[8] == "") null else split[8])
val callSign = CallSign(if (split[9] == "") null else split[9]) 15 15 val callSign = CallSign(if (split[9] == "") null else split[9])
val vesselType = VesselType(split[10].toIntOrNull()) 16 16 val vesselType = VesselType(split[10].toDoubleOrNull())
val status = Status(if (split[11] == "") null else split[11]) 17 17 val status = Status(if (split[11] == "") null else split[11])
val length = Length(split[12].toDoubleOrNull()) 18 18 val length = Length(split[12].toDoubleOrNull())
val width = Width(split[13].toDoubleOrNull()) 19 19 val width = Width(split[13].toDoubleOrNull())
val draft = Draft(split[14].toDoubleOrNull()) 20 20 val draft = Draft(split[14].toDoubleOrNull())
val cargo = Cargo(split[15].toIntOrNull()) 21 21 val cargo = Cargo(split[15].toDoubleOrNull())
22 22
fun getHexColorStroke(): String { 23 23 fun getHexColorStroke(): String {
var hex = Integer.toHexString(this.mmsi.value?.toInt()!!) 24 24 var hex = Integer.toHexString(this.mmsi.value?.toInt()!!)
if (hex.length > 6) { 25 25 if (hex.length > 6) {
hex = hex.substring(hex.length - 6) 26 26 hex = hex.substring(hex.length - 6)
} 27 27 }
return hex 28 28 return hex
} 29 29 }
src/main/kotlin/application/model/MessageData.kt View file @ df68a9f
package application.model 1 1 package application.model
2 2
import java.time.LocalDateTime 3 3 import java.time.LocalDateTime
4 4
interface MessageDataVisitor { 5 5 interface MessageDataVisitor {
fun visit(messageData: MMSI) 6 6 fun visit(messageData: MMSI)
fun visit(messageData: Time) 7 7 fun visit(messageData: Time)
fun visit(messageData: Latitude) 8 8 fun visit(messageData: Latitude)
fun visit(messageData: Longitude) 9 9 fun visit(messageData: Longitude)
fun visit(messageData: SpeedOverGround) 10 10 fun visit(messageData: SpeedOverGround)
fun visit(messageData: CourseOverGround) 11 11 fun visit(messageData: CourseOverGround)
fun visit(messageData: Heading) 12 12 fun visit(messageData: Heading)
fun visit(messageData: VesselName) 13 13 fun visit(messageData: VesselName)
fun visit(messageData: IMO) 14 14 fun visit(messageData: IMO)
fun visit(messageData: CallSign) 15 15 fun visit(messageData: CallSign)
fun visit(messageData: VesselType) 16 16 fun visit(messageData: VesselType)
fun visit(messageData: Status) 17 17 fun visit(messageData: Status)
fun visit(messageData: Length) 18 18 fun visit(messageData: Length)
fun visit(messageData: Width) 19 19 fun visit(messageData: Width)
fun visit(messageData: Draft) 20 20 fun visit(messageData: Draft)
fun visit(messageData: Cargo) 21 21 fun visit(messageData: Cargo)
} 22 22 }
23 23
interface MessageData { 24 24 interface MessageData {
25 25
fun accept(visitor: MessageDataVisitor) 26 26 fun accept(visitor: MessageDataVisitor)
27 27
} 28 28 }
29 29
data class MMSI(val value: String?) : MessageData { 30 30 data class MMSI(val value: String?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 31 31 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 32 32 }
33 33
data class Time(val value: LocalDateTime) : MessageData { 34 34 data class Time(val date: LocalDateTime) : MessageData {
35 val value: String?
36
37 init {
38 value = date.toString()
39 }
40
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 35 41 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 36 42 }
37 43
data class Latitude(val value: Double?) : MessageData { 38 44 data class Latitude(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 39 45 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 40 46 }
41 47
data class Longitude(val value: Double?) : MessageData { 42 48 data class Longitude(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 43 49 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 44 50 }
45 51
data class SpeedOverGround(val value: Double?) : MessageData { 46 52 data class SpeedOverGround(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 47 53 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 48 54 }
49 55
data class CourseOverGround(val value: Double?) : MessageData { 50 56 data class CourseOverGround(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 51 57 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 52 58 }
53 59
data class Heading(val value: Double?) : MessageData { 54 60 data class Heading(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 55 61 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 56 62 }
57 63
data class VesselName(val value: String?) : MessageData { 58 64 data class VesselName(val value: String?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 59 65 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 60 66 }
61 67
data class IMO(val value: String?) : MessageData { 62 68 data class IMO(val value: String?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 63 69 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 64 70 }
65 71
data class CallSign(val value: String?) : MessageData { 66 72 data class CallSign(val value: String?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 67 73 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 68 74 }
69 75
data class VesselType(val value: Int?) : MessageData { 70 76 data class VesselType(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 71 77 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 72 78 }
73 79
data class Status(val value: String?) : MessageData { 74 80 data class Status(val value: String?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 75 81 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 76 82 }
77 83
data class Length(val value: Double?) : MessageData { 78 84 data class Length(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 79 85 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 80 86 }
81 87
data class Width(val value: Double?) : MessageData { 82 88 data class Width(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 83 89 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 84 90 }
85 91
data class Draft(val value: Double?) : MessageData { 86 92 data class Draft(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 87 93 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 88 94 }
89 95
data class Cargo(val value: Int?) : MessageData { 90 96 data class Cargo(val value: Double?) : MessageData {
override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this) 91 97 override fun accept(visitor: MessageDataVisitor) = visitor.visit(messageData = this)
} 92 98 }
93 99
class GetValueVisitor() : MessageDataVisitor { 94 100 class GetValueVisitor() : MessageDataVisitor {
var value: String = "" 95 101 var value: String = ""
96 102
override fun visit(messageData: MMSI) { 97 103 override fun visit(messageData: MMSI) {
value = messageData.value.toString() 98 104 value = messageData.value.toString()
} 99 105 }
100 106
override fun visit(messageData: Time) { 101 107 override fun visit(messageData: Time) {
value = messageData.value.toString() 102 108 value = messageData.value.toString()
} 103 109 }
104 110
override fun visit(messageData: Latitude) { 105 111 override fun visit(messageData: Latitude) {
value = messageData.value.toString() 106 112 value = messageData.value.toString()
} 107 113 }
108 114
override fun visit(messageData: Longitude) { 109 115 override fun visit(messageData: Longitude) {
value = messageData.value.toString() 110 116 value = messageData.value.toString()
} 111 117 }
112 118
override fun visit(messageData: SpeedOverGround) { 113 119 override fun visit(messageData: SpeedOverGround) {
value = messageData.value.toString() 114 120 value = messageData.value.toString()
} 115 121 }
116 122
override fun visit(messageData: CourseOverGround) { 117 123 override fun visit(messageData: CourseOverGround) {
value = messageData.value.toString() 118 124 value = messageData.value.toString()
} 119 125 }
120 126
override fun visit(messageData: Heading) { 121 127 override fun visit(messageData: Heading) {
value = messageData.value.toString() 122 128 value = messageData.value.toString()
} 123 129 }
124 130
override fun visit(messageData: VesselName) { 125 131 override fun visit(messageData: VesselName) {
src/main/kotlin/application/model/Vessel.kt View file @ df68a9f
package application.model 1 1 package application.model
2 2
import java.util.* 3 3 import java.util.*
4 4
class Vessel(val mmsi: String?) { 5 5 class Vessel(val mmsi: String?) {
val messages: SortedMap<Long, Message> = sortedMapOf() 6 6 val messages: SortedMap<Long, Message> = sortedMapOf()
private val messageBeforeSelectedTime: Map<Long, Message> 7 7 private val messageBeforeSelectedTime: Map<Long, Message>
get() { 8 8 get() {
return messages.filter { observableCurrentTime.value > it.key } 9 9 return messages.filter { observableCurrentTime.value > it.key }
} 10 10 }
11 11
var messageToDisplay: Message? = null 12 12 var messageToDisplay: Message? = null
get() { 13 13 get() {
field = 14 14 field =
messages.asSequence().map { it }.firstOrNull { observableCurrentTime.value < it.key }.let { it?.value } 15 15 messages.asSequence().map { it }.firstOrNull { observableCurrentTime.value < it.key }.let { it?.value }
return field 16 16 return field
} 17 17 }
18 18
fun getAllTimeBeforeSelectedTime(): ArrayList<MessageData?> { 19 19 fun getAllTimeBeforeSelectedTime(): ArrayList<String> {
val timeList = arrayListOf<MessageData?>() 20 20 val timeList = arrayListOf<String>()
messageBeforeSelectedTime.forEach { 21 21 messageBeforeSelectedTime.forEach {
timeList.add(it.value.time) 22 22 timeList.add(it.value.time.value!!)
} 23 23 }
24 24
return timeList 25 25 return timeList
} 26 26 }
27 27
fun getAllLatitudeBeforeSelectedTime(): ArrayList<MessageData?> { 28 28 fun getAllLatitudeBeforeSelectedTime(): ArrayList<Double> {
val latitudeList = arrayListOf<MessageData?>() 29 29 val latitudeList = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 30 30 messageBeforeSelectedTime.forEach {
latitudeList.add(it.value.latitude) 31 31 latitudeList.add(it.value.latitude.value!!)
} 32 32 }
33 33
return latitudeList 34 34 return latitudeList
} 35 35 }
36 36
fun getAllLongitudeBeforeSelectedTime(): ArrayList<MessageData?> { 37 37 fun getAllLongitudeBeforeSelectedTime(): ArrayList<Double> {
val longitudeList = arrayListOf<MessageData?>() 38 38 val longitudeList = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 39 39 messageBeforeSelectedTime.forEach {
longitudeList.add(it.value.longitude) 40 40 longitudeList.add(it.value.longitude.value!!)
} 41 41 }
42 42
return longitudeList 43 43 return longitudeList
} 44 44 }
45 45
fun getAllSpeedOverGroundBeforeSelectedTime(): ArrayList<MessageData?> { 46 46 fun getAllSpeedOverGroundBeforeSelectedTime(): ArrayList<Double> {
val speedOverGroundList = arrayListOf<MessageData?>() 47 47 val speedOverGroundList = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 48 48 messageBeforeSelectedTime.forEach {
speedOverGroundList.add(it.value.speedOverGround) 49 49 speedOverGroundList.add(it.value.speedOverGround.value!!)
} 50 50 }
51 51
return speedOverGroundList 52 52 return speedOverGroundList
} 53 53 }
54 54
fun getAllCourseOverGroundBeforeSelectedTime(): ArrayList<MessageData?> { 55 55 fun getAllCourseOverGroundBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 56 56 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 57 57 messageBeforeSelectedTime.forEach {
res.add(it.value.courseOverGround) 58 58 res.add(it.value.courseOverGround.value!!)
} 59 59 }
60 60
return res 61 61 return res
} 62 62 }
63 63
fun getAllHeadingBeforeSelectedTime(): ArrayList<MessageData?> { 64 64 fun getAllHeadingBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 65 65 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 66 66 messageBeforeSelectedTime.forEach {
res.add(it.value.heading) 67 67 res.add(it.value.heading.value!!)
} 68 68 }
69 69
return res 70 70 return res
} 71 71 }
72 72
fun getAllVesselNameBeforeSelectedTime(): ArrayList<MessageData?> { 73 73 fun getAllVesselNameBeforeSelectedTime(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 74 74 val res = arrayListOf<String>()
messageBeforeSelectedTime.forEach { 75 75 messageBeforeSelectedTime.forEach {
res.add(it.value.vesselName) 76 76 res.add(it.value.vesselName.value!!)
} 77 77 }
return res 78 78 return res
} 79 79 }
80 80
fun getAllIMOBeforeSelectedTime(): ArrayList<MessageData?> { 81 81 fun getAllIMOBeforeSelectedTime(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 82 82 val res = arrayListOf<String>()
messageBeforeSelectedTime.forEach { 83 83 messageBeforeSelectedTime.forEach {
res.add(it.value.imo) 84 84 res.add(it.value.imo.value!!)
} 85 85 }
return res 86 86 return res
} 87 87 }
88 88
fun getAllCallSignBeforeSelectedTime(): ArrayList<MessageData?> { 89 89 fun getAllCallSignBeforeSelectedTime(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 90 90 val res = arrayListOf<String>()
messageBeforeSelectedTime.forEach { 91 91 messageBeforeSelectedTime.forEach {
res.add(it.value.callSign) 92 92 res.add(it.value.callSign.value!!)
} 93 93 }
return res 94 94 return res
} 95 95 }
96 96
fun getAllVesselTypeBeforeSelectedTime(): ArrayList<MessageData?> { 97 97 fun getAllVesselTypeBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 98 98 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 99 99 messageBeforeSelectedTime.forEach {
res.add(it.value.vesselType) 100 100 res.add(it.value.vesselType.value!!)
} 101 101 }
return res 102 102 return res
} 103 103 }
104 104
fun getAllStatusBeforeSelectedTime(): ArrayList<MessageData?> { 105 105 fun getAllStatusBeforeSelectedTime(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 106 106 val res = arrayListOf<String>()
messageBeforeSelectedTime.forEach { 107 107 messageBeforeSelectedTime.forEach {
res.add(it.value.status) 108 108 res.add(it.value.status.value!!)
} 109 109 }
return res 110 110 return res
} 111 111 }
112 112
fun getAllLengthBeforeSelectedTime(): ArrayList<MessageData?> { 113 113 fun getAllLengthBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 114 114 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 115 115 messageBeforeSelectedTime.forEach {
res.add(it.value.length) 116 116 res.add(it.value.length.value!!)
} 117 117 }
return res 118 118 return res
} 119 119 }
120 120
fun getAllWidthBeforeSelectedTime(): ArrayList<MessageData?> { 121 121 fun getAllWidthBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 122 122 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 123 123 messageBeforeSelectedTime.forEach {
res.add(it.value.width) 124 124 res.add(it.value.width.value!!)
} 125 125 }
return res 126 126 return res
} 127 127 }
128 128
fun getAllDraftBeforeSelectedTime(): ArrayList<MessageData?> { 129 129 fun getAllDraftBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 130 130 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 131 131 messageBeforeSelectedTime.forEach {
res.add(it.value.draft) 132 132 res.add(it.value.draft.value!!)
} 133 133 }
return res 134 134 return res
} 135 135 }
136 136
fun getAllCargoBeforeSelectedTime(): ArrayList<MessageData?> { 137 137 fun getAllCargoBeforeSelectedTime(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 138 138 val res = arrayListOf<Double>()
messageBeforeSelectedTime.forEach { 139 139 messageBeforeSelectedTime.forEach {
res.add(it.value.cargo) 140 140 res.add(it.value.cargo.value!!)
} 141 141 }
return res 142 142 return res
} 143 143 }
144 144
fun getAllTime(): ArrayList<MessageData?> { 145 145 fun getAllTime(): ArrayList<String> {
val timeList = arrayListOf<MessageData?>() 146 146 val timeList = arrayListOf<String>()
messages.forEach { 147 147 messages.forEach {
timeList.add(it.value.time) 148 148 timeList.add(it.value.time.value!!)
} 149 149 }
150 150
return timeList 151 151 return timeList
} 152 152 }
153 153
fun getAllLatitude(): ArrayList<MessageData?> { 154 154 fun getAllLatitude(): ArrayList<Double> {
val latitudeList = arrayListOf<MessageData?>() 155 155 val latitudeList = arrayListOf<Double>()
messages.forEach { 156 156 messages.forEach {
latitudeList.add(it.value.latitude) 157 157 latitudeList.add(it.value.latitude.value!!)
} 158 158 }
159 159
return latitudeList 160 160 return latitudeList
} 161 161 }
162 162
fun getAllLongitude(): ArrayList<MessageData?> { 163 163 fun getAllLongitude(): ArrayList<Double> {
val longitudeList = arrayListOf<MessageData?>() 164 164 val longitudeList = arrayListOf<Double>()
messages.forEach { 165 165 messages.forEach {
longitudeList.add(it.value.longitude) 166 166 longitudeList.add(it.value.longitude.value!!)
} 167 167 }
168 168
return longitudeList 169 169 return longitudeList
} 170 170 }
171 171
fun getAllSpeedOverGround(): ArrayList<MessageData?> { 172 172 fun getAllSpeedOverGround(): ArrayList<Double> {
val speedOverGroundList = arrayListOf<MessageData?>() 173 173 val speedOverGroundList = arrayListOf<Double>()
messages.forEach { 174 174 messages.forEach {
speedOverGroundList.add(it.value.speedOverGround) 175 175 speedOverGroundList.add(it.value.speedOverGround.value!!)
} 176 176 }
177 177
return speedOverGroundList 178 178 return speedOverGroundList
} 179 179 }
180 180
fun getAllCourseOverGround(): ArrayList<MessageData?> { 181 181 fun getAllCourseOverGround(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 182 182 val res = arrayListOf<Double>()
messages.forEach { 183 183 messages.forEach {
res.add(it.value.courseOverGround) 184 184 res.add(it.value.courseOverGround.value!!)
} 185 185 }
186 186
return res 187 187 return res
} 188 188 }
189 189
fun getAllHeading(): ArrayList<MessageData?> { 190 190 fun getAllHeading(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 191 191 val res = arrayListOf<Double>()
messages.forEach { 192 192 messages.forEach {
res.add(it.value.heading) 193 193 res.add(it.value.heading.value!!)
} 194 194 }
195 195
return res 196 196 return res
} 197 197 }
198 198
fun getAllVesselName(): ArrayList<MessageData?> { 199 199 fun getAllVesselName(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 200 200 val res = arrayListOf<String>()
messages.forEach { 201 201 messages.forEach {
res.add(it.value.vesselName) 202 202 res.add(it.value.vesselName.value!!)
} 203 203 }
return res 204 204 return res
} 205 205 }
206 206
fun getAllIMO(): ArrayList<MessageData?> { 207 207 fun getAllIMO(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 208 208 val res = arrayListOf<String>()
messages.forEach { 209 209 messages.forEach {
res.add(it.value.imo) 210 210 res.add(it.value.imo.value!!)
} 211 211 }
return res 212 212 return res
} 213 213 }
214 214
fun getAllCallSign(): ArrayList<MessageData?> { 215 215 fun getAllCallSign(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 216 216 val res = arrayListOf<String>()
messages.forEach { 217 217 messages.forEach {
res.add(it.value.callSign) 218 218 res.add(it.value.callSign.value!!)
} 219 219 }
return res 220 220 return res
} 221 221 }
222 222
fun getAllVesselType(): ArrayList<MessageData?> { 223 223 fun getAllVesselType(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 224 224 val res = arrayListOf<Double>()
messages.forEach { 225 225 messages.forEach {
res.add(it.value.vesselType) 226 226 res.add(it.value.vesselType.value!!)
} 227 227 }
return res 228 228 return res
} 229 229 }
230 230
fun getAllStatus(): ArrayList<MessageData?> { 231 231 fun getAllStatus(): ArrayList<String> {
val res = arrayListOf<MessageData?>() 232 232 val res = arrayListOf<String>()
messages.forEach { 233 233 messages.forEach {
res.add(it.value.status) 234 234 res.add(it.value.status.value!!)
} 235 235 }
return res 236 236 return res
} 237 237 }
238 238
fun getAllLength(): ArrayList<MessageData?> { 239 239 fun getAllLength(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 240 240 val res = arrayListOf<Double>()
messages.forEach { 241 241 messages.forEach {
res.add(it.value.length) 242 242 res.add(it.value.length.value!!)
} 243 243 }
return res 244 244 return res
} 245 245 }
246 246
fun getAllWidth(): ArrayList<MessageData?> { 247 247 fun getAllWidth(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 248 248 val res = arrayListOf<Double>()
messages.forEach { 249 249 messages.forEach {
res.add(it.value.width) 250 250 res.add(it.value.width.value!!)
} 251 251 }
return res 252 252 return res
} 253 253 }
254 254
fun getAllDraft(): ArrayList<MessageData?> { 255 255 fun getAllDraft(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 256 256 val res = arrayListOf<Double>()
messages.forEach { 257 257 messages.forEach {
res.add(it.value.draft) 258 258 res.add(it.value.draft.value!!)
} 259 259 }
return res 260 260 return res
} 261 261 }
262 262
fun getAllCargo(): ArrayList<MessageData?> { 263 263 fun getAllCargo(): ArrayList<Double> {
val res = arrayListOf<MessageData?>() 264 264 val res = arrayListOf<Double>()
messages.forEach { 265 265 messages.forEach {
res.add(it.value.cargo) 266 266 res.add(it.value.cargo.value!!)
} 267 267 }
return res 268 268 return res
} 269 269 }
270 270
companion object { 271 271 companion object {
var maxTime: Long = 0 272 272 var maxTime: Long = 0
var minTime: Long = 0 273 273 var minTime: Long = 0
} 274 274 }
275 275
} 276 276 }
src/main/kotlin/application/model/VesselGenerator.kt View file @ df68a9f
package application.model 1 1 package application.model
2 2
import java.io.File 3 3 import java.io.File
import java.time.ZoneOffset 4 4 import java.time.ZoneOffset
import java.util.* 5 5 import java.util.*
6 6
fun createVesselCollection(file: File): SortedMap<String, Vessel> { 7 7 fun createVesselCollection(file: File): SortedMap<String, Vessel> {
val messages: ArrayList<Message> = arrayListOf() 8 8 val messages: ArrayList<Message> = arrayListOf()
val vessels: SortedMap<String, Vessel> = sortedMapOf() 9 9 val vessels: SortedMap<String, Vessel> = sortedMapOf()
var maxTime: Long = 0 10 10 var maxTime: Long = 0
var minTime: Long = Long.MAX_VALUE 11 11 var minTime: Long = Long.MAX_VALUE
12 12
file.forEachLine { 13 13 file.forEachLine {
val arrayMessage = it.split(",") 14 14 val arrayMessage = it.split(",")
if (arrayMessage[0].toIntOrNull() !== null) { 15 15 if (arrayMessage[0].toIntOrNull() !== null) {
val message = Message(arrayMessage) 16 16 val message = Message(arrayMessage)
messages.add(message) 17 17 messages.add(message)
if (!vessels.containsKey(message.mmsi.value)) { 18 18 if (!vessels.containsKey(message.mmsi.value)) {
vessels[message.mmsi.value] = Vessel(message.mmsi.value!!) 19 19 vessels[message.mmsi.value] = Vessel(message.mmsi.value!!)
} 20 20 }
val time = message.time.value.toEpochSecond(ZoneOffset.UTC) 21 21 val time = message.time.date.toEpochSecond(ZoneOffset.UTC)
vessels[message.mmsi.value]?.messages?.set(time, message) 22 22 vessels[message.mmsi.value]?.messages?.set(time, message)
if (time > maxTime) { 23 23 if (time > maxTime) {
maxTime = time 24 24 maxTime = time
} 25 25 }
if (time < minTime){ 26 26 if (time < minTime){
minTime = time 27 27 minTime = time
} 28 28 }
} 29 29 }
} 30 30 }
31 31
Vessel.maxTime = maxTime 32 32 Vessel.maxTime = maxTime