Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 07-06-2012, 09:10 AM   #4336
King of the sidebar
 
Neil S's Avatar
 
Join Date: Sep 2004
Location: Northern Virginia
Posts: 15,950
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by gaming_mouse View Post
Neil, you seem like a good programmer, so I am genuinely curious: Whatever you are referring to, how would it affect you practically as, say, a Rails programmer? Or is it just a matter a principle for you?
Well Rails, when it gets bad enough in the past, has just not been available on certain new versions of Ruby. It took them forever to be available on 1.9 at all, if I recall.

So how it would affect me if I used Rails (which I don't really care for) would be that I would be required to keep parallel versions of Ruby on hand for Rails.

Which wouldn't be fun.
Neil S is offline   Reply With Quote
Old 07-06-2012, 01:30 PM   #4337
Carpal \'Tunnel
 
Gullanian's Avatar
 
Join Date: Dec 2006
Location: London
Posts: 13,012
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Sorry bit of shameless self promotion, just finished writing our new web store:
http://www.scirra.com/store

This page is one I'm most happy with:
http://www.scirra.com/store/music-bu...k-prescription

I don't know if anyone else has written a store before? I found it to be one of the most challenging things I've ever done. It loads as much as it can with AJAX as well (namely clicking left menus, adding to cart without page reloading, changing currency without page reloading etc) which makes it very speedy and responsive, but was another layer that complicated things. It should all degrade gracefully as well for non JS browsers (although I haven't extensively tested this!)

One of the hardest parts was the database design, and of course payment handling. The database has some fairly complex relationships in it and doing things like revenue sharing for authors in multiple currencies is a pita!
Gullanian is offline   Reply With Quote
Old 07-06-2012, 02:36 PM   #4338
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,936
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Gull,

The whole cart feels really slick -- nice work. i especially love the subtle graphic effects when things change. One tiny tiny nit -- remove the "update" button and just make the cart update as you type a new quantity, or maybe when you leave the form field?
gaming_mouse is offline   Reply With Quote
Old 07-06-2012, 03:04 PM   #4339
veteran
 
Colombo's Avatar
 
Join Date: Feb 2005
Posts: 3,349
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I'm trying to construct a SQL database that will keep track of survey results.

Here are some finer details:
  • A survey has many questions. A single question can be used in many surveys.
  • A question has many possible answers. A single answer can be used for many questions.
  • One user can do many surveys. One survey has many users.
  • We want to keep track of the index of each question in any survey it appears in
  • On user can answer a specific question only once, regardless of what survey it is in.

The last bullet point is the one giving me the most trouble.

I've been wrapping my head around this for a few days and I've been trying to design a UML class diagram before constructing this in SQL. Here's what I've got right now:
Spoiler:


I think that I'm very close here, but I'm not a fan of the 'QuestionAnswer' class and think I'm doing something wrong. It just doesn't seem right. I'm not sure it should be considered an association class between an OfferedAnswer and a Question...

Could anyone give me any pointers here? I need to keep track of a user's responses, while also ensuring that each response is uniqued on (userID, questionID).
Colombo is offline   Reply With Quote
Old 07-06-2012, 03:14 PM   #4340
Carpal \'Tunnel
 
tyler_cracker's Avatar
 
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 13,908
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Business logic belongs in code. Don't try to handle those complex relationships in your storage layer.
tyler_cracker is offline   Reply With Quote
Old 07-06-2012, 03:15 PM   #4341
Carpal \'Tunnel
 
tyler_cracker's Avatar
 
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 13,908
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Also I'm on my phone + lol uml = I didn't look at your drawring too closely.
tyler_cracker is offline   Reply With Quote
Old 07-06-2012, 03:52 PM   #4342
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,936
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by tyler_cracker View Post
Business logic belongs in code. Don't try to handle those complex relationships in your storage layer.
What do you mean? There's no logic there, it's just a db schema.
gaming_mouse is offline   Reply With Quote
Old 07-06-2012, 04:06 PM   #4343
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,936
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by Colombo View Post

Could anyone give me any pointers here? I need to keep track of a user's responses, while also ensuring that each response is uniqued on (userID, questionID).
Not sure I understand the question. Obviously you need a QuestionAnswer table of some sort to store the answers to the questions.

I do think this schema is going to lead to some difficulties in the UI where you create surveys and have the option to choose questions from existing ones, and how you handle the display of questions in a survey where a user has already answered -- do you just skip those? Without knowing why you've decided this question reuse is so important it's hard to evaluate.
gaming_mouse is offline   Reply With Quote
Old 07-06-2012, 04:15 PM   #4344
old hand
 
sdturner02's Avatar
 
Join Date: Jul 2010
Posts: 1,211
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I've done something very similar to this in the past. This shouldn't be too tough, you just need to use primary keys.

/* holds data for individual surveys */
create table surveys
(
survey_id int unsigned not null auto_increment primary key,
description text not null
)
engine=INNODB;

/*
Table for the text and type of each question.
The qid column has an auto incrementing primary key so each question can be uniquely identified.
*/

create table questions
(
qid int unsigned not null auto_increment primary key,
qtext text not null,
qtype text not null
)
engine=INNODB;

/*
This table creates relationships between surveys and questions. The primary keys of the surveys table and questions table are used as a composite key. This allows a single question to be used on different surveys, but only once.
*/

create table survey_questions
(
survey_id int unsigned not null default 0,
qid int unsigned not null default 0,
primary key (survey_id, qid)
)
engine=INNODB;

/*
Table that holds the answers to each question.The primary key is a composite of the unique userID and qid for each question. This allows each user to only provide an answer for each question once.
*/

create table user_answers
(
userID int unsigned not null default 0,
qid int unsigned not null default 0,
answer_text text not null,
primary key (userID, qid)
)
engine=INNODB;

Also, from your picture it looks like you might be duplicating data. The NumQuestions field contains data that is available elsewhere (that's why I left it out in mine). If you need the # of questions in a survey, why don't you try something like

SELECT count(*) FROM survey_questions WHERE survey_id = current_survey

where "current_survey" is just the survey_id of whichever one you're trying to find the number of questions for.
sdturner02 is offline   Reply With Quote
Old 07-06-2012, 04:47 PM   #4345
old hand
 
sdturner02's Avatar
 
Join Date: Jul 2010
Posts: 1,211
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by gaming_mouse View Post
Not sure I understand the question. Obviously you need a QuestionAnswer table of some sort to store the answers to the questions.

I do think this schema is going to lead to some difficulties in the UI where you create surveys and have the option to choose questions from existing ones, and how you handle the display of questions in a survey where a user has already answered -- do you just skip those? Without knowing why you've decided this question reuse is so important it's hard to evaluate.
This can probably be handled pretty easily with a subquery. If you want to pull the questions in a particular survey, but only ones that the user hasn't answered elsewhere, I think this would work:

SELECT questions.*
FROM questions, survey_questions
WHERE questions.qid = survey_questions.qid
AND survey_questions.survey_id = current_survey
AND questions.qid NOT IN (SELECT qid FROM user_answers WHERE userID = current_user)
sdturner02 is offline   Reply With Quote
Old 07-06-2012, 05:49 PM   #4346
Carpal \'Tunnel
 
gaming_mouse's Avatar
 
Join Date: Oct 2004
Location: taking notes on u (see profile)
Posts: 11,936
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by sdturner02 View Post
This can probably be handled pretty easily with a subquery. If you want to pull the questions in a particular survey, but only ones that the user hasn't answered elsewhere, I think this would work:

SELECT questions.*
FROM questions, survey_questions
WHERE questions.qid = survey_questions.qid
AND survey_questions.survey_id = current_survey
AND questions.qid NOT IN (SELECT qid FROM user_answers WHERE userID = current_user)
What's hard isn't writing a query to figure out what questions they havn't answered. What's hard is all the UX issues it raises:

Do you silently omit the question?
Do you display it but greyed out with the existing answer which cannot be changed?
Do you just show a message saying Question 6 has been skipped because you already answered it? Or do you just renumber the questions? Etc, etc.

You really have to think hard about your business goals and the user experience to answer questions like this. They might seem trivial and easy, but ime figuring stuff like this out is by far the hardest and most time consuming part of application development.
gaming_mouse is offline   Reply With Quote
Old 07-06-2012, 05:52 PM   #4347
old hand
 
sdturner02's Avatar
 
Join Date: Jul 2010
Posts: 1,211
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I totally, 100% agree. I thought you were talking about the just the actual DB query.
sdturner02 is offline   Reply With Quote
Old 07-06-2012, 08:04 PM   #4348
journeyman
 
n00b590's Avatar
 
Join Date: Jun 2010
Location: TRYING TO MAKE MY WAY IN THE WORLD
Posts: 256
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

I'm running some database calculations using python and MySQL (with SQLAlchemy) and I'm getting REALLY slow database write speeds.. over six hours to write/update 400,000 records. Any idea what could be causing this? I did some googling and didn't find anything useful. I have a fairly powerful computer, 16 GB of RAM, so I don't think that's the bottleneck. And the insert isn't too complicated: "INSERT INTO data(session_id,game_id,count) VALUES (:a,:b,1) ON DUPLICATE KEY UPDATE count = count + 1". Are my MySQL settings screwed up somehow (I remember raising some buffer RAM value when I installed MySQL)? Select queries seem to run just fine, it's only inserts that are super slow.
n00b590 is offline   Reply With Quote
Old 07-06-2012, 09:51 PM   #4349
journeyman
 
n00b590's Avatar
 
Join Date: Jun 2010
Location: TRYING TO MAKE MY WAY IN THE WORLD
Posts: 256
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Wow never mind, http://dev.mysql.com/doc/refman/5.0/...ert-speed.html helped a lot. Start/commit transaction and combine all the inserts into one query FTW. Down to 30 secs now
n00b590 is offline   Reply With Quote
Old 07-07-2012, 01:57 AM   #4350
ɹǝʍoʇpunoɹ
 
RoundTower's Avatar
 
Join Date: Feb 2005
Location: soah made my profile
Posts: 13,925
Re: ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

Quote:
Originally Posted by gaming_mouse View Post
What's hard isn't writing a query to figure out what questions they havn't answered. What's hard is all the UX issues it raises:

Do you silently omit the question?
Do you display it but greyed out with the existing answer which cannot be changed?
Do you just show a message saying Question 6 has been skipped because you already answered it? Or do you just renumber the questions? Etc, etc.

You really have to think hard about your business goals and the user experience to answer questions like this. They might seem trivial and easy, but ime figuring stuff like this out is by far the hardest and most time consuming part of application development.
all this.

It seems no matter what you do you have to mix a little of business logic and database schema.
RoundTower is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 10:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive