Skip to content

Commit

Permalink
results saved in separate file for each subject
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyabo committed Jul 10, 2012
1 parent c0a6332 commit 8d0aae1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
results.csv
results/
videos/
node_modules/
27 changes: 20 additions & 7 deletions emotions.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
require('zappa').run 3001, ->

fs = require("fs")
path = require("path")
dateFormat = require('dateformat')

@use 'static': __dirname + '/static'

video = @include './video'

resultsFile = fs.createWriteStream __dirname + '/results.csv', {'flags': 'a'}
#resultsFile = fs.createWriteStream __dirname + '/results.csv', {'flags': 'a'}
resultsDir = __dirname + "/results"

mkdir = (dir) -> if !path.existsSync(dir) then fs.mkdirSync(dir, parseInt('0755', 8))

mkdir(resultsDir)


@use 'bodyParser', 'methodOverride', @app.router, 'static'

Expand Down Expand Up @@ -75,19 +81,19 @@ require('zappa').run 3001, ->
input id:"startSubmit", type:"submit", value:"Start"
###

script src: 'home.js'

#script src: 'home.js'



###
@coffee '/home.js': ->
$ ->
$(".videolist a").click ->
if $("#subject").val().trim() is "" or $("#dimension").val() is ""
alert("Please, fill in the form fields")
return false
return true

###



Expand Down Expand Up @@ -143,14 +149,14 @@ require('zappa').run 3001, ->
$("#video").data("isPlaying", false)

buffer = []
maxBufferSize = 10
maxBufferSize = 1

sendBufferToServer = ->
tosend = buffer
buffer = []
$.ajax
type: 'post'
url: 'save_value'
url: 'save_value?subject=' + subject
dataType: 'json'
data:
buffer: tosend
Expand All @@ -166,7 +172,7 @@ require('zappa').run 3001, ->
value: ui.value
playing: $("#video").data("isPlaying")

if buffer.length > maxBufferSize
if buffer.length >= maxBufferSize
sendBufferToServer()


Expand Down Expand Up @@ -211,6 +217,10 @@ require('zappa').run 3001, ->


@post '/save_value': ->
if not (@query.subject in video.users)
@next(new Error "Subject must be properly specified")

subj = @query.subject

q = (s) ->
if (s.indexOf(",") >= 0)
Expand All @@ -223,7 +233,9 @@ require('zappa').run 3001, ->
formattedDate = q(dateFormat(Date.now(), "dddd, mmmm dS, yyyy, h:MM:ss TT"))
csv = csv + formattedDate + "," + ((q(v) for k, v of obj).join(",") + "\n")

resultsFile = fs.createWriteStream("#{resultsDir}/#{subj}.csv", {'flags': 'a'})
resultsFile.write csv, (err) =>

unless err?
@send
result: 'Ok'
Expand All @@ -233,6 +245,7 @@ require('zappa').run 3001, ->




@view layout: ->
doctype 5
html ->
Expand Down
2 changes: 1 addition & 1 deletion video.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
]

users: [
"8935", "7656", "9234", "1334"
"8935", "7656", "9234", "1334", "12EAB14"
]


0 comments on commit 8d0aae1

Please sign in to comment.