Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaros95 committed Apr 15, 2019
1 parent 5647f18 commit 2ac729e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
57 changes: 57 additions & 0 deletions tools/QtGAITGui/Level_weight_shifting.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "Level_weight_shifting.hpp"
#include <QDebug>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QLineEdit>
#include <chrono>
#include "progressbar.hpp"

LevelWS::LevelWS(ProgressBar *left, ProgressBar *right)
Expand Down Expand Up @@ -44,3 +51,53 @@ void LevelWS::checkTgtStatus()
m_timer.stop();
}
}

void LevelWS::loadJsonFile(QString file)
{
QFile dataFile(file);

auto jsonDoc = QJsonDocument::fromJson(dataFile.readAll());

levelsRoot = jsonDoc.object();
}

void LevelWS::start()
{
currentLevel = levelsRoot.keys()[0];

runLevel();
}
void LevelWS::runLevel()
{
auto levelData = levelsRoot[currentLevel].toObject();

long duration = levelData["Time"].toDouble();

auto leftArray = levelData["Left"].toArray();
auto rightArray = levelData["RIght"].toArray();

setLvlRequirements({leftArray[0].toDouble(), leftArray[1].toDouble()}, ,
{rightArray[0].toDouble(), rightArray[1].toDouble()},
std::chrono::seconds(duration));

auto seriesNames = root[timepoints.first()].toObject().keys();

for (auto timepointStr : timepoints) {
auto timepoint = timepointStr.toDouble();
auto tpData = root[timepointStr].toObject();
for (auto seriesStr : seriesNames) {
auto points = tpData[seriesStr].toArray();
auto *series_x =
m_chart->getSeries((seriesStr + "-X").toStdString().c_str());
series_x->append({timepoint, points[0].toDouble()});

auto *series_y =
m_chart->getSeries((seriesStr + "-Y").toStdString().c_str());
series_y->append({timepoint, points[1].toDouble()});

auto *series_z =
m_chart->getSeries((seriesStr + "-Z").toStdString().c_str());
series_z->append({timepoint, points[2].toDouble()});
}
}
}
10 changes: 9 additions & 1 deletion tools/QtGAITGui/Level_weight_shifting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define Level_weight_shifting_hpp

#include <stdio.h>
#include <QJsonObject>
#include <QObject>
#include <QTimer>
#include <chrono>
Expand All @@ -20,17 +21,24 @@ class LevelWS : public QObject {
void setLvlRequirements(Target left,
Target right,
std::chrono::seconds timeRequirement);
void loadJsonFile(QString file);
public slots:
void onLeftFSRChanged(bool onTarget);
void onRightFSRChanged(bool onTarget);

signals:
void start();

void runLevel();

private:
void levelComplete();

private:
void checkTgtStatus();

private:
QJsonObject levelsRoot;
QString currentLevel;
QTimer m_timer;

ProgressBar *m_leftBar;
Expand Down

0 comments on commit 2ac729e

Please sign in to comment.