Track FrogPilot drives

Added tracking to track the total drives, distance, and time the user has driven on FrogPilot.
This commit is contained in:
FrogAi
2024-03-27 07:03:45 -07:00
parent 1e0cd266af
commit d74145f345
5 changed files with 67 additions and 17 deletions
+3
View File
@@ -286,6 +286,9 @@ std::unordered_map<std::string, uint32_t> keys = {
{"ForceFingerprint", PERSISTENT},
{"ForceMPHDashboard", PERSISTENT},
{"FPSCounter", PERSISTENT},
{"FrogPilotDrives", PERSISTENT},
{"FrogPilotKilometers", PERSISTENT},
{"FrogPilotMinutes", PERSISTENT},
{"FrogPilotTogglesUpdated", PERSISTENT},
{"FrogsGoMoo", PERSISTENT},
{"FrogsGoMooTune", PERSISTENT},
+33
View File
@@ -191,6 +191,7 @@ class Controls:
self.always_on_lateral = self.params.get_bool("AlwaysOnLateral")
self.always_on_lateral_main = self.always_on_lateral and self.params.get_bool("AlwaysOnLateralMain")
self.drive_added = False
self.fcw_random_event_triggered = False
self.holiday_theme_alerted = False
self.onroad_distance_pressed = False
@@ -199,6 +200,8 @@ class Controls:
self.random_event_triggered = False
self.speed_check = False
self.drive_distance = 0
self.drive_time = 0
self.max_acceleration = 0
self.previous_lead_distance = 0
self.previous_speed_limit = 0
@@ -1074,6 +1077,36 @@ class Controls:
if self.CP.openpilotLongitudinalControl and self.frogpilot_variables.conditional_experimental_mode:
self.experimental_mode = self.sm['frogpilotPlan'].conditionalExperimental
self.drive_distance += CS.vEgo * DT_CTRL
self.drive_time += DT_CTRL
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_nonblocking("FrogPilotKilometers", new_total_distance)
self.params_storage.put_float_nonblocking("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_nonblocking("FrogPilotMinutes", new_total_time)
self.params_storage.put_float_nonblocking("FrogPilotMinutes", new_total_time)
self.drive_time = 0
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_nonblocking("FrogPilotDrives", new_total_drives)
self.params_storage.put_int_nonblocking("FrogPilotDrives", new_total_drives)
self.drive_added = True
if any(be.pressed and be.type == FrogPilotButtonType.lkas for be in CS.buttonEvents) and self.experimental_mode_via_lkas:
if self.frogpilot_variables.conditional_experimental_mode:
conditional_status = self.params_memory.get_int("CEStatus")
+3
View File
@@ -153,6 +153,9 @@ def manager_init(frogpilot_functions) -> None:
("ForceFingerprint", "0"),
("ForceMPHDashboard", "0"),
("FPSCounter", "0"),
("FrogPilotDrives", "0"),
("FrogPilotKilometers", "0"),
("FrogPilotMinutes", "0"),
("FrogsGoMooTune", "1"),
("FullMap", "0"),
("GasRegenCmd", "0"),
+24 -16
View File
@@ -5,7 +5,6 @@
#include <QJsonObject>
#include <QVBoxLayout>
#include "common/params.h"
#include "selfdrive/ui/qt/request_repeater.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) {
metric_ = Params().getBool("IsMetric");
metric_ = params.getBool("IsMetric");
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;
grid_layout->setVerticalSpacing(10);
grid_layout->setContentsMargins(0, 10, 0, 10);
int row = 0;
grid_layout->addWidget(newLabel(title, "title"), row++, 0, 1, 3);
grid_layout->addItem(new QSpacerItem(0, 50), row++, 0, 1, 1);
grid_layout->addWidget(newLabel(title, FrogPilot ? "frogpilot_title" : "title"), row++, 0, 1, 3);
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.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);
main_layout->addLayout(grid_layout);
main_layout->addStretch(1);
};
add_stats_layouts(tr("ALL TIME"), all_);
main_layout->addStretch();
add_stats_layouts(tr("PAST WEEK"), week_);
add_stats_layouts(tr("FROGPILOT"), frogPilot_, true);
if (auto dongleId = getDongleId()) {
QString url = CommaApi::BASE_URL + "/v1.1/devices/" + *dongleId + "/stats";
@@ -57,13 +57,25 @@ DriveStats::DriveStats(QWidget* parent) : QFrame(parent) {
border-radius: 10px;
}
QLabel[type="title"] { font-size: 51px; font-weight: 500; }
QLabel[type="number"] { font-size: 78px; font-weight: 500; }
QLabel[type="unit"] { font-size: 51px; font-weight: 300; color: #A0A0A0; }
QLabel[type="title"] { font-size: 50px; font-weight: 500; }
QLabel[type="frogpilot_title"] { font-size: 50px; font-weight: 500; color: #178643; }
QLabel[type="number"] { font-size: 65px; font-weight: 400; }
QLabel[type="unit"] { font-size: 50px; font-weight: 300; color: #A0A0A0; }
)");
}
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) {
labels.routes->setText(QString::number((int)obj["routes"].toDouble()));
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)));
};
QJsonObject json = stats_.object();
update(json["all"].toObject(), all_);
update(json["week"].toObject(), week_);
}
@@ -89,9 +100,6 @@ void DriveStats::parseResponse(const QString& response, bool success) {
}
void DriveStats::showEvent(QShowEvent* event) {
bool metric = Params().getBool("IsMetric");
if (metric_ != metric) {
metric_ = metric;
updateStats();
}
metric_ = params.getBool("IsMetric");
updateStats();
}
+4 -1
View File
@@ -3,6 +3,8 @@
#include <QJsonDocument>
#include <QLabel>
#include "common/params.h"
class DriveStats : public QFrame {
Q_OBJECT
@@ -15,10 +17,11 @@ private:
inline QString getDistanceUnit() const { return metric_ ? tr("KM") : tr("Miles"); }
bool metric_;
Params params;
QJsonDocument stats_;
struct StatsLabels {
QLabel *routes, *distance, *distance_unit, *hours;
} all_, week_;
} all_, week_, frogPilot_;
private slots:
void parseResponse(const QString &response, bool success);