Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
164 changes: 7 additions & 157 deletions gqueries/README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,163 +5,13 @@ user wants to know the total co2 emissions of an area, it can request the
ETEngine for gquery `total_co2_emissions` and does not have to worry about
the underlying intricacies.

## Folder structure
## GQL functions

Gqueries have been subdivided into five main categories

1. General: cross sections and global definitions
* Input elements: gqueries that return max and min values for input statements
* Mechanical turk: gqueries for
[Mechanical Turk](https://github.com/quintel/mechanical_turk)
(our rspec-based testing ground)
* Modules: module specific queries
* Output elements: gqueries for charts, dashboard etc.
You can use GQL specific functions, such as `CHILDREN()`. You can find all the
available GQL functions in the [docs]
(https://docs.energytransitionmodel.com/contrib/gql/).

We note that the subdivision of gqueries in folders has only one purpose:
providing the human user with some structure. ETEngine does not 'see' this
structure.
## GQL guidelines

## GQL Syntax

### GQL specific

You can use GQL specific functions, such as `CHILDREN()` that returns the
decendants or a certain Converter in the Graph. You can find [all the
available GQL functions online]
(https://github.com/quintel/documentation/blob/master/general/GQL.md).

### Ruby specific

Since GQLv3, you can use Ruby syntax to the GQL-statements as well, such as

1+1
10 * 0.5 + 10 * 2

You can also use very advanced 'features' of Ruby, such as:

(1..10).inject :+

Please refrain from doing that (too much), since that *usually* makes
the GQL-statements harder to read.

### WARNING: different handling of empty values

Ruby does handle nil values differently than GQL-syntax:

This will just ignore the nil value:

SUM(
1,
2,
nil
)
=> 3

This however wil raise an error.

1 + 2 + nil
=> TypeError: nil can't be coerced into Fixnum

## Styleguide

A lot of different people use our gqueries, so please apply the following
guidelines when writing gqueries.

#### Use (2 spaces) indentation

Please use an indentations of 2 spaces. This keeps everything more or less
together.

Indent everything neatly, please.

#### Try to be condense, if possible

In stead of:

SUM(
PRODUCT(
Q(hv_net_delta_capacity_central),
0.20
),
PRODUCT(
Q(hv_net_delta_capacity_decentral),
0.25
)
)

Use:

Q(hv_net_delta_capacity_central) * 0.2 + Q(hv_net_delta_capacity_decentral) * 0.25

#### Use Ruby syntax on one line

In stead of:

PRODUCT(1,1)

Use:

1 * 1

#### Use GQL syntax on multiple lines

And In stead of:

Q(etflex_score_co2)
+
Q(etflex_score_costs)
+
Q(etflex_score_renewability)

Use:

SUM(
Q(etflex_score_co2),
Q(etflex_score_costs),
Q(etflex_score_renewability)
)

#### Use condense statements

In stead of:

IF(Q(hv_net_capacity_buffer_decentral_check) > 800
,
10
,
20
)

Use condense GQL-syntax:

IF((Q(hv_net_capacity_buffer_decentral_check) > 800),
10,
20
)

So, please put the **commas** at the end of a line.

Or condense ruby-syntax:

Q(hv_net_capacity_buffer_decentral_check) > 800 ? 10 : 20

#### Surround operators with spaces

In stead of:

Q(area_used_for_corn_crops)/AREA(areable_land)*100

Use:

Q(area_used_for_corn_crops) / AREA(areable_land) * 100

#### Do not make your text file wider than 79 characters

Please do not write very long lines. It is bad practice and makes stuff harder
to read. Use a maximum width of **79** characters, beyond that and it does not
turn up nicely in your text editor or on etengine.

## Questions?

Please ask [Chael](https://github.com/ChaelKruip) or
[Dennis](https://github.com/DennisSchoenmakers)
A lot of different people use the gqueries, so please apply the following
guidelines when writing gqueries. See the [docs](https://docs.energytransitionmodel.com/contrib/authoring-gqueries).

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions gqueries/modules/etflex/etflex_electricity_demand.gql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading