Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
雑につくるKPIツールのススメ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
TAKAHASHI Kazunari
March 28, 2015
510
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
雑につくるKPIツールのススメ
TAKAHASHI Kazunari
March 28, 2015
More Decks by TAKAHASHI Kazunari
See All by TAKAHASHI Kazunari
fat-settings-yml
1syo
0
890
みなとRuby会議02やりたい
1syo
1
330
Testing Wercker plugin with bats
1syo
0
590
私を変えた1冊の本
1syo
0
860
普通のCSVアップロードフォームを作りたい(改)
1syo
9
1.1k
普通のCSVアップロードフォームを作りたい
1syo
17
3k
kaja-2013
1syo
0
540
untestable production code
1syo
0
560
authorization-for-buktorg
1syo
0
380
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Ruling the World: When Life Gets Gamed
codingconduct
0
250
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
840
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
The Spectacular Lies of Maps
axbom
PRO
1
800
Making Projects Easy
brettharned
120
6.7k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.7k
The browser strikes back
jonoalderson
0
1.2k
Designing Powerful Visuals for Engaging Learning
tmiket
1
410
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
Building Adaptive Systems
keathley
44
3k
Transcript
ࡶʹͭ͘Δ KPIπʔϧͷεεϝ 2015/03/28 Minami.rb ࠷ॳͰ࠷ޙͷLTେձ
ࢲ…. • @1syo • Rails Programmer • Yokohama.rb • 2012
Ruby kaja award winner • MinatoRubyKaig01 organizer • TDDBC Yokohama TA
MinatoRubyKaigi02
ͨͿΜ9݄, 10݄
KPIπʔϧͱʁ • Ϣʔβʔ.. • ച্… • ࣍ɺ݄࣍ɺྦྷܭ.. • Έ͍ͨͳΞϨ..
։ൃͷ࣮… • ϦϦʔεޙ͔Βඞཁ • ཁ͕݅;ΜΘΓ͍ͯ͠Δ • ظͱ͔ͳ͍
Ͳ͔͜ͰखΛൈ͔ͳ͍ͱਏ͍
ࣈͷਖ਼֬͞ > ͍উख
άϥϑ = ࢮ
ͪΐͬͱલͷͭ
#! /bin/sh! host=localhost! database=db! user=dbuser! password=password! ! from_date=`date --date '1
days ago' +\%Y-\%m-\%d`! to_date=`date +\%Y-\%m-\%d`! !
[email protected]
!
[email protected]
! subject=counter! bound=`date +"%Y%m%d%H%M%S"`! filename="filename_$from_date.csv"! ! sql="SELECT * FROM users WHERE created_at BETWEEN $from_date AND $to_date"! result=`mysql -u$user -p$password -h$host $database - e"$sql" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\r\n//g'`!
/usr/sbin/sendmail -t -i <<__MAIL__! From: "$from" ! To: "$to"! Subject:
"$subject"! MIME-Version: 1.0! Content-Type: multipart/mixed; boundary=\"---------"$bound"\"! ! -----------"$bound"! Content-Type: Text/Plain; charset=ISO-2022-JP! Content-Transfer-Encoding: 7bit! ! Now: "$from_date"! ! --! `hostname`! "$from"! ! -----------"$bound"! Content-Type: application/octet-stream! name="$filename"! Content-Transfer-Encoding: base64! Content-Disposition: attachment;! filename="$filename"! ! `echo -e "$result" | base64`! ! -----------"$bound"--! __MAIL__
֓ཁ • mysqlίϚϯυͰSQLΛୟ͍ͯ • ݁ՌΛawkͰCSVʹͯ͠ • mailͷఴϑΝΠϧʹͯ͠ૹ৴
͋ͱΤΫηϧઌੜཔΉʂ
ૂ͍ • SQLͰਖ਼֬ͳࣈΛग़͢ͷʹઐ೦͍ͨ͠ • ΈΜͳେ͖ΤΫηϧઌੜͷݞʹΓ͍ͨ • ؒҧ͍Λࢦఠ͞ΕͨΒ͙ʹमਖ਼͍ͨ͠
Α͍ • SQLͰΞΫηεͰ͖ΕେूܭͰ͖Δ • ߹ʹΑͬͯshellΛۦͯ͠ϑΝΠϧू ܭͰ͖Δ • େྔੜ࢈͍͢͠
ѱ͍ • sendmail͕͑ͳ͍ͱͳ͍ͱख٧·Γ • ʮʓʓ͞Μݟ͍ͨʯ͕݁ߏ໘ • ूܭ݁Ռ͕ࢄ
࠷ۙͷͭ
module KPI! module Summary! class SalesReport! def client! @client ||=
Mysql2::Client.new(! host: Settings.kpi.database.host,! database: Settings.kpi.database.xxxxxxx,! username: config['username'],! password: config['password']! )! end! ! ! ### தུ ####! def collect! sql = <<-__SQL__! select *! from (#লུ...) salse_reports! where placed_at >= '#{start_at}'! and placed_at < '#{end_at}'! order by placed_at! __SQL__! client.query(sql)! end! ! def rows! @rows ||= collect.map { |row| row.values }! end! ! def save! spreadsheet = KPI::GoogleDrive::Collection.new.spreadsheet(@start_at)! sheet = spreadsheet.worksheet(:sales_report, rows)! sheet.clear! sheet.save! end! end! end! end
֓ཁ • msql2 ͰSQLୟ͍ͯ • ݁ՌΛRubyͰΰχϣΰχϣͯ͠ • GoogleDriveʹอଘ͢Δ
͋ͱGoogleઌੜཔΉʂ
ྑ͍ • sendmail͕͍Βͳ͍ • ݖݶ༩͕ΤϯυϢʔβʔͰͰ͖Δ • ूܭ݁Ռͷू͕Ͱ͖Δ • APIܦ༝Ͱ࠶ར༻Ͱ͖Δ •
GoogleDocsͷ͍͢͝ػೳͷԸܙΛड͚ΕΔ
ѱ͍ • OAuthͷ։ൃ໘ • refresh_tokenʹ༗ޮظݶ͕͋Δ • ηϧͷܗࣜࢦఆʹบ͕͋Δ
GoogleDocsͷ͍͢͝ػೳ
QUERYؔ =QUERY(A2:E6,"select count(A) where B > 5”) ूܭʹඞཁͳதؒσʔλΛGoogleDocsʹొ ͢Ε͋ͱˢͰରԠͰ͖ΔΑ͏ʹͳͬͨ
DEMO
ࡶʹߦ͜͏!