Tuesday, May 7, 2013

Tracking Families in a Database

Developers out there: What is the best way to track families in a database? Trivial question, right?

You'd better get this right! Your application may end up being used by your company's (or client's) employees with a vip at the end of a phone call, and it's important for your company's employee to quickly add/update/change records to reflect changes to their family (you wouldn't want to send out a happy anniversary card if the donor is divorced, or send one to his neighbor, but miss hers)!

Oh, it is important to get right; but it's a trivial problem... so... think about it for a moment before you read on.

Here's one common approach:


Tables (columns:
people (name, date of birth, etc)
relationships (RelationshipType, personid, personid)
relationship_types (Father, Mother, Cousin, Uncle, Twice Married Half sister's mother cousin, etc)

That sounds fun. Some individuals would end up with dozens of connections; often connections are duplicated because it's hard to check for duplicates in such a scenario, and your business rules better be perfect otherwise your data is going to get corrupt. Not an instant nightmare, but a nightmare that'll get you two years after your application is in production and you suddenly need detailed reports requiring that family relationship info.

So say we have a family Mother: Sue; Dad: Bob; and child: Tofu. Tofu has 2 relationship entries linking him to Bob; Bob has 2 relationship entries linking him as husband to Sue and father to Tofu, Sue has 2 relationship entries linking her to Tofu as Mother and Bob as Wife. 6 relationship entries for 3 people. Add in more children, grandparents, 2nd marriages, and suddenly you have a pretty precarious situation. Almost certainly to get a full picture of a person's relationships you will find out your database knows about relationships that your app doesn't, because those records weren't added.

Is there a better way? Sure. Track events in people's lives instead.



people (First Name, Last Name, ...)
life_events* (EventType, Date)
people_life_events (Assocation Table: Event, Person, Title)
person_life_event_title (Lookup table: name; example: Father, Mother, Child, Husband, Wife, etc)
life_event_type (Lookup table: name; examples: Marriage, Birth, Divorce, etc)

*side note: life_events seems the best term to me; although I prefer one word table names. There are some options out there, but they aren't great. milestone, event, occasion, happening, or epochal.

Example: Dad: Bob; Mom: Sue; Son: Tofu.
3 Person records (Bob, Sue, Tofu)
2 Life Events (connecting event_type(marriage) and event_type(birth) with their persons)
2 associations in life_event_people for the Marriage, 3 for the birth
3 person_life_event_title records (husband, wife, child)
2 life_event_type records (marriage, birth)

Here's a Google Doc to help you visualize the data:


[or you can view the actual Google Doc here]

Now, there is no duplicate entry; and your application will know even complicated relationships correctly every time.

You might get to the point one day where you decide person_life_event_title can be converted to an enum. You certainly don't have to use it for generating reports; just use the string 'Father' etc. This is true for the event_types also.

Hint: Spend time on your models. It's the foundation on which your entire application will stand. Don't worry about how you're going to work with the data, worry about making a solid foundation. Your database shouldn't have to change much, if at all, besides adding new tables and new associations if you build it correctly.

Now Discuss:

Thursday, April 4, 2013

Django ListFilter e=1

I ran into some odd issue with Django the other day when attempting to inherit the ListFilter class in the Django Admin app.

I was creating a custom filter to allow a date range to be selected; and doing this required that I add the date parameters into the query string. Not a big deal, I thought. Well, turns out; it was a bigger deal than I thought. Apparently Django Admin had decided that query string parameters needed to be explicitly declared by the filters; otherwise the app would silently error on them; and replace them with e=1 (strange choice, I think). I wandered all over the internets to find an answer to why my query string class_start_time=2013-01-01 was being converted to e=1. Nothing. Crickets.

I ended up debugging the app itself to determine the root cause of the problem; Pycharm made this a fairly painless procedure.

All of that to say: If you ever find yourself wanting to inherit the ListFilter; and adding some of your own query string values; you need to remove those from the params dictionary that will get passed to your classes __init__ method. 

del params[parameter_name]

Most of the time, the Admin app makes life very easy, and sometimes you end up spending an afternoon debugging source files to figure out what's going on. At least there are well written source files to debug!

Here's a link to the StackOverflow question I posted on this: http://stackoverflow.com/questions/15792884/creating-custom-list-filter-in-django/15797139#15797139


Friday, December 21, 2012

Github, Python, and Baseball

Github Account! With stuff!

I have recently updated my Github account with something other than the non-trivial (although needing some clean-up) slideshow django-cms plugin. Maybe it's kinda trivial too, but it was fun :)

https://github.com/mcneo

A long time ago I mentioned that I wrote a baseball simulator that helped me correctly gauge the abilities of hitters in baseball using their Plate Discipline metrics. It worked, although the power numbers were wrong. I have cleaned it up a ton, mostly to match PEP 8 coding standards. I still have plenty of things I could do to improve the accuracy of the code; primarily by removing BABIP (batting average for balls in play) from the equation and using Line Drive, Ground Ball, and Fly Ball rates instead. That will at least divorce my code from those statistics that take longer to stabilize (BABIP mostly *doesn't* stabilize -- unless you are Ichiro Suzuki).

+Nathan Sanders You asked for this like 3 years ago :) I finally delivered.

Tuesday, September 11, 2012

Upcoming Projects and Stuff

I have a ton of stuff I'm really excited about working on. I'll try to keep this blog updated so people can keep up with me, now that I've got some free time.
  • My Web site (rather than just being a redirect to Blogger)
  • A Web site for Mike Bliss (the magician)
  • A health Web site
  • Python baseball sim
  • Learn Groovy
  • Implement a half dozen different design patterns using javascript, and make them available on my Web site

Load Speed

Something often overlooked by people outside the web development industry is page load speed. Plenty of people know it's importance, but yet, it often takes a back seat to presentation on Web sites. I'm not going to focus on why it takes the back seat, that would require too many words for a Tuesday. I just want to highlight one of the things I was striving for in my last project.

My last project.* It was a really inexpensive Web site for a small business. One of the items I discussed with the owner of the company was price, and there was no money in it for a designer. Normally, I wouldn't be willing to work on such a site, but I made an exception. I rationalized the time I was going to spend on the project as having the opportunity to really bake a template into Django-cms. You can see the finished project here: jlong.jeremymcneal.com.**

*Not in the final sense, I'm working on some new stuff already. When I retire, I'll still be programming, it's one of my favorite past times.

** There are some odd content things on this site. Ignore those, this isn't the final version.

The template I utilized has absolutely 0 images on it. The files required to download and display the page are under 80k, and 70k of that is jQuery. And when I compress that, I'll be down to under 60k.

it's great to have Web sites that look pretty. But page speed is often under-rated; and often more critical to making a Web site a success, as opposed to just an art piece. Often, if you're doing good work with your css; your site can still be aesthetically pleasing as well as successful.

Warning: Don't get caught up in the details too much. Remember what the purpose of your site is, and focus on how you can best spend your time to improve it's (hopefully) track-able success.* You can be doing everything else right on a site, but if your not doing this on your site, you are wasting your time.

*Google Analytics

Note: it's been awhile since I've written a post, and blogger has really improved their interface.

Please leave a comment. I <3 comments.

Saturday, January 7, 2012

How to win at Tic Tac Toe

I couldn't sleep the other nite. As a result, I ended up thinking about the strategy of Tic Tac Toe. There really isn't a whole lot to think about, but in my head I went through all of the possible game states. Not a difficult feat since the game is both vertically and horizontally symmetrical. In the end, I was able to distill it down to a few basic principles. The center is the most valuable resource in the game. Always go for that. It is part of 4 possible ways to win. Next are the corners. Each of them are part of 3 possible ways to win. The middle outside spots are the worst. They are only able to help you win in 2 ways.

3 | 2 | 3
2 | 4 | 2

3 | 2 | 3

In practice then, if you are the X then you should start the game by taking the middle. If you don't you are likely to lose. The "O" player should then take a corner. If the "O" player takes a middle outside square, then the "X" player should take the corner square next to the spot taken by the "O" player. The "O" will be forced to block the potential cross victory position. The "X" player can now take a middle spot that connects his other two "X" spots, which will create a dual possibility for the win. He can also take any remaining corner spot for a dual win option on the next play.

If the "O" player is wise and takes a corner spot, the game is probably a draw. Almost any move from here creates a domino effect of blocking moves. It should be a draw. However, if the "X" player takes the opposite corner spot, then the "O" player has plenty of choices where the outcome isn't obvious. If they take an adjacent middle outside spot on the next move, then the "X" player may have to block an "O" victory, however the blocking will create the dual win situation for the "X" player. If they take any other middle outside spot, then the "X" player can setup the dual victory as well by taking the most open corner location.

The game does have a few non-obvious traps. If you are the "X" player you CAN win even against a more seasoned player by thinking about the game in terms of spot values.

Wednesday, May 18, 2011

Seriously

It's been over a year since my last post.

What have I been spending my time on the last year?

Mainly a biweekly drive to St. Louis to see my girlfriend, Caroline. We met at the wedding of Toli and Tonya last May, and have been driving back and forth ever since. That's been the most exciting thing for me over the last 360 days.

I'm still at K-Land in Branson. I still do web development. I still do ASP.net. However, I'm getting to shift some of my work to Django which is a web framework written in my still favorite language: Python. I'm still here. I'm still alive.

Technologies that I think are cool: Linux, Python, Android, HTC Sense, Git, Django, Mootools, Django-cms, Amazon S3, Zinnia, and StarCraft II.

Speaking of Zinnia, I've decided I'm soon going to move my blog over to Zinnia.

I really want to post at least once a month, that's always been my goal for this blog.

Thursday, June 10, 2010

Alberto Callaspo vs Wilson Betemit

From May through July 22nd, 2010; Alberto Callaspo was the starting Royals third baseman, and had been one of the most productive bats in 2009 for Kansas City. He was traded to the Angels to help them upgrade at third base and provide some depth. Although in the offseason most fans thought that Callaspo's bat needed to be in the lineup, very few were upset over the trade that sent him packing.

And for the remainder of the season, we get to watch Wilson Betemit handle the duties at Third Base. Wilson Betemit, who is too old to be a real prospect (he is 28 years old), but who started the season at Triple A Omaha. Presumably because no other Major League team wanted him. The reason for this was simple. He wasn't very good. This year, in limited duty, he's been getting the job done. In fact, he's been better than Alberto Callaspo. It's logical to assume that this is because of small sample size. But, looking closely at the data, it appears that he may have figured something out. He's improved in two key areas of plate discipline. He is swinging at fewer pitches outside the strike zone, and he has been good at making contact on pitches inside the strike zone. The result? 30 hits in 96 plate appearances and 12 walks. He's certainly gotten lucky on some of those batted balls, but he's also a good bet to make solid contact. In the only two seasons where he saw any kind of regular duty at the Major League level he slugged 32 homers in 696 At Bats; and that happened when he was just 24 and 25 years old. He has a history of power.

Using my own baseball sim, which is heavily dependent on Plate Discipline, his batting average should be around .260 - .320 (usually around .290) with solid OBP numbers between .320-.360. He should post a slg in the 475 - 525 range, which is pretty solid. His numbers are very comparable to Alberto Callaspo, but with a touch more power. Wilson Betemit is a good guy to have around. He'll be a solid regular and a fantastic backup who should get to see playing time almost every day. And if you want to give him 600 ABs, he might reward you with 30 homeruns, and is a pretty good bet for 15 homers. He's not a defensive sub though, so he should probably stay in the American League. Hello Betemit, you're our new Callaspo. Let's hope his new found plate discipline isn't a mirage.

Here's the quote I lean on for belief that he actually HAS changed his approach:
"I just wanted to go up there and have quality at-bats," Betemit said. "I didn't want to just go up there and swing. I want to go up there, get a good a good pitch to hit and have a good at-bat." [kcroyals.com Betemit primed...]

My sim's line for Wilson Betemit: .300/.343/.543 (that's avg, obp, and slg) with an OPS of .886 and an iso of .212 in 580 Plate Appearances. that includes 35 walks and 18 homeruns.

My sim is much less friendly to Alberto Callaspo. .284/.308/.515 with an OPS of .823 and an iso of .214 in 516 Plate Appearances. Good for 16 homeruns and 17 walks.

Monday, February 1, 2010

2015, Google Eats World

The Web has taken over. It eats into the lives of just about every American. People pay bills, taxes, search for services, and friends on the Internet. In 2005, it started it's near domination of the media market. New technologies were pushing the envelope and people onto the Web. In 2010, portable Web has become a force, and social media has become a part of our lives. In 2015, we will all be robots, plugged into the matrix and providing battery power to CSS3, HTML 5, Javascript, and the Google Mothership.

The Web has come a long way from where it was in 2005. In 2005, Internet explorer dominated the browser world. Macromedia Flash was the big ticket item in advanced Web sites. Only a few Web sites used Javascript, and only sparingly, because it was so difficult to maintain. Few people cared if their Web site worked outside of Internet Explorer 6. Java Applets were still in use, but were fading. The reigning Web server technology was Classic ASP and Sun's Java on the Tomcat Server. I was just out of College and couldn't grow a beard.

In 2010, the Web has matured as a mixed content medium, challenging traditional media in every aspect. Competition in the browser market is heavy, forcing massive change and improvement to the Web. Adobe Flash has become more on the fringe, primarily used for serving video content. Javascript using advanced frameworks has become the norm in all Web sites, and AJAX has become the big thing. The server side tech has been changed, but not yet matured. ASP.Net is now at version 3 and is largely the same framework in 2005. PHP has been updated and has progressed, but not that much. Web frameworks have become much more popular, either built on PHP or the typical LAMP stack. And I remember 2005 fondly, when I walked up the hill both ways in the lava, and the Sun was bigger than the Beates, and people still had moral character.

The Web in 2015 will see lots of gradual change to it's traditional browser market, but lots of change as new products utilize Web access. Items such as the iPhone and Google's Droid will really push the the future of the Web to new dimensions. Screens will get larger, while mobile devices will create a different platform entirely. The big winner will be the Web frameworks that will handle the browser and device and providing the proper template and appearance for the given medium while maintaining a single place for all Web content. HTML 5, CSS 3, and JavaScript will largely kill 3rd party browser plug-ins such as Adobe Flash. Web frameworks will finally mature and truly enable the fast and seamless production of most Web sites, while providing simple mechanisms for large corporations to be able to offer Off the Shelf Web site plug-ins for the most typical of needs (such as credit card processing). Social Media will play a big role in what Web Application framework eventually takes over. Facebook will have at least one major and serious competitor, and that will be a Google + OpenSocial duo-thing driven largely be the Android and iPhone devices of tomorrow. Our phones will have input devices that map to the back of our heads so we can plug-in to the matrix at any time and any place, ready for Google to search our very brains, nay, our souls even. I will fondly remember the good ole days of self thought and self determination, a place where people still believe in love and cherished those who actually are close to them, instead of half a world away.

The Web will change, but slower than we might think. Many traditional Web sites will still be around, but there will be a whole new wave of products that might take over. Mobile browsing will be the norm, and new cutting edge products will propel the mobile, non-traditional Web. It's not unlikely that giant global catastrophes will have largely halted progress on the Web, but barring such contingency, the future is still a place of increased Web usage.

Friday, April 24, 2009

Puerto Rico: the Album

I will be adding more as I go along, so check back tomorrow.

Wednesday, April 22, 2009

Puerto Rico: Day 1

Today was spent at the Beach, swimming and snorkeling. We also visited a secluded and stunning waterfall that Morgan's uncle Kelly knew. I'll post some pictures later. The Beach we visited was Crash Boat Beach. Take a look: http://www.panoramio.com/photo/1585423. We had BBQ chicken on a stick called Pinchos for Lunch. And dinner was home-made Morgan Wyatt Spaghetti.

Everyone here speaks Spanish, and some speak English. I was a bit surprised, it's pretty bi-lingual, but not as much as expected. We didn't have any problems.

We are staying at a little 3 bedroom house, probably around 1000 square feet at most. The bedrooms are air conditioned, but the rest isn't. Free WIFI though. It's roughly 80 degrees here, I think. I'm pretty happy with that :)

Friday, January 16, 2009

10 Years of Coding

I just realized that I have been writing code for roughly 10 years now. Well in 1999, I wrote my first "Hello World" program in Fundamentals of Computer Science.

Coding is fun. But it's not as easy as I thought it was going to be. Development time is measurable in months, not days. Pouring 100 hours into a project is just starting the project. Architecting the app is fun. But you never feel done.

I write most of my code in JavaScript and VB. 7 years ago I would have thought myself a drop-out of "real" programming. To be honest, in business, you rarely venture into the unknown because the expense is also unknown; and that is bad. But, both JavaScript and VB are not what they were 7 years ago. VB is as *real* as Python, although not as nearly as awesome; and JavaScript is fun because the results are almost always something interactive and tangible feeling.

10 years ago, I thought one programmer could write "Windows" in a decade, and do it better. Turns out coding is harder than I thought.

In 2000, I said that Linux would replace Windows by 2005. I was wrong. But Linux surpassed Windows in overall quality in 2007 (obviously my opinion).

I always thought I'd be coding really cool things in my spare time. Since I code all day. At night, I don't want too. I thought I would be able to code both at work and for fun at night. That appears not to be the case.

HTML is still here. Cross Browser testing is worse than ever before. Web site development is more difficult. The internet is more useful with Google, Pandora, Stumbleupon, Hulu, Facebook, Friend's Blogs, de-centralized news, etc.

Before you were a programmer what was your biggest misconception?

Tuesday, January 13, 2009

Old Code is Bad Code?

For the last six months or so, I've entertained myself far too much with Stumbleupon. I ran across this post (Never Fall in Love with Your Code, Because it's Crap). The basic premise is that what you once thought was great code, you have come to realize wasn't so great. I find this to be mostly false.

