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
pull/1189/head
Ayman Saleh 5 years ago committed by GitHub
parent a32fe80d39
commit 763493e988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      tools/clib/FrameReader.cpp
  2. 3
      tools/nui/.gitignore
  3. 5
      tools/nui/FileReader.cpp
  4. 14
      tools/nui/get_files_comma_api.py
  5. 55
      tools/nui/main.cpp
  6. 12
      tools/nui/nui
  7. 2
      tools/nui/nui.pro

@ -46,7 +46,7 @@ FrameReader::FrameReader(const char *fn) {
avformat_network_init(); avformat_network_init();
av_register_all(); 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(); }); t = new std::thread([&]() { this->loaderThread(); });
} }

@ -1,8 +1,9 @@
Makefile Makefile
.*.swp .*.swp
*.o *.o
nui _nui
moc_* moc_*
.qmake.stash .qmake.stash
nui.app/* nui.app/*
routes.json

@ -8,8 +8,9 @@ FileReader::FileReader(const QString& file_) : file(file_) {
void FileReader::process() { void FileReader::process() {
timer.start(); timer.start();
// TODO: Support reading files from the API QString str = file.simplified();
startRequest(QUrl("http://data.comma.life/"+file)); str.replace(" ", "");
startRequest(QUrl(str));
} }
void FileReader::startRequest(const QUrl &url) { void FileReader::startRequest(const QUrl &url) {

@ -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"))

@ -9,6 +9,12 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QReadWriteLock> #include <QReadWriteLock>
#include <QLineEdit> #include <QLineEdit>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <stdlib.h>
#include <QTextStream>
#include "FileReader.hpp" #include "FileReader.hpp"
#include "Unlogger.hpp" #include "Unlogger.hpp"
@ -16,8 +22,11 @@
class Window : public QWidget { class Window : public QWidget {
public: public:
Window(QString route_, int seek); Window(QString route_, int seek, int use_api);
bool addSegment(int i); bool addSegment(int i);
QJsonArray camera_paths;
QJsonArray log_paths;
int use_api;
protected: protected:
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
@ -36,6 +45,7 @@ class Window : public QWidget {
QMap<int, LogReader*> lrs; QMap<int, LogReader*> lrs;
QMap<int, FrameReader*> frs; QMap<int, FrameReader*> frs;
// cache the bar // cache the bar
QPixmap *px = NULL; QPixmap *px = NULL;
int seg_add = 0; int seg_add = 0;
@ -43,7 +53,7 @@ class Window : public QWidget {
QLineEdit *timeLE; 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 = new QLineEdit(this);
timeLE->setPlaceholderText("Placeholder Text"); timeLE->setPlaceholderText("Placeholder Text");
timeLE->move(50, 650); timeLE->move(50, 650);
@ -55,6 +65,22 @@ Window::Window(QString route_, int seek) : route(route_) {
connect(unlogger, SIGNAL (elapsed()), this, SLOT (update())); connect(unlogger, SIGNAL (elapsed()), this, SLOT (update()));
thread->start(); 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); this->setFocusPolicy(Qt::StrongFocus);
// add the first segment // add the first segment
@ -63,17 +89,33 @@ Window::Window(QString route_, int seek) : route(route_) {
bool Window::addSegment(int i) { bool Window::addSegment(int i) {
if (lrs.find(i) == lrs.end()) { 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; QThread* thread = new QThread;
if (use_api != 0)
lrs.insert(i, new LogReader(fn, &events, &events_lock, &unlogger->eidx)); 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); lrs[i]->moveToThread(thread);
connect(thread, SIGNAL (started()), lrs[i], SLOT (process())); connect(thread, SIGNAL (started()), lrs[i], SLOT (process()));
thread->start(); thread->start();
//connect(lrs[i], SIGNAL (finished()), this, SLOT (update())); //connect(lrs[i], SIGNAL (finished()), this, SLOT (update()));
QString frn = QString("%1/%2/fcamera.hevc").arg(route).arg(i); 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))); 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 true;
} }
return false; return false;
@ -195,6 +237,8 @@ int main(int argc, char *argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);
QString route(argv[1]); QString route(argv[1]);
int use_api = QString::compare(QString("use_api"), route, Qt::CaseInsensitive);
int seek = QString(argv[2]).toInt(); int seek = QString(argv[2]).toInt();
printf("seek: %d\n", seek); printf("seek: %d\n", seek);
route = route.replace("|", "/"); route = route.replace("|", "/");
@ -206,7 +250,8 @@ int main(int argc, char *argv[]) {
//route = "02ec6bea180a4d36/2019-10-25--10-18-09"; //route = "02ec6bea180a4d36/2019-10-25--10-18-09";
} }
Window window(route, seek); Window window(route, seek, use_api);
window.resize(1920, 800); window.resize(1920, 800);
window.setWindowTitle("nui unlogger"); window.setWindowTitle("nui unlogger");
window.show(); window.show();

@ -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

@ -3,7 +3,7 @@
###################################################################### ######################################################################
TEMPLATE = app TEMPLATE = app
TARGET = nui TARGET = _nui
INCLUDEPATH += . INCLUDEPATH += .
# Input # Input

Loading…
Cancel
Save