Track FrogPilot drives

This commit is contained in:
FrogAi
2024-03-01 09:35:33 -07:00
parent 1c58cd07ec
commit 3e5c66abeb
6 changed files with 75 additions and 22 deletions

View File

@@ -278,6 +278,9 @@ std::unordered_map<std::string, uint32_t> keys = {
{"ForceFingerprint", PERSISTENT}, {"ForceFingerprint", PERSISTENT},
{"ForceMPHDashboard", PERSISTENT}, {"ForceMPHDashboard", PERSISTENT},
{"FPSCounter", PERSISTENT}, {"FPSCounter", PERSISTENT},
{"FrogPilotDrives", PERSISTENT},
{"FrogPilotKilometers", PERSISTENT},
{"FrogPilotMinutes", PERSISTENT},
{"FrogPilotTogglesUpdated", PERSISTENT}, {"FrogPilotTogglesUpdated", PERSISTENT},
{"FrogsGoMoo", PERSISTENT}, {"FrogsGoMoo", PERSISTENT},
{"FrogsGoMooTune", PERSISTENT}, {"FrogsGoMooTune", PERSISTENT},

View File

@@ -217,7 +217,7 @@ def is_connected_to_internet(timeout=5):
def crash_log(params, candidate): def crash_log(params, candidate):
serial_id = params.get("HardwareSerial", encoding='utf-8') serial_id = params.get("HardwareSerial", encoding='utf-8')
control_keys, vehicle_keys, visual_keys = [ control_keys, vehicle_keys, visual_keys, tracking_keys = [
"AdjustablePersonalities", "PersonalitiesViaWheel", "PersonalitiesViaScreen", "AlwaysOnLateral", "AlwaysOnLateralMain", "AdjustablePersonalities", "PersonalitiesViaWheel", "PersonalitiesViaScreen", "AlwaysOnLateral", "AlwaysOnLateralMain",
"ConditionalExperimental", "CESpeed", "CESpeedLead", "CECurves", "CECurvesLead", "CENavigation", "CENavigationIntersections", "ConditionalExperimental", "CESpeed", "CESpeedLead", "CECurves", "CECurvesLead", "CENavigation", "CENavigationIntersections",
"CENavigationLead", "CENavigationTurns", "CESlowerLead", "CEStopLights", "CEStopLightsLead", "CESignal", "CustomPersonalities", "CENavigationLead", "CENavigationTurns", "CESlowerLead", "CEStopLights", "CEStopLightsLead", "CESignal", "CustomPersonalities",
@@ -241,17 +241,19 @@ def crash_log(params, candidate):
"ModelUI", "DynamicPathWidth", "LaneLinesWidth", "PathEdgeWidth", "PathWidth", "RoadEdgesWidth", "UnlimitedLength", "QOLVisuals", "DriveStats", "ModelUI", "DynamicPathWidth", "LaneLinesWidth", "PathEdgeWidth", "PathWidth", "RoadEdgesWidth", "UnlimitedLength", "QOLVisuals", "DriveStats",
"FullMap", "HideSpeed", "HideSpeedUI", "ShowSLCOffset", "SpeedLimitChangedAlert", "WheelSpeed", "RandomEvents", "ScreenBrightness", "WheelIcon", "FullMap", "HideSpeed", "HideSpeedUI", "ShowSLCOffset", "SpeedLimitChangedAlert", "WheelSpeed", "RandomEvents", "ScreenBrightness", "WheelIcon",
"RotatingWheel", "NumericalTemp", "Fahrenheit", "ShowCPU", "ShowGPU", "ShowIP", "ShowMemoryUsage", "ShowStorageLeft", "ShowStorageUsed", "Sidebar" "RotatingWheel", "NumericalTemp", "Fahrenheit", "ShowCPU", "ShowGPU", "ShowIP", "ShowMemoryUsage", "ShowStorageLeft", "ShowStorageUsed", "Sidebar"
], [
"FrogPilotDrives", "FrogPilotKilometers", "FrogPilotMinutes"
] ]
control_params, vehicle_params, visual_params = map(lambda keys: get_frogpilot_params(params, keys), [control_keys, vehicle_keys, visual_keys]) control_params, vehicle_params, visual_params, tracking_params = map(lambda keys: get_frogpilot_params(params, keys), [control_keys, vehicle_keys, visual_keys, tracking_keys])
control_values, vehicle_values, visual_values = map(format_params, [control_params, vehicle_params, visual_params]) control_values, vehicle_values, visual_values, tracking_values = map(format_params, [control_params, vehicle_params, visual_params, tracking_params])
control_chunks, vehicle_chunks, visual_chunks = map(lambda data: chunk_data(data, 50), [control_values, vehicle_values, visual_values]) control_chunks, vehicle_chunks, visual_chunks, tracking_chunks = map(lambda data: chunk_data(data, 50), [control_values, vehicle_values, visual_values, tracking_values])
while not is_connected_to_internet(): while not is_connected_to_internet():
time.sleep(60) time.sleep(60)
with sentry_sdk.configure_scope() as scope: with sentry_sdk.configure_scope() as scope:
for chunks, label in zip([control_chunks, vehicle_chunks, visual_chunks], ["FrogPilot Controls", "FrogPilot Vehicles", "FrogPilot Visuals"]): for chunks, label in zip([control_chunks, vehicle_chunks, visual_chunks, tracking_chunks], ["FrogPilot Controls", "FrogPilot Vehicles", "FrogPilot Visuals", "FrogPilot Tracking"]):
set_sentry_scope(scope, chunks, label) set_sentry_scope(scope, chunks, label)
sentry.capture_warning(f"Fingerprinted: {candidate}", serial_id) sentry.capture_warning(f"Fingerprinted: {candidate}", serial_id)

View File

@@ -177,9 +177,11 @@ class Controls:
# FrogPilot variables # FrogPilot variables
self.params = Params() self.params = Params()
self.params_memory = Params("/dev/shm/params") self.params_memory = Params("/dev/shm/params")
self.params_storage = Params("/persist/comma/params")
self.frogpilot_variables = SimpleNamespace() self.frogpilot_variables = SimpleNamespace()
self.drive_added = False
self.driving_gear = False self.driving_gear = False
self.fcw_random_event_triggered = False self.fcw_random_event_triggered = False
self.holiday_theme_alerted = False self.holiday_theme_alerted = False
@@ -189,6 +191,8 @@ class Controls:
self.random_event_triggered = False self.random_event_triggered = False
self.stopped_for_light_previously = False self.stopped_for_light_previously = False
self.drive_distance = 0
self.drive_time = 0
self.max_acceleration = 0 self.max_acceleration = 0
self.previous_lead_distance = 0 self.previous_lead_distance = 0
self.previous_speed_limit = SpeedLimitController.desired_speed_limit self.previous_speed_limit = SpeedLimitController.desired_speed_limit
@@ -574,6 +578,39 @@ class Controls:
if self.sm['modelV2'].frameDropPerc > 20: if self.sm['modelV2'].frameDropPerc > 20:
self.events.add(EventName.modeldLagging) self.events.add(EventName.modeldLagging)
# Store the total distance traveled
self.drive_distance += CS.vEgo * DT_CTRL
self.drive_time += DT_CTRL
# Store the current drive's data after a minute when at a standstill - Need to do this live for comma powerless users
if self.drive_time > 60 and CS.standstill:
current_total_distance = self.params.get_float("FrogPilotKilometers")
distance_to_add = self.drive_distance / 1000
new_total_distance = current_total_distance + distance_to_add
self.params.put_float("FrogPilotKilometers", new_total_distance)
self.params_storage.put_float("FrogPilotKilometers", new_total_distance)
self.drive_distance = 0
current_total_time = self.params.get_float("FrogPilotMinutes")
time_to_add = self.drive_time / 60
new_total_time = current_total_time + time_to_add
self.params.put_float("FrogPilotMinutes", new_total_time)
self.params_storage.put_float("FrogPilotMinutes", new_total_time)
self.drive_time = 0
# Only count the drive if it lasted longer than 5 minutes
if self.sm.frame * DT_CTRL > 60 * 5 and not self.drive_added:
new_total_drives = self.params.get_int("FrogPilotDrives") + 1
self.params.put_int("FrogPilotDrives", new_total_drives)
self.params_storage.put_int("FrogPilotDrives", new_total_drives)
self.drive_added = True
# Acceleration Random Event alerts # Acceleration Random Event alerts
if self.random_events: if self.random_events:
acceleration = CS.aEgo acceleration = CS.aEgo

0
selfdrive/manager/manager.py Normal file → Executable file
View File

View File

@@ -5,7 +5,6 @@
#include <QJsonObject> #include <QJsonObject>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "common/params.h"
#include "selfdrive/ui/qt/request_repeater.h" #include "selfdrive/ui/qt/request_repeater.h"
#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/util.h"
@@ -16,19 +15,19 @@ static QLabel* newLabel(const QString& text, const QString &type) {
} }
DriveStats::DriveStats(QWidget* parent) : QFrame(parent) { DriveStats::DriveStats(QWidget* parent) : QFrame(parent) {
metric_ = Params().getBool("IsMetric"); metric_ = params.getBool("IsMetric");
QVBoxLayout* main_layout = new QVBoxLayout(this); QVBoxLayout* main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(50, 50, 50, 60); main_layout->setContentsMargins(50, 25, 50, 20);
auto add_stats_layouts = [=](const QString &title, StatsLabels& labels) { auto add_stats_layouts = [=](const QString &title, StatsLabels& labels, bool FrogPilot=false) {
QGridLayout* grid_layout = new QGridLayout; QGridLayout* grid_layout = new QGridLayout;
grid_layout->setVerticalSpacing(10); grid_layout->setVerticalSpacing(10);
grid_layout->setContentsMargins(0, 10, 0, 10); grid_layout->setContentsMargins(0, 10, 0, 10);
int row = 0; int row = 0;
grid_layout->addWidget(newLabel(title, "title"), row++, 0, 1, 3); grid_layout->addWidget(newLabel(title, FrogPilot ? "frogpilot_title" : "title"), row++, 0, 1, 3);
grid_layout->addItem(new QSpacerItem(0, 50), row++, 0, 1, 1); grid_layout->addItem(new QSpacerItem(0, 10), row++, 0, 1, 1);
grid_layout->addWidget(labels.routes = newLabel("0", "number"), row, 0, Qt::AlignLeft); grid_layout->addWidget(labels.routes = newLabel("0", "number"), row, 0, Qt::AlignLeft);
grid_layout->addWidget(labels.distance = newLabel("0", "number"), row, 1, Qt::AlignLeft); grid_layout->addWidget(labels.distance = newLabel("0", "number"), row, 1, Qt::AlignLeft);
@@ -39,11 +38,12 @@ DriveStats::DriveStats(QWidget* parent) : QFrame(parent) {
grid_layout->addWidget(newLabel(tr("Hours"), "unit"), row + 1, 2, Qt::AlignLeft); grid_layout->addWidget(newLabel(tr("Hours"), "unit"), row + 1, 2, Qt::AlignLeft);
main_layout->addLayout(grid_layout); main_layout->addLayout(grid_layout);
main_layout->addStretch(1);
}; };
add_stats_layouts(tr("ALL TIME"), all_); add_stats_layouts(tr("ALL TIME"), all_);
main_layout->addStretch();
add_stats_layouts(tr("PAST WEEK"), week_); add_stats_layouts(tr("PAST WEEK"), week_);
add_stats_layouts(tr("FROGPILOT"), frogPilot_, true);
if (auto dongleId = getDongleId()) { if (auto dongleId = getDongleId()) {
QString url = CommaApi::BASE_URL + "/v1.1/devices/" + *dongleId + "/stats"; QString url = CommaApi::BASE_URL + "/v1.1/devices/" + *dongleId + "/stats";
@@ -57,13 +57,25 @@ DriveStats::DriveStats(QWidget* parent) : QFrame(parent) {
border-radius: 10px; border-radius: 10px;
} }
QLabel[type="title"] { font-size: 51px; font-weight: 500; } QLabel[type="title"] { font-size: 50px; font-weight: 500; }
QLabel[type="number"] { font-size: 78px; font-weight: 500; } QLabel[type="frogpilot_title"] { font-size: 50px; font-weight: 500; color: #178643; }
QLabel[type="unit"] { font-size: 51px; font-weight: 300; color: #A0A0A0; } QLabel[type="number"] { font-size: 65px; font-weight: 400; }
QLabel[type="unit"] { font-size: 50px; font-weight: 300; color: #A0A0A0; }
)"); )");
} }
void DriveStats::updateStats() { void DriveStats::updateStats() {
QJsonObject json = stats_.object();
auto updateFrogPilot = [this](const QJsonObject& obj, StatsLabels& labels) {
labels.routes->setText(QString::number(params.getInt("FrogPilotDrives")));
labels.distance->setText(QString::number(int(params.getFloat("FrogPilotKilometers") * (metric_ ? 1 : KM_TO_MILE))));
labels.distance_unit->setText(getDistanceUnit());
labels.hours->setText(QString::number(int(params.getFloat("FrogPilotMinutes") / 60)));
};
updateFrogPilot(json["frogpilot"].toObject(), frogPilot_);
auto update = [=](const QJsonObject& obj, StatsLabels& labels) { auto update = [=](const QJsonObject& obj, StatsLabels& labels) {
labels.routes->setText(QString::number((int)obj["routes"].toDouble())); labels.routes->setText(QString::number((int)obj["routes"].toDouble()));
labels.distance->setText(QString::number(int(obj["distance"].toDouble() * (metric_ ? MILE_TO_KM : 1)))); labels.distance->setText(QString::number(int(obj["distance"].toDouble() * (metric_ ? MILE_TO_KM : 1))));
@@ -71,7 +83,6 @@ void DriveStats::updateStats() {
labels.hours->setText(QString::number((int)(obj["minutes"].toDouble() / 60))); labels.hours->setText(QString::number((int)(obj["minutes"].toDouble() / 60)));
}; };
QJsonObject json = stats_.object();
update(json["all"].toObject(), all_); update(json["all"].toObject(), all_);
update(json["week"].toObject(), week_); update(json["week"].toObject(), week_);
} }
@@ -89,9 +100,6 @@ void DriveStats::parseResponse(const QString& response, bool success) {
} }
void DriveStats::showEvent(QShowEvent* event) { void DriveStats::showEvent(QShowEvent* event) {
bool metric = Params().getBool("IsMetric"); metric_ = params.getBool("IsMetric");
if (metric_ != metric) { updateStats();
metric_ = metric;
updateStats();
}
} }

View File

@@ -3,6 +3,8 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QLabel> #include <QLabel>
#include "common/params.h"
class DriveStats : public QFrame { class DriveStats : public QFrame {
Q_OBJECT Q_OBJECT
@@ -15,10 +17,11 @@ private:
inline QString getDistanceUnit() const { return metric_ ? tr("KM") : tr("Miles"); } inline QString getDistanceUnit() const { return metric_ ? tr("KM") : tr("Miles"); }
bool metric_; bool metric_;
Params params;
QJsonDocument stats_; QJsonDocument stats_;
struct StatsLabels { struct StatsLabels {
QLabel *routes, *distance, *distance_unit, *hours; QLabel *routes, *distance, *distance_unit, *hours;
} all_, week_; } all_, week_, frogPilot_;
private slots: private slots:
void parseResponse(const QString &response, bool success); void parseResponse(const QString &response, bool success);