-
Notifications
You must be signed in to change notification settings - Fork 0
Conners issue 58 saccade work #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: issue-58-saccades
Are you sure you want to change the base?
Changes from 3 commits
29af7d0
29aca03
967bfd1
429f26e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,15 +186,18 @@ void Database::insertGaze(QString event_time, QString session_id, QString calibr | |
| } | ||
|
|
||
| //Inserts values/data into the appropriate attribute for the saccade and saccade_gaze tables | ||
| // void Database::insertSaccade(QString saccade_id, QString fixation_run_id, QString start_time, QString end_time, QString start_fixation, QString end_fixation, QString start_x, QString start_y, QString end_x, QString end_y, QString amplitude, QString peak_velocity, QString average_velocity, QString direction, QString duration){ | ||
| // QString query=QString("INSERT INTO saccade(saccade_id,fixation_run_id,start_time,end_time,start_fixation,end_fixation,start_x,start_y,end_x,end_y,amplitude,peak_velocity,average_velocity,direction,duration) VALUES(%1,%2,%3,%4,\"%5\",\"%6\",%7,%8,%9,%10,%11,%12,%13,%14,%15);").arg(saccade_id,fixation_run_id,start_time,end_time,start_fixation,end_fixation,start_x,start_y,end_x,end_y,amplitude,peak_velocity,average_velocity,direction,duration); | ||
| // sqlite3_exec(db,query.toStdString().c_str(),NULL,0,NULL); | ||
| // } | ||
|
|
||
| // void Database::insertSaccadeGaze(QString saccade_id, QString event_time) { | ||
| // QString query = QString("INSERT INTO saccade_gaze(saccade_id,event_time) VALUES(%1,%2);").arg(saccade_id,event_time); | ||
| // sqlite3_exec(db,query.toStdString().c_str(),NULL,0,NULL); | ||
| // } | ||
| void Database::insertSaccade(QString saccade_id, QString fixation_run_id, QString start_time, QString end_time, | ||
| QString start_fixation, QString end_fixation, QString start_x, QString start_y, | ||
| QString end_x, QString end_y, QString amplitude, QString peak_velocity, | ||
| QString average_velocity, QString direction, QString duration){ | ||
| QString query=QString("INSERT INTO saccade(saccade_id,fixation_run_id,start_time,end_time,start_fixation,end_fixation,start_x,start_y,end_x,end_y,amplitude,peak_velocity,average_velocity,direction,duration) VALUES(%1,%2,%3,%4,\"%5\",\"%6\",%7,%8,%9,%10,%11,%12,%13,%14,%15);").arg(saccade_id,fixation_run_id,start_time,end_time,start_fixation,end_fixation,start_x,start_y,end_x,end_y,amplitude,peak_velocity,average_velocity,direction,duration); | ||
| sqlite3_exec(db,query.toStdString().c_str(),NULL,0,NULL); | ||
| } | ||
|
Comment on lines
+189
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method of constructing SQL queries by string formatting is vulnerable to SQL injection. An attacker could provide malicious input for parameters like |
||
|
|
||
| void Database::insertSaccadeGaze(QString saccade_id, QString event_time) { | ||
| QString query = QString("INSERT INTO saccade_gaze(saccade_id,event_time) VALUES(%1,%2);").arg(saccade_id,event_time); | ||
| sqlite3_exec(db,query.toStdString().c_str(),NULL,0,NULL); | ||
| } | ||
|
|
||
|
|
||
| // The following parameters are unused here and should always be inserted as "" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |||||||||||||||||||||
| #include "gaze.h" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #include <iostream> | ||||||||||||||||||||||
| #include <QDebug> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class Database { | ||||||||||||||||||||||
| public: | ||||||||||||||||||||||
|
|
@@ -56,9 +57,9 @@ class Database { | |||||||||||||||||||||
| void insertSession(QString,QString,QString,QString,QString,QString,QString,QString,QString,QString); | ||||||||||||||||||||||
| void insertWebContext(QString,QString,QString,QString,QString); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| //Declarations for inserting values into the attributes for the saccade and saccade_gaze tables | ||||||||||||||||||||||
| //void insertSaccade(QString,QString,QString,QString,QString,QString,QString,QString,QString,QString,QString,QString,QString,QString,QString); | ||||||||||||||||||||||
| //void insertSaccadeGaze(QString,QString); | ||||||||||||||||||||||
| void insertSaccade(QString, QString, QString, QString, QString, QString, QString, QString, QString, QString, QString, QString,QString, QString, QString); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| void insertSaccadeGaze(QString, QString); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| QVector<QString> getSessions(); | ||||||||||||||||||||||
| QVector<QString> getAllIDEContextIDs(); | ||||||||||||||||||||||
|
|
@@ -77,9 +78,9 @@ class Database { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| QVector<QVector<QString>> runFilterQuery(QString); | ||||||||||||||||||||||
| void executeLongUpdateQuery(QString); | ||||||||||||||||||||||
| sqlite3* db; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private: | ||||||||||||||||||||||
| sqlite3* db; | ||||||||||||||||||||||
| QString file_path; | ||||||||||||||||||||||
| bool open = false; | ||||||||||||||||||||||
|
Comment on lines
+82
to
86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The database handle
Suggested change
|
||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,3 +68,65 @@ void Fixation::calculateDatabaseFields() { | |||||||||||||||||||
| void Fixation::print() { | ||||||||||||||||||||
| std::cout << fixation_event_time << "," << x << "," << y << "," << target.toUtf8().constData() << "," << source_file_line << "," << source_file_col << "," << token.toUtf8().constData() << "," << syntactic_category.toUtf8().constData() << "," << xpath.toUtf8().constData() << "," << left_pupil_diameter << "," << right_pupil_diameter << "," << duration << std::endl; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| /////////////////////////////// | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| Saccade::Saccade() {} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void Saccade::calculateDatabaseFields() { | ||||||||||||||||||||
| long long start_time = -1, end_time = -1; | ||||||||||||||||||||
| int gaze_count = 0; | ||||||||||||||||||||
| std::map<QString,int> candidate_targets; | ||||||||||||||||||||
| for(auto gaze : gaze_vec) { | ||||||||||||||||||||
| if(!gaze.isValid()) { continue; } | ||||||||||||||||||||
| if(fixation_event_time == 0 || fixation_event_time > gaze.event_time) { | ||||||||||||||||||||
| fixation_event_time = gaze.event_time; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ++gaze_count; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if(start_time == -1 || start_time > gaze.system_time) { | ||||||||||||||||||||
| start_time = gaze.system_time; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if(end_time == -1 || end_time < gaze.system_time) { | ||||||||||||||||||||
| end_time = gaze.system_time; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| left_pupil_diameter += isnan(gaze.left_pupil_diameter) || gaze.left_pupil_diameter == -1.0 ? 0 : gaze.left_pupil_diameter; | ||||||||||||||||||||
| right_pupil_diameter += isnan(gaze.right_pupil_diameter) || gaze.left_pupil_diameter == -1.0 ? 0 : gaze.right_pupil_diameter; | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There appears to be a copy-paste error here. When calculating
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| QString candidate_key = gaze.gaze_target + "\t"; | ||||||||||||||||||||
| candidate_key += (gaze.source_file_line == -1 ? QString("") : QString::number(gaze.source_file_line)) + "\t"; | ||||||||||||||||||||
| candidate_key += (gaze.source_file_col == -1 ? QString("") : QString::number(gaze.source_file_col)) + "\t"; | ||||||||||||||||||||
| candidate_key += gaze.source_token + "\t"; | ||||||||||||||||||||
| candidate_key += gaze.source_token_syntatic_context + "\t"; | ||||||||||||||||||||
| candidate_key += gaze.source_token_xpath + "\t"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if(candidate_targets.count(candidate_key) == 0) { candidate_targets.emplace(candidate_key,1); } | ||||||||||||||||||||
| else { ++(candidate_targets.find(candidate_key)->second); } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| std::pair<QString,int> most_frequent = std::make_pair(QString(""),0); | ||||||||||||||||||||
| for(auto candidate = candidate_targets.begin(); candidate != candidate_targets.end(); ++candidate) { | ||||||||||||||||||||
| if(most_frequent.first == "" || most_frequent.second < candidate->second) { most_frequent = *candidate; } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| QStringList fields = most_frequent.first.split("\t"); | ||||||||||||||||||||
| target = fields[0] == "" ? "" : fields[0]; | ||||||||||||||||||||
| source_file_line = fields[1] == "" ? -1 : fields[1].toInt(); | ||||||||||||||||||||
| source_file_col = fields[2] == "" ? -1 : fields[2].toInt(); | ||||||||||||||||||||
| token = fields[3] == "" ? "" : fields[3]; | ||||||||||||||||||||
| syntactic_category = fields[4] == "" ? "" : fields[4]; | ||||||||||||||||||||
| xpath = fields[5] == "" ? "" : fields[5]; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| left_pupil_diameter = left_pupil_diameter / double(gaze_count); | ||||||||||||||||||||
| right_pupil_diameter = right_pupil_diameter / double(gaze_count); | ||||||||||||||||||||
|
Comment on lines
+127
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Suggested change
|
||||||||||||||||||||
| duration = end_time - start_time; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| void Saccade::print() { | ||||||||||||||||||||
| std::cout << fixation_event_time << "," << x << "," << y << "," << target.toUtf8().constData() << "," << source_file_line << "," << source_file_col << "," << token.toUtf8().constData() << "," << syntactic_category.toUtf8().constData() << "," << xpath.toUtf8().constData() << "," << left_pupil_diameter << "," << right_pupil_diameter << "," << duration << std::endl; | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,11 +28,20 @@ class FixationAlgorithm | |||||
|
|
||||||
| QVector<Fixation>& getFixations(); | ||||||
|
|
||||||
| //issue 58 - Adding virtual function for generating saccades | ||||||
| virtual QVector<Saccade> generateSaccades()=0; | ||||||
| QVector<Saccade>& getSaccades(); | ||||||
|
|
||||||
| protected: | ||||||
| virtual Fixation computeFixationEstimate(QVector<Gaze>)=0; | ||||||
|
|
||||||
| QVector<Gaze> session_gazes; | ||||||
| QVector<Fixation> fixations; | ||||||
|
|
||||||
| //issue 58 - a vector to store our saccades | ||||||
| //Also, not sure if we'll need a saccade estimate | ||||||
| QVector<Saccade> saccades; | ||||||
| Saccade computeSaccadeEstimate(QVector<Gaze>); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function
Suggested change
|
||||||
| }; | ||||||
|
|
||||||
| #endif // FIXATIONALGORITHM_H | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
session_saccadesis declared but its value is never used. This is considered dead code and should be removed to improve code clarity.