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. 59
      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();
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(); });
}

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

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

@ -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 <QReadWriteLock>
#include <QLineEdit>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <stdlib.h>
#include <QTextStream>
#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<int, LogReader*> lrs;
QMap<int, FrameReader*> 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();

@ -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
TARGET = nui
TARGET = _nui
INCLUDEPATH += .
# Input

Loading…
Cancel
Save