Skip to content
48 changes: 48 additions & 0 deletions model/createHelperData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* randomly sorts videos(with AI and without AI) and inserts rows in database
Author: Vaishali*/
const db = require('../db/database');
const userStudy = require('../model/userStudy');

class createHelperData {
constructor() {
this.id = 'id_1';
}
set name(name) {
this._name = name.charAt(0).toUpperCase() + name.slice(1);
}
get name() {
return this._name;
}
sayHello() {
console.log('Hello, my name is ' + this.name + ', I have ID: ' + this.id);
}

create1(userId, callback) {
return db.query('SELECT * FROM us_user ORDER BY id ASC', callback);
}

create
}

var justAGuy = new createHelperData();
justAGuy.name = 'martin'; // The setter will be used automatically here.
justAGuy.sayHello(); // Will output 'Hello, my name is Martin, I have ID: id_1'

// userStudy.getAllUsers().then(function (result) {
// userDetails = result;
// console.log("Initialized user details");
// // Use user details from here
// console.log(result)
// }, function (err) {
// console.log(err);
// })

justAGuy.create1().then(function (result) {
userDetails = result;
console.log("Initialized user details");
// Use user details from here
console.log(result)
}, function (err) {
console.log(err);
});

8 changes: 6 additions & 2 deletions model/userStudy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ let userStudy = {
},
addVideo : function(data, callback){
return db.query(`INSERT into us_user_video (user_id,youtube_id, ai_support) VALUES ($1, $2, $3)`, [data.id, data.youtube_id, data.ai_support], callback);
}

},
getHelperVideo: function (callback) {
return db.query(`SELECT u.volunteer_id, u.video_id, v.title, u.ai_support FROM us_helper_video u
JOIN video v
ON u.video_id = v.youtube_id `, callback);
},
};


Expand Down
13 changes: 13 additions & 0 deletions model/userStudy2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const db = require('../db/database');
let userStudy2 = {

getAllUsers: function (callback) {
return db.query('SELECT * FROM us_user_blind ORDER BY id ASC', callback);
},

getUserById: function (id, callback) {
return db.query(`SELECT * FROM us_user_blind where uuid = ${id}`, callback);
},
};

module.exports = userStudy2;
13 changes: 13 additions & 0 deletions public/javascripts/homeUserStudy2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$(document).ready(function () {
fetchUsers();
});

function fetchUsers() {
$.get('/userStudy2/users', function (rows) {
let generatedHtml = '';
for (let i = 0; i < rows.length; i++) {
generatedHtml += `<a href="/userStudy/videoHelper?userId=${rows[i].uuid}&pid=${rows[i].id}" class="list-group-item"> ${rows[i].name} </a>`
}
$( ".list-group" ).append(generatedHtml);
});
}
Empty file.
56 changes: 55 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var express = require('express');
var router = express.Router();
const video = require('../backend/video');
const userStudy = require('../model/userStudy');
const userStudy2 = require('../model/userStudy2');

const db = require('../db/database');

