Smokes, Whiskey and .NET

ritSegessager

New Member
Hello everyone,<BR><BR> <BR><BR>I am quite new to the wonderful world of database design, and I would be most appreciative if any gurus in this field could point me in the right direction. I apologize in advance for the somewhat fanciful scenario, but it is the only way I can make my problem clear.<BR><BR> <BR><BR>Suppose that there is a company, "Good Kid Industries", that wants to create a website using the .Net framework. They have a set of rules that defines an international standard "The Good Kid Standard". This standard can be applied to any child under 10 years old. The rules can be summarized as follows:<BR><BR> <BR><BR>1) No kid shall consume more than 20 cookies for any 12 day period.<BR><BR> <BR><BR>Realizing that these are bleak modern times they also declare:<BR><BR> <BR><BR>2) No kid shall smoke more than 7 cigarettes for any 6 day period.<BR><BR> <BR><BR>and<BR><BR> <BR><BR>3) No kid shall drink more than 40 oz of whisky for any 10 day period.<BR><BR> <BR><BR>Now Good Kid Industries has many, many parents who want to partake in the program. Each parent enters in their child's activities on an hourly basis for the day (for the sake of this example the parent's are omniscient when it comes to their children's activities ... hey, I told you it was a fanciful example). The day is broken up into hours. This data is stored in a database and consists of the child's name, and how many cookies, cigarettes and whisky they consumed each hour.<BR><BR> <BR><BR>Now, my question. When it comes to designing the website and database, what is the most efficient way to determine which children have run afoul of the "Good Kid Standard". It would be nice if for each kid we could cut up the logs into 12, 10 and 6 day chunks and just query how many cookies, drinks or cigarettes respectively they have consumed in this period. But this won't work since the standard is for ANY 12, 10 and 6 day period. Meaning if we cut it into chunks, if Johnny had 18 cookies just before the 12 day period ended and 10 cookies the very next day, he would have consumed 28 cookies in 2 days. Clearly he has failed to be a "Good Kid", but if we were just checking every 12 day block he would pass since in the first block he would have consumed 18 cookies and in the next only 10.<BR><BR>So it seems that in order to determine compliance, the webserver has to drag out all of the records for a particular period. Then for every single HOUR of that period, go back 12 days to that hour and determine the cookies consumed. THEN for every single hour of that period go back 10 days to the hour and determine the amount of whisky consumed. THEN for every single hour of that period go back 6 days to the hour and determine the number of cigarettes consumed. This seems to be incredibly costly in processor work for the server, especially if several parents want to determine for a period of months whether or not their child meets the "Good Kid Standard". I am sure I must be looking at the solution to this problem the wrong way. Can anyone give me any pointers here?<BR><BR> <BR><BR>Thanks in advance<BR><BR> <BR><BR>Dan<BR><BR>First I'm not sure that my answer makes sense<BR><BR>Second I feel like I'm being asked to do your homework. Do you need help with something or would you like someone just to engineer a product for you for free?<BR><BR>Third this question has nothing to do with ASP, Databases or .Net.<BR><BR>Finally, the best solution to your problem IS to break it up into 12, 10 and 6 day chunks. Oh, I know, you say you can't..because if I have 12 days, is it days 1,2,3,4,5,6 or days 2,3,4,5,6,7 or days 3,4,5,6,7,8...but I think you can.<BR><BR>Determine whether a child has been naugthy or not each day and store the results...VOILA..i believe that's your solution. In other words, store every possible result.<BR><BR>example:<BR>Parent enters information for child 12 times in the day (n) (I'll assume parents are only doing this 12 times a day). When 1am roles by, determine if child is naught by looking look at days n-1, n-2, n-3, n-4, n-5 and n-6. Store in database @from_date = n-6, @today = n, @isNaught = ?<BR><BR><BR>While you still have a range, your upper bound is defined, thus solving your problem.<BR><BR><BR>I should also point out that you'd be surprised at how fast TSQL will execute on MS SQL. Even if parents entered information 24 times a day, that's still only about 10 000 loops, which you could probably cut down with some fancier SQL. I don't know about you, but my computer can run 10 000 loops quite easily.<BR><BR>If this is for a class, the lesson is simple. If you think something is too processor intensive, the solution is often hard drive room. The trick is finding the balance which will be the least expensive. Since 6 day rules are harder to calculate, maybe you should store all their information, while dynamically calculating 10 and 12 day rules.<BR><BR>I might be totally off....I might be indeed...<BR><BR>Karleither you are asking us to:<BR><BR>a) do your homework project<BR>b) do your project for work (with cleverly re-named entities of course)<BR><BR>my suggestion would be to do it yourself. if i made some terribly wrong assumptions then i apologize in advance.Thanks for your reply Karl,<BR><BR>I can see how this would seem like a homework example, but I assure you it isn't. I just renamed my present business problem and was posting it not so someone could write it for me but rather a) Whether my concerns over processor time, particularly on a web server were valid and b) If my approach to the problem was completely off base, if someone could nudge me in the direction of the right approach.<BR><BR>At the risk of sounding (even more) like a dunderhead you suggest:<BR><BR>Since 6 day rules are harder to calculate, maybe you should store all their information, while dynamically calculating 10 and 12 day rules.<BR><BR><BR>Q1: Why are 6 day rules harder to calculate than 10 or 12 day rules?<BR><BR>Q2: What exactly do you mean by storing all of the information for 6 day rules?<BR><BR><BR>DanBecause there are more calculations to be made for 6 day rules.<BR><BR>Simple example:<BR><BR>you want to look at it over a 13 day span. With a 6 day rule, it could be any of 7 possibilities..whereas a 12 day rule would only have 2 possibilities.<BR><BR><BR>1,2,3,4,5,6<BR>2,3,4,5,6,7<BR>3,4,5,6,7,8<BR>4,5,6,7,8,9<BR>5,6,7,8,9,10<BR>6,7,8,9,10,11<BR>7,8,9,10,11,12<BR>8,9,10,11,12,13<BR><BR><BR>or<BR><BR>1,2,3,4,5,6,7,8,9,10,11,12<BR>2,3,4,5,6,7,8,9,10,11,12,13<BR><BR><BR><BR>so if you are trying to achieve a balance between processor and storage usage, you might consider storing all posibility for 6 day rules on a per day basic, while dynamically calculating 12 day rules on request.<BR><BR>More precisly what I mean about storing all the information, is that each day, you store<BR>start=1,end=6, wasBad= ?<BR>start=2,end=7, wasBad=?<BR>start=3,end=8, wasBad=?<BR>start=4,end=9, wasBad=?<BR>start=5,end=10, wasBad=?<BR>start=6,end=11, wasBad=?<BR>start=7,end=12, wasBad=?<BR>start=8,end=13, wasBad=?<BR><BR>which would allow you to quickly determine whether a child was bad or not.<BR><BR>You may even find that reversing that logic may yield a better ratio...in you'll be storing less, and you'll be doing just a bit more calculations.<BR><BR>Hope that clears it up.<BR><BR>Karl<BR>Thanks very much Karl! Your answers really helped!<BR><BR>Dan
 
Back
Top