Sometimes I look back at code I wrote, and think. This is disgusting. Sometimes, I look back and think, that was brilliant. Actually, I rarely ever think my code is brilliant. I just try to make things work in a clear manner. That clear manner part sometimes gets me in trouble. I do things the hard way sometimes because I want to maintain that clean manner. And sometimes I don't. The times I don't are the times I will not look upon favorable in the future. Even if I do small, smart things within the large stupid framework I've made.

In some respects, I think I've grown dimmer. But I do have more experience and can solve *most* problems better. I think this is age. Older and slower, but more sure and reliable.

What about the other coders who read my blog? Do you think of all your old code as terrible, and the new code as great?

Wednesday, December 3, 2008

More Pics, Why am I showing you these...

I've created an album titled "Some Foods" on Picasa. So far, there's a shadow on a glass of chocolate milk I was making that reads "Coca-Cola." And what I had for lunch today (the date of this post). Lunch was fantastic. You can see in the picture 4 scrambled eggs, 4 pieces of toast, and hot chocolate. So good. So good.

Wednesday, November 19, 2008

STL LAN 2008



Post of some pictures from a terrific weekend. Thanks Andrew!

Wednesday, November 5, 2008

What determined your vote?

Here is what I try to do when voting... I try to prioritize the most important issues facing the country, and then I try to determine which candidate will most effectively solve those issues.

