{"action":"created","comment":{"url":"https://api.github.com/repos/AIFDR/inasafe/pulls/comments/41986843","id":41986843,"diff_hunk":"@@ -0,0 +1,315 @@\n+\n+\n+# coding=utf-8\n+\"\"\"\n+InaSAFE Disaster risk assessment tool developed by AusAid -\n+**Building Exposure Report Mixin Class**\n+\n+Contact : ole.moller.nielsen@gmail.com\n+\n+.. note:: This program is free software; you can redistribute it and/or modify\n+     it under the terms of the GNU General Public License as published by\n+     the Free Software Foundation; either version 2 of the License, or\n+     (at your option) any later version.\n+\"\"\"\n+__author__ = 'Samweli Twesa Mwakisambwe \"Samweli\" <smwltwesa6@gmail.com>'\n+__date__ = '13/10/15'\n+\n+from collections import OrderedDict\n+\n+from safe.utilities.i18n import tr\n+from safe.impact_reports.report_mixin_base import ReportMixin\n+\n+import safe.messaging as m\n+\n+\n+class AreaExposureReportMixin(ReportMixin):\n+    \"\"\"Population specific report.\n+    \"\"\"\n+\n+    def __init__(self):\n+        \"\"\"Area specific report mixin.\n+\n+        .. versionadded:: 3.2\n+\n+        ..Notes::\n+\n+\n+        \"\"\"\n+        self._question = ''\n+        self._areas = {}\n+        self._affected_areas = {}\n+        self._areas_population = {}\n+        self._total_population = 0\n+        self._unaffected_population = 0\n+        self._affected_population = {}\n+        self._other_population_counts = {}\n+\n+    def generate_report(self):\n+        \"\"\"Breakdown by building type.\n+\n+        :returns: The report.\n+        :rtype: list\n+        \"\"\"\n+        message = m.Message()\n+        message.add(m.Paragraph(self.question))\n+        message.add(self.impact_summary())\n+\n+        return message\n+\n+    def impact_summary(self):\n+        \"\"\"The impact summary as per category\n+\n+        :returns: The impact summary.\n+        :rtype: safe.messaging.Message\n+        \"\"\"\n+        message = m.Message(style_class='container')\n+        table = m.Table(style_class='table table-condensed table-striped')\n+        table.caption = None\n+\n+        row = m.Row()\n+        row.add(m.Cell(tr('Area id'), header=True))\n+        row.add(m.Cell(tr('Affected Area (ha)'), header=True))\n+        row.add(m.Cell(tr('Affected Area (%)'), header=True))\n+        row.add(m.Cell(tr('Total (ha)'), header=True))\n+        row.add(m.Cell(tr('Affected People'), header=True))\n+        row.add(m.Cell(tr('Affected People(%)'), header=True))\n+        row.add(m.Cell(tr('Total Number of People'), header=True))\n+\n+        table.add(row)\n+\n+        second_row = m.Row()\n+        second_row.add(m.Cell(tr('All')))\n+        total_affected_area = self.total_affected_areas\n+        total_area = self.total_areas\n+        percentage_affected_area = ((total_affected_area / total_area ) \\\n+                                    if total_area != 0 else 0) * 100\n+        percentage_affected_area = round(percentage_affected_area, 1)\n+\n+        total_affected_population = self.total_affected_population\n+        total_population = self.total_population\n+        percentage_affected_people = ((total_affected_population / total_population ) \\\n+                                    if total_population != 0 else 0) * 100\n+        percentage_affected_people = round(percentage_affected_people, 1)\n+        total_affected_area *= 1e8\n+        total_affected_area = round(total_affected_area, 0)\n+        total_area *= 1e8\n+        total_area = round(total_area, 0)\n+\n+        second_row.add(m.Cell(total_affected_area))\n+        second_row.add(m.Cell(percentage_affected_area))\n+        second_row.add(m.Cell(total_area))\n+        second_row.add(m.Cell(total_affected_population))\n+        second_row.add(m.Cell(percentage_affected_area))\n+        second_row.add(m.Cell(total_population))\n+\n+        table.add(second_row)\n+\n+        break_row = m.Row()\n+        break_row.add(m.Cell(tr('Breakdown by Area'), header=True))\n+        table.add(break_row)\n+\n+        areas = self.areas\n+        affected_areas = self.affected_areas\n+\n+        for t, v in areas.iteritems():\n+            affected = affected_areas[t] if t in affected_areas else 0.\n+            single_total_area = v\n+            affected_area_ratio = (affected / single_total_area) if v != 0 else 0\n+\n+            percent_affected = affected_area_ratio * 100\n+            percent_affected = round(percent_affected, 1)\n+            number_people_affected = affected_area_ratio * self.areas_population[t]\n+\n+            # rounding to float without decimal, we can't have number of people with decimal\n+\n+            number_people_affected = round(number_people_affected, 0)\n+\n+            percent_people_affected = ((number_people_affected / self.areas_population[t]) \\","path":"safe/impact_reports/area_exposure_report_mixin.py","position":128,"original_position":128,"commit_id":"09b869dccce5c2e0fc701dd59d375ba46624d77e","original_commit_id":"09b869dccce5c2e0fc701dd59d375ba46624d77e","user":{"login":"timlinux","id":178003,"avatar_url":"https://avatars.githubusercontent.com/u/178003?v=3","gravatar_id":"","url":"https://api.github.com/users/timlinux","html_url":"https://github.com/timlinux","followers_url":"https://api.github.com/users/timlinux/followers","following_url":"https://api.github.com/users/timlinux/following{/other_user}","gists_url":"https://api.github.com/users/timlinux/gists{/gist_id}","starred_url":"https://api.github.com/users/timlinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timlinux/subscriptions","organizations_url":"https://api.github.com/users/timlinux/orgs","repos_url":"https://api.github.com/users/timlinux/repos","events_url":"https://api.github.com/users/timlinux/events{/privacy}","received_events_url":"https://api.github.com/users/timlinux/received_events","type":"User","site_admin":false},"body":"pull left\r\n","created_at":"2015-10-14T12:30:17Z","updated_at":"2015-10-14T12:30:17Z","html_url":"https://github.com/AIFDR/inasafe/pull/2442#discussion_r41986843","pull_request_url":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442","_links":{"self":{"href":"https://api.github.com/repos/AIFDR/inasafe/pulls/comments/41986843"},"html":{"href":"https://github.com/AIFDR/inasafe/pull/2442#discussion_r41986843"},"pull_request":{"href":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442"}}},"pull_request":{"url":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442","id":47645563,"html_url":"https://github.com/AIFDR/inasafe/pull/2442","diff_url":"https://github.com/AIFDR/inasafe/pull/2442.diff","patch_url":"https://github.com/AIFDR/inasafe/pull/2442.patch","issue_url":"https://api.github.com/repos/AIFDR/inasafe/issues/2442","number":2442,"state":"open","locked":false,"title":"Added new IF Classified polygon hazard on polygon people","user":{"login":"Samweli","id":2663775,"avatar_url":"https://avatars.githubusercontent.com/u/2663775?v=3","gravatar_id":"","url":"https://api.github.com/users/Samweli","html_url":"https://github.com/Samweli","followers_url":"https://api.github.com/users/Samweli/followers","following_url":"https://api.github.com/users/Samweli/following{/other_user}","gists_url":"https://api.github.com/users/Samweli/gists{/gist_id}","starred_url":"https://api.github.com/users/Samweli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Samweli/subscriptions","organizations_url":"https://api.github.com/users/Samweli/orgs","repos_url":"https://api.github.com/users/Samweli/repos","events_url":"https://api.github.com/users/Samweli/events{/privacy}","received_events_url":"https://api.github.com/users/Samweli/received_events","type":"User","site_admin":false},"body":"Added the new IF from experimental branch.\r\nAnalysis setup\r\n\r\n![analysis_setup](https://cloud.githubusercontent.com/assets/2663775/10481860/621b26c2-727c-11e5-9028-aa21398584ba.png)\r\n\r\n\r\nAnalysis results\r\n![analysis_results](https://cloud.githubusercontent.com/assets/2663775/10481865/6a1dd810-727c-11e5-8b6c-311860bb08e6.png)\r\n\r\n\r\n","created_at":"2015-10-14T11:11:17Z","updated_at":"2015-10-14T12:30:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f62b68f69cfa903cdb23d55c0ce4dcb36400e262","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442/commits","review_comments_url":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442/comments","review_comment_url":"https://api.github.com/repos/AIFDR/inasafe/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AIFDR/inasafe/issues/2442/comments","statuses_url":"https://api.github.com/repos/AIFDR/inasafe/statuses/09b869dccce5c2e0fc701dd59d375ba46624d77e","head":{"label":"Samweli:develop","ref":"develop","sha":"09b869dccce5c2e0fc701dd59d375ba46624d77e","user":{"login":"Samweli","id":2663775,"avatar_url":"https://avatars.githubusercontent.com/u/2663775?v=3","gravatar_id":"","url":"https://api.github.com/users/Samweli","html_url":"https://github.com/Samweli","followers_url":"https://api.github.com/users/Samweli/followers","following_url":"https://api.github.com/users/Samweli/following{/other_user}","gists_url":"https://api.github.com/users/Samweli/gists{/gist_id}","starred_url":"https://api.github.com/users/Samweli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Samweli/subscriptions","organizations_url":"https://api.github.com/users/Samweli/orgs","repos_url":"https://api.github.com/users/Samweli/repos","events_url":"https://api.github.com/users/Samweli/events{/privacy}","received_events_url":"https://api.github.com/users/Samweli/received_events","type":"User","site_admin":false},"repo":{"id":39379262,"name":"inasafe","full_name":"Samweli/inasafe","owner":{"login":"Samweli","id":2663775,"avatar_url":"https://avatars.githubusercontent.com/u/2663775?v=3","gravatar_id":"","url":"https://api.github.com/users/Samweli","html_url":"https://github.com/Samweli","followers_url":"https://api.github.com/users/Samweli/followers","following_url":"https://api.github.com/users/Samweli/following{/other_user}","gists_url":"https://api.github.com/users/Samweli/gists{/gist_id}","starred_url":"https://api.github.com/users/Samweli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Samweli/subscriptions","organizations_url":"https://api.github.com/users/Samweli/orgs","repos_url":"https://api.github.com/users/Samweli/repos","events_url":"https://api.github.com/users/Samweli/events{/privacy}","received_events_url":"https://api.github.com/users/Samweli/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Samweli/inasafe","description":"InaSAFE - QGIS plugin for estimating impact from natural disasters","fork":true,"url":"https://api.github.com/repos/Samweli/inasafe","forks_url":"https://api.github.com/repos/Samweli/inasafe/forks","keys_url":"https://api.github.com/repos/Samweli/inasafe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Samweli/inasafe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Samweli/inasafe/teams","hooks_url":"https://api.github.com/repos/Samweli/inasafe/hooks","issue_events_url":"https://api.github.com/repos/Samweli/inasafe/issues/events{/number}","events_url":"https://api.github.com/repos/Samweli/inasafe/events","assignees_url":"https://api.github.com/repos/Samweli/inasafe/assignees{/user}","branches_url":"https://api.github.com/repos/Samweli/inasafe/branches{/branch}","tags_url":"https://api.github.com/repos/Samweli/inasafe/tags","blobs_url":"https://api.github.com/repos/Samweli/inasafe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Samweli/inasafe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Samweli/inasafe/git/refs{/sha}","trees_url":"https://api.github.com/repos/Samweli/inasafe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Samweli/inasafe/statuses/{sha}","languages_url":"https://api.github.com/repos/Samweli/inasafe/languages","stargazers_url":"https://api.github.com/repos/Samweli/inasafe/stargazers","contributors_url":"https://api.github.com/repos/Samweli/inasafe/contributors","subscribers_url":"https://api.github.com/repos/Samweli/inasafe/subscribers","subscription_url":"https://api.github.com/repos/Samweli/inasafe/subscription","commits_url":"https://api.github.com/repos/Samweli/inasafe/commits{/sha}","git_commits_url":"https://api.github.com/repos/Samweli/inasafe/git/commits{/sha}","comments_url":"https://api.github.com/repos/Samweli/inasafe/comments{/number}","issue_comment_url":"https://api.github.com/repos/Samweli/inasafe/issues/comments{/number}","contents_url":"https://api.github.com/repos/Samweli/inasafe/contents/{+path}","compare_url":"https://api.github.com/repos/Samweli/inasafe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Samweli/inasafe/merges","archive_url":"https://api.github.com/repos/Samweli/inasafe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Samweli/inasafe/downloads","issues_url":"https://api.github.com/repos/Samweli/inasafe/issues{/number}","pulls_url":"https://api.github.com/repos/Samweli/inasafe/pulls{/number}","milestones_url":"https://api.github.com/repos/Samweli/inasafe/milestones{/number}","notifications_url":"https://api.github.com/repos/Samweli/inasafe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Samweli/inasafe/labels{/name}","releases_url":"https://api.github.com/repos/Samweli/inasafe/releases{/id}","created_at":"2015-07-20T11:08:00Z","updated_at":"2015-07-20T11:08:03Z","pushed_at":"2015-10-14T08:03:12Z","git_url":"git://github.com/Samweli/inasafe.git","ssh_url":"git@github.com:Samweli/inasafe.git","clone_url":"https://github.com/Samweli/inasafe.git","svn_url":"https://github.com/Samweli/inasafe","homepage":"www.inasafe.org","size":144142,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"AIFDR:develop","ref":"develop","sha":"f16353426abc9c5fd8f65e2eb0e87e11c4159468","user":{"login":"AIFDR","id":582004,"avatar_url":"https://avatars.githubusercontent.com/u/582004?v=3","gravatar_id":"","url":"https://api.github.com/users/AIFDR","html_url":"https://github.com/AIFDR","followers_url":"https://api.github.com/users/AIFDR/followers","following_url":"https://api.github.com/users/AIFDR/following{/other_user}","gists_url":"https://api.github.com/users/AIFDR/gists{/gist_id}","starred_url":"https://api.github.com/users/AIFDR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AIFDR/subscriptions","organizations_url":"https://api.github.com/users/AIFDR/orgs","repos_url":"https://api.github.com/users/AIFDR/repos","events_url":"https://api.github.com/users/AIFDR/events{/privacy}","received_events_url":"https://api.github.com/users/AIFDR/received_events","type":"Organization","site_admin":false},"repo":{"id":3135721,"name":"inasafe","full_name":"AIFDR/inasafe","owner":{"login":"AIFDR","id":582004,"avatar_url":"https://avatars.githubusercontent.com/u/582004?v=3","gravatar_id":"","url":"https://api.github.com/users/AIFDR","html_url":"https://github.com/AIFDR","followers_url":"https://api.github.com/users/AIFDR/followers","following_url":"https://api.github.com/users/AIFDR/following{/other_user}","gists_url":"https://api.github.com/users/AIFDR/gists{/gist_id}","starred_url":"https://api.github.com/users/AIFDR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AIFDR/subscriptions","organizations_url":"https://api.github.com/users/AIFDR/orgs","repos_url":"https://api.github.com/users/AIFDR/repos","events_url":"https://api.github.com/users/AIFDR/events{/privacy}","received_events_url":"https://api.github.com/users/AIFDR/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AIFDR/inasafe","description":"InaSAFE - QGIS plugin for estimating impact from natural disasters","fork":false,"url":"https://api.github.com/repos/AIFDR/inasafe","forks_url":"https://api.github.com/repos/AIFDR/inasafe/forks","keys_url":"https://api.github.com/repos/AIFDR/inasafe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AIFDR/inasafe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AIFDR/inasafe/teams","hooks_url":"https://api.github.com/repos/AIFDR/inasafe/hooks","issue_events_url":"https://api.github.com/repos/AIFDR/inasafe/issues/events{/number}","events_url":"https://api.github.com/repos/AIFDR/inasafe/events","assignees_url":"https://api.github.com/repos/AIFDR/inasafe/assignees{/user}","branches_url":"https://api.github.com/repos/AIFDR/inasafe/branches{/branch}","tags_url":"https://api.github.com/repos/AIFDR/inasafe/tags","blobs_url":"https://api.github.com/repos/AIFDR/inasafe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AIFDR/inasafe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AIFDR/inasafe/git/refs{/sha}","trees_url":"https://api.github.com/repos/AIFDR/inasafe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AIFDR/inasafe/statuses/{sha}","languages_url":"https://api.github.com/repos/AIFDR/inasafe/languages","stargazers_url":"https://api.github.com/repos/AIFDR/inasafe/stargazers","contributors_url":"https://api.github.com/repos/AIFDR/inasafe/contributors","subscribers_url":"https://api.github.com/repos/AIFDR/inasafe/subscribers","subscription_url":"https://api.github.com/repos/AIFDR/inasafe/subscription","commits_url":"https://api.github.com/repos/AIFDR/inasafe/commits{/sha}","git_commits_url":"https://api.github.com/repos/AIFDR/inasafe/git/commits{/sha}","comments_url":"https://api.github.com/repos/AIFDR/inasafe/comments{/number}","issue_comment_url":"https://api.github.com/repos/AIFDR/inasafe/issues/comments{/number}","contents_url":"https://api.github.com/repos/AIFDR/inasafe/contents/{+path}","compare_url":"https://api.github.com/repos/AIFDR/inasafe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AIFDR/inasafe/merges","archive_url":"https://api.github.com/repos/AIFDR/inasafe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AIFDR/inasafe/downloads","issues_url":"https://api.github.com/repos/AIFDR/inasafe/issues{/number}","pulls_url":"https://api.github.com/repos/AIFDR/inasafe/pulls{/number}","milestones_url":"https://api.github.com/repos/AIFDR/inasafe/milestones{/number}","notifications_url":"https://api.github.com/repos/AIFDR/inasafe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AIFDR/inasafe/labels{/name}","releases_url":"https://api.github.com/repos/AIFDR/inasafe/releases{/id}","created_at":"2012-01-09T10:34:29Z","updated_at":"2015-10-04T16:25:12Z","pushed_at":"2015-10-14T11:11:17Z","git_url":"git://github.com/AIFDR/inasafe.git","ssh_url":"git@github.com:AIFDR/inasafe.git","clone_url":"https://github.com/AIFDR/inasafe.git","svn_url":"https://github.com/AIFDR/inasafe","homepage":"www.inasafe.org","size":167712,"stargazers_count":75,"watchers_count":75,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":80,"mirror_url":null,"open_issues_count":260,"forks":80,"open_issues":260,"watchers":75,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442"},"html":{"href":"https://github.com/AIFDR/inasafe/pull/2442"},"issue":{"href":"https://api.github.com/repos/AIFDR/inasafe/issues/2442"},"comments":{"href":"https://api.github.com/repos/AIFDR/inasafe/issues/2442/comments"},"review_comments":{"href":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442/comments"},"review_comment":{"href":"https://api.github.com/repos/AIFDR/inasafe/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AIFDR/inasafe/pulls/2442/commits"},"statuses":{"href":"https://api.github.com/repos/AIFDR/inasafe/statuses/09b869dccce5c2e0fc701dd59d375ba46624d77e"}}}}