GitHub PullRequestReviewCommentEvent at 2014-11-04 15:02:15
Repository: oq-commonlib
Actor: ptormene
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/gem/oq-commonlib/pulls/comments/19807252","id":19807252,"diff_hunk":"@@ -0,0 +1,108 @@\n+#  -*- coding: utf-8 -*-\n+#  vim: tabstop=4 shiftwidth=4 softtabstop=4\n+\n+#  Copyright (c) 2014, GEM Foundation\n+\n+#  OpenQuake is free software: you can redistribute it and/or modify it\n+#  under the terms of the GNU Affero General Public License as published\n+#  by the Free Software Foundation, either version 3 of the License, or\n+#  (at your option) any later version.\n+\n+#  OpenQuake is distributed in the hope that it will be useful,\n+#  but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#  GNU General Public License for more details.\n+\n+#  You should have received a copy of the GNU Affero General Public License\n+#  along with OpenQuake.  If not, see <http://www.gnu.org/licenses/>.\n+\n+import os\n+import logging\n+import collections\n+\n+import numpy\n+from openquake.risklib import scientific\n+from openquake.commonlib import riskmodels, general\n+from openquake.commonlib.calculators import calculators, base, calc\n+from openquake.commonlib.export import export\n+\n+\n+def add_epsilons(assets_by_site, num_samples, seed, correlation):\n+    \"\"\"\n+    Add an attribute named .epsilons to each asset in the assets_by_site\n+    container.\n+    \"\"\"\n+    assets_by_taxonomy = sum(\n+        (general.groupby(assets, key=lambda a: a.taxonomy)\n+         for assets in assets_by_site), {})\n+\n+    for taxonomy, assets in assets_by_taxonomy.iteritems():\n+        logging.info('Building (%d, %d) epsilons for taxonomy %s',\n+                     len(assets), num_samples, taxonomy)\n+        eps_matrix = scientific.make_epsilons(\n+            numpy.zeros((len(assets), num_samples)),\n+            seed, correlation)\n+        for asset, epsilons in zip(assets, eps_matrix):\n+            asset.epsilons = epsilons\n+\n+AggLossCurve = collections.namedtuple(\n+    'AggLossCurve', 'loss_type unit mean stddev')\n+\n+\n+def scenario_risk(riskinputs, riskmodel, monitor):\n+    \"\"\"\n+    Core function for a scenario computation.\n+    :returns:\n+        a dictionary (\"agg\"|\"ins\", loss_type) -> losses\n+    \"\"\"\n+    logging.info('Process %d, considering %d risk input(s) of weight %d',\n+                 os.getpid(), len(riskinputs),\n+                 sum(ri.weight for ri in riskinputs))\n+    with monitor:\n+        result = general.AccumDict()  # agg_type, loss_type -> losses\n+        for loss_type, outs in riskmodel.gen_outputs(riskinputs):\n+            (_assets, _loss_ratio_matrix, aggregate_losses,\n+             _insured_loss_matrix, insured_losses) = outs\n+            result += {('agg', loss_type): aggregate_losses}\n+            if insured_losses is not None:\n+                result += {('ins', loss_type): insured_losses}\n+    return result\n+\n+\n+@calculators.add('scenario_risk')\n+class ScenarioRiskCalculator(base.BaseRiskCalculator):\n+    \"\"\"\n+    Run a scenario risk calculation\n+    \"\"\"\n+    core_func = scenario_risk\n+\n+    def pre_execute(self):","path":"openquake/commonlib/calculators/scenario_risk.py","position":79,"original_position":79,"commit_id":"663a3908fad208694d5f5de74eaf341e579a7c16","original_commit_id":"47d0722d16b8f69d7bd4bde75316b813289bebc0","user":{"login":"ptormene","id":350930,"avatar_url":"https://avatars.githubusercontent.com/u/350930?v=2","gravatar_id":"","url":"https://api.github.com/users/ptormene","html_url":"https://github.com/ptormene","followers_url":"https://api.github.com/users/ptormene/followers","following_url":"https://api.github.com/users/ptormene/following{/other_user}","gists_url":"https://api.github.com/users/ptormene/gists{/gist_id}","starred_url":"https://api.github.com/users/ptormene/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ptormene/subscriptions","organizations_url":"https://api.github.com/users/ptormene/orgs","repos_url":"https://api.github.com/users/ptormene/repos","events_url":"https://api.github.com/users/ptormene/events{/privacy}","received_events_url":"https://api.github.com/users/ptormene/received_events","type":"User","site_admin":false},"body":"Please add a docstring","created_at":"2014-11-04T15:02:15Z","updated_at":"2014-11-04T15:02:15Z","html_url":"https://github.com/gem/oq-commonlib/pull/53#discussion_r19807252","pull_request_url":"https://api.github.com/repos/gem/oq-commonlib/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/gem/oq-commonlib/pulls/comments/19807252"},"html":{"href":"https://github.com/gem/oq-commonlib/pull/53#discussion_r19807252"},"pull_request":{"href":"https://api.github.com/repos/gem/oq-commonlib/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/gem/oq-commonlib/pulls/53","id":23830355,"html_url":"https://github.com/gem/oq-commonlib/pull/53","diff_url":"https://github.com/gem/oq-commonlib/pull/53.diff","patch_url":"https://github.com/gem/oq-commonlib/pull/53.patch","issue_url":"https://api.github.com/repos/gem/oq-commonlib/issues/53","number":53,"state":"open","locked":false,"title":"Examples, tests and notebook for the feature of oq-lite","user":{"login":"micheles","id":2463856,"avatar_url":"https://avatars.githubusercontent.com/u/2463856?v=2","gravatar_id":"","url":"https://api.github.com/users/micheles","html_url":"https://github.com/micheles","followers_url":"https://api.github.com/users/micheles/followers","following_url":"https://api.github.com/users/micheles/following{/other_user}","gists_url":"https://api.github.com/users/micheles/gists{/gist_id}","starred_url":"https://api.github.com/users/micheles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micheles/subscriptions","organizations_url":"https://api.github.com/users/micheles/orgs","repos_url":"https://api.github.com/users/micheles/repos","events_url":"https://api.github.com/users/micheles/events{/privacy}","received_events_url":"https://api.github.com/users/micheles/received_events","type":"User","site_admin":false},"body":"This is the content of the course I gave yesterday. It requires the companion https://github.com/gem/oq-risklib/pull/81. The tests are running here: https://ci.openquake.org/job/zdevel_oq-commonlib/179","created_at":"2014-11-04T13:08:05Z","updated_at":"2014-11-04T15:02:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3c96e69053f40339e16bd75d1d587f931bcf4fa5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gem/oq-commonlib/pulls/53/commits","review_comments_url":"https://api.github.com/repos/gem/oq-commonlib/pulls/53/comments","review_comment_url":"https://api.github.com/repos/gem/oq-commonlib/pulls/comments/{number}","comments_url":"https://api.github.com/repos/gem/oq-commonlib/issues/53/comments","statuses_url":"https://api.github.com/repos/gem/oq-commonlib/statuses/663a3908fad208694d5f5de74eaf341e579a7c16","head":{"label":"gem:oq-lite","ref":"oq-lite","sha":"663a3908fad208694d5f5de74eaf341e579a7c16","user":{"login":"gem","id":316546,"avatar_url":"https://avatars.githubusercontent.com/u/316546?v=2","gravatar_id":"","url":"https://api.github.com/users/gem","html_url":"https://github.com/gem","followers_url":"https://api.github.com/users/gem/followers","following_url":"https://api.github.com/users/gem/following{/other_user}","gists_url":"https://api.github.com/users/gem/gists{/gist_id}","starred_url":"https://api.github.com/users/gem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gem/subscriptions","organizations_url":"https://api.github.com/users/gem/orgs","repos_url":"https://api.github.com/users/gem/repos","events_url":"https://api.github.com/users/gem/events{/privacy}","received_events_url":"https://api.github.com/users/gem/received_events","type":"Organization","site_admin":false},"repo":{"id":8800992,"name":"oq-commonlib","full_name":"gem/oq-commonlib","owner":{"login":"gem","id":316546,"avatar_url":"https://avatars.githubusercontent.com/u/316546?v=2","gravatar_id":"","url":"https://api.github.com/users/gem","html_url":"https://github.com/gem","followers_url":"https://api.github.com/users/gem/followers","following_url":"https://api.github.com/users/gem/following{/other_user}","gists_url":"https://api.github.com/users/gem/gists{/gist_id}","starred_url":"https://api.github.com/users/gem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gem/subscriptions","organizations_url":"https://api.github.com/users/gem/orgs","repos_url":"https://api.github.com/users/gem/repos","events_url":"https://api.github.com/users/gem/events{/privacy}","received_events_url":"https://api.github.com/users/gem/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gem/oq-commonlib","description":"Common libraries for OpenQuake Engine and Desktop Tools","fork":false,"url":"https://api.github.com/repos/gem/oq-commonlib","forks_url":"https://api.github.com/repos/gem/oq-commonlib/forks","keys_url":"https://api.github.com/repos/gem/oq-commonlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gem/oq-commonlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gem/oq-commonlib/teams","hooks_url":"https://api.github.com/repos/gem/oq-commonlib/hooks","issue_events_url":"https://api.github.com/repos/gem/oq-commonlib/issues/events{/number}","events_url":"https://api.github.com/repos/gem/oq-commonlib/events","assignees_url":"https://api.github.com/repos/gem/oq-commonlib/assignees{/user}","branches_url":"https://api.github.com/repos/gem/oq-commonlib/branches{/branch}","tags_url":"https://api.github.com/repos/gem/oq-commonlib/tags","blobs_url":"https://api.github.com/repos/gem/oq-commonlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gem/oq-commonlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gem/oq-commonlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/gem/oq-commonlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gem/oq-commonlib/statuses/{sha}","languages_url":"https://api.github.com/repos/gem/oq-commonlib/languages","stargazers_url":"https://api.github.com/repos/gem/oq-commonlib/stargazers","contributors_url":"https://api.github.com/repos/gem/oq-commonlib/contributors","subscribers_url":"https://api.github.com/repos/gem/oq-commonlib/subscribers","subscription_url":"https://api.github.com/repos/gem/oq-commonlib/subscription","commits_url":"https://api.github.com/repos/gem/oq-commonlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/gem/oq-commonlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/gem/oq-commonlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/gem/oq-commonlib/issues/comments/{number}","contents_url":"https://api.github.com/repos/gem/oq-commonlib/contents/{+path}","compare_url":"https://api.github.com/repos/gem/oq-commonlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gem/oq-commonlib/merges","archive_url":"https://api.github.com/repos/gem/oq-commonlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gem/oq-commonlib/downloads","issues_url":"https://api.github.com/repos/gem/oq-commonlib/issues{/number}","pulls_url":"https://api.github.com/repos/gem/oq-commonlib/pulls{/number}","milestones_url":"https://api.github.com/repos/gem/oq-commonlib/milestones{/number}","notifications_url":"https://api.github.com/repos/gem/oq-commonlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gem/oq-commonlib/labels{/name}","releases_url":"https://api.github.com/repos/gem/oq-commonlib/releases{/id}","created_at":"2013-03-15T14:24:17Z","updated_at":"2014-09-02T07:58:48Z","pushed_at":"2014-11-04T14:28:39Z","git_url":"git://github.com/gem/oq-commonlib.git","ssh_url":"git@github.com:gem/oq-commonlib.git","clone_url":"https://github.com/gem/oq-commonlib.git","svn_url":"https://github.com/gem/oq-commonlib","homepage":"","size":7291,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"gem:master","ref":"master","sha":"0d412a18367e7caffc9cbd2ff539b13ef856d3ee","user":{"login":"gem","id":316546,"avatar_url":"https://avatars.githubusercontent.com/u/316546?v=2","gravatar_id":"","url":"https://api.github.com/users/gem","html_url":"https://github.com/gem","followers_url":"https://api.github.com/users/gem/followers","following_url":"https://api.github.com/users/gem/following{/other_user}","gists_url":"https://api.github.com/users/gem/gists{/gist_id}","starred_url":"https://api.github.com/users/gem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gem/subscriptions","organizations_url":"https://api.github.com/users/gem/orgs","repos_url":"https://api.github.com/users/gem/repos","events_url":"https://api.github.com/users/gem/events{/privacy}","received_events_url":"https://api.github.com/users/gem/received_events","type":"Organization","site_admin":false},"repo":{"id":8800992,"name":"oq-commonlib","full_name":"gem/oq-commonlib","owner":{"login":"gem","id":316546,"avatar_url":"https://avatars.githubusercontent.com/u/316546?v=2","gravatar_id":"","url":"https://api.github.com/users/gem","html_url":"https://github.com/gem","followers_url":"https://api.github.com/users/gem/followers","following_url":"https://api.github.com/users/gem/following{/other_user}","gists_url":"https://api.github.com/users/gem/gists{/gist_id}","starred_url":"https://api.github.com/users/gem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gem/subscriptions","organizations_url":"https://api.github.com/users/gem/orgs","repos_url":"https://api.github.com/users/gem/repos","events_url":"https://api.github.com/users/gem/events{/privacy}","received_events_url":"https://api.github.com/users/gem/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gem/oq-commonlib","description":"Common libraries for OpenQuake Engine and Desktop Tools","fork":false,"url":"https://api.github.com/repos/gem/oq-commonlib","forks_url":"https://api.github.com/repos/gem/oq-commonlib/forks","keys_url":"https://api.github.com/repos/gem/oq-commonlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gem/oq-commonlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gem/oq-commonlib/teams","hooks_url":"https://api.github.com/repos/gem/oq-commonlib/hooks","issue_events_url":"https://api.github.com/repos/gem/oq-commonlib/issues/events{/number}","events_url":"https://api.github.com/repos/gem/oq-commonlib/events","assignees_url":"https://api.github.com/repos/gem/oq-commonlib/assignees{/user}","branches_url":"https://api.github.com/repos/gem/oq-commonlib/branches{/branch}","tags_url":"https://api.github.com/repos/gem/oq-commonlib/tags","blobs_url":"https://api.github.com/repos/gem/oq-commonlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gem/oq-commonlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gem/oq-commonlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/gem/oq-commonlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gem/oq-commonlib/statuses/{sha}","languages_url":"https://api.github.com/repos/gem/oq-commonlib/languages","stargazers_url":"https://api.github.com/repos/gem/oq-commonlib/stargazers","contributors_url":"https://api.github.com/repos/gem/oq-commonlib/contributors","subscribers_url":"https://api.github.com/repos/gem/oq-commonlib/subscribers","subscription_url":"https://api.github.com/repos/gem/oq-commonlib/subscription","commits_url":"https://api.github.com/repos/gem/oq-commonlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/gem/oq-commonlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/gem/oq-commonlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/gem/oq-commonlib/issues/comments/{number}","contents_url":"https://api.github.com/repos/gem/oq-commonlib/contents/{+path}","compare_url":"https://api.github.com/repos/gem/oq-commonlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gem/oq-commonlib/merges","archive_url":"https://api.github.com/repos/gem/oq-commonlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gem/oq-commonlib/downloads","issues_url":"https://api.github.com/repos/gem/oq-commonlib/issues{/number}","pulls_url":"https://api.github.com/repos/gem/oq-commonlib/pulls{/number}","milestones_url":"https://api.github.com/repos/gem/oq-commonlib/milestones{/number}","notifications_url":"https://api.github.com/repos/gem/oq-commonlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gem/oq-commonlib/labels{/name}","releases_url":"https://api.github.com/repos/gem/oq-commonlib/releases{/id}","created_at":"2013-03-15T14:24:17Z","updated_at":"2014-09-02T07:58:48Z","pushed_at":"2014-11-04T14:28:39Z","git_url":"git://github.com/gem/oq-commonlib.git","ssh_url":"git@github.com:gem/oq-commonlib.git","clone_url":"https://github.com/gem/oq-commonlib.git","svn_url":"https://github.com/gem/oq-commonlib","homepage":"","size":7291,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gem/oq-commonlib/pulls/53"},"html":{"href":"https://github.com/gem/oq-commonlib/pull/53"},"issue":{"href":"https://api.github.com/repos/gem/oq-commonlib/issues/53"},"comments":{"href":"https://api.github.com/repos/gem/oq-commonlib/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/gem/oq-commonlib/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/gem/oq-commonlib/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/gem/oq-commonlib/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/gem/oq-commonlib/statuses/663a3908fad208694d5f5de74eaf341e579a7c16"}}}}