The single most important issue to me remains, as it has, since I began voting 9 years ago: abortion. The second is the defense of our nation. And the third is taxes.

With those three things in mind, I believe John McCain provided the best chance to solve those issues. I do think Barack Obama is an outstanding leader, but I want someone who will protect the unborn. Barack won't http://www.barackobama.com/2007/07/17/obama_on_judges_supreme_court.php

The defense of America? Barack Obama is oppossed to war, and would, in my opinion, provide a world where a Hitler could prosper. And this is a world that is finally small enough for a one world goverment to take power. http://www.barackobama.com/issues/foreign_policy/index.php#onrussia

What about taxes? This is a deep and divided question. Ultimately, lower taxes and smaller government is my hope. And you can argue the point either way here. McCain likes to say he's a small government man. But I want proof. Obama claims he'll cut taxes on the middle and lower class... While at the same time increasing government beauracracy at home. The national government shouldn't be trying to solve the problems of failed local governments and cities in policing themselves. That should be left to the cities and states.

Ultimately, the abortion issue for me is so great that I would be willing to fight and die to defend the lives of the unborn. And here's some biblical thought on that matter:

“…if the watchman sees the sword coming and does not blow the trumpet to warn the people and the sword comes and takes the life of one of them, that man will be taken away because of his sin, but I will hold the watchman accountable for his blood.” Ezek 33:6

