[6.4.0][启自驾指引] 丰富埋点数据;优化代码逻辑

This commit is contained in:
renwj
2024-04-26 18:33:44 +08:00
parent 00e14a22bd
commit fd5ec5750a
9 changed files with 175 additions and 77 deletions

View File

@@ -191,8 +191,17 @@ object StatusManager {
}?.takeIf {
it.isNotEmpty()
}?.also { l ->
runCatching {
MogoAnalyticUtils.track("vehicle_state_exp", HashMap<String, Any>().also { itx -> itx["data"] = l.joinToString(",") { it.toString() } })
l.filter { it.isException() }.takeIf { it.isNotEmpty() }?.also { ll ->
val result = runCatching {
MogoAnalyticUtils.track(
"vehicle_state_exp",
HashMap<String, Any>().also { itx ->
itx["data"] = ll.joinToString(",") { it.toString() }
})
}
if (result.isFailure) {
Logger.w(TAG, "error => ${result.exceptionOrNull()?.stackTraceToString() }")
}
}
}?.forEachIndexed { index, status ->
val shl = 1 shl index

View File

@@ -24,6 +24,9 @@ internal class AcceleratorImpl(ctx: Context): IFlow<AcceleratorStatus>(ctx), IMo
@Volatile
private var isError: Boolean = false
@Volatile
private var extra: Any? = null
override fun onCreate() {
CallerChassisThrottleStateListenerManager.addListener(TAG, this)
CallerAutopilotActionsListenerManager.addListener(TAG, this)
@@ -38,23 +41,25 @@ internal class AcceleratorImpl(ctx: Context): IFlow<AcceleratorStatus>(ctx), IMo
override fun onAutopilotThrottle(throttle: Float) {
super.onAutopilotThrottle(throttle)
if (last != throttle) {
send(AcceleratorStatus(throttle, isError))
send(AcceleratorStatus(throttle, isError).also { it.rawData = extra })
last = throttle
}
}
override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList<UnableLaunchReason>?) {
if (!isAutopilotAbility) {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_THROTTLE }?.also {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_THROTTLE }?.also { itx ->
isError = true
send(AcceleratorStatus(last ?: 0.0f, true).also { it.rawData = it })
send(AcceleratorStatus(last ?: 0.0f, true).also { extra = itx; it.rawData = itx })
}
if (target == null) {
isError = false
extra = null
send(AcceleratorStatus(last ?: 0.0f, false))
}
} else {
isError = false
extra = null
send(AcceleratorStatus(last ?: 0.0f, false))
}
}

View File

@@ -27,6 +27,9 @@ internal class BrakeImpl(ctx: Context): IFlow<BrakeStatus>(ctx), IMoGoChassisBra
@Volatile
private var isError: Boolean = false
@Volatile
private var extra: Any? = null
override fun onCreate() {
CallerChassisBrakeStateListenerManager.addListener(TAG, this)
CallerAutopilotActionsListenerManager.addListener(TAG, this)
@@ -41,23 +44,28 @@ internal class BrakeImpl(ctx: Context): IFlow<BrakeStatus>(ctx), IMoGoChassisBra
override fun onAutopilotBrake(brake: Float) {
super.onAutopilotBrake(brake)
if (last != brake) {
send(BrakeStatus(brake, isError).also { it.rawData = brake })
send(BrakeStatus(brake, isError).also { it.rawData = extra })
last = brake
}
}
override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList<UnableLaunchReason>?) {
if (!isAutopilotAbility) {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_BRAKE }?.also {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_BRAKE }?.also { itx ->
isError = true
send(BrakeStatus(last, true).also { it.rawData = it })
send(BrakeStatus(last, true).also {
extra = itx
it.rawData = extra
})
}
if (target == null) {
isError = false
extra = null
send(BrakeStatus(last, false))
}
} else {
isError = false
extra = null
send(BrakeStatus(last, false))
}
}

View File

@@ -28,6 +28,9 @@ internal class DoubleFlashImpl(ctx: Context): IFlow<DoubleFlashStatus>(ctx), IMo
@Volatile
private var last: LightSwitch? = null
@Volatile
private var extra: Any? = null
override fun onCreate() {
CallerChassisLamplightListenerManager.addListener(TAG, this)
CallerAutopilotActionsListenerManager.addListener(TAG, this)
@@ -45,7 +48,7 @@ internal class DoubleFlashImpl(ctx: Context): IFlow<DoubleFlashStatus>(ctx), IMo
if (last != lightSwitch) {
last = lightSwitch
if (lightSwitch == LIGHT_FLASH) {
send(DoubleFlashStatus(lightSwitch.number, isError))
send(DoubleFlashStatus(lightSwitch.number, isError).also { it.rawData = extra })
}
}
@@ -53,16 +56,18 @@ internal class DoubleFlashImpl(ctx: Context): IFlow<DoubleFlashStatus>(ctx), IMo
override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList<UnableLaunchReason>?) {
if (!isAutopilotAbility) {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_HAZARD_LIGHTS }?.also {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_HAZARD_LIGHTS }?.also { itx ->
isError = true
send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, true).also { it.rawData = last to it })
send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, true).also { extra = last to itx; it.rawData = extra })
}
if (target == null) {
isError = false
extra = null
send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, false).also { it.rawData = last })
}
} else {
isError = false
extra = null
send(DoubleFlashStatus(last?.number ?: Int.MIN_VALUE, false).also { it.rawData = last })
}
}

