mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-08 23:22:04 +08:00
updated: uptime connectivity check (#35836)
* start * p * comment * 2 * p * no time * order * space * fix
This commit is contained in:
@@ -73,7 +73,9 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"LastOffroadStatusPacket", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, JSON}},
|
||||
{"LastPowerDropDetected", {CLEAR_ON_MANAGER_START, STRING}},
|
||||
{"LastUpdateException", {CLEAR_ON_MANAGER_START, STRING}},
|
||||
{"LastUpdateRouteCount", {PERSISTENT, INT}},
|
||||
{"LastUpdateTime", {PERSISTENT, TIME}},
|
||||
{"LastUpdateUptimeOnroad", {PERSISTENT, FLOAT}},
|
||||
{"LiveDelay", {PERSISTENT, BYTES}},
|
||||
{"LiveParameters", {PERSISTENT, JSON}},
|
||||
{"LiveParametersV2", {PERSISTENT, BYTES}},
|
||||
@@ -106,7 +108,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
||||
{"RecordFront", {PERSISTENT, BOOL}},
|
||||
{"RecordFrontLock", {PERSISTENT, BOOL}}, // for the internal fleet
|
||||
{"SecOCKey", {PERSISTENT | DONT_LOG, STRING}},
|
||||
{"RouteCount", {PERSISTENT, INT}},
|
||||
{"RouteCount", {PERSISTENT, INT, "0"}},
|
||||
{"SnoozeUpdate", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, BOOL}},
|
||||
{"SshEnabled", {PERSISTENT, BOOL}},
|
||||
{"TermsVersion", {PERSISTENT, STRING}},
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <QtXml/QDomDocument>
|
||||
|
||||
#include "common/swaglog.h"
|
||||
#include "common/util.h"
|
||||
#include "system/hardware/hw.h"
|
||||
|
||||
QString getVersion() {
|
||||
@@ -57,6 +58,10 @@ QMap<QString, QString> getSupportedLanguages() {
|
||||
}
|
||||
|
||||
QString timeAgo(const QDateTime &date) {
|
||||
if (!util::system_time_valid()) {
|
||||
return date.date().toString();
|
||||
}
|
||||
|
||||
int diff = date.secsTo(QDateTime::currentDateTimeUtc());
|
||||
|
||||
QString s;
|
||||
|
||||
+20
-13
@@ -31,8 +31,13 @@ FINALIZED = os.path.join(STAGING_ROOT, "finalized")
|
||||
|
||||
OVERLAY_INIT = Path(os.path.join(BASEDIR, ".overlay_init"))
|
||||
|
||||
DAYS_NO_CONNECTIVITY_MAX = 14 # do not allow to engage after this many days
|
||||
DAYS_NO_CONNECTIVITY_PROMPT = 10 # send an offroad prompt after this many days
|
||||
# do not allow to engage after this many hours onroad and this many routes
|
||||
HOURS_NO_CONNECTIVITY_MAX = 27
|
||||
ROUTES_NO_CONNECTIVITY_MAX = 84
|
||||
# send an offroad prompt after this many hours onroad and this many routes
|
||||
HOURS_NO_CONNECTIVITY_PROMPT = 23
|
||||
ROUTES_NO_CONNECTIVITY_PROMPT = 80
|
||||
|
||||
|
||||
class UserRequest:
|
||||
NONE = 0
|
||||
@@ -271,13 +276,15 @@ class Updater:
|
||||
if len(self.branches):
|
||||
self.params.put("UpdaterAvailableBranches", ','.join(self.branches.keys()))
|
||||
|
||||
last_update = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
|
||||
last_uptime_onroad = self.params.get("UptimeOnroad", return_default=True)
|
||||
last_route_count = self.params.get("RouteCount", return_default=True)
|
||||
if update_success:
|
||||
write_time_to_param(self.params, "LastUpdateTime")
|
||||
self.params.put("LastUpdateTime", datetime.datetime.now(datetime.UTC).replace(tzinfo=None))
|
||||
self.params.put("LastUpdateUptimeOnroad", last_uptime_onroad)
|
||||
self.params.put("LastUpdateRouteCount", last_route_count)
|
||||
else:
|
||||
t = self.params.get("LastUpdateTime")
|
||||
if t is not None:
|
||||
last_update = t
|
||||
last_uptime_onroad = self.params.get("LastUpdateUptimeOnroad") or last_uptime_onroad
|
||||
last_route_count = self.params.get("LastUpdateRouteCount") or last_route_count
|
||||
|
||||
if exception is None:
|
||||
self.params.remove("LastUpdateException")
|
||||
@@ -315,8 +322,8 @@ class Updater:
|
||||
for alert in ("Offroad_UpdateFailed", "Offroad_ConnectivityNeeded", "Offroad_ConnectivityNeededPrompt"):
|
||||
set_offroad_alert(alert, False)
|
||||
|
||||
now = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
|
||||
dt = now - last_update
|
||||
dt_uptime_onroad = (self.params.get("UptimeOnroad", return_default=True) - last_uptime_onroad) / (60*60)
|
||||
dt_route_count = self.params.get("RouteCount", return_default=True) - last_route_count
|
||||
build_metadata = get_build_metadata()
|
||||
if failed_count > 15 and exception is not None and self.has_internet:
|
||||
if build_metadata.tested_channel:
|
||||
@@ -325,11 +332,11 @@ class Updater:
|
||||
extra_text = exception
|
||||
set_offroad_alert("Offroad_UpdateFailed", True, extra_text=extra_text)
|
||||
elif failed_count > 0:
|
||||
if dt.days > DAYS_NO_CONNECTIVITY_MAX:
|
||||
if dt_uptime_onroad > HOURS_NO_CONNECTIVITY_MAX and dt_route_count > ROUTES_NO_CONNECTIVITY_MAX:
|
||||
set_offroad_alert("Offroad_ConnectivityNeeded", True)
|
||||
elif dt.days > DAYS_NO_CONNECTIVITY_PROMPT:
|
||||
remaining = max(DAYS_NO_CONNECTIVITY_MAX - dt.days, 1)
|
||||
set_offroad_alert("Offroad_ConnectivityNeededPrompt", True, extra_text=f"{remaining} day{'' if remaining == 1 else 's'}.")
|
||||
elif dt_uptime_onroad > HOURS_NO_CONNECTIVITY_PROMPT and dt_route_count > ROUTES_NO_CONNECTIVITY_PROMPT:
|
||||
remaining = max(HOURS_NO_CONNECTIVITY_MAX - dt_uptime_onroad, 1)
|
||||
set_offroad_alert("Offroad_ConnectivityNeededPrompt", True, extra_text=f"{remaining} hour{'' if remaining == 1 else 's'}.")
|
||||
|
||||
def check_for_update(self) -> None:
|
||||
cloudlog.info("checking for updates")
|
||||
|
||||
Reference in New Issue
Block a user