Skip to content

Commit

Permalink
Merge pull request #541 from handymenny/subtypes-in-metada
Browse files Browse the repository at this point in the history
parsing: add subtypes to metadata
  • Loading branch information
handymenny authored Nov 17, 2024
2 parents ac10e5f + ffacb36 commit a270623
Show file tree
Hide file tree
Showing 70 changed files with 236 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ data class IndexLine(
@EncodeDefault(EncodeDefault.Mode.ALWAYS) var description: String = "",
var inputs: List<String> = emptyList(),
var compressed: Boolean = false,
var defaultNR: Boolean = false,
val parserVersion: String,
) {
// This is only used to extract description and defaultNR from capabilities JSON
// This is only used to extract description from capabilities JSON
private var metadata: MutableMap<String, String>? = null

init {
// if metadata is set, extract description and default nr from that
// if metadata is set, extract description from that
metadata?.let {
description = it["description"] ?: ""
defaultNR = it["defaultNR"].toBoolean()
// unset metadata to free resources
metadata = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ class JavalinApp {
return listOf(Rat.EUTRA)
}

// if there's subTypes in metadata return that
val subTypes = capabilities.getStringMetadata("subTypes")
if (!subTypes.isNullOrEmpty()) {
return subTypes.split(", ").mapNotNull(Rat::of)
}

val defaultRatList = listOf(Rat.EUTRA, Rat.NR, Rat.EUTRA_NR)

if (inputsLength == 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class RequestParse(
val input: InputSource? = null,
val inputNR: InputSource? = null,
val inputENDC: InputSource? = null,
val defaultNR: Boolean = false,
val type: LogType,
val description: String = "",
) {
Expand All @@ -60,14 +59,7 @@ class RequestParse(

require(ratList.size >= inputs.size) { "Something weird, inputs list >= rat List" }

return RequestParse(
input,
inputNR,
inputENDC,
ratList.first() == Rat.NR,
type,
description,
)
return RequestParse(input, inputNR, inputENDC, type, description)
}
}
}
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/it/smartphonecombo/uecapabilityparser/util/Parsing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,35 @@ class Parsing(
capabilities.logType = type
capabilities.timestamp = Instant.now().toEpochMilli()
capabilities.setMetadata("processingTime", "${processTime}ms")
if (defaultRat == Rat.NR) capabilities.setMetadata("defaultNR", "true")

// Set description
if (description.isNotEmpty()) {
capabilities.setMetadata("description", description)
}

if (type == LogType.H) {
// set subtypes
val subTypes =
getInputs().mapNotNull {
when (it) {
input -> defaultRat
inputNR -> Rat.NR
inputENDC -> Rat.EUTRA_NR
else -> null
}
}

if (subTypes.isNotEmpty()) {
capabilities.addMetadata("subTypes", subTypes.joinToString(", "))
}
}

return capabilities
}

private fun getInputs(): List<InputSource?> =
arrayOf(input, inputNR, inputENDC).filterNot { it == null || it.size() == 0L }

private fun parseCapabilities(): Capabilities {
val imports = LogType.getImporter(type) ?: return Capabilities()

Expand Down Expand Up @@ -79,16 +98,12 @@ class Parsing(
val inputDir = "$path/input"
val outputDir = "$path/output"
val id = capabilities.id
val inputs = arrayOf(input, inputNR, inputENDC)
val inputsPath = mutableListOf<String>()

inputs
.filterNot { it == null || it.size() == 0L }
.forEachIndexed { index, data ->
val inputsPath =
getInputs().mapIndexed { index, data ->
val fileName = "$id-$index"
val inputPath = "$inputDir/$fileName"
IOUtils.outputFile(data!!.readBytes(), inputPath, compression)
inputsPath.add(fileName)
fileName
}

val encodedString = Json.custom().encodeToString(capabilities)
Expand All @@ -101,7 +116,6 @@ class Parsing(
capabilities.getStringMetadata("description") ?: "",
inputsPath,
compression,
capabilities.getStringMetadata("defaultNR").toBoolean(),
capabilities.parserVersion,
)
libraryIndex?.putLine(indexLine)
Expand All @@ -112,7 +126,7 @@ class Parsing(
fun fromRequest(req: RequestParse): Parsing? {
val defaultRat =
when {
req.defaultNR || req.input == null && req.inputNR != null -> Rat.NR
req.input == null && req.inputNR != null -> Rat.NR
req.input == null && req.inputENDC != null -> Rat.EUTRA_NR
req.input != null -> Rat.EUTRA
else -> null
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/cli/oracleJson/ueCapHexEutra.json
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,9 @@
"rat": "EUTRA"
}
],
"metadata": {},
"metadata": {
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
"timestamp": 0
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/cli/oracleJson/ueCapHexMrdcSplit.json
Original file line number Diff line number Diff line change
Expand Up @@ -20421,7 +20421,9 @@
"rat": "NR"
}
],
"metadata": {},
"metadata": {
"subTypes": "eutra, nr, eutra-nr"
},
"id": "",
"parserVersion": "staging",
"timestamp": 0
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/cli/oracleJson/ueCapHexNr.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
}
],
"metadata": {
"defaultNR": "true"
"subTypes": "nr"
},
"id": "",
"parserVersion": "staging",
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/cli/oracleJson/ueCapHexSegmented.json
Original file line number Diff line number Diff line change
Expand Up @@ -43673,7 +43673,9 @@
]
}
],
"metadata": {},
"metadata": {
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
"timestamp": 0
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/cli/oracleMultiJson/nsgJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
],
"metadata": {
"description": "UE NR Cap from NSG, Timestamps: 1727632521830058",
"subTypes": "eutra",
"deviceName": "Google Pixel 7 Pro",
"deviceType": "Exynos",
"simId": "2",
Expand Down Expand Up @@ -21058,6 +21059,7 @@
],
"metadata": {
"description": "UE LTE Cap from NSG, Timestamps: 1727632592636862, 1727632592911284",
"subTypes": "eutra, eutra-nr",
"deviceName": "Google Pixel 7 Pro",
"deviceType": "Exynos",
"simId": "2",
Expand Down Expand Up @@ -25481,6 +25483,7 @@
],
"metadata": {
"description": "UE LTE Cap from NSG, Timestamps: 1708175715402271",
"subTypes": "eutra",
"deviceName": "",
"deviceType": "Qualcomm",
"simId": "1",
Expand Down
12 changes: 8 additions & 4 deletions src/test/resources/cli/oracleMultiJson/pcap.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@
}
],
"metadata": {
"description": "UE NR Cap from PCAP, Timestamps: 1612629633088060"
"description": "UE NR Cap from PCAP, Timestamps: 1612629633088060",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -9605,7 +9606,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1612629644496007, 1612629644517236"
"description": "UE LTE Cap from PCAP, Timestamps: 1612629644496007, 1612629644517236",
"subTypes": "eutra, eutra-nr"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -10035,7 +10037,8 @@
}
],
"metadata": {
"description": "UE NR Cap from PCAP, Timestamps: 1612629724916405"
"description": "UE NR Cap from PCAP, Timestamps: 1612629724916405",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -10465,7 +10468,8 @@
}
],
"metadata": {
"description": "UE NR Cap from PCAP, Timestamps: 1612629762343068"
"description": "UE NR Cap from PCAP, Timestamps: 1612629762343068",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down
6 changes: 4 additions & 2 deletions src/test/resources/cli/oracleMultiJson/scat.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from DLF, Timestamps: 1638043858674893"
"description": "UE LTE Cap from DLF, Timestamps: 1638043858674893",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -1220,7 +1221,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from SDM, Timestamps: 1591378346163000"
"description": "UE LTE Cap from SDM, Timestamps: 1591378346163000",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down
6 changes: 4 additions & 2 deletions src/test/resources/cli/oracleMultiJson/segmented.json
Original file line number Diff line number Diff line change
Expand Up @@ -80333,7 +80333,8 @@
}
],
"metadata": {
"description": "UE NR Cap from PCAP, Timestamps: 315965578030978"
"description": "UE NR Cap from PCAP, Timestamps: 315965578030978",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -212615,7 +212616,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1720055421197912, 1720055421300828, 1720055421338463"
"description": "UE LTE Cap from PCAP, Timestamps: 1720055421197912, 1720055421300828, 1720055421338463",
"subTypes": "eutra, nr, eutra-nr"
},
"id": "",
"parserVersion": "staging",
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/nsgJson/oracle/airscreenQcom.json
Original file line number Diff line number Diff line change
Expand Up @@ -4413,6 +4413,7 @@
],
"metadata": {
"description": "UE LTE Cap from NSG, Timestamps: 1708175715402271",
"subTypes": "eutra",
"deviceName": "",
"deviceType": "Qualcomm",
"simId": "1",
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/nsgJson/oracle/nsgExy.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
],
"metadata": {
"description": "UE NR Cap from NSG, Timestamps: 1727632521830058",
"subTypes": "eutra",
"deviceName": "Google Pixel 7 Pro",
"deviceType": "Exynos",
"simId": "2",
Expand Down Expand Up @@ -21058,6 +21059,7 @@
],
"metadata": {
"description": "UE LTE Cap from NSG, Timestamps: 1727632592636862, 1727632592911284",
"subTypes": "eutra, eutra-nr",
"deviceName": "Google Pixel 7 Pro",
"deviceType": "Exynos",
"simId": "2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4346,7 +4346,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670593060602816"
"description": "UE LTE Cap from PCAP, Timestamps: 1670593060602816",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670070858782740"
"description": "UE LTE Cap from PCAP, Timestamps: 1670070858782740",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -1539,7 +1540,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670070870420631"
"description": "UE LTE Cap from PCAP, Timestamps: 1670070870420631",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -1696,7 +1698,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670070955683923"
"description": "UE LTE Cap from PCAP, Timestamps: 1670070955683923",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -1853,7 +1856,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670070967045658"
"description": "UE LTE Cap from PCAP, Timestamps: 1670070967045658",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -2059,7 +2063,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670071011211689"
"description": "UE LTE Cap from PCAP, Timestamps: 1670071011211689",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -2175,7 +2180,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670071018386306"
"description": "UE LTE Cap from PCAP, Timestamps: 1670071018386306",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -5230,7 +5236,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670071191057261"
"description": "UE LTE Cap from PCAP, Timestamps: 1670071191057261",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down Expand Up @@ -8236,7 +8243,8 @@
}
],
"metadata": {
"description": "UE LTE Cap from PCAP, Timestamps: 1670071462011478"
"description": "UE LTE Cap from PCAP, Timestamps: 1670071462011478",
"subTypes": "eutra"
},
"id": "",
"parserVersion": "staging",
Expand Down
Loading

0 comments on commit a270623

Please sign in to comment.