开发者

Psych Experiment in Python (w/Django) - how to port to interactive web app?

开发者 https://www.devze.com 2023-03-26 19:09 出处:网络
I\'m writing a psychology experiment in Python, and I need to make it available as a web app.I\'ve already got the Python basically working as a command-line program.On the recommendation of a CS budd

I'm writing a psychology experiment in Python, and I need to make it available as a web app. I've already got the Python basically working as a command-line program. On the recommendation of a CS buddy I'm using Django with a sqlite db. This is also working, my development server is up and the database tables are ready and waiting.

What I don't understand is how to glue these two pieces together. The Django tutorials I've found are all about building things like blogs, messaging systems or polls; systems based on sending form data. I can't do that, because I'm timing responses to presented stimuli in mi开发者_如何转开发lliseconds - I need to build an interactive app that doesn't rely (during the exercise) on form POST data or URL changes.

In short: I have no idea how to go from my simple command line program to a "real time" interactive web application.

Maximum kudos for links to relevant tutorials! I will also really appreciate a high-level explanation of the concept I'm missing here.

(FYI, I asked a previous question (choice of database) about this project here)


You are going to need to use HTML/Javascript, and then you can collect and send the results to the server. The results can get gamed though, as the code for the exercise is going to be client side.

Edit: I recommend a Javascript library, jQuery: http://docs.jquery.com/Tutorials

Edit 2:

I'll be a bit more specific, you need at least two models in Django, Exercise, and ExecutedExercise. Exercise will have fields with its name, number, etc., generic data for each exercise. ExecutedExercise will have two fields, a foreign key to Exercise, and a field to store how long it took to finish.

Now in Javascript, you're going to time the exercises, and then post them to a Django view that will handle the data storage. How to post them? You could use http://api.jquery.com/jQuery.post/ Create the data string, data = { e1: timingE1, e2: timingE2 } and post it to the view. You can handle the POST parameters in that view, create a ExecutedExercise object (you'll have the time it took for each exercise) and save them.

0

精彩评论

暂无评论...
验证码 换一张
取 消