[charter m1]司机端埋点逻辑

This commit is contained in:
wangmingjun
2023-03-01 16:55:57 +08:00
parent c33b2bae36
commit 62fbe08b3b
8 changed files with 212 additions and 65 deletions

View File

@@ -0,0 +1,146 @@
package com.magic.mogo.och.charter;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS;
import android.text.TextUtils;
import com.magic.mogo.och.charter.constant.CharterConst;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.utils.MogoAnalyticUtils;
import com.mogo.eagle.core.data.app.AppConfigInfo;
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener;
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.DateTimeUtils;
import com.mogo.eagle.core.utilcode.util.UiThreadHandler;
import java.util.HashMap;
/**
* @author: wangmingjun
* @date: 2023/3/1
*/
public class CharterAnalyticsManager {
private static final class SingletonHolder {
private static final CharterAnalyticsManager INSTANCE = new CharterAnalyticsManager();
}
public static CharterAnalyticsManager getInstance() {
return CharterAnalyticsManager.SingletonHolder.INSTANCE;
}
private String mStartAutopilotKey;
private HashMap<String, Object> mStartAutopilotParams = new HashMap<>();
private Runnable startAutopilotRunnable = () -> {
// 15s内未开启上报失败埋点
triggerStartAutopilotFailureEvent("", "15s后app等待超时");
};
public void triggerStartAutopilotFailureEventByAdas(String failCode, String failMsg){
removeWaitingCallback();
triggerStartAutopilotFailureEvent(failCode, failMsg);
}
private void triggerStartAutopilotFailureEvent(String failCode, String failMsg){
if (mStartAutopilotParams.isEmpty()) return;
CallerLogger.INSTANCE.e( M_BUS + "triggerStartAutopilotFailureEvent", failMsg );
if (CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState() !=
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING){
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_FAILURE_CODE, failCode);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_FAILURE_MSG, failMsg);
}
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_RESULT
, CallerAutoPilotStatusListenerManager.INSTANCE.getAutoPilotStatusInfo().getState() ==
IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING);
MogoAnalyticUtils.INSTANCE.track(mStartAutopilotKey, mStartAutopilotParams);
clearStartAutopilotParams();//清空参数数据,防止误传
}
private void removeWaitingCallback() {
if (startAutopilotRunnable != null &&
UiThreadHandler.getsUiHandler().hasCallbacks(startAutopilotRunnable)) {
UiThreadHandler.removeCallbacks(startAutopilotRunnable);
}
}
public void clearStartAutopilotFailureMSG(){
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_FAILURE_CODE, "");
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_FAILURE_MSG, "");
}
private void clearStartAutopilotParams(){
mStartAutopilotParams.clear();
}
/**
* 触发'开启自动驾驶'埋点流程
* 开启自动驾驶15s内成功则发送成功埋点否则发送失败埋点
* @param restart false点击'滑动出发'启动)/true接管后点击'自动驾驶'按钮启动)
* @param send 是否直接发送埋点15s内开启成功则直接发送成功埋点
*/
public void triggerStartAutopilotEvent(
boolean restart, boolean send, String startName, String endName, int lineId) {
mStartAutopilotKey = restart ?
CharterConst.EVENT_KEY_RESTART_AUTOPILOT : CharterConst.EVENT_KEY_START_SERVICE;
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
String plateNum = AppConfigInfo.INSTANCE.getPlateNumber();
String dateTime = DateTimeUtils.getTimeText(
System.currentTimeMillis(), DateTimeUtils.yyyy_MM_dd_HH_mm_ss);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_SN, sn);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_PLATE_NUM, TextUtils.isEmpty(plateNum) ? "" : plateNum);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_ENV_ONLINE,
DebugConfig.getNetMode() == DebugConfig.NET_MODE_RELEASE ? true : false);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_TIME, dateTime);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_NAME, startName);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_END_NAME, endName);
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_LINE_ID, lineId);
if (send) {
if (mStartAutopilotParams.isEmpty()) return;
// 开启成功,上报埋点
clearStartAutopilotFailureMSG();
removeWaitingCallback();
mStartAutopilotParams.put(CharterConst.EVENT_PARAM_START_RESULT, true);
MogoAnalyticUtils.INSTANCE.track(mStartAutopilotKey, mStartAutopilotParams);
clearStartAutopilotParams();//清空参数数据,防止误传
} else {
UiThreadHandler.postDelayed(startAutopilotRunnable, CharterConst.LOOP_PERIOD_15S);
}
}
/**
* 触发"无法开启自驾已知异常"埋点
* @param startName
* @param endName
* @param lineId
*/
public void triggerUnableStartAPReasonEvent(String startName, String endName, int lineId,
String reason) {
String sn = MoGoAiCloudClientConfig.getInstance().getSn();
String plateNum = AppConfigInfo.INSTANCE.getPlateNumber();
String dateTime = DateTimeUtils.getTimeText(
System.currentTimeMillis(), DateTimeUtils.yyyy_MM_dd_HH_mm_ss);
HashMap<String, Object> params = new HashMap<>();
params.put(CharterConst.EVENT_PARAM_SN, sn);
params.put(CharterConst.EVENT_PARAM_PLATE_NUM, TextUtils.isEmpty(plateNum) ? "" : plateNum);
params.put(CharterConst.EVENT_PARAM_ENV_ONLINE,
DebugConfig.getNetMode() == DebugConfig.NET_MODE_RELEASE ? true : false);
params.put(CharterConst.EVENT_PARAM_TIME, dateTime);
params.put(CharterConst.EVENT_PARAM_START_NAME, startName);
params.put(CharterConst.EVENT_PARAM_END_NAME, endName);
params.put(CharterConst.EVENT_PARAM_LINE_ID, lineId);
params.put(CharterConst.EVENT_PARAM_UNABLE_START_REASON, reason);
MogoAnalyticUtils.INSTANCE.track(CharterConst.EVENT_KEY_AP_UNABLE_START_REASON, params);
}
}

