commit
a994e99c12
18 changed files with 89 additions and 399 deletions
@ -0,0 +1,48 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import unittest |
||||
|
||||
from parameterized import parameterized |
||||
|
||||
from openpilot.selfdrive.test.process_replay.regen import regen_segment |
||||
from openpilot.selfdrive.test.process_replay.process_replay import check_openpilot_enabled, CONFIGS |
||||
from openpilot.selfdrive.test.openpilotci import get_url |
||||
from openpilot.tools.lib.logreader import LogReader |
||||
from openpilot.tools.lib.framereader import FrameReader |
||||
|
||||
EXCLUDED_PROCESSES = {"dmonitoringd", "dmonitoringmodeld"} |
||||
TESTED_SEGMENTS = [ |
||||
("PRIUS_C2", "0982d79ebb0de295|2021-01-04--17-13-21--13"), # TOYOTA PRIUS 2017: NEO, pandaStateDEPRECATED, no peripheralState, sensorEventsDEPRECATED |
||||
# Enable these once regen on CI becomes faster or use them for different tests running controlsd in isolation |
||||
# ("MAZDA_C3", "bd6a637565e91581|2021-10-30--15-14-53--4"), # MAZDA.CX9_2021: TICI, incomplete managerState |
||||
# ("FORD_C3", "54827bf84c38b14f|2023-01-26--21-59-07--4"), # FORD.BRONCO_SPORT_MK1: TICI |
||||
] |
||||
|
||||
|
||||
def ci_setup_data_readers(route, sidx): |
||||
lr = LogReader(get_url(route, sidx, "rlog")) |
||||
# dm disabled |
||||
frs = { |
||||
'roadCameraState': FrameReader(get_url(route, sidx, "fcamera")), |
||||
} |
||||
if next((True for m in lr if m.which() == "wideRoadCameraState"), False): |
||||
frs["wideRoadCameraState"] = FrameReader(get_url(route, sidx, "ecamera")) |
||||
|
||||
return lr, frs |
||||
|
||||
|
||||
class TestRegen(unittest.TestCase): |
||||
@parameterized.expand(TESTED_SEGMENTS) |
||||
def test_engaged(self, case_name, segment): |
||||
tested_procs = [p for p in CONFIGS if p.proc_name not in EXCLUDED_PROCESSES] |
||||
|
||||
route, sidx = segment.rsplit("--", 1) |
||||
lr, frs = ci_setup_data_readers(route, sidx) |
||||
output_logs = regen_segment(lr, frs, processes=tested_procs, disable_tqdm=True) |
||||
|
||||
engaged = check_openpilot_enabled(output_logs) |
||||
self.assertTrue(engaged, f"openpilot not engaged in {case_name}") |
||||
|
||||
|
||||
if __name__=='__main__': |
||||
unittest.main() |
||||
@ -1,97 +0,0 @@ |
||||
#include "selfdrive/ui/qt/widgets/drive_stats.h" |
||||
|
||||
#include <QDebug> |
||||
#include <QGridLayout> |
||||
#include <QJsonObject> |
||||
#include <QVBoxLayout> |
||||
|
||||
#include "common/params.h" |
||||
#include "selfdrive/ui/qt/request_repeater.h" |
||||
#include "selfdrive/ui/qt/util.h" |
||||
|
||||
static QLabel* newLabel(const QString& text, const QString &type) { |
||||
QLabel* label = new QLabel(text); |
||||
label->setProperty("type", type); |
||||
return label; |
||||
} |
||||
|
||||
DriveStats::DriveStats(QWidget* parent) : QFrame(parent) { |
||||
metric_ = Params().getBool("IsMetric"); |
||||
|
||||
QVBoxLayout* main_layout = new QVBoxLayout(this); |
||||
main_layout->setContentsMargins(50, 50, 50, 60); |
||||
|
||||
auto add_stats_layouts = [=](const QString &title, StatsLabels& labels) { |
||||
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(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.hours = newLabel("0", "number"), row, 2, Qt::AlignLeft); |
||||
|
||||
grid_layout->addWidget(newLabel((tr("Drives")), "unit"), row + 1, 0, Qt::AlignLeft); |
||||
grid_layout->addWidget(labels.distance_unit = newLabel(getDistanceUnit(), "unit"), row + 1, 1, Qt::AlignLeft); |
||||
grid_layout->addWidget(newLabel(tr("Hours"), "unit"), row + 1, 2, Qt::AlignLeft); |
||||
|
||||
main_layout->addLayout(grid_layout); |
||||
}; |
||||
|
||||
add_stats_layouts(tr("ALL TIME"), all_); |
||||
main_layout->addStretch(); |
||||
add_stats_layouts(tr("PAST WEEK"), week_); |
||||
|
||||
if (auto dongleId = getDongleId()) { |
||||
QString url = CommaApi::BASE_URL + "/v1.1/devices/" + *dongleId + "/stats"; |
||||
RequestRepeater* repeater = new RequestRepeater(this, url, "ApiCache_DriveStats", 30); |
||||
QObject::connect(repeater, &RequestRepeater::requestDone, this, &DriveStats::parseResponse); |
||||
} |
||||
|
||||
setStyleSheet(R"( |
||||
DriveStats { |
||||
background-color: #333333; |
||||
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; } |
||||
)"); |
||||
} |
||||
|
||||
void DriveStats::updateStats() { |
||||
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)))); |
||||
labels.distance_unit->setText(getDistanceUnit()); |
||||
labels.hours->setText(QString::number((int)(obj["minutes"].toDouble() / 60))); |
||||
}; |
||||
|
||||
QJsonObject json = stats_.object(); |
||||
update(json["all"].toObject(), all_); |
||||
update(json["week"].toObject(), week_); |
||||
} |
||||
|
||||
void DriveStats::parseResponse(const QString& response, bool success) { |
||||
if (!success) return; |
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(response.trimmed().toUtf8()); |
||||
if (doc.isNull()) { |
||||
qDebug() << "JSON Parse failed on getting past drives statistics"; |
||||
return; |
||||
} |
||||
stats_ = doc; |
||||
updateStats(); |
||||
} |
||||
|
||||
void DriveStats::showEvent(QShowEvent* event) { |
||||
bool metric = Params().getBool("IsMetric"); |
||||
if (metric_ != metric) { |
||||
metric_ = metric; |
||||
updateStats(); |
||||
} |
||||
} |
||||
@ -1,25 +0,0 @@ |
||||
#pragma once |
||||
|
||||
#include <QJsonDocument> |
||||
#include <QLabel> |
||||
|
||||
class DriveStats : public QFrame { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit DriveStats(QWidget* parent = 0); |
||||
|
||||
private: |
||||
void showEvent(QShowEvent *event) override; |
||||
void updateStats(); |
||||
inline QString getDistanceUnit() const { return metric_ ? tr("KM") : tr("Miles"); } |
||||
|
||||
bool metric_; |
||||
QJsonDocument stats_; |
||||
struct StatsLabels { |
||||
QLabel *routes, *distance, *distance_unit, *hours; |
||||
} all_, week_; |
||||
|
||||
private slots: |
||||
void parseResponse(const QString &response, bool success); |
||||
}; |
||||
Loading…
Reference in new issue