{"action":"created","comment":{"url":"https://api.github.com/repos/Wikia/app/pulls/comments/44433334","id":44433334,"diff_hunk":"@@ -0,0 +1,152 @@\n+<?php\n+\n+require_once( __DIR__ . '/../Maintenance.php' );\n+\n+/**\n+ * Maintenance script counts current number of recognized templates in content namespaces\n+ *\n+ * @author Kamil Koterba <kamil@wikia-inc.com>\n+ * @ingroup Maintenance\n+ */\n+class TemplateClassificationRecognizedMetricMaintenance extends Maintenance {\n+\n+\t/**\n+\t * Set script options\n+\t */\n+\tpublic function __construct() {\n+\t\tparent::__construct();\n+\n+\t\t$this->mDescription = 'Maintenance script counts current number of recognized templates in content namespaces';\n+\t}\n+\n+\t/**\n+\t * Script entry point\n+\t */\n+\tpublic function execute() {\n+\t\tglobal $wgContentNamespaces, $wgDWStatsDB;\n+\n+\t\t$statsDBRead = wfGetDB( DB_SLAVE, [], $wgDWStatsDB );\n+\t\t$wamTop500 = $this->getWamTop500( $statsDBRead, ( new \\WikiaSQL ) );\n+\n+\t\t$top500CNRecognizedCount = 0;\n+\t\t$top500CNAllCount = 0;\n+\n+\t\tforeach ( $wamTop500 as $wikia ) {\n+\t\t\t$wikiaDBName = WikiFactory::IDtoDB($wikia->wiki_id);\n+\t\t\t$wikiaDBRead = wfGetDB( DB_SLAVE, [], $wikiaDBName );\n+\n+\t\t\t$CNTemplatesOnWikia = $this->getContentNamespacesTemplates( $wikiaDBRead, $wgContentNamespaces );\n+\t\t\t$recognizedTemplates  = $this->getRecognizedTemplatesOnWikia(\n+\t\t\t\t( new TemplateClassificationService() ),\n+\t\t\t\t$wikia->wiki_id\n+\t\t\t);\n+\n+\t\t\t$CNRecognizedTemplates = $this->intersectSets( $CNTemplatesOnWikia, $recognizedTemplates );\n+\n+\t\t\t$top500CNRecognizedCount += count( $CNRecognizedTemplates );\n+\t\t\t$top500CNAllCount += count( $CNTemplatesOnWikia );\n+\t\t}\n+\n+\t\t/*\n+\t\t * Store value in DB\n+\t\t * TODO uncomment and test when storage is ready\n+\t\t */\n+//\t\t$statsDBWrite = wfGetDB( DB_MASTER, [], $wgStatsDB ); // Change DB\n+//\t\t$timestamp = date( 'Y-m-d' );\n+//\t\t$this->setStats( $top500CNRecognizedCount, $top500CNAllCount, $timestamp, $statsDBWrite );\n+\n+\t\t$this->pushGecko( $top500CNRecognizedCount, $top500CNAllCount );\n+\t}\n+\n+\tprivate function getRecognizedTemplatesOnWikia( TemplateClassificationService $tcService, $wikiaId ) {\n+\t\t$templates = $tcService->getTemplatesOnWiki( $wikiaId );\n+\t\tforeach ( $templates as $pageId => $type ) {\n+\t\t\tif ( !$this->isRecognized( $type ) ) {\n+\t\t\t\tunset( $templates[$pageId] );\n+\t\t\t}\n+\t\t}\n+\t\treturn $templates;\n+\t}\n+\n+\tprivate function isRecognized($type) {\n+\t\treturn $type !== TemplateClassificationService::TEMPLATE_UNKNOWN\n+\t\t\t&& $type !== ''\n+\t\t\t&& $type !== 'other';\n+\t}\n+\n+\tprivate function getWamTop500($db, \\WikiaSQL $sql) {\n+\t\treturn $sql->SELECT( 'wiki_id' )\n+\t\t\t->FROM( 'fact_wam_scores' )\n+\t\t\t->WHERE( 'time_id' )->EQUAL_TO( date( 'Y-m-d', time() - 60 * 60 * 24 ) )\n+\t\t\t->ORDER_BY( 'wam_rank' )\n+\t\t\t->LIMIT( 500 )\n+\t\t\t->run($db);\n+\t}\n+\n+\t/**\n+\t * Remove non content templates from list of recognized templates\n+\t */\n+\tprivate function intersectSets( $CNTemplatesOnWikia, $recognizedTemplates ) {\n+\t\t$CNRecognizedTemplates = [];\n+\t\tforeach( $recognizedTemplates as $pageId => $type ) {\n+\t\t\tif ( in_array( $pageId, $CNTemplatesOnWikia ) ) {\n+\t\t\t\t$CNRecognizedTemplates[] = $pageId;\n+\t\t\t}\n+\t\t}\n+\t\treturn $CNRecognizedTemplates;\n+\t}\n+\n+\tprivate function getContentNamespacesTemplates($db, $contentNamespaces) {\n+\t\t$sql = ( new \\WikiaSQL() )\n+\t\t\t->SELECT()->DISTINCT( 'p2.page_id as temp_id' )\n+\t\t\t->FROM( 'page' )->AS_( 'p' )\n+\t\t\t->INNER_JOIN( 'templatelinks' )->AS_( 't' )\n+\t\t\t->ON( 't.tl_from', 'p.page_id' )\n+\t\t\t->INNER_JOIN( 'page' )->AS_( 'p2' )\n+\t\t\t->ON( 'p2.page_title', 't.tl_title' )\n+\t\t\t->WHERE( 'p.page_namespace' )->IN( $contentNamespaces )\n+\t\t\t->AND_( 'p2.page_namespace' )->EQUAL_TO( NS_TEMPLATE )\n+\t\t\t->AND_( 'p.page_id' )->NOT_EQUAL_TO( Title::newMainPage()->getArticleID() );\n+\n+\t\t$pages = $sql->runLoop( $db, function ( &$pages, $row ) {\n+\t\t\t$pages[] = $row->temp_id;\n+\t\t});\n+\n+\t\treturn $pages;\n+\t}\n+\n+\tprivate function setStats( $recognizedCNCount, $totalCNCount, $timestamp, $dbw ) {\n+\t\t( new \\WikiaSQL() )->INSERT( 'recognized_content_namespace_templates_count' )\n+\t\t\t->SET( 'timestamp', $timestamp )\n+\t\t\t->SET( 'recognized_cn', $recognizedCNCount )\n+\t\t\t->SET( 'total_cn', $totalCNCount )\n+\t\t\t->run( $dbw );\n+\t}\n+\n+\tprivate function pushGecko( $top500CNRecognizedCount, $top500CNAllCount ) {\n+\t\tglobal $wgGeckoboardApiKey, $wgGeckoboardPushUrl, $wgTemplateClassificationGeckometerWidgetKey;\n+\n+\t\t$metric = 0;\n+\t\tif( $top500CNAllCount > 0 ) {\n+\t\t\t$metric = $top500CNRecognizedCount / $top500CNAllCount * 100;\n+\t\t}\n+\t\t$data = [\n+\t\t\t\t\"item\" => strval($metric),\n+\t\t\t\t\"min\" => [\"value\" => 0],\n+\t\t\t\t\"max\" => [\"value\" => 100]","path":"maintenance/wikia/TemplateClassificationRecognizedMetric.php","position":136,"original_position":136,"commit_id":"880f3917ddfe2123bf581a5d9dcf50259312542a","original_commit_id":"880f3917ddfe2123bf581a5d9dcf50259312542a","user":{"login":"Grunny","id":230630,"avatar_url":"https://avatars.githubusercontent.com/u/230630?v=3","gravatar_id":"","url":"https://api.github.com/users/Grunny","html_url":"https://github.com/Grunny","followers_url":"https://api.github.com/users/Grunny/followers","following_url":"https://api.github.com/users/Grunny/following{/other_user}","gists_url":"https://api.github.com/users/Grunny/gists{/gist_id}","starred_url":"https://api.github.com/users/Grunny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Grunny/subscriptions","organizations_url":"https://api.github.com/users/Grunny/orgs","repos_url":"https://api.github.com/users/Grunny/repos","events_url":"https://api.github.com/users/Grunny/events{/privacy}","received_events_url":"https://api.github.com/users/Grunny/received_events","type":"User","site_admin":false},"body":"These should use single quotes and be spacey per conventions.","created_at":"2015-11-10T17:03:36Z","updated_at":"2015-11-10T17:03:36Z","html_url":"https://github.com/Wikia/app/pull/8995#discussion_r44433334","pull_request_url":"https://api.github.com/repos/Wikia/app/pulls/8995","_links":{"self":{"href":"https://api.github.com/repos/Wikia/app/pulls/comments/44433334"},"html":{"href":"https://github.com/Wikia/app/pull/8995#discussion_r44433334"},"pull_request":{"href":"https://api.github.com/repos/Wikia/app/pulls/8995"}}},"pull_request":{"url":"https://api.github.com/repos/Wikia/app/pulls/8995","id":50120694,"html_url":"https://github.com/Wikia/app/pull/8995","diff_url":"https://github.com/Wikia/app/pull/8995.diff","patch_url":"https://github.com/Wikia/app/pull/8995.patch","issue_url":"https://api.github.com/repos/Wikia/app/issues/8995","number":8995,"state":"open","locked":false,"title":"CE-2187 Adding maintenance script for calculating TempalteClasssifica…","user":{"login":"kamilkoterba","id":2316139,"avatar_url":"https://avatars.githubusercontent.com/u/2316139?v=3","gravatar_id":"","url":"https://api.github.com/users/kamilkoterba","html_url":"https://github.com/kamilkoterba","followers_url":"https://api.github.com/users/kamilkoterba/followers","following_url":"https://api.github.com/users/kamilkoterba/following{/other_user}","gists_url":"https://api.github.com/users/kamilkoterba/gists{/gist_id}","starred_url":"https://api.github.com/users/kamilkoterba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kamilkoterba/subscriptions","organizations_url":"https://api.github.com/users/kamilkoterba/orgs","repos_url":"https://api.github.com/users/kamilkoterba/repos","events_url":"https://api.github.com/users/kamilkoterba/events{/privacy}","received_events_url":"https://api.github.com/users/kamilkoterba/received_events","type":"User","site_admin":false},"body":"…tion metric\r\nhttps://wikia-inc.atlassian.net/browse/CE-2187\r\n\r\nTable for storage is not created yet so sketch of code for storing in DB is commented for now.\r\nI'd like to have this reviewed to check the metric on production and than add support for storing in DB, as this may be useful for next step which is having chart with metric changes.\r\n\r\nScript will be ran daily. Related chef PR https://github.com/Wikia/chef-repo/pull/7278\r\n\r\nrelated config\r\nhttps://github.com/Wikia/config/pull/1449\r\n\r\n/cc @Wikia/community-engineering @SebastianMarzjan ","created_at":"2015-11-09T13:15:54Z","updated_at":"2015-11-10T17:03:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e21d173e69d0e8e3e0ad8ce4694ee47eaa9a423b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Wikia/app/pulls/8995/commits","review_comments_url":"https://api.github.com/repos/Wikia/app/pulls/8995/comments","review_comment_url":"https://api.github.com/repos/Wikia/app/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wikia/app/issues/8995/comments","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/880f3917ddfe2123bf581a5d9dcf50259312542a","head":{"label":"Wikia:CE-2187-tc-metric","ref":"CE-2187-tc-metric","sha":"880f3917ddfe2123bf581a5d9dcf50259312542a","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":5532313,"name":"app","full_name":"Wikia/app","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/app","description":"Wikia Application Code","fork":false,"url":"https://api.github.com/repos/Wikia/app","forks_url":"https://api.github.com/repos/Wikia/app/forks","keys_url":"https://api.github.com/repos/Wikia/app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/app/teams","hooks_url":"https://api.github.com/repos/Wikia/app/hooks","issue_events_url":"https://api.github.com/repos/Wikia/app/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/app/events","assignees_url":"https://api.github.com/repos/Wikia/app/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/app/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/app/tags","blobs_url":"https://api.github.com/repos/Wikia/app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/app/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/app/languages","stargazers_url":"https://api.github.com/repos/Wikia/app/stargazers","contributors_url":"https://api.github.com/repos/Wikia/app/contributors","subscribers_url":"https://api.github.com/repos/Wikia/app/subscribers","subscription_url":"https://api.github.com/repos/Wikia/app/subscription","commits_url":"https://api.github.com/repos/Wikia/app/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/app/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/app/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/app/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/app/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/app/merges","archive_url":"https://api.github.com/repos/Wikia/app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/app/downloads","issues_url":"https://api.github.com/repos/Wikia/app/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/app/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/app/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/app/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/app/releases{/id}","created_at":"2012-08-23T20:55:58Z","updated_at":"2015-11-04T16:43:48Z","pushed_at":"2015-11-10T16:54:06Z","git_url":"git://github.com/Wikia/app.git","ssh_url":"git@github.com:Wikia/app.git","clone_url":"https://github.com/Wikia/app.git","svn_url":"https://github.com/Wikia/app","homepage":"http://dev.wikia.com","size":1684637,"stargazers_count":92,"watchers_count":92,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":70,"mirror_url":null,"open_issues_count":63,"forks":70,"open_issues":63,"watchers":92,"default_branch":"dev"}},"base":{"label":"Wikia:dev","ref":"dev","sha":"2ce5e4615e05d17dc20ebd847cecab3e376a9a61","user":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"repo":{"id":5532313,"name":"app","full_name":"Wikia/app","owner":{"login":"Wikia","id":1171011,"avatar_url":"https://avatars.githubusercontent.com/u/1171011?v=3","gravatar_id":"","url":"https://api.github.com/users/Wikia","html_url":"https://github.com/Wikia","followers_url":"https://api.github.com/users/Wikia/followers","following_url":"https://api.github.com/users/Wikia/following{/other_user}","gists_url":"https://api.github.com/users/Wikia/gists{/gist_id}","starred_url":"https://api.github.com/users/Wikia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wikia/subscriptions","organizations_url":"https://api.github.com/users/Wikia/orgs","repos_url":"https://api.github.com/users/Wikia/repos","events_url":"https://api.github.com/users/Wikia/events{/privacy}","received_events_url":"https://api.github.com/users/Wikia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Wikia/app","description":"Wikia Application Code","fork":false,"url":"https://api.github.com/repos/Wikia/app","forks_url":"https://api.github.com/repos/Wikia/app/forks","keys_url":"https://api.github.com/repos/Wikia/app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wikia/app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wikia/app/teams","hooks_url":"https://api.github.com/repos/Wikia/app/hooks","issue_events_url":"https://api.github.com/repos/Wikia/app/issues/events{/number}","events_url":"https://api.github.com/repos/Wikia/app/events","assignees_url":"https://api.github.com/repos/Wikia/app/assignees{/user}","branches_url":"https://api.github.com/repos/Wikia/app/branches{/branch}","tags_url":"https://api.github.com/repos/Wikia/app/tags","blobs_url":"https://api.github.com/repos/Wikia/app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wikia/app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wikia/app/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wikia/app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wikia/app/statuses/{sha}","languages_url":"https://api.github.com/repos/Wikia/app/languages","stargazers_url":"https://api.github.com/repos/Wikia/app/stargazers","contributors_url":"https://api.github.com/repos/Wikia/app/contributors","subscribers_url":"https://api.github.com/repos/Wikia/app/subscribers","subscription_url":"https://api.github.com/repos/Wikia/app/subscription","commits_url":"https://api.github.com/repos/Wikia/app/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wikia/app/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wikia/app/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wikia/app/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wikia/app/contents/{+path}","compare_url":"https://api.github.com/repos/Wikia/app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wikia/app/merges","archive_url":"https://api.github.com/repos/Wikia/app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wikia/app/downloads","issues_url":"https://api.github.com/repos/Wikia/app/issues{/number}","pulls_url":"https://api.github.com/repos/Wikia/app/pulls{/number}","milestones_url":"https://api.github.com/repos/Wikia/app/milestones{/number}","notifications_url":"https://api.github.com/repos/Wikia/app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wikia/app/labels{/name}","releases_url":"https://api.github.com/repos/Wikia/app/releases{/id}","created_at":"2012-08-23T20:55:58Z","updated_at":"2015-11-04T16:43:48Z","pushed_at":"2015-11-10T16:54:06Z","git_url":"git://github.com/Wikia/app.git","ssh_url":"git@github.com:Wikia/app.git","clone_url":"https://github.com/Wikia/app.git","svn_url":"https://github.com/Wikia/app","homepage":"http://dev.wikia.com","size":1684637,"stargazers_count":92,"watchers_count":92,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":70,"mirror_url":null,"open_issues_count":63,"forks":70,"open_issues":63,"watchers":92,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Wikia/app/pulls/8995"},"html":{"href":"https://github.com/Wikia/app/pull/8995"},"issue":{"href":"https://api.github.com/repos/Wikia/app/issues/8995"},"comments":{"href":"https://api.github.com/repos/Wikia/app/issues/8995/comments"},"review_comments":{"href":"https://api.github.com/repos/Wikia/app/pulls/8995/comments"},"review_comment":{"href":"https://api.github.com/repos/Wikia/app/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wikia/app/pulls/8995/commits"},"statuses":{"href":"https://api.github.com/repos/Wikia/app/statuses/880f3917ddfe2123bf581a5d9dcf50259312542a"}}}}