Python中的Psych实验(w / Django) - 如何移植到交互式Web应用程序? [英] Psych Experiment in Python (w/Django) - how to port to interactive web app?

查看:138
本文介绍了Python中的Psych实验(w / Django) - 如何移植到交互式Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Python中编写心理学实验,我需要将其作为网络应用程序提供。我已经把Python作为一个命令行程序。根据CS好友的推荐,我使用的是Django和sqlite数据库。这也是工作,我的开发服务器已经启动,数据库表已准备就绪并等待。



我不明白是如何将这两个组合在一起。我发现的Django教程都是关于构建博客,邮件系统或民意调查的东西;基于发送表单数据的系统我不能这样做,因为我以毫秒为单位来呈现刺激的时间响应 - 我需要构建一个交互式应用程序,不需要在表单POST数据或URL更改中依赖(在练习中)。

$ b简而言之:我不知道如何从简单的命令行程序到实时交互式Web应用程序。



最大的喜爱链接到相关教程!我也很欣赏我在这里遗漏的概念的高级解释。



谢谢你,
Tr3y



(FYI,我问过关于这个项目的前一个问题(选择数据库)这里

解决方案

您将需要使用HTML / Javascript,那么您可以收集并将结果发送到服务器。结果可以得到gamed,因为该练习的代码将是客户端。



编辑:我推荐一个Javascript库,jQuery: http://docs.jquery.com/Tutorials



编辑2 :



我将会更具体一些,在Django,Exercise和ExecutedExercise中至少需要两个模型。练习中将包含名称,编号等字段,每个练习的通用数据。 ExecutedExercise将有两个字段,一个是Foreign的外键,一个字段用于存储完成所需的时间。



现在在Javascript中,你将要练习,然后将它们发布到将处理数据存储的Django视图。如何发布?您可以使用 http://api.jquery.com/jQuery.post/ 创建数据string,data = {e1:timingE1,e2:timingE2}并将其发布到视图。您可以处理该视图中的POST参数,创建一个ExecutedExercise对象(每次练习都需要花费时间)并保存。


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 milliseconds - 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.

Thank you, Tr3y

(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.

这篇关于Python中的Psych实验(w / Django) - 如何移植到交互式Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