Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Aggrobot
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shadab Ahmed
April 07, 2015
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Aggrobot
This is the deck for a talk given at the RubyConf India 2015. The topic was Aggrobot
Shadab Ahmed
April 07, 2015
Other Decks in Technology
See All in Technology
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
210
Webの常識が通じないHTMLメールのダークモード
teamlab
PRO
0
120
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
100
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
190
AI駆動開発の時代になったのでトヨタ生産方式から見直す
terurou
7
6k
Rustuna: Rustによる高速なOptuna実装
pfn
PRO
0
190
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
430
go-sqletch
moznion
0
140
Active Record Connection Adaptersにおける長年の課題に再び取り組む
yahonda
0
140
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
140
夫婦で子育てするための育児標準化
codmoninc
PRO
0
330
WasmをRustにする
sansantech
PRO
0
250
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
Documentation Writing (for coders)
carmenintech
77
5.6k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Transcript
gem 'aggrobot' ! @shadabansari
CONFESSIONS
Not my first talk on Aggrobot at RubyConf India
RubyConf India 2014 " Lightning Talks
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
INCEPTION SUCCESSFUL
Aggrobot Go make me an Aggregation
Aggregations Operations on Data groups
Rails Methods .sum .average .minimum .maximum .count .pluck .group
Example
Average score of Sachin Tendulkar against each country Data #
Scores of Sachin Operation # Average Grouping # Country
$ Score.column_names ["id", "name", "venue", "score", "month", "year", "match_result", "not_out",
"against", "played_in",…] Table Structure Extremely Denormalized
Score .where(name: 'Sachin Tendulkar') .group(:against) .average(:score) CODE
Score .where(name: 'Sachin Tendulkar') .group(:against) .pluck(:name, 'AVG(score)') .to_h CODE WITH
PLUCK
Aggrobot.start(Score.where(name: 'Sachin Tendulkar')) do hash do group_by :against select avg_score:
avg(:score) iterate end end AGGROBOT CODE
hash do # group_by :against # select avg_score: avg(:score) #
iterate end AGGROBOT CODE vs OUTPUT { <against name> : {avg_score : <value>} }
Declarative vs Imperative
Aggrobot.start(Score.where(name: 'Sachin Tendulkar')) do list do group_by :against select avg_score:
avg(:score) iterate end end AGGROBOT CODE with LIST
More Examples
Average score of Sachin Tendulkar against each country for each
year
def year_grouping Aggrobot.block do hash do group_by :year select avg_score:
avg(:score) iterate end end end AGGROBOT CODE BLOCK
module Aggrobot def self.block(&block) block end end AGGROBOT.BLOCK
def country_grouping Aggrobot.block do hash do group_by :against recurse year_grouping
end end end AGGROBOT CODE BLOCK
Function Composition
Aggrobot.start( Score.where(name: 'Sachin Tendulkar'), country_grouping) AGGROBOT CODE
More Functional Code
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
Aggrobot.start( Score.where(name: 'Sachin Tendulkar'), country_grouping(year_grouping)) Aggrobot.start( Score.where(name: 'Sachin Tendulkar'), year_grouping(country_grouping))
AGGROBOT CODE
Extra Constraints
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`
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,
More Constraints
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+
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
def country_grouping Aggrobot.block do hash do group_by :against recurse score_grouping
end end end AGGROBOT CODE BLOCK
Let us Do something crazy
Let us Blow our mind
By Running an aggregation With 600+ queries & Just 4
Aggrobot Blocks
DEMO APP
ARCHITECTURE
SUGAR ARR ARR = ActiveRecord::Relation
PING PONG with ActiveRecord::Relation
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)
AGGREGATION AGGREGATION AGGREGATION AGGREGATION AGGREGATION AGGREGATION AGGREGATION AGGREGATION AGGREGATION AGGREGATION
INCEPTION INCEPTION INCEPTION INCEPTION INCEPTION INCEPTION INCEPTION INCEPTION INCEPTION INCEPTION
Work In Progress
DOCUMENTATION
WHAT DOCUMENTATION ?
CODE
YOU’RE NOT SUPPOSED TO DO THAT !!
% github: shadabahmed/aggrobot
THAT’S ALL !!
QUESTIONS ????
THANK YOU