Created
June 5, 2016 05:10
-
-
Save bzz0217/c71f386eaea5d3fc6f0fc39d18d0b444 to your computer and use it in GitHub Desktop.
Qiita - 言語別投稿数推移
This file contains 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
<?php | |
require 'vendor/autoload.php'; | |
ORM::configure('mysql:host=localhost;dbname=qiita'); | |
ORM::configure('username', 'xxxx'); | |
ORM::configure('password', 'xxxx'); | |
$sql = "SELECT CASE WHEN ( `title` like '%php%' OR `body` like '%php%' ) THEN 'PHP' | |
WHEN ( `title` like '%ruby%' OR `body` like '%ruby%' ) THEN 'Ruby' | |
WHEN ( `title` like '%python%' OR `body` like '%python%' ) THEN 'Python' | |
WHEN ( `title` like '%swift%' OR `body` like '%swift%' ) THEN 'Swift' | |
WHEN ( `title` like '%javascript%' OR `body` like '%javascript%' ) THEN 'Javascript' | |
ELSE 'その他' | |
END AS lang | |
, LEFT(`item_created_at`, 7) AS ym | |
, COUNT(*) as cnt | |
FROM `items` | |
GROUP BY lang, ym | |
ORDER BY lang, ym ASC"; | |
$items = ORM::for_table('items')->raw_query($sql)->find_many(); | |
$ym = array(); | |
foreach($items as $rec){ | |
if ($rec->ym!="2015-10"){ | |
$data[$rec->lang][$rec->ym] = $rec->cnt; | |
if (array_search($rec->ym, $ym)===false){ | |
$ym[] = $rec->ym; | |
} | |
} | |
} | |
require_once './view.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment