Improve Android retrain start feedback
This commit is contained in:
@@ -10,7 +10,7 @@ android {
|
|||||||
applicationId = "xyz.kusoft.tradebotmonitor"
|
applicationId = "xyz.kusoft.tradebotmonitor"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 11
|
versionCode = 12
|
||||||
versionName = "0.2.8"
|
versionName = "0.2.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-4
@@ -39,6 +39,7 @@ class MainActivity : Activity() {
|
|||||||
private var activeTab: String = "ai"
|
private var activeTab: String = "ai"
|
||||||
private var palette: AppPalette = AppPalette.dark()
|
private var palette: AppPalette = AppPalette.dark()
|
||||||
private var trainingStatusSignature: String = ""
|
private var trainingStatusSignature: String = ""
|
||||||
|
private var retrainRequestInFlight: Boolean = false
|
||||||
|
|
||||||
private val refreshRunnable = object : Runnable {
|
private val refreshRunnable = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
@@ -643,14 +644,23 @@ class MainActivity : Activity() {
|
|||||||
LinearLayout(this).apply {
|
LinearLayout(this).apply {
|
||||||
val activeJob = coordination.optJSONObject("active_job")
|
val activeJob = coordination.optJSONObject("active_job")
|
||||||
val latestJob = coordination.optJSONObject("latest_job")
|
val latestJob = coordination.optJSONObject("latest_job")
|
||||||
val job = activeJob ?: latestJob
|
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
addView(text("Процесс переобучения", 12f, Typeface.NORMAL, palette.muted))
|
addView(text("Процесс переобучения", 12f, Typeface.NORMAL, palette.muted))
|
||||||
if (job == null) {
|
if (activeJob == null) {
|
||||||
val agentOnline = coordination.optBoolean("agent_online", false)
|
val agentOnline = coordination.optBoolean("agent_online", false)
|
||||||
addView(keyValueLine("Состояние", if (agentOnline) "готов к запуску" else "ждет Windows-agent", if (agentOnline) palette.green else palette.amber).top(dp(8)))
|
addView(keyValueLine("Состояние", if (agentOnline) "готов к запуску" else "ждет Windows-agent", if (agentOnline) palette.green else palette.amber).top(dp(8)))
|
||||||
|
if (latestJob != null) {
|
||||||
|
val latestStatus = latestJob.optStringClean("status")
|
||||||
|
val latestPhase = latestJob.optStringClean("phase")
|
||||||
|
val latestMessage = latestJob.optStringClean("message")
|
||||||
|
addView(keyValueLine("Последнее обучение", trainingJobLabel(latestStatus, latestPhase), trainingJobColor(latestStatus, latestPhase)).top(dp(8)))
|
||||||
|
if (latestMessage.isNotBlank()) {
|
||||||
|
addView(text(latestMessage.take(160), 12f, Typeface.NORMAL, palette.muted).top(dp(6)))
|
||||||
|
}
|
||||||
|
}
|
||||||
return@apply
|
return@apply
|
||||||
}
|
}
|
||||||
|
val job = activeJob
|
||||||
val status = job.optStringClean("status")
|
val status = job.optStringClean("status")
|
||||||
val phase = job.optStringClean("phase")
|
val phase = job.optStringClean("phase")
|
||||||
val progress = job.optInt("progress_percent", if (status == "completed") 100 else 0).coerceIn(0, 100)
|
val progress = job.optInt("progress_percent", if (status == "completed") 100 else 0).coerceIn(0, 100)
|
||||||
@@ -674,7 +684,7 @@ class MainActivity : Activity() {
|
|||||||
private fun retrainSettingsBlock(retrain: JSONObject, backtest: JSONObject): View {
|
private fun retrainSettingsBlock(retrain: JSONObject, backtest: JSONObject): View {
|
||||||
val coordination = retrain.optJSONObject("coordination") ?: JSONObject()
|
val coordination = retrain.optJSONObject("coordination") ?: JSONObject()
|
||||||
val activeJob = coordination.optJSONObject("active_job")
|
val activeJob = coordination.optJSONObject("active_job")
|
||||||
val isTrainingActive = activeJob?.optStringClean("status") in setOf("pending", "running")
|
val isTrainingActive = retrainRequestInFlight || (activeJob?.optStringClean("status") in setOf("pending", "running"))
|
||||||
return LinearLayout(this).apply {
|
return LinearLayout(this).apply {
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
addView(trainingComputerPanel(retrain).top(dp(12)))
|
addView(trainingComputerPanel(retrain).top(dp(12)))
|
||||||
@@ -687,7 +697,7 @@ class MainActivity : Activity() {
|
|||||||
addView(keyValueLine("Replay сделок", replay.optInt("trades", 0).toString()).top(dp(4)))
|
addView(keyValueLine("Replay сделок", replay.optInt("trades", 0).toString()).top(dp(4)))
|
||||||
addView(keyValueLine("Replay PnL", signedMoney(replay.optDouble("net_pnl", 0.0)), colorForSigned(replay.optDouble("net_pnl", 0.0))).top(dp(4)))
|
addView(keyValueLine("Replay PnL", signedMoney(replay.optDouble("net_pnl", 0.0)), colorForSigned(replay.optDouble("net_pnl", 0.0))).top(dp(4)))
|
||||||
if (isTrainingActive) {
|
if (isTrainingActive) {
|
||||||
addView(disabledActionButton("Обучение уже идет").top(dp(10)))
|
addView(disabledActionButton(if (retrainRequestInFlight) "Отправляю команду" else "Обучение уже идет").top(dp(10)))
|
||||||
} else {
|
} else {
|
||||||
addView(actionRow(
|
addView(actionRow(
|
||||||
"Запустить сейчас" to {
|
"Запустить сейчас" to {
|
||||||
@@ -1101,15 +1111,20 @@ class MainActivity : Activity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun triggerRetrainNow() {
|
private fun triggerRetrainNow() {
|
||||||
|
if (retrainRequestInFlight) return
|
||||||
|
retrainRequestInFlight = true
|
||||||
|
render()
|
||||||
executor.execute {
|
executor.execute {
|
||||||
try {
|
try {
|
||||||
val message = TradeBotApi(prefs.apiBaseUrl, prefs.commandToken).requestRetrain()
|
val message = TradeBotApi(prefs.apiBaseUrl, prefs.commandToken).requestRetrain()
|
||||||
mainHandler.post {
|
mainHandler.post {
|
||||||
|
retrainRequestInFlight = false
|
||||||
toast(message.take(180))
|
toast(message.take(180))
|
||||||
refreshData(silent = false)
|
refreshData(silent = false)
|
||||||
}
|
}
|
||||||
} catch (error: Exception) {
|
} catch (error: Exception) {
|
||||||
mainHandler.post {
|
mainHandler.post {
|
||||||
|
retrainRequestInFlight = false
|
||||||
toast(error.message ?: "retrain не запущен")
|
toast(error.message ?: "retrain не запущен")
|
||||||
refreshData(silent = false)
|
refreshData(silent = false)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user