View File

@@ -27,6 +27,9 @@ internal class GearImpl(ctx: Context): IFlow<GearStatus>(ctx), IMoGoChassisGearS
@Volatile
private var isError: Boolean = false
@Volatile
private var extra: Any? = null
override fun onCreate() {
CallerChassisGearStateListenerManager.addListener(TAG, this)
CallerAutopilotActionsListenerManager.addListener(TAG, this)
@@ -40,23 +43,25 @@ internal class GearImpl(ctx: Context): IFlow<GearStatus>(ctx), IMoGoChassisGearS
override fun onAutopilotGearData(gear: GearPosition) {
if (last != gear) {
send(GearStatus(gear.number, isError))
send(GearStatus(gear.number, isError).also { it.rawData = extra })
last = gear
}
}
override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList<UnableLaunchReason>?) {
if (!isAutopilotAbility) {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_GEAR }?.also {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_GEAR }?.also { itx ->
isError = true
send(GearStatus(last.number, true).also { it.rawData = it })
send(GearStatus(last.number, true).also { extra = itx; it.rawData = itx })
}
if (target == null) {
isError = false
extra = null
send(GearStatus(last.number, false))
}
} else {
isError = false
extra = null
send(GearStatus(last.number, false))
}
}

View File

@@ -14,10 +14,11 @@ import com.zhjt.mogo_core_function_devatools.status.entity.RouteState.RouteStart
import com.zhjt.mogo_core_function_devatools.status.flow.IFlow
import mogo_msg.MogoReportMsg.MogoReportMessage
import java.lang.Exception
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentSkipListMap
internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx), IMoGoAutopilotStatusListener {
internal class RouteDownloadImpl(ctx: Context) : IFlow<RouteDownloadStatus>(ctx),
IMoGoAutopilotStatusListener {
companion object {
private const val TAG = "RouteDownloadImpl"
@@ -26,7 +27,7 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx),
@Volatile
private var toDownloadLineId: Long? = null
private val linked by lazy { ConcurrentHashMap<Int, Any>() }
private val extra by lazy { ConcurrentSkipListMap<Int, Any>() }
override fun onCreate() {
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
@@ -40,12 +41,11 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx),
override fun onAutopilotStatusResponse(state: Int) {
super.onAutopilotStatusResponse(state)
Logger.d(TAG, "--- onAutopilotStatusResponse -- 1 --: $state")
if (state == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {
val lineId = toDownloadLineId
Logger.d(TAG, "--- onAutopilotStatusResponse -- 2 --: $lineId")
if (lineId != null && lineId >= 0) {
linked.clear()
extra.clear()
send(RouteDownloadStatus(lineId, RouteComplete))
toDownloadLineId = null
}
@@ -55,25 +55,28 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx),
override fun onAutopilotTrajectoryDownloadReq(autoPilotLine: AutoPilotLine, downloadType: Int) {
super.onAutopilotTrajectoryDownloadReq(autoPilotLine, downloadType)
Logger.d(TAG, "--- onAutopilotTrajectoryDownloadReq --: 1:$autoPilotLine, 2:$downloadType")
if (downloadType == 0 && autoPilotLine.lineId >= 0) {
linked.clear()
linked[0] = autoPilotLine.lineId
toDownloadLineId = autoPilotLine.lineId
val lineId = autoPilotLine.lineId
send(RouteDownloadStatus(lineId = lineId, state = RouteNone).also { autoPilotLine.lineId })
val lineId = autoPilotLine.lineId
if (downloadType == 0 && lineId >= 0) {
extra.clear()
extra[0] = lineId to System.currentTimeMillis()
toDownloadLineId = lineId
send(RouteDownloadStatus(lineId = lineId, state = RouteNone).also {
it.rawData = extra
})
}
}
override fun onAutopilotGuardian(guardianInfo: MogoReportMessage?) {
super.onAutopilotGuardian(guardianInfo)
var lineId = Long.MIN_VALUE
Logger.d(TAG, "--- onAutopilotGuardian -- 1 --: ${ guardianInfo?.code }")
if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START == guardianInfo?.code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS == guardianInfo?.code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE == guardianInfo?.code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING == guardianInfo?.code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT == guardianInfo?.code
val code = guardianInfo?.code
Logger.d(TAG, "--- onAutopilotGuardian -- 1 --: $code")
if (MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START == code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS == code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE == code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING == code ||
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT == code
) {
var lineId = Long.MIN_VALUE
Logger.d(TAG, "--- onAutopilotGuardian -- 2 --")
val msg = guardianInfo.msg
try {
@@ -82,7 +85,8 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx),
if (matchResult != null) {
lineId = matchResult.groupValues[1].toLong()
}
} catch (ignore: Exception) { }
} catch (ignore: Exception) {
}
if (lineId == Long.MIN_VALUE) {
try {
val regex = Regex("lineID=(\\d+)")
@@ -90,30 +94,41 @@ internal class RouteDownloadImpl(ctx: Context): IFlow<RouteDownloadStatus>(ctx),
if (matchResult != null) {
lineId = matchResult.groupValues[1].toLong()
}
} catch (ignore: Exception) { }
} catch (ignore: Exception) {
}
}
}
Logger.d(TAG, "--- onAutopilotGuardian -- 3 --:lineId => $toDownloadLineId, parse_line_id: $lineId")
if (toDownloadLineId != lineId) {
return
}
if (guardianInfo == null || !guardianInfo.hasCode())
return
Logger.d(TAG, "--- onAutopilotGuardian -- 4 --:line_id => $lineId, code: ${guardianInfo.code}")
when (guardianInfo.code) {
"ISYS_INIT_TRAJECTORY_START" -> { // 1. 轨迹管理_轨迹开始下载本地已有对应轨迹也触发
linked[1] = lineId
send(RouteDownloadStatus(lineId, RouteStart).also { it.rawData = linked })
extra[1] = lineId to "${System.currentTimeMillis()} => ($code,$toDownloadLineId)"
Logger.d(
TAG,
"--- onAutopilotGuardian -- 3 --:lineId => $toDownloadLineId, parse_line_id: $lineId"
)
if (toDownloadLineId != lineId) {
return
}
"ISYS_INIT_TRAJECTORY_SUCCESS" -> { // 2. 轨迹管理_轨迹下载成功本地已有对应轨迹也触发
linked[2] = lineId
send(RouteDownloadStatus(lineId, RouteComplete).also { it.rawData = linked })
toDownloadLineId = null
}
"ISYS_INIT_TRAJECTORY_FAILURE" -> { // 3. 轨迹管理_轨迹下载失败,本地无对应轨迹
linked[3] = lineId
send(RouteDownloadStatus(lineId, RouteFailed).also { it.rawData = linked })
toDownloadLineId = null
Logger.d(
TAG,
"--- onAutopilotGuardian -- 4 --:line_id => $lineId, code: ${guardianInfo.code}"
)
when (code) {
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_START -> { // 1. 轨迹管理_轨迹开始下载(本地已有对应轨迹也触发)
extra[2] = lineId to System.currentTimeMillis()
send(RouteDownloadStatus(lineId, RouteStart).also { it.rawData = extra })
}
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_SUCCESS -> { // 2. 轨迹管理_轨迹下载成功本地已有对应轨迹也触发
extra[3] = lineId to System.currentTimeMillis()
send(RouteDownloadStatus(lineId, RouteComplete).also { it.rawData = extra })
toDownloadLineId = null
}
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_FAILURE,
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_WARNING,
MogoReport.Code.Info.ISYS.INIT_TRAJECTORY_TIMEOUT -> {
// 3. 轨迹管理_轨迹下载失败本地无对应轨迹
extra[4] = lineId to System.currentTimeMillis()
send(RouteDownloadStatus(lineId, RouteFailed).also { it.rawData = extra })
toDownloadLineId = null
}
}
}
}

View File

@@ -24,6 +24,9 @@ internal class SteerImpl(ctx: Context): IFlow<SteerStatus>(ctx), IMoGoChassisSte
@Volatile
private var isError: Boolean = false
@Volatile
private var extra: Any? = null
override fun onCreate() {
CallerChassisSteeringStateListenerManager.addListener(TAG, this)
CallerAutopilotActionsListenerManager.addListener(TAG, this)
@@ -37,7 +40,7 @@ internal class SteerImpl(ctx: Context): IFlow<SteerStatus>(ctx), IMoGoChassisSte
override fun onAutopilotSteeringData(steering: Float) {
if (last != steering) {
send(SteerStatus(steering, isError).also { it.rawData = steering })
send(SteerStatus(steering, isError).also { it.rawData = extra })
last = steering
}
}
@@ -45,16 +48,18 @@ internal class SteerImpl(ctx: Context): IFlow<SteerStatus>(ctx), IMoGoChassisSte
override fun onAutopilotAbility(isAutopilotAbility: Boolean, unableLaunchData: UnableLaunchData?, unableAutopilotReasons: ArrayList<UnableLaunchReason>?) {
Logger.d(TAG, "onAutopilotAbility->($isAutopilotAbility, $unableLaunchData, ${unableAutopilotReasons?.joinToString(",")}")
if (!isAutopilotAbility) {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_STEERING }?.also {
val target = unableAutopilotReasons?.find { it.unableType == CHASSIS_STEERING }?.also { itx ->
isError = true
send(SteerStatus(last, true).also { it.rawData = last to it })
send(SteerStatus(last, true).also { data -> data.rawData = (last to itx).also { this.extra = it } })
}
if (target == null) {
isError = false
extra = null
send(SteerStatus(last, false).also { it.rawData = last })
}
} else {
isError = false
extra = null
send(SteerStatus(last, false).also { it.rawData = last })
}
}