router.get('/', function(req, res, next) {
Expand Down Expand Up @@ -103,12 +105,43 @@ router.post('/updateBlockAndScene', function(req, res, next) {
router.get('/userStudy', function (req, res) {
res.render('homeUserStudy', { title: 'User Study' });
});

//poorva
router.get('/userStudy2', function (req, res) {
res.render('homeUserStudy2', { title: 'User Study 2' });
});

//list of video for a user
router.get('/userStudy/video', function (req, res) {
res.render('videoUserStudy', { title: 'User Study Video' });
});

//list of video for visually impaired users
router.get('/userStudy/videoHelper', function (req, res) {
res.render('videoHelper', { title: 'User Study Video Helper' });
});


//list of visually impaired users
router.get('/userStudy/helper/video', function (req, res) {
console.log({ param: req.query.userId });
let userId = req.query.userId;
if (userId) {
let queryResult = userStudy.getHelperVideo();
queryResult
.then(result => {
res.send(result);
})
.catch((err) => {
res.send(err);
});
}
});



//list of users
//list of users study 1
router.get('/userStudy/users/', function (req, res) {
console.log({param: req.query.userId});
let userId = req.query.userId;
Expand All @@ -135,6 +168,23 @@ router.get('/userStudy/users/', function (req, res) {
}
});


//list of users study 2
router.get('/userStudy2/users/', function (req, res) {
// let userId = req.query.userId;
// if(userId){
//let queryResult = userStudy2.getVideoByUserId(userId);
let queryResult = db.query(`SELECT * from us_user_blind`);
queryResult
.then(result => {
res.send(result);
})
.catch((err) => {
res.send(err);
});
// }
});

router.post('/saveNonAiDescription', function(req, res, next) {
let inputJson = req.body;
console.log(inputJson);
Expand All @@ -155,6 +205,10 @@ router.post('/saveAiDescription', function(req, res, next) {
}).catch((err) => {
res.send({success: false});
});
})



res.render('index', { title: 'Express' });
});

module.exports = router;
27 changes: 27 additions & 0 deletions views/homeUserStudy2.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>User Study 2</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="../stylesheets/homeUserStudy2.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<div style="background-color: #1a4b6e; padding: 16px;">
<div>
<h1 style="color: white; text-align: center;"><u>Participant List</u></h1>
<br>
<p><h2 style="color: white">Please click on the Participant Number assigned to you</h2></p>
</div>
<div class="list-group" >
</div>
</div>
</div>
</body>
<script src="../javascripts/homeUserStudy2.js"></script>

</html>
91 changes: 91 additions & 0 deletions views/videoHelper.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<head>
<title>User Study</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-dark" style="background-color: #1a4b6e;">
<div class="container">
<a class="navbar-brand" href="#" style="margin:0px auto; font-weight: bold;">YouDescribe User Study</a>
</div>
</nav>
<div class="container">
<div>
<h1>List of Video</h1>
<p id="date"> </p>
<p>Please select the video</p>
</div>
<div class="container">
<div class="list-group">

</div>
</b>
<!--iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfwGYCxzlpzy05nsvR74vqMRqUt6DPvIDI2Sy4hsQDktRSwug/viewform?embedded=true" width="640" height="1015" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe-->
</div>

<script>

//get parameters from query string
let url = location.search.substring(1);
console.log('URL:' + url);
let urlParams = new URLSearchParams(url);
let userId = urlParams.get('userId');
let targetUrl = '/userStudy/helper/video?userId=' + userId;
console.log('target URL:' + targetUrl);


$(document).ready(function () {
getDateTime();
fetchVideo();
});


function getDateTime(){
let date = new Date(Date.now()).toLocaleString();
document.getElementById('date').innerHTML = date;
console.log(date);
}


function fetchVideo() {

$.get(targetUrl, function (rows) {
let videos = '';
for (let i = 0; i < rows.length; i++) {
let vid = rows[i];
let videoId = vid.video_id;
let videoTitle = vid.title;

//let aiSupportStr = vid.ai_support == 'true' ? 'With AI support' : 'Start from scratch';
let aiParam = vid.ai_support == 'true' ? 'yes' : 'no';
videos += `<b><a href="/playvideo/${videoId}?u=${userId}&ai=${aiParam}" class="list-group-item" >
<img class="vid-thumbnail" src="https://i1.ytimg.com/vi/${videoId}/hqdefault.jpg" alt=${videoTitle} style="width:100px;height:100px;">

Video ${i+1}: ${videoTitle} </a></b>
<form action="/submitform/" method="POST">
<b><font color="1a4b6e"> Please Rate the above video from 0 to 5:</b></font> <input type="number" min="0" max="5" step="1" id="rating" style="width: 5%; border: 1px solid #ccc; padding: 10px 7px;border-radius: 4px; box-sizing: border-box;" name="rating" required><br>
<br>
<b><font color="1a4b6e"> Any other comments:</b></font> <input type="text" id="comment" style= "width: 75%; padding: 10px 7px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box;" name="comment"><br>
<br>
</form><br>`;


}

$( ".list-group" ).append( videos);
});
}

</script>
<input type="submit" style= "width:100%; background-color: #4CAF50; color: white; padding: 10px 10px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer;" value="I completed"></input>


</body>
</html>