I find this ironic because I would also have been less willing (but still willing) to fight in the American Civil War, or the American Revolution. And just in case there's a question about it: for America and the North. Here's why:

During the revolution, it would have been freedom for individual rights. Freedom from oppression is a cause worth dying for. The North because ending slavery in my country would have been worth dying for; and protecting states rights would have taken a back seat to that goal. Amongst the Northerners who died in the Civil War, there are only 2 reasons they would cite: 1) To end slavery; 2) maintain the union. I would not have been willing to die to maintain the union. (It's a different topic, but should a Christian take another's life for the sake of these things is different than sacrificing one's life for something. I certainly do not advocate murder; lest we be like Cain.)

And this is ironic because I would see ending slavery as the great moral issue from the beginning of the revolution to the emancipation proclamation. And abortion as the great moral issue from Roe vs Wade to beyond tomorrow. Barack Obama is the first African American president and he would not be willing to take a stand for those who cannot stand for themselves, and who have no voice.

Here's a controversial question for everyone. If Barack Obama is not willing to protect the LIFE of those who cannot themselves protect it. Would he have been willing to lay down his life to protect something less consequential... the liberty of his fellow man?

At this point in time, it may seem that it doesn't matter. Perhaps Barack Obama will come to know a personal Lord and savior in Jesus Christ the Son of God. Will he humbly submit to God, and then take up his cross and follow righteousness and truth to whatever place that leads? I can only hope, but so did Daniel when
Nebuchadnezzar was king. And I believe some day I shall meet Nebuchadnezzar in Heaven. Perhaps it won't be a Hebrew slave that Barack Obama gets to see God through, but perhaps a slave to righteousness. (note: you may believe that Barack Obama has already placed his faith in Jesus Christ. I highly doubt this, but I do not know Barack Obama personally.)

For the record I have no doubt that Barack Obama is passionate about his views, he is capable of leading, and he is intelligent. I just doubt his wisdom. How I wish Alan Keyes would have defeated him in Illinois. Perhaps today could have been about President-Elect Alan Keyes. He was both intelligent and wise, it's an easy trade to give up charisma for wisdom.

Tuesday, October 28, 2008

Feed Reader!

I'm just curious as to what people are using to stay updated with all of their friends blogs, and all that RSS data?

I use Google Reader. And I think it's pretty slick. What's your Feed Reader?

I do wish I could publish a list of what I'm keeping track of. Here's some things I track:
  • Christian Science Monitor
  • Slashdot
  • Google Webmaster's Blog
  • My Friend's Blogs
  • Slick Deals
  • KHouse
  • Joel Rosenburg
  • The Royals Authority
  • Andy Braner's The Journey
  • CNET
  • Wired
I don't actually read that much of most of these. I just glance at the headlines.

Friday, October 24, 2008

Freedom to Think... Coming Soon

Can we make FREEDOM an engineered fact in the 21st Century? Eben Moglen seems to think so. Listen carefully and you'll learn how copyright, patents, open source, and technology are part of today's freedom. And by freedom, I mean freedom from tyranny.



Friday, September 26, 2008

Subversion

Does anyone use Subversion for their Version Control? I've been having some issues with it, such as the recursive feature not working. That makes it sucky when I edit my site for a day and then have to go pick through the files to see what I've updated and then commit them.

And then getting lastest files is the same problem. I have to hunt through what's changed.

I use RapidSVN 0.9.6 for my GUI to Subversion. I'm not much on doing things on the command line. I'm really happy with it other than that.

Thursday, July 3, 2008

Tim Oliphant: American Gladiator

Tim Oliphant is competing in the upcoming July 7th episode of American Gladiator. Tim works in the Marketing Department with me at Kanakuk Kamps, and is our media director. He's very talented, and the many videos you find of Kanakuk Kamps on Kanakuk.com is a product of his handy work. In the future look of Kanakuk.com, even more of Tim's work will be on display.

But this upcoming week we are all excited to be watching Tim Oliphant prove that he's the man and that he can take anything Wolf, Titan, Justice, or any of the gladiators can dish out.

Here's the episode Preview:


Tim is a great guy, very friendly and outspoken. I'm pretty sure he'll do well, because he's a very athletic guy, and in great shape.

Monday night 7:00 PM, you should be watching this show!