Skip to content

Commit

Permalink
GPC Report functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
open-risk committed Jan 6, 2022
1 parent ec19023 commit 0503e71
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 38 deletions.
6 changes: 4 additions & 2 deletions docs/source/Reporting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ Reporting

Reports are the primary means to disseminate results of analyses outside the Equinox environment

The Objectives and Results Explorer provides the functionality for extracting business information from the Equinox system. This page provides a basic introduction. Further information is available in the user manuals
Topbar Navigation
-------------------
Reporting functionality is accessed via the topbar menu system. This is defined as part of the core Start app. in the topbar template.


The type of analysis and reporting provided in this section is linked to the objectives set out in the Sustainable Portfolio Management mandate. In its simplest, the end point of an interaction with Equinox is the production of a set of numbers (a Report) about various aspects of the portfolio.

Report Types
~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 5 additions & 1 deletion docs/source/pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ Playbooks

Reporting Pages
-----------------
Reporting Pages are where portfolio managers generate information material to communicate to other stakeholders.
Reporting Pages are where portfolio managers generate information material to communicate to other stakeholders.

Reports are the primary means to disseminate results of analyses outside the Equinox environment

The Objectives and Results Explorer provides the functionality for extracting business information from the Equinox system. The type of analysis and reporting provided in this section is linked to the objectives set out in the Sustainable Portfolio Management mandate.
1 change: 1 addition & 0 deletions portfolio/Asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from django.urls import reverse
from datetime import datetime


ASSET_CLASS_CHOICES = [(0, '(a) Residential'),
(1, '(b) CRE'),
(2, '(c) SME/Corporate'),
Expand Down
104 changes: 80 additions & 24 deletions portfolio/EmissionsSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,38 @@
# SOFTWARE.

from django.db import models
from portfolio.model_choices import *
from django.urls import reverse

# The IPCC Gases
GHG_GAS_CHOICES = [(0, 'CO2e'),
(1, 'CO2'),
(1, 'CH4'),
(1, 'N2O'),
(1, 'SF6'),
(1, 'CF4'),
(1, 'C2F6'),
(1, 'NF3'),
(1, 'CHF3'),
(1, 'CH2F2'),
(1, 'CH3F'),
(1, 'C2HF5'),
(1, 'C2H2F4'),
(1, 'CH2FCF3'),
(1, 'C2H3F3'),
(1, 'C2H4F3'),
(1, 'C2H4F2'),
(1, 'C3HF7'),
(1, 'C3H2F6'),
(1, 'C3H3F5')]

(2, 'CH4'),
(3, 'N2O'),
(4, 'SF6'),
(5, 'CF4'),
(6, 'C2F6'),
(7, 'NF3'),
(8, 'CHF3'),
(9, 'CH2F2'),
(10, 'CH3F'),
(11, 'C2HF5'),
(12, 'C2H2F4'),
(13, 'CH2FCF3'),
(14, 'C2H3F3'),
(15, 'C2H4F3'),
(16, 'C2H4F2'),
(17, 'C3HF7'),
(18, 'C3H2F6'),
(19, 'C3H3F5')]

NOTATION_KEYS = [(0, 'NO'), (1, 'IE'), (2, 'C'),
(3, 'NE'), (4, 'NA')]

DQ_KEYS = [(0, 'L'), (1, 'M'), (2, 'H')]

class EmissionsSource(models.Model):
"""
The Emission Source model holds activity and emissions type data that characterize and quantify the emissions of an Asset.
The Emission Source model holds granular activity and emissions type data that characterize and quantify the emissions of an Asset.
"""
Expand All @@ -63,16 +66,14 @@ class EmissionsSource(models.Model):
help_text="Asset to which this source belongs")

emissions_factor = models.ForeignKey('reference.EmissionFactor', blank=True, null=True, on_delete=models.CASCADE,
help_text="Applicable Emissions Factor")
help_text="Applicable Emissions Factor")

# CHARACTERISTICS

emitted_gas = models.IntegerField(blank=True, null=True,
choices=GHG_GAS_CHOICES,
help_text='Type of GHG Emission. Choose CO2e if already aggregated')



#
# BOOKKEEPING FIELDS
#
Expand All @@ -88,3 +89,58 @@ def get_absolute_url(self):
class Meta:
verbose_name = "Emissions Source"
verbose_name_plural = "Emissions Sources"


class GPCEmissionsSource(models.Model):
"""
The GPC Emission Source model holds aggregated emission data per source that conforms to the GPC reporting recommendations
"""

# IDENTITY

source_identifier = models.CharField(max_length=80, null=True,
help_text='An internal identifier for the source')

# LINKS

gpc_subsector = models.ForeignKey('reference.GPCSector', blank=True, null=True, on_delete=models.CASCADE,
help_text="GPC Emissions (sub)sector to which this source belongs")

# CHARACTERISTICS

notation_key = models.IntegerField(null=True, blank=True, choices=NOTATION_KEYS,
help_text='GPC Notation Key (NO, IE, etc)')

co2_amount = models.FloatField(null=True, blank=True, help_text='CO2 amount in tonnes')
ch4_amount = models.FloatField(null=True, blank=True, help_text='CH4 amount in tonnes')
n2o_amount = models.FloatField(null=True, blank=True, help_text='N2O amount in tonnes')
hfc_amount = models.FloatField(null=True, blank=True, help_text='HFC amount in tonnes')
pfc_amount = models.FloatField(null=True, blank=True, help_text='PFC amount in tonnes')
sf6_amount = models.FloatField(null=True, blank=True, help_text='SF6 amount in tonnes')
nf3_amount = models.FloatField(null=True, blank=True, help_text='NF3 amount in tonnes')
tco2e_amount = models.FloatField(null=True, blank=True, help_text='Total CO2 equivalent amount in tonnes')
co2b_amount = models.FloatField(null=True, blank=True, help_text='CO2 (b) amount in tonnes')

