2015年3月12日 星期四

Final Project

For my final project, I created an online survey that can store data. I used Servi.js to save data from a form and save it to a database on my server.  Also, because the servi database seems can only save data from one form each time, so I used javascript to make one html page act as several pages. This way I can store data from one person all at once. I am currently using this survey for my thesis experiment as well.




Please find the survey here:
http://104.236.59.251:3001

Here is the server code for data storage:


var servi = require('servi');
var app = new servi(true);
var namesDB = useDatabase("dataStorage"); 



port(3001);
start();
// --- routes --- //

route('/', submitform);
route('/submitform', video1);

function submitform(request){
// Show the form file
    request.serveFile("final.html");
}


function video1(request) {

var storeData = {
name: request.params.Name,
Gender: request.params.Gender, 
Age: request.params.Age, 
NormalHearing: request.params.Hearing,
Parkinson: request.params.Parkinson,

Video1_primaryEmotion: request.params.q0,
Video1_howMuch:  request.params.q1,
Video1_otherEmotion: request.params.q2,
Video1_whatsTheEmotion: request.params.q3,
Video1_howMuchOfOtherEmotion: request.params.q4,
Video1_pleaseness: request.params.q5,
Video1_haveYouSeenTheVideo: request.params.q6,
Video1_CloseEyes: request.params.q7,
Video1_commoents: request.params.q8,

Video2_primaryEmotion: request.params.v2q0,
Video2_howMuch:  request.params.v2q1,
Video2_otherEmotion: request.params.v2q2,
Video2_whatsTheEmotion: request.params.v2q3,
Video2_howMuchOfOtherEmotion: request.params.v2q4,
Video2_pleaseness: request.params.v2q5,
Video2_haveYouSeenTheVideo: request.params.v2q6,
Video2_CloseEyes: request.params.v2q7,
Video2_commoents: request.params.v2q8,

Video3_primaryEmotion: request.params.v3q0,
Video3_howMuch:  request.params.v3q1,
Video3_otherEmotion: request.params.v3q2,
Video3_whatsTheEmotion: request.params.v3q3,
Video3_howMuchOfOtherEmotion: request.params.v3q4,
Video3_pleaseness: request.params.v3q5,
Video3_haveYouSeenTheVideo: request.params.v3q6,
Video3_CloseEyes: request.params.v3q7,
Video3_commoents: request.params.v3q8,

Video4_primaryEmotion: request.params.v4q0,
Video4_howMuch:  request.params.v4q1,
Video4_otherEmotion: request.params.v4q2,
Video4_whatsTheEmotion: request.params.v4q3,
Video4_howMuchOfOtherEmotion: request.params.v4q4,
Video4_pleaseness: request.params.v4q5,
Video4_haveYouSeenTheVideo: request.params.v4q6,
Video4_CloseEyes: request.params.v4q7,
Video4_commoents: request.params.v4q8

};

namesDB.add(storeData);
request.serveFile('ThankYyou.html');
// console.log(namesDB);
}