Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Aggrobot

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

 Aggrobot

This is the deck for a talk given at the RubyConf India 2015. The topic was Aggrobot

Avatar for Shadab Ahmed

Shadab Ahmed

April 07, 2015

Other Decks in Technology

Transcript

  1. RubyConf India 2014 " Lightning Talks Blah Blah Blah.....Aggrobot... blah

    blah.. blah.....Full talk would've been so much more awesome, sadly it wasn’t selected L Oh Man I Look so happy but I am sad .. I should definitely select his talk next time
  2. Average score of Sachin Tendulkar against each country Data #

    Scores of Sachin Operation # Average Grouping # Country
  3. $ Score.column_names ["id", "name", "venue", "score", "month", "year", "match_result", "not_out",

    "against", "played_in",…] Table Structure Extremely Denormalized
  4. hash do # group_by :against # select avg_score: avg(:score) #

    iterate end AGGROBOT CODE vs OUTPUT { <against  name>  : {avg_score : <value>} }
  5. def year_grouping Aggrobot.block do hash do group_by :year select avg_score:

    avg(:score) iterate end end end AGGROBOT CODE BLOCK
  6. def year_grouping(sub_grouping = nil) ... sub_grouping ? recurse(sub_grouping) : iterate

    ... end def country_grouping(sub_grouping = nil) ... sub_grouping ? recurse(sub_grouping) : iterate ... end AGGROBOT CODE BLOCK
  7. Average Score of Sachin Tendulkar against each country for each

    year* *Only Top 2 countries by total runs scored, rest should be grouped as `Others`
  8. def country_grouping Aggrobot.block do hash do group_by :against other_group: 'Others',

    sort_by: sum(:score) select avg_score: avg(:score) recurse year_grouping end end end AGGROBOT CODE BLOCK , limit_to: 2,
  9. Total Score, Average Score, Number of Wins of Sachin Tendulkar

    against each country bucket-ized by score* *Buckets of 0-10, 11-30, 31-50, 51-75, 76-100, 101-150, 151-200, 201-300, 301+
  10. SCORE_BUCKETS = [0..10, 11..30, 31..50, 51..75, 76..100, 101..150, 151..200, 201..300,

    301..Float::INFINITY] def score_grouping Aggrobot.block do hash do group_by :score, buckets: SCORE_BUCKETS select avg_score: avg(:score), total_score: sum(:score), wins: count_condition('match_result = "Won"') iterate end end end AGGROBOT CODE BLOCK
  11. Aggrobot.block group_by :a recurse Aggrobot.block group_by :b recurse Aggrobot.block group_by

    :c recurse Aggrobot.block group_by :d Aggrobot.start(rel, block) AGGROBOT CHAINING # rel.group(:a) # rel.where(a: 'a1').group(:b) # rel.where(a: 'a1’).where(b: ‘b1’).group(:c) # rel.where(a: 'a1’).where(b: ‘b1’) .where(c: ‘c1’).group(:d)