View File

@@ -22,6 +22,22 @@ data class QueryCurrentOrderResponse(var data: Result):BaseData(){ //线路id ,
var startTime: Long,
var endTime: Long,
var passengerPhone: String
)
){
override fun equals(o: Any?): Boolean {
if (this === o) return true
if (o == null || javaClass != o.javaClass) return false
val result = o as Result
return orderNo == result.orderNo
&& sn == result.sn
&& lineId == result.lineId
&& startSiteId == result.startSiteId
&& startSiteName == result.startSiteName
&& siteId == result.siteId
&& siteName == result.siteName
&& wgs84Lon == result.wgs84Lon
&& wgs84Lon == result.wgs84Lon
&& passengerPhone == result.passengerPhone
}
}
}

View File

@@ -154,8 +154,8 @@ class DriverM1Fragment : CharterBaseFragment<DriverM1Fragment?, DriverM1Presente
fun updateReturnCarStatus(returnSuccess: Boolean) {
requireActivity().runOnUiThread {
group_stations_panel.visibility = GONE
no_line_data_view.visibility = VISIBLE
if (returnSuccess){
no_line_data_view.visibility = VISIBLE
slidePanelView?.visibility = GONE
}else{
slidePanelView?.visibility = VISIBLE

View File

@@ -4,7 +4,6 @@ import com.magic.mogo.och.charter.constant.CharterConst
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
@@ -23,7 +22,7 @@ object DriverM1LooperManager {
if (mQueryLineDisposable != null && !mQueryLineDisposable!!.isDisposed) {
return
}
CallerLogger.i(SceneConstant.M_BUS_P + TAG, "startQueryDriverLineLoop()")
CallerLogger.i(SceneConstant.M_CHARTER_D + TAG, "startQueryDriverLineLoop()")
mQueryLineDisposable = Observable.interval(
CharterConst.LOOP_DELAY,
CharterConst.LOOP_2S, TimeUnit.MILLISECONDS
@@ -39,7 +38,7 @@ object DriverM1LooperManager {
fun stopQueryDriverLineLoop() {
if (mQueryLineDisposable != null) {
CallerLogger.i(SceneConstant.M_BUS_P + TAG, "stopQueryDriverLineLoop()")
CallerLogger.i(SceneConstant.M_CHARTER_D + TAG, "stopQueryDriverLineLoop()")
mQueryLineDisposable!!.dispose()
mQueryLineDisposable = null
}
@@ -49,7 +48,7 @@ object DriverM1LooperManager {
if (mQueryCountDownDisposable != null && !mQueryCountDownDisposable!!.isDisposed) {
return
}
CallerLogger.i(SceneConstant.M_BUS_P + TAG, "starCountDownLoop()")
CallerLogger.i(SceneConstant.M_CHARTER_D + TAG, "starCountDownLoop()")
mQueryCountDownDisposable = Observable.interval(
CharterConst.LOOP_DELAY,
CharterConst.LOOP_5M, TimeUnit.MINUTES
@@ -65,7 +64,7 @@ object DriverM1LooperManager {
fun stopCountDownLoop() {
if (mQueryCountDownDisposable != null) {
CallerLogger.i(SceneConstant.M_BUS_P + TAG, "stopCountDownLoop()")
CallerLogger.i(SceneConstant.M_CHARTER_D + TAG, "stopCountDownLoop()")
mQueryCountDownDisposable!!.dispose()
mQueryCountDownDisposable = null
}

View File

@@ -7,6 +7,7 @@ import com.alibaba.android.arouter.launcher.ARouter
import com.alibaba.android.arouter.utils.TextUtils
import com.amap.api.maps.model.LatLng
import com.elegant.network.utils.GsonUtil
import com.magic.mogo.och.charter.CharterAnalyticsManager
import com.magic.mogo.och.charter.R
import com.magic.mogo.och.charter.bean.CheckOrderCountDownResponse
import com.magic.mogo.och.charter.bean.QueryBusinessStatusResponse
@@ -23,7 +24,6 @@ import com.mogo.commons.module.intent.IMogoIntentListener
import com.mogo.commons.module.intent.IntentManager
import com.mogo.eagle.core.data.BaseData
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
import com.mogo.eagle.core.data.config.FunctionBuildConfig
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.data.telematic.TelematicConstant
import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener
@@ -86,7 +86,7 @@ class DriverM1Model {
private var currentChangeDestMsg: ChangeDestMsg? = null
private var mCurrentResult: QueryRoutesResponse.Result? = null
private var mCurrentRoute: QueryRoutesResponse.Result? = null
//0: 代表没有启动过 1代表是启动第一次当>=1 代表是重试 每次到站/路线结束清空置为0
@@ -112,8 +112,8 @@ class DriverM1Model {
})
fun init() {
mContext = AbsMogoApplication.getApp()
fun init(context: Context) {
mContext = context
// 定位监听
CallerChassisLocationGCJ02ListenerManager.addListener(TAG, mMapLocationListener)
CallerChassisLocationGCJ02ListenerManager.setListenerHz(TAG,2)
@@ -295,6 +295,7 @@ class DriverM1Model {
pushOperationalToMsgBox(obj.pushTimeStamp, obj.message
,OCHSocketMessageManager.OPERATION_ORDER_TYPE)
sendMsgToClient(DPOrderClosedMsg())
queryCurrentServiceStatus()
}
override fun target(): Class<OrderCloseMsg> {
@@ -395,7 +396,7 @@ class DriverM1Model {
triggerUnableStartAPReasonEvent()
return
}
triggerStartServiceEvent(true, false)
triggerStartServiceEvent(false, false)
val parameters = initAutopilotControlParameters()
if (null == parameters) {
d(SceneConstant.M_CHARTER_D + TAG, "行程日志-AutopilotControlParameters is empty.")
@@ -429,7 +430,7 @@ class DriverM1Model {
}
fun isHaveOrder(): Boolean {
return mCurrentOrder == null
return mCurrentOrder != null
}
// 登出
@@ -437,28 +438,28 @@ class DriverM1Model {
loginService!!.loginOut(mLatitude, mLongitude)
}
fun triggerStartServiceEvent(isRestart: Boolean, send: Boolean) {
// if (stationList == null || backgroundCurrentStationIndex >= stationList.size - 1) {
// return
// }
// val currentStation: BusStationBean = stationList[backgroundCurrentStationIndex]
// val nextStation: BusStationBean = stationList[backgroundCurrentStationIndex + 1]
// BusAnalyticsManager.getInstance().triggerStartAutopilotEvent(
// isRestart, send,
// currentStation.getName(), nextStation.getName(), currentLineId
// )
private fun triggerStartServiceEvent(isRestart: Boolean, send: Boolean) {
if (mCurrentOrder == null) {
return
}
mCurrentOrder?.lineId?.let {
CharterAnalyticsManager.getInstance().triggerStartAutopilotEvent(
isRestart, send,
mCurrentOrder?.startSiteName, mCurrentOrder?.siteName, it
)
}
}
fun triggerUnableStartAPReasonEvent() {
// if (stationList == null || backgroundCurrentStationIndex >= stationList.size - 1) {
// return
// }
// val currentStation: BusStationBean = stationList[backgroundCurrentStationIndex]
// val nextStation: BusStationBean = stationList[backgroundCurrentStationIndex + 1]
// BusAnalyticsManager.getInstance().triggerUnableStartAPReasonEvent(
// currentStation.getName(), nextStation.getName(), currentLineId,
// OCHAdasAbilityManager.getInstance().autopilotUnAbilityReason
// )
private fun triggerUnableStartAPReasonEvent() {
if (mCurrentOrder == null) {
return
}
mCurrentOrder?.lineId?.let {
CharterAnalyticsManager.getInstance().triggerUnableStartAPReasonEvent(
mCurrentOrder?.startSiteName, mCurrentOrder?.siteName, it,
OCHAdasAbilityManager.getInstance().autopilotUnAbilityReason
)
}
}
fun getCurrentStationIndex(): Int {
@@ -485,7 +486,7 @@ class DriverM1Model {
}
private fun initAutopilotControlParameters(): AutopilotControlParameters? {
if ( mCurrentOrder == null || mCurrentResult == null) return null
if ( mCurrentOrder == null || mCurrentRoute == null) return null
var parameters = AutopilotControlParameters()
parameters.routeID = mCurrentOrder?.lineId!!
parameters.routeName = mCurrentOrder?.lineName!!
@@ -501,12 +502,12 @@ class DriverM1Model {
if (parameters.autoPilotLine == null) {
parameters.autoPilotLine = AutopilotControlParameters.AutoPilotLine(
mCurrentOrder!!.lineId.toLong(),
mCurrentResult!!.csvFileUrl, mCurrentResult!!.csvFileMd5,
mCurrentResult!!.txtFileUrl, mCurrentResult!!.txtFileMd5,
mCurrentResult!!.contrailSaveTime, mCurrentResult!!.carModel,
mCurrentResult!!.csvFileUrlDPQP, mCurrentResult!!.csvFileMd5DPQP,
mCurrentResult!!.txtFileUrlDPQP, mCurrentResult!!.txtFileMd5DPQP,
mCurrentResult!!.contrailSaveTimeDPQP!!
mCurrentRoute!!.csvFileUrl, mCurrentRoute!!.csvFileMd5,
mCurrentRoute!!.txtFileUrl, mCurrentRoute!!.txtFileMd5,
mCurrentRoute!!.contrailSaveTime, mCurrentRoute!!.carModel,
mCurrentRoute!!.csvFileUrlDPQP, mCurrentRoute!!.csvFileMd5DPQP,
mCurrentRoute!!.txtFileUrlDPQP, mCurrentRoute!!.txtFileMd5DPQP,
mCurrentRoute!!.contrailSaveTimeDPQP!!
)
}
return parameters
@@ -587,10 +588,11 @@ class DriverM1Model {
DriverM1ServiceManager.queryCurrentOrder(mContext
,object: OchCommonServiceCallback<QueryCurrentOrderResponse>{
override fun onSuccess(data: QueryCurrentOrderResponse?) {
if (data == null || data.code != 0 || mCurrentOrder === data.data){
if (data == null || data.code != 0 || data.data.equals(mCurrentOrder)){
isArrivedStation = false
return
}
d(SceneConstant.M_CHARTER_D + TAG, "queryCurrentOrder order =" +
GsonUtils.toJson(data.data))
mCurrentOrder = data.data
@@ -672,7 +674,7 @@ class DriverM1Model {
if (data == null || data.code != 0) return
d(SceneConstant.M_CHARTER_D + TAG, "checkoutContrail-=="
+ GsonUtils.toJson(data.data))
mCurrentResult = data.data
mCurrentRoute = data.data
}
override fun onFail(code: Int, msg: String?) {

View File

@@ -35,7 +35,7 @@ class DriverM1Presenter(view: DriverM1Fragment?) :
private var mCurrentAutopilotStatus : Int = -1
init {
DriverM1Model.get().init()
DriverM1Model.get().init(context)
registerListener()
}

View File

@@ -146,13 +146,13 @@
<ImageView
android:id="@+id/driverm1ArrowBg"
android:layout_width="@dimen/dp_4"
android:layout_height="match_parent"
android:layout_height="0dp"
android:scaleType="fitXY"
android:layout_marginTop="@dimen/dp_20"
android:src="@drawable/bus_och_dot_line"
app:layout_constraintLeft_toLeftOf="@+id/driverm1CircleIvBg"
app:layout_constraintRight_toRightOf="@+id/driverm1CircleIvBg"
app:layout_constraintTop_toBottomOf="@+id/driverm1CircleIvBg"
app:layout_constraintBottom_toTopOf="@+id/driverm1nextCircleIv"
app:layout_constraintTop_toTopOf="@+id/driverm1CircleIvBg"/>
@@ -198,7 +198,7 @@
android:id="@+id/group_stations_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:visibility="visible"
app:constraint_referenced_ids="driverm1_line_name,driverm1_order_count_down
,cur_station_title,cur_station_title1,line1,line2,driverm1StationName1Tv,
driverm1StationName2Tv,driverm1nextCircleIv,driverm1CircleIvBg,driverm1ArrowBg

View File

@@ -9,17 +9,6 @@ class CharterConst {
// OCH arouter 路由path
const val PATH = "/driver/api"
// 测试用的广播
const val BROADCAST_TEST_BUS_CONTROL_TYPE_EXTRA_KEY = "sceneType"
// 无状态
const val STATION_STATUS_IDLE = 0
// 已过站(历史站)
const val STATION_STATUS_LEAVING = 1
// 到站(当前站)
const val STATION_STATUS_STOPPED = 2
// 未到站(未到站)
const val STATION_STATUS_ARRIVING = 3
// 上报心跳轮询ms
const val LOOP_PERIOD_60S = 60 * 1000L
// 开始服务启动自动驾驶等待时间(埋点上传)
@@ -32,15 +21,10 @@ class CharterConst {
// 尝试下发给MEC轨迹最多10次
const val LOOP_SEND_TRAJ_TIMES = 10
//起点UUID
const val BUS_START_MAP_MAKER = "bus_start_map_maker";
//终点UUID
const val BUS_END_MAP_MAKER = "bus_end_map_maker";
// 埋点key接管后点击'自动驾驶'按钮启动
const val EVENT_KEY_RESTART_AUTOPILOT = "event_key_och_bus_restart_autopilot"
const val EVENT_KEY_RESTART_AUTOPILOT = "event_key_och_charter_restart_autopilot"
// 埋点key开始服务开启自动驾驶成功/失败)
const val EVENT_KEY_START_SERVICE = "event_key_och_bus_start_service"
const val EVENT_KEY_START_SERVICE = "event_key_och_charter_start_service"
const val EVENT_PARAM_SN = "sn"
const val EVENT_PARAM_TIME = "time"
const val EVENT_PARAM_START_NAME = "start_name"
@@ -52,7 +36,7 @@ class CharterConst {
const val EVENT_PARAM_PLATE_NUM = "plate_number" // 车牌号
const val EVENT_PARAM_ENV_ONLINE = "env_online" // 是否线上环境true/false
// 埋点key开启自动驾驶前已识别的异常会导致无法开启自驾
const val EVENT_KEY_AP_UNABLE_START_REASON = "event_key_och_bus_ap_unable_start_reason"
const val EVENT_KEY_AP_UNABLE_START_REASON = "event_key_och_charter_ap_unable_start_reason"
const val EVENT_PARAM_UNABLE_START_REASON = "unable_start_reason";
/**