Commit f8c53f3c authored by Adrien Dorsaz's avatar Adrien Dorsaz

Add a way to store on disk recorded data

parent 10fa741f
......@@ -25,6 +25,7 @@ Emotions::Emotions()
_arousalSet = new QMap<double,double>();
_valenceSet = new QMap<double,double>();
_lastPlot=QDateTime::currentDateTime();
getClassifiers();
}
......@@ -35,6 +36,53 @@ void Emotions::arousalValence(double arousal, double valence){
if(_record){
insertValue(_arousalSet, arousal);
insertValue(_valenceSet, valence);
QString* movie = new QString(EMOTION_MOVIE);
if(!movie->isEmpty()){
QFile file(_dataPath+"."+EMOTION_MOVIE);
if (!file.open(QIODevice::WriteOnly|QIODevice::Append)) {
qDebug() << "Emotions : cannot open file "+file.fileName()+" : "
<< qPrintable(file.errorString()) << file.fileName()<< endl;
return;
}
QString* arousalStr=new QString("");
arousalStr->setNum(arousal,'f', EMOTION_AROUSAL_ACCURACY);
QString* valenceStr=new QString("");
valenceStr->setNum(valence,'f', EMOTION_VALENCE_ACCURACY);
QString emotion = getEmotion();
QDateTime time = QDateTime::currentDateTime();
QString* line = new QString(*arousalStr+" "+*valenceStr+" "+emotion+" "+time.toString("hh:mm:ss:zzz")+"\n");
file.write(line->toAscii());
file.close();
if(_lastPlot.msecsTo(time)>EMOTION_PLOT_TIME){
// QProcess to call R script
/*
* This script will make a boxplot of valence and arousal every
* EMOTION_PLOT_TIME seconds and save them in a pdf.
*
* WARNING : be aware that your computer will make a lot of job using this script
* and it will certainly _overload_ your CPU. You can reduce it by increasing
* EMOTION_PLOT_TIME.
*/
/*QString program = "plot_movie.R";
QStringList arguments;
arguments << file.fileName()
<< _dataPath+".calm"
<< _dataPath+".exited"
<< _dataPath+".positive"
<< _dataPath+".negative";
QProcess *plotProcess = new QProcess(this);
plotProcess->startDetached(program, arguments);
_lastPlot=QDateTime::currentDateTime();
*/
}
}
}
if(_saveCalm){
......@@ -184,4 +232,3 @@ QString Emotions::getEmotion(){
}
return emotion;
}
......@@ -6,6 +6,9 @@
#include <QDebug>
#include <QMapIterator>
#include <QVariant>
#include <QDateTime>
#include <QProcess>
#include "sbs2common.h"
#include "naivebayesclassifier.h"
......@@ -14,6 +17,13 @@
#define EMOTION_VALENCE_ACCURACY 5
#define EMOTION_USERNAME "adrien"
/* Set a movie title in EMOTION_MOVIE to store the recoreded data in a file
* It will save : arousal, valence, emotion, time in a file with filename
* ended by the EMOTION_MOVIE string
*/
#define EMOTION_MOVIE ""
#define EMOTION_PLOT_TIME 10000
class Emotions : public QObject{
Q_OBJECT
......@@ -35,6 +45,7 @@ private:
// Sets with value and current number of found values
QMap<double, double>* _arousalSet;
QMap<double, double>* _valenceSet;
QString curArousal;
QString curValence;
......@@ -45,6 +56,8 @@ private:
QString getEmotion();
void storeClass(QString klassName, NaiveBayesClassifier *classifier);
QDateTime _lastPlot;
public:
Emotions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment