From 1cae066cda8d72bd04fa694805ae900d0a21d5ec Mon Sep 17 00:00:00 2001 From: Ayman Saleh <30412615+ayman-saleh@users.noreply.github.com> Date: Sun, 1 Mar 2020 22:06:33 -0800 Subject: [PATCH] NUI comma api intergration (#1186) * Prototyping comma api call * Adding nui command * Fixing hard coded vals * Adding generalized nui changes * Added both public and private api support * Removing debug statement * Chaning private api tag to use env variables * FrameReader change for string parsing old-commit-hash: 763493e98887d207cd6632e13b0a7a31573ad41d --- tools/clib/FrameReader.cpp | 2 +- tools/nui/.gitignore | 3 +- tools/nui/FileReader.cpp | 5 +-- tools/nui/get_files_comma_api.py | 14 ++++++++ tools/nui/main.cpp | 59 ++++++++++++++++++++++++++++---- tools/nui/nui | 12 +++++++ tools/nui/nui.pro | 4 +-- 7 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 tools/nui/get_files_comma_api.py create mode 100755 tools/nui/nui diff --git a/tools/clib/FrameReader.cpp b/tools/clib/FrameReader.cpp index 91d31deec2..8048dbffdc 100644 --- a/tools/clib/FrameReader.cpp +++ b/tools/clib/FrameReader.cpp @@ -46,7 +46,7 @@ FrameReader::FrameReader(const char *fn) { avformat_network_init(); av_register_all(); - snprintf(url, sizeof(url)-1, "http://data.comma.life/%s", fn); + snprintf(url, sizeof(url)-1,"%s",fn); t = new std::thread([&]() { this->loaderThread(); }); } diff --git a/tools/nui/.gitignore b/tools/nui/.gitignore index 634d1cc12c..9341b87ec5 100644 --- a/tools/nui/.gitignore +++ b/tools/nui/.gitignore @@ -1,8 +1,9 @@ Makefile .*.swp *.o -nui +_nui moc_* .qmake.stash nui.app/* +routes.json diff --git a/tools/nui/FileReader.cpp b/tools/nui/FileReader.cpp index 7c207dff83..d52305b10e 100644 --- a/tools/nui/FileReader.cpp +++ b/tools/nui/FileReader.cpp @@ -8,8 +8,9 @@ FileReader::FileReader(const QString& file_) : file(file_) { void FileReader::process() { timer.start(); - // TODO: Support reading files from the API - startRequest(QUrl("http://data.comma.life/"+file)); + QString str = file.simplified(); + str.replace(" ", ""); + startRequest(QUrl(str)); } void FileReader::startRequest(const QUrl &url) { diff --git a/tools/nui/get_files_comma_api.py b/tools/nui/get_files_comma_api.py new file mode 100644 index 0000000000..83fb73561f --- /dev/null +++ b/tools/nui/get_files_comma_api.py @@ -0,0 +1,14 @@ +import json +import os +import sys + +from tools.lib.route import Route + +route_name = sys.argv[1] +routes = Route(route_name) +data_dump = { + "camera":routes.camera_paths(), + "logs":routes.log_paths() +} + +json.dump(data_dump, open("routes.json", "w")) \ No newline at end of file diff --git a/tools/nui/main.cpp b/tools/nui/main.cpp index 4bae08ed46..2f3d18c0ff 100644 --- a/tools/nui/main.cpp +++ b/tools/nui/main.cpp @@ -9,6 +9,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "FileReader.hpp" #include "Unlogger.hpp" @@ -16,8 +22,11 @@ class Window : public QWidget { public: - Window(QString route_, int seek); + Window(QString route_, int seek, int use_api); bool addSegment(int i); + QJsonArray camera_paths; + QJsonArray log_paths; + int use_api; protected: void keyPressEvent(QKeyEvent *event) override; void mousePressEvent(QMouseEvent *event) override; @@ -35,6 +44,7 @@ class Window : public QWidget { QMap lrs; QMap frs; + // cache the bar QPixmap *px = NULL; @@ -43,7 +53,7 @@ class Window : public QWidget { QLineEdit *timeLE; }; -Window::Window(QString route_, int seek) : route(route_) { +Window::Window(QString route_, int seek, int use_api_) : route(route_), use_api(use_api_) { timeLE = new QLineEdit(this); timeLE->setPlaceholderText("Placeholder Text"); timeLE->move(50, 650); @@ -55,6 +65,22 @@ Window::Window(QString route_, int seek) : route(route_) { connect(unlogger, SIGNAL (elapsed()), this, SLOT (update())); thread->start(); + if (use_api != 0){ + QString settings; + QFile file; + file.setFileName("routes.json"); + file.open(QIODevice::ReadOnly | QIODevice::Text); + settings = file.readAll(); + file.close(); + + QJsonDocument sd = QJsonDocument::fromJson(settings.toUtf8()); + qWarning() << sd.isNull(); // <- print false :) + QJsonObject sett2 = sd.object(); + + this->camera_paths = sett2.value("camera").toArray(); + this->log_paths = sett2.value("logs").toArray(); + } + this->setFocusPolicy(Qt::StrongFocus); // add the first segment @@ -63,17 +89,33 @@ Window::Window(QString route_, int seek) : route(route_) { bool Window::addSegment(int i) { if (lrs.find(i) == lrs.end()) { - QString fn = QString("%1/%2/rlog.bz2").arg(route).arg(i); + QString fn = QString("http://data.comma.life/%1/%2/rlog.bz2").arg(route).arg(i); + QThread* thread = new QThread; - lrs.insert(i, new LogReader(fn, &events, &events_lock, &unlogger->eidx)); + if (use_api != 0) + lrs.insert(i, new LogReader(fn, &events, &events_lock, &unlogger->eidx)); + else { + QString log_fn = this->log_paths.at(i).toString(); + lrs.insert(i, new LogReader(log_fn, &events, &events_lock, &unlogger->eidx)); + + } + lrs[i]->moveToThread(thread); connect(thread, SIGNAL (started()), lrs[i], SLOT (process())); thread->start(); //connect(lrs[i], SIGNAL (finished()), this, SLOT (update())); - QString frn = QString("%1/%2/fcamera.hevc").arg(route).arg(i); - frs.insert(i, new FrameReader(qPrintable(frn))); + QString frn = QString("http://data.comma.life/%1/%2/fcamera.hevc").arg(route).arg(i); + + if (use_api != 0) + frs.insert(i, new FrameReader(qPrintable(frn))); + else{ + QString camera_fn = this->camera_paths.at(i).toString(); + frs.insert(i, new FrameReader(qPrintable(camera_fn))); + } + + return true; } return false; @@ -195,6 +237,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); QString route(argv[1]); + + int use_api = QString::compare(QString("use_api"), route, Qt::CaseInsensitive); int seek = QString(argv[2]).toInt(); printf("seek: %d\n", seek); route = route.replace("|", "/"); @@ -206,7 +250,8 @@ int main(int argc, char *argv[]) { //route = "02ec6bea180a4d36/2019-10-25--10-18-09"; } - Window window(route, seek); + Window window(route, seek, use_api); + window.resize(1920, 800); window.setWindowTitle("nui unlogger"); window.show(); diff --git a/tools/nui/nui b/tools/nui/nui new file mode 100755 index 0000000000..35d3cfa68f --- /dev/null +++ b/tools/nui/nui @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ $# -gt 0 ]; then + if [ "$INTERNAL" = 1 ]; then + ./_nui "$1" + else + python get_files_comma_api.py $1 && ./_nui use_api + fi +else + echo "Please Enter a Route" +fi + \ No newline at end of file diff --git a/tools/nui/nui.pro b/tools/nui/nui.pro index 2a3c91439f..c0a136098d 100644 --- a/tools/nui/nui.pro +++ b/tools/nui/nui.pro @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:69b914687867cabc35e1ba333479fd2f1d976d813e6d97fad48b94e5b470b57b -size 1105 +oid sha256:6da22e2e4503c7db82c6632d552a5e3914e7b5fdefc50118683a1b2e816be317 +size 1106