mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 15:23:57 +08:00
UI: remove drive stats (#30183)
* UI: remove drive stats
* little more
* vanish
old-commit-hash: f80db10720
This commit is contained in:
@@ -88,7 +88,6 @@ private:
|
||||
std::unordered_map<std::string, uint32_t> keys = {
|
||||
{"AccessToken", CLEAR_ON_MANAGER_START | DONT_LOG},
|
||||
{"ApiCache_Device", PERSISTENT},
|
||||
{"ApiCache_DriveStats", PERSISTENT},
|
||||
{"ApiCache_NavDestinations", PERSISTENT},
|
||||
{"AssistNowToken", PERSISTENT},
|
||||
{"AthenadPid", PERSISTENT},
|
||||
|
||||
@@ -20,7 +20,7 @@ if arch == "Darwin":
|
||||
qt_env['FRAMEWORKS'] += ['OpenCL']
|
||||
|
||||
qt_util = qt_env.Library("qt_util", ["#selfdrive/ui/qt/api.cc", "#selfdrive/ui/qt/util.cc"], LIBS=base_libs)
|
||||
widgets_src = ["ui.cc", "qt/widgets/input.cc", "qt/widgets/drive_stats.cc", "qt/widgets/wifi.cc",
|
||||
widgets_src = ["ui.cc", "qt/widgets/input.cc", "qt/widgets/wifi.cc",
|
||||
"qt/widgets/ssh_keys.cc", "qt/widgets/toggle.cc", "qt/widgets/controls.cc",
|
||||
"qt/widgets/offroad_alerts.cc", "qt/widgets/prime.cc", "qt/widgets/keyboard.cc",
|
||||
"qt/widgets/scrollview.cc", "qt/widgets/cameraview.cc", "#third_party/qrcode/QrCode.cc",
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
#ifdef ENABLE_MAPS
|
||||
#include "selfdrive/ui/qt/maps/map_settings.h"
|
||||
#else
|
||||
#include "selfdrive/ui/qt/widgets/drive_stats.h"
|
||||
#endif
|
||||
|
||||
// HomeWindow: the container for the offroad and onroad UIs
|
||||
@@ -152,7 +150,7 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) {
|
||||
#ifdef ENABLE_MAPS
|
||||
left_widget->addWidget(new MapSettings);
|
||||
#else
|
||||
left_widget->addWidget(new DriveStats);
|
||||
left_widget->addWidget(new QWidget);
|
||||
#endif
|
||||
left_widget->addWidget(new PrimeAdWidget);
|
||||
left_widget->setStyleSheet("border-radius: 10px;");
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>مراجعة</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>القيادة</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>ساعات</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>كامل الوقت</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>الأسبوع الماضي</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>كم</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>ميل</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>Überprüfen</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>Fahrten</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>Stunden</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>Gesamtzeit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>Letzte Woche</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>KM</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>Meilen</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>Désengager pour éteindre</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>Trajets</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>Heures</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>DEPUIS TOUJOURS</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>CETTE SEMAINE</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>KM</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>Miles</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>確認</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>運転履歴</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>時間</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>累計</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>先週</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>マイル</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>다시보기</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>주행</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>시간</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>전체</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>지난 주</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>마일</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>Revisar</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>Dirigidas</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>Horas</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>TOTAL</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>SEMANA PASSADA</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>KM</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>Milhas</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>ทบทวน</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>การขับขี่</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>ชั่วโมง</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>ทั้งหมด</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>สัปดาห์ที่ผ่านมา</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>กิโลเมตร</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>ไมล์</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>Sürücüler</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>Saat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>TÜM ZAMANLAR</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>GEÇEN HAFTA</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>KM</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>Mil</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>预览</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>旅程数</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>小时</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>全部</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>过去一周</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>公里</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>英里</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
@@ -274,33 +274,6 @@
|
||||
<translation>回顧</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriveStats</name>
|
||||
<message>
|
||||
<source>Drives</source>
|
||||
<translation>旅程</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hours</source>
|
||||
<translation>小時</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ALL TIME</source>
|
||||
<translation>總共</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>PAST WEEK</source>
|
||||
<translation>上週</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>KM</source>
|
||||
<translation>公里</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Miles</source>
|
||||
<translation>英里</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DriverViewScene</name>
|
||||
<message>
|
||||
|
||||
Reference in New Issue
Block a user