Monday, May 10, 2010

Check - It Works!

I figured it out. I have attributes in my Stat database table that the user doesn't provide input for. The value, for the hidden attributes, is gotten from the other attributes that the user does provide input for.

What I did:

In the Model:

before_validation :cache_virtual_columns
def total_points
((twopfgm * 2)+(threepfgm * 3)+(ftm * 1))
end
def field_goal_percent
sprintf("%0.3f", ((twopfgm+threepfgm)/(twopfga+threepfga.to_f)))
end

private
def cache_virtual_columns
self.total_points = total_points
self.field_goal_percent = field_goal_percent
end

In the Form:

%= f.hidden_field :total_points
%= f.hidden_field :field_goal_percent


When a new Stat record is created, it checks the Model and before doing validations does the cache_virtual_columns method. cache_virtual_columns has the total_points and field_goal_percent DB columns equal the value in their method. This updates the Stat record to contain values for each attribute.

Thursday, May 6, 2010

“Always two there are, a master and an apprentice.”


I'm having a blast hacking away on my project. Rails is a fun language to learn. Lately I've been hitting a wall on the execution side. I will be working and get to a point where everything I do isn't working. I know what I want to implement and have an idea of how it should be implemented but nothing seems to work. I run searches to find an example of what to do but come up empty. Things get dark when I am unable to figure it out.


Here's my dilemma, I have a form for a user to enter stats. The user enters 2 point field goals made/attempted, 3 point field goals made/attempted, free throws made/attempted, offensive/defensive rebounds, and others. I have other model attributes that the user doesn't provide input for on the form. They are total points, field goal %, 3 point field goal %, free throw %, and total rebounds. I'm thinking the model can take the attributes the user entered, obtain certain values and perform the calculations to populate the extra attributes all before the record is saved.

For example, to calculate the points scored for the current stat record being created;

# before record saves, do total_points method

before_save :total_points


# calculates total points of current record

def points

@twopoints = :twopfgm * 2

@threepoints = :threepfgm * 3

@onepoints = :ftm * 1

@twopoints + @threepoints + @onepoints

end


private

# update :total_points attribute of record with points

def total_points

stat.update_attribute(:total_points, points)

end



This doesn't work. I'm in the process of figuring this out.

Sunday, May 2, 2010

To Boldly Go Where No Man(Me) Has Gone Before

Captain's log, Stardate 542010.5.

I've been working on my project for week's. The past couple days have been uneventful but I've made excellent progress. I am figuring out the relationships between League, Game, Player, and Stat. I've been learning about nesting resources and nesting models in one form. I've split them into pairs.

League has many Games. Game belongs to League.
Player has many Stats. Stat belongs to Player.

This gives me these routes.

/leagues
/leagues/:id
/leagues/:league_id/games
/leagues/:league_id/games/:id
/players
/players/:id
/players/:player_id/stats
/players/:player_id/stats/:id

Now I am able to create a league with many games and players with many stats. I'm working on getting the players with their stats to belong to a specific game in a specific league. I want to access players on its own so I'm hesitant to nest it. Plus, Rule of thumb: resources should never be nested more than 1 level deep. So I shouldn't do Games to Players to Stats.

I would like to have the form below to create the box score for each game. It will also track each players stats.
It would start with a drop-down menu to choose league. Selecting a league will activate the drop-down menu of games in that league. Selecting a game will do something that will allow me to get the form to choose a player from a drop-down menu and add their stats for that game. And do this for multiple players.

When I view the game I see


May the force be with you.

Tuesday, April 27, 2010

Secret Society of ...

Greetings to All of my Followers ... both of you ... whom I follow more

Hope all is well in your kingdoms.

I call to order the meeting of the Hackers Guild.

Take your seat at the round table.

First order of business, the rules. The first rule of Hackers Guild is you don't talk about Hackers Guild!

Now repeat the mantra:
I don't know who you are. I don't know what you want. If you are looking for ransom, I can tell you I don't have money. But what I do have are a very particular set of skills; skills I have acquired over a very long career. Skills that make me a nightmare for people like you. If you let my computer go now, that'll be the end of it. I will not look for you, I will not pursue you. But if you don't, I will look for you, I will find you, and I will hack you.
I've been locked up in my room hacking away learning what works and what doesn't work with Rails. I've gotten close with google searching, Stack Overflow, and the API's. I've made friends with different gems and git and github for plugins. I'm learning a lot and getting things to work. I just don't know if it's the best way. I got file upload for images working but not for videos. I got authentication up and running. I got a calendar to contain events.

This is all my deliberate practice to learn what I need to implement my own software. My current task is implementing a basketball stat tracking system for one team with a group of players. I've broken it down to 4 models. The models are League, Game, Player, and Stat. I will be able to create a new League that will contain many Games. Each Game will contain the Stats of each Player for that Game. Similar to a box score but only one team. I also want each Player view to show the career stats for each league or year. I'm working on figuring out the relationships between the models. That will help with the routes. I'm also figuring out how to handle fields that require calculating two or more attributes to get the value. Like field goal %, you take the number of field goals made divided by field goals attempted to get the value.

This is my focus.

Is there anything else to discuss?

This closes the meeting of the Hackers Guild.

Live long and prosper

Tuesday, March 30, 2010

Social Networking

I am now on Twitter, Facebook, TechHui, and Blogger. I have no idea what to do with them all. How do I utilize them and for what purpose? Facebook asks "What's on your mind?" Twitter asks "What's happening?" TechHui asks "What brings you here?" Are random thoughts alright? It seems like the way to keep friends and family up to date. I guess I'm still trying to find my voice. What do I want to say?

Friday, February 19, 2010

Practicing Hacking

I am a big believer in deliberate practice. I've done my research and understand the concept. It is "activities designed, typically by a teacher, for the sole purpose of effectively improving specific aspects of an individual's performance (Anders Ericsson)." It's designed to improve performance, it's repeated a lot, feedback on results is continuously available, it's highly demanding mentally, it's difficult, and it requires specific goals.

Integrating Deliberate Practice

Deliberate practice seems straightforward, but I'm having a difficult time integrating it with learning a programming language. I have no problem implementing deliberate practice with sports or playing a musical instrument. These fields have better rules and objectives when measuring success. It is clear to me on how to improve performance for these fields.

If I wanted to improve my dribbling in basketball I would practice with one hand at a time standing still then while moving slow then by moving fast. After I improve I would increase difficulty.

If I wanted to improve in playing the guitar I would practice each chord individually and then practice transitioning from one chord to another.

Knowledge Work

The previous fields are more on the physical side. Learning a programming language is more knowledge work. How do you optimize performance on knowledge work? I'm trying to figure out a systematic approach for building a deliberate practice strategy for learning a programming language.

My Current Process

I am in the process of learning Ruby on Rails. I want to build web applications. I've been hacking on my application getting things done and figuring stuff out but I do not feel I'm becoming a expert Rails programmer. As soon as I solve my task I have forgotten the process I used to figure it out. I see the finished code but cannot quite remember what searches I did that yielded results and what searches didn't. I also wonder how to repeat the process to deliberately practice that new solution. And if my solution is the correct way to do it.

Will building applications and continuous hacking create an expert programmer?

Saturday, January 9, 2010

Self learning

Self learning has been challenging. Building my blog website application from scratch has been fun but has not been the smoothest experience. I know what I want to implement and need to work to implement the features. The problem is that the work schedule is in my head and not written down. My focus is jumping from one thing to another thing. I'll be working on the layout of the comments and notice something in the comment form I want to improve and switch jobs. And neither one gets fixed. I will be figuring out a schedule of work to do and follow it.