Heirarchy editor notes

These are some notes on the heirarchy editor object which has been introduced to handle the input of carbon footprint data for food, goods and services.

The purpose of this editor is to provide an relatively extensible tool which allows the user to input GHG data using the coding defined by heirarchies. This editor can:

Examples of the configuration discussed in this document can be viewed in the development implementation of the EPack, which can be viewed here. It needs to be emphasised that:

Previous situation

The code written some years ago was essentially written to one tab, then copied to the other tabs and edited to change names and codes for things.

There were essentially 3 input methods presented:

Heiriarchical factors library

The heirarchical factors library presents a number of heirarchies defined on top of an underlying detailed carbon factor source. At the moment the carbon factor sources are:

Other sources are being discovered and could relatively easily be added.

Reasoning behind the heirarchy editor

This library was initially incorporated into a modified version 3.1 of the EPack, the process of doing this made it very clear that to progress a better foundation was needed, which:

Details of the heirarchy editor

The heirarchy editor is an object which is created under a tab in the EPack. Its is created using a function createheirachyeditor.

createheirarchyeditor

            
                createheirarchyeditor(yeardata, datasection, divid, hcodes, baseheirarchy, editors, options, printit)
            
        

The arguments of createheirarchyeditor are as follows:

The following example shows the code for the food tab, which replaces the previous 433 lines of code:

            
        const food_heirarchy = 'newfood';
        var g_foodheirarchy = null;

        function formFoodTable(yeardata, heirarchy, printit) {
            var hcodes = [
                'newfood'
            ]

            var options = {
                period: 'select',
                hcode: heirarchy
            };
            editors = [
                editortypes.spendsummary,
                editortypes.spendheirarchy,
                editortypes.knownemissions,
                editortypes.individualitems
            ]
            g_foodheirarchy = createheirarchyeditor(yeardata, 'food', 'foodinputs', hcodes, 'coicop', editors, options, printit);

        }
        async function formFood(printit) {
            var yeardata = getYearData();
            formFoodTable(yeardata, food_heirarchy, printit);
            console.log('Formed food table');
        }
        async function formFoodPrint() {
            formFood(true);
        }
        function showFood() {
            if (g_foodheirarchy) {
                g_foodheirarchy.showTable();
            }
        }

            
        

The food tab is populated for the current year when the EPack is initiated by either a call to formFood or formFoodPrint (if printing), it is called again whenever the year is changed.

An instance of the heirarchyeditor (g_foodheirarchy) is created by formFoodTable for the current year and default heirarchy.

hcodes

            
                var hcodes = [
                'newfood'
                ]
            
        

The hcodes array defines what heirarchies are available for editing. In this case there is only one heirarchy so the user doesn't get to choose. In the case of the current goods the hcodes array has 2 elements, so the user gets a choice.

            
                var hcodes = [
                    'epack_goods_ex_services',
                    'simplegoods'
                ]
            
        

options

The options array simply defines a couple of defaults:

            
                var options = {
                    period: 'select',
                    hcode: heirarchy
                };
    
            
        

Here editors which calculate Annual GHG have a list of periods (Weekly, Monthly, Annual) to select from because of period: 'select'. The heirachy passed in to formFoodTable is the default heirarchy for the editor.

editors

This controls which editors are presented to the user, and the order in which they are presented. Within the heirarchy editor the columns presented in each editor are controlled by a set of switches associated with the value chosen from editortypes. This makes deriving another editor with slightly different columns as simple as possible, so for example we could have an editor for byweight which had columns appropriate to input by weight, rather than by spend.

For the current configuration of the food tab editors are configured thus:

            
                editors = [
                    editortypes.spendsummary,
                    editortypes.spendheirarchy,
                    editortypes.knownemissions,
                    editortypes.individualitems
                ]
            
        

When the user first opens the food tab, each editor is shown with a heading, beneath which is a button with a + sign and title. When the button is pressed the editor opens and the + changes to a - (to close the editor). The editors are now described:

editortypes.spendsummary

This editor gives a row for each member of the heirarchy, the user inputs spend and annual GHG emissions are calculated based on the currently selected period for the row.

editortypes.spendheirarchy

This opens up another set of openable buttons for each member of the heirarchy. When a member is opened an editor is shown with a row for each code in the member. In this case the codes are coicop codes. The inputs are stored in a yeardata.coicop in this case, so that these are shared with any heirarchy derived from coicop, regardless of what tab it appears on.

editortypes.knownemissions

This opens an editor where the user adds rows containing emissions, which are totalled. Optionally the user can enter a date and notes (which is recommended)

editortypes.individualemissions

This opens an editor where each row represents a purchase using a code and spend from the baseheirarchy (normally coicop). There is a helper button which presents the current heirarchy from which the user can select the required code. As with knownemissions a user can enter a date and notes. This editor is intended for detailed entry of a basket of goods.

Issues and possible development