AD_DQ = models.IntegerField(null=True, blank=True, choices=DQ_KEYS,
help_text='Activity Data Quality Key (L, M, H)')

EF_DQ = models.IntegerField(null=True, blank=True, choices=DQ_KEYS,
help_text='Emission Factor Data Quality Key (L, M, H)')

comments = models.TextField(null=True, blank=True, help_text="Explanatory comments (i.e. description of methods or notation keys used)")
#
# BOOKKEEPING FIELDS
#
creation_date = models.DateTimeField(auto_now_add=True)
last_change_date = models.DateTimeField(auto_now=True)

def __str__(self):
return self.source_identifier

def get_absolute_url(self):
return reverse('portfolio:GPCEmissionsSource_edit', kwargs={'pk': self.pk})

class Meta:
verbose_name = "GPC Emissions Source"
verbose_name_plural = "GPC Emissions Sources"
13 changes: 10 additions & 3 deletions reference/GPCSector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@

from treebeard.mp_tree import MP_Node

GPC_SCOPES = [(0, 'Scope 1'), (1, 'Scope 2'), (2, 'Scope 3')]


class GPCSector(MP_Node):
"""
GPC Sector Category
GPC Sector Category Tree
"""
name = models.CharField(max_length=30)
name = models.CharField(max_length=50, help_text="A concise name")

gpc_ref_no = models.CharField(max_length=10, help_text="The GPC Reference number")

gpc_scope = models.IntegerField(blank=True, null=True, choices=GPC_SCOPES,
help_text="Applicable GHG Emission Scope (Numerical: 1, 2, 3). This is linked to the GPC Reference Number")

description = models.CharField(max_length=200)
description = models.TextField(blank=True, null=True, help_text="Detailed Sectoral Description")

node_order_by = ['name']

Expand Down
20 changes: 17 additions & 3 deletions reference/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
from django.contrib import admin

from django.core import serializers
from django.http import HttpResponse
from treebeard.admin import TreeAdmin
from treebeard.forms import movenodeform_factory
from reference.EmissionFactor import EmissionFactor
from reference.GPCSector import GPCSector

actions = ['export']


@admin.action(description='Export Selected Entries')
def export(self, request, queryset):
response = HttpResponse(content_type="application/json")
serializers.serialize("json", queryset, stream=response)
return response


admin.site.add_action(export)


@admin.register(EmissionFactor)
class EmissionFactorAdmin(admin.ModelAdmin):
"""Emission Factor admin"""
view_on_site = False
search_fields = ['Description', 'Gases', 'Fuel', 'Technology_Practices', 'Regional_Conditions', 'IPCC_Category']
list_display = ('EF_ID', 'IPCC_Category', 'Gases', 'Fuel', 'Value', 'Unit', 'Parameter_Type', 'Description', 'Data_Source')
list_display = (
'EF_ID', 'IPCC_Category', 'Gases', 'Fuel', 'Value', 'Unit', 'Parameter_Type', 'Description', 'Data_Source')
list_filter = ('Parameter_Type',)
save_as = True

Expand Down Expand Up @@ -41,7 +55,7 @@ class GPCSectorAdmin(TreeAdmin):
view_on_site = False
list_display = ('name',)
save_as = True
date_hierarchy = ('creation_date')
# date_hierarchy = ('creation_date')

form = movenodeform_factory(GPCSector)

Expand Down
2 changes: 1 addition & 1 deletion results_explorer/templates/ghg_reduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load humanize %}

{% block title %}
{{ title }} Result Types
{{ title }} GHG Reduction
{% endblock %}

{% block extrahead %}
Expand Down
83 changes: 83 additions & 0 deletions results_explorer/templates/gpc_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{% extends "start/generic.html" %}
{% load static %}
{% load custom_tags %}
{% load humanize %}

{% block title %}
{{ title }} GPC Report
{% endblock %}

{% block extrahead %}
{{ block.super }}
<script type="text/javascript" charset="utf-8"
src="{% static 'results_explorer/js/jquery.dataTables.js' %}"></script>
{% endblock %}

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static 'results_explorer/css/table.css' %}">
{% endblock %}

{% block messages %}
<div class="helpblock">
<p>GPC Report</p>
</div>
{% endblock %}

{% block content %}

<div class="card card-primary card-outline">

<div class="card-body pad table-responsive">


<div class="card card-info">
<div class="card-header">
<h4> GPC Report of GHG Inventory Emissions</h4>
</div>

<div class="card card-body">
<table id="data_list">
<thead>
<tr>
{% for entry in TableHeader %}
<th>
{{ entry }}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for key, value in TableRows.items %}
<tr>
{% for c in value %}
<td>
{{ c }}
</td>
{% endfor %}
</tr>
{% endfor %}

</tbody>

</table>

</div>
</div>

</div>

<script>
$('#data_list').DataTable({
"pagingType": "full_numbers",
"responsive": true,
"bSort": true,
"displayLength": 50,
"autoWidth": true,
"searching": false
});
</script>



{% endblock %}
1 change: 1 addition & 0 deletions results_explorer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

urlpatterns = [
url(r'^ghg_reduction$', views.ghg_reduction, name='ghg_reduction'),
url(r'^gpc_report$', views.gpc_report, name='gpc_report'),
url(r'^result_types$', views.result_types, name='result_types'),
url(r'^results_view/(?P<pk>\d+)$', views.results_view, name='results_view'),
url(r'^visualization_view/(?P<pk>\d+)$', views.visualization_view, name='visualization_view'),
Expand Down
Loading

0 comments on commit 0503e71

Please sign in to comment.