GitHub PullRequestReviewCommentEvent at 2014-12-11 09:16:15
Repository: negawatt-server
Actor: amitaibu
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/Gizra/negawatt-server/pulls/comments/21664903","id":21664903,"diff_hunk":"@@ -511,4 +540,63 @@ protected function getQueryForNormalizedValues() {\n    *  Array of allowed frequencies for that meter type.\n    */\n   abstract protected function getAllowedFrequencies();\n+\n+  /**\n+   * Analyze the processed entities from two consecutive time slices for anomalies.\n+   *\n+   * Currently checks for difference higher than +/- 10%.\n+   * If an anomaly found, generate a warning message.\n+   *\n+   * @param $prev_entities\n+   *  Array of entities from the previous time-slice.\n+   * @param $entities\n+   *  Array of entities from the current time-slice.\n+   */\n+  protected function analyzeEntitiesFromConsecutiveTimeSlices($prev_entities, $entities) {\n+    if (!$entities || !$prev_entities) {\n+      // No entities to compare, nothing to do.\n+      return;\n+    }\n+\n+    // Make field 'rate_type' the prev entities array key.\n+    foreach ($prev_entities as $entity) {\n+      $prev_entities[$entity->rate_type] = $entity;\n+    }\n+\n+    // Go through rate types, and look for anomaly.\n+    foreach ($entities as $entity) {\n+      $avg_power = $entity->avg_power;\n+      $prev_avg_power = $prev_entities[$entity->rate_type]->avg_power;\n+      if ($prev_avg_power) {\n+        $avg_power_diff = $avg_power / $prev_avg_power;\n+        if ($avg_power_diff < 0.90 || $avg_power_diff > 1.10) {\n+          // Avg power difference is suspicious, put an alert\n+          $node = $this->getMeterNode();\n+          // Get account node (OG audience reference).\n+          $wrapper = entity_metadata_wrapper('node', $node);\n+          $account_node = $wrapper->{OG_AUDIENCE_FIELD}->value();\n+          // Prepare message arguments.\n+          $arguments = array(\n+            '!meter_url' => l($node->title, 'node/' . $node->nid),\n+            '!account_url' => l($account_node->title, 'node/' . $account_node->nid),\n+            '@location' => $wrapper->field_place_address->value() .', ' . $wrapper->field_place_locality->value(),\n+            '@date' => date('Y-m-d H:i', $this->getTimestampBeginning()),\n+            '@rate_type' => $this->getRateType(),\n+            '@frequency' => $this->getFrequency(),\n+            '@description' => format_string('Average consumption at current month (@cur_avg_power) differs by more than 10% from previous month (@prev_avg_power).',","path":"negawatt/modules/custom/negawatt_normalizer/plugins/electricity_normalizer/ElectricityNormalizerBase.php","position":128,"original_position":128,"commit_id":"d7ed7863da1f61a9654d63237b290c1f9e5e9a04","original_commit_id":"d7ed7863da1f61a9654d63237b290c1f9e5e9a04","user":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"body":"move to the message template, and just capture the ``cur_avg_power``, ``prev_avg_power`` arguments","created_at":"2014-12-11T09:16:15Z","updated_at":"2014-12-11T09:16:15Z","html_url":"https://github.com/Gizra/negawatt-server/pull/144#discussion_r21664903","pull_request_url":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144","_links":{"self":{"href":"https://api.github.com/repos/Gizra/negawatt-server/pulls/comments/21664903"},"html":{"href":"https://github.com/Gizra/negawatt-server/pull/144#discussion_r21664903"},"pull_request":{"href":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144"}}},"pull_request":{"url":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144","id":25631745,"html_url":"https://github.com/Gizra/negawatt-server/pull/144","diff_url":"https://github.com/Gizra/negawatt-server/pull/144.diff","patch_url":"https://github.com/Gizra/negawatt-server/pull/144.patch","issue_url":"https://api.github.com/repos/Gizra/negawatt-server/issues/144","number":144,"state":"open","locked":false,"title":"Implement alerts","user":{"login":"shahardo","id":4487099,"avatar_url":"https://avatars.githubusercontent.com/u/4487099?v=3","gravatar_id":"","url":"https://api.github.com/users/shahardo","html_url":"https://github.com/shahardo","followers_url":"https://api.github.com/users/shahardo/followers","following_url":"https://api.github.com/users/shahardo/following{/other_user}","gists_url":"https://api.github.com/users/shahardo/gists{/gist_id}","starred_url":"https://api.github.com/users/shahardo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahardo/subscriptions","organizations_url":"https://api.github.com/users/shahardo/orgs","repos_url":"https://api.github.com/users/shahardo/repos","events_url":"https://api.github.com/users/shahardo/events{/privacy}","received_events_url":"https://api.github.com/users/shahardo/received_events","type":"User","site_admin":false},"body":"#141 ","created_at":"2014-12-07T12:57:17Z","updated_at":"2014-12-11T09:16:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3303a0169fee3100a8cd865c3729acc914c12470","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144/commits","review_comments_url":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144/comments","review_comment_url":"https://api.github.com/repos/Gizra/negawatt-server/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Gizra/negawatt-server/issues/144/comments","statuses_url":"https://api.github.com/repos/Gizra/negawatt-server/statuses/d7ed7863da1f61a9654d63237b290c1f9e5e9a04","head":{"label":"Gizra:141","ref":"141","sha":"d7ed7863da1f61a9654d63237b290c1f9e5e9a04","user":{"login":"Gizra","id":2484795,"avatar_url":"https://avatars.githubusercontent.com/u/2484795?v=3","gravatar_id":"","url":"https://api.github.com/users/Gizra","html_url":"https://github.com/Gizra","followers_url":"https://api.github.com/users/Gizra/followers","following_url":"https://api.github.com/users/Gizra/following{/other_user}","gists_url":"https://api.github.com/users/Gizra/gists{/gist_id}","starred_url":"https://api.github.com/users/Gizra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gizra/subscriptions","organizations_url":"https://api.github.com/users/Gizra/orgs","repos_url":"https://api.github.com/users/Gizra/repos","events_url":"https://api.github.com/users/Gizra/events{/privacy}","received_events_url":"https://api.github.com/users/Gizra/received_events","type":"Organization","site_admin":false},"repo":{"id":24016302,"name":"negawatt-server","full_name":"Gizra/negawatt-server","owner":{"login":"Gizra","id":2484795,"avatar_url":"https://avatars.githubusercontent.com/u/2484795?v=3","gravatar_id":"","url":"https://api.github.com/users/Gizra","html_url":"https://github.com/Gizra","followers_url":"https://api.github.com/users/Gizra/followers","following_url":"https://api.github.com/users/Gizra/following{/other_user}","gists_url":"https://api.github.com/users/Gizra/gists{/gist_id}","starred_url":"https://api.github.com/users/Gizra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gizra/subscriptions","organizations_url":"https://api.github.com/users/Gizra/orgs","repos_url":"https://api.github.com/users/Gizra/repos","events_url":"https://api.github.com/users/Gizra/events{/privacy}","received_events_url":"https://api.github.com/users/Gizra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Gizra/negawatt-server","description":"negawatt data server","fork":false,"url":"https://api.github.com/repos/Gizra/negawatt-server","forks_url":"https://api.github.com/repos/Gizra/negawatt-server/forks","keys_url":"https://api.github.com/repos/Gizra/negawatt-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gizra/negawatt-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gizra/negawatt-server/teams","hooks_url":"https://api.github.com/repos/Gizra/negawatt-server/hooks","issue_events_url":"https://api.github.com/repos/Gizra/negawatt-server/issues/events{/number}","events_url":"https://api.github.com/repos/Gizra/negawatt-server/events","assignees_url":"https://api.github.com/repos/Gizra/negawatt-server/assignees{/user}","branches_url":"https://api.github.com/repos/Gizra/negawatt-server/branches{/branch}","tags_url":"https://api.github.com/repos/Gizra/negawatt-server/tags","blobs_url":"https://api.github.com/repos/Gizra/negawatt-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gizra/negawatt-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gizra/negawatt-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gizra/negawatt-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gizra/negawatt-server/statuses/{sha}","languages_url":"https://api.github.com/repos/Gizra/negawatt-server/languages","stargazers_url":"https://api.github.com/repos/Gizra/negawatt-server/stargazers","contributors_url":"https://api.github.com/repos/Gizra/negawatt-server/contributors","subscribers_url":"https://api.github.com/repos/Gizra/negawatt-server/subscribers","subscription_url":"https://api.github.com/repos/Gizra/negawatt-server/subscription","commits_url":"https://api.github.com/repos/Gizra/negawatt-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gizra/negawatt-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gizra/negawatt-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gizra/negawatt-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/Gizra/negawatt-server/contents/{+path}","compare_url":"https://api.github.com/repos/Gizra/negawatt-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gizra/negawatt-server/merges","archive_url":"https://api.github.com/repos/Gizra/negawatt-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gizra/negawatt-server/downloads","issues_url":"https://api.github.com/repos/Gizra/negawatt-server/issues{/number}","pulls_url":"https://api.github.com/repos/Gizra/negawatt-server/pulls{/number}","milestones_url":"https://api.github.com/repos/Gizra/negawatt-server/milestones{/number}","notifications_url":"https://api.github.com/repos/Gizra/negawatt-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gizra/negawatt-server/labels{/name}","releases_url":"https://api.github.com/repos/Gizra/negawatt-server/releases{/id}","created_at":"2014-09-14T07:40:46Z","updated_at":"2014-12-11T08:37:45Z","pushed_at":"2014-12-11T09:04:32Z","git_url":"git://github.com/Gizra/negawatt-server.git","ssh_url":"git@github.com:Gizra/negawatt-server.git","clone_url":"https://github.com/Gizra/negawatt-server.git","svn_url":"https://github.com/Gizra/negawatt-server","homepage":"","size":26186,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":66,"forks":0,"open_issues":66,"watchers":0,"default_branch":"master"}},"base":{"label":"Gizra:112","ref":"112","sha":"0533de29718824cf56861a9d20a65768be4292c1","user":{"login":"Gizra","id":2484795,"avatar_url":"https://avatars.githubusercontent.com/u/2484795?v=3","gravatar_id":"","url":"https://api.github.com/users/Gizra","html_url":"https://github.com/Gizra","followers_url":"https://api.github.com/users/Gizra/followers","following_url":"https://api.github.com/users/Gizra/following{/other_user}","gists_url":"https://api.github.com/users/Gizra/gists{/gist_id}","starred_url":"https://api.github.com/users/Gizra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gizra/subscriptions","organizations_url":"https://api.github.com/users/Gizra/orgs","repos_url":"https://api.github.com/users/Gizra/repos","events_url":"https://api.github.com/users/Gizra/events{/privacy}","received_events_url":"https://api.github.com/users/Gizra/received_events","type":"Organization","site_admin":false},"repo":{"id":24016302,"name":"negawatt-server","full_name":"Gizra/negawatt-server","owner":{"login":"Gizra","id":2484795,"avatar_url":"https://avatars.githubusercontent.com/u/2484795?v=3","gravatar_id":"","url":"https://api.github.com/users/Gizra","html_url":"https://github.com/Gizra","followers_url":"https://api.github.com/users/Gizra/followers","following_url":"https://api.github.com/users/Gizra/following{/other_user}","gists_url":"https://api.github.com/users/Gizra/gists{/gist_id}","starred_url":"https://api.github.com/users/Gizra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gizra/subscriptions","organizations_url":"https://api.github.com/users/Gizra/orgs","repos_url":"https://api.github.com/users/Gizra/repos","events_url":"https://api.github.com/users/Gizra/events{/privacy}","received_events_url":"https://api.github.com/users/Gizra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Gizra/negawatt-server","description":"negawatt data server","fork":false,"url":"https://api.github.com/repos/Gizra/negawatt-server","forks_url":"https://api.github.com/repos/Gizra/negawatt-server/forks","keys_url":"https://api.github.com/repos/Gizra/negawatt-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Gizra/negawatt-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Gizra/negawatt-server/teams","hooks_url":"https://api.github.com/repos/Gizra/negawatt-server/hooks","issue_events_url":"https://api.github.com/repos/Gizra/negawatt-server/issues/events{/number}","events_url":"https://api.github.com/repos/Gizra/negawatt-server/events","assignees_url":"https://api.github.com/repos/Gizra/negawatt-server/assignees{/user}","branches_url":"https://api.github.com/repos/Gizra/negawatt-server/branches{/branch}","tags_url":"https://api.github.com/repos/Gizra/negawatt-server/tags","blobs_url":"https://api.github.com/repos/Gizra/negawatt-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Gizra/negawatt-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Gizra/negawatt-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Gizra/negawatt-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Gizra/negawatt-server/statuses/{sha}","languages_url":"https://api.github.com/repos/Gizra/negawatt-server/languages","stargazers_url":"https://api.github.com/repos/Gizra/negawatt-server/stargazers","contributors_url":"https://api.github.com/repos/Gizra/negawatt-server/contributors","subscribers_url":"https://api.github.com/repos/Gizra/negawatt-server/subscribers","subscription_url":"https://api.github.com/repos/Gizra/negawatt-server/subscription","commits_url":"https://api.github.com/repos/Gizra/negawatt-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Gizra/negawatt-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Gizra/negawatt-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Gizra/negawatt-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/Gizra/negawatt-server/contents/{+path}","compare_url":"https://api.github.com/repos/Gizra/negawatt-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Gizra/negawatt-server/merges","archive_url":"https://api.github.com/repos/Gizra/negawatt-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Gizra/negawatt-server/downloads","issues_url":"https://api.github.com/repos/Gizra/negawatt-server/issues{/number}","pulls_url":"https://api.github.com/repos/Gizra/negawatt-server/pulls{/number}","milestones_url":"https://api.github.com/repos/Gizra/negawatt-server/milestones{/number}","notifications_url":"https://api.github.com/repos/Gizra/negawatt-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Gizra/negawatt-server/labels{/name}","releases_url":"https://api.github.com/repos/Gizra/negawatt-server/releases{/id}","created_at":"2014-09-14T07:40:46Z","updated_at":"2014-12-11T08:37:45Z","pushed_at":"2014-12-11T09:04:32Z","git_url":"git://github.com/Gizra/negawatt-server.git","ssh_url":"git@github.com:Gizra/negawatt-server.git","clone_url":"https://github.com/Gizra/negawatt-server.git","svn_url":"https://github.com/Gizra/negawatt-server","homepage":"","size":26186,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":66,"forks":0,"open_issues":66,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144"},"html":{"href":"https://github.com/Gizra/negawatt-server/pull/144"},"issue":{"href":"https://api.github.com/repos/Gizra/negawatt-server/issues/144"},"comments":{"href":"https://api.github.com/repos/Gizra/negawatt-server/issues/144/comments"},"review_comments":{"href":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144/comments"},"review_comment":{"href":"https://api.github.com/repos/Gizra/negawatt-server/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Gizra/negawatt-server/pulls/144/commits"},"statuses":{"href":"https://api.github.com/repos/Gizra/negawatt-server/statuses/d7ed7863da1f61a9654d63237b290c1f9e5e9a04"}}}}