Created
March 8, 2011 19:02
-
-
Save gmgent/860786 to your computer and use it in GitHub Desktop.
used to build a string for feeding to flash (like FusionCharts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Stacker | |
| include Utils | |
| attr_reader :chart_to_go | |
| attr_accessor :caption | |
| attr_accessor :start_date | |
| attr_accessor :input_records | |
| attr_accessor :date_string | |
| def initialize(caption, start_date, y_axis) | |
| @caption = caption | |
| @start_date = start_date | |
| @y_axis = y_axis | |
| @input_records = [] | |
| @games = [] | |
| @final = [] | |
| @numrecs=30 | |
| end | |
| def change_numrecs(x) | |
| @numrecs=x.to_i | |
| end | |
| def read_line(title, count, date, year) | |
| @input_records << [title, count, date, year] | |
| end | |
| def build_date_string(differential) | |
| if differential == 0 then | |
| @date_string = "#{pad_month(@start_date.month)}/#{pad_month(@start_date.day)}/#{@start_date.year}" | |
| else | |
| cur_date = @start_date + differential.days | |
| @date_string = "#{pad_month(cur_date.month)}/#{pad_month(cur_date.day)}/#{cur_date.year}" | |
| end | |
| end | |
| def run | |
| build_query | |
| build_it | |
| end | |
| def build_query | |
| collect_game_types | |
| #step through dates and build new final table | |
| #build date string | |
| for i in 1..@numrecs do | |
| build_date_string(i-1) | |
| #loop through games | |
| @games.each do |look_for_this_game| | |
| game_matched_today = false | |
| #now loop through input recs | |
| @input_records.each do |this_line| | |
| if @date_string == this_line[2] && look_for_this_game == this_line[0] | |
| #exact match | |
| @final << [this_line[0], this_line[1], this_line[2], this_line[3]] | |
| game_matched_today = true | |
| end | |
| end | |
| #end game loop | |
| if !game_matched_today then | |
| @final << [look_for_this_game, 0, @date_string, @date_string.split("/")[2]] | |
| end | |
| end #game loop | |
| end # i loop | |
| end | |
| def collect_game_types | |
| #loop through and collect games | |
| @input_records.each do |this_game_type| | |
| @games << this_game_type[0] | |
| end | |
| @games.uniq! | |
| @games | |
| end | |
| def build_it | |
| @chart_to_go = "" | |
| #set | |
| @chart_to_go << "" | |
| #add categories | |
| for i in 1..@numrecs do | |
| build_date_string(i-1) | |
| @chart_to_go << "" | |
| end | |
| @chart_to_go << "" | |
| #add datasets | |
| @games.each do |look_for_this_game| | |
| @chart_to_go << "" | |
| for i in 1..@numrecs do | |
| build_date_string(i-1) | |
| @chart_to_go << "" | |
| end | |
| @chart_to_go << "" | |
| end | |
| @chart_to_go << "" | |
| end | |
| def final | |
| @final | |
| end | |
| def get_value_for_game_day(game, day) | |
| return_val=0 | |
| @final.each do |this_rec| | |
| if this_rec[0] == game && this_rec[2] == day then | |
| return_val = this_rec[1].to_i | |
| end | |
| end | |
| return_val | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment