Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
corradio committed Apr 18, 2017
1 parent 5e3f3e6 commit bb2a4ab
Show file tree
Hide file tree
Showing 47 changed files with 193 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*secrets*
*.env

app
mobileapp

datascience

Expand Down
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Check the [contributing](#contribute) section for more details.
### Carbon intensity calcuation and data source
The carbon intensity of each country is measured from the perspective of a consumer. It represents the greenhouse gas footprint of 1 kWh consumed inside a given country. The footprint is measured in gCO2eq (grams CO2 equivalent), meaning each greenhouse gas is converted to its CO2 equivalent in terms of global warming potential over 100 year (for instance, 1 gram of methane emitted has the same global warming impact during 100 years as ~20 grams of CO2 over the same period).

The carbon intensity of each type of power plant takes into account emissions arising from the whole lifecyle of the plant (construction, fuel production, operational emissions, and decomissioning). Carbon-intensity factors used in the map are detailed in [co2eq-parameters.js](https://github.com/corradio/electricitymap/blob/master/shared/co2eq_parameters.js). These numbers come from the following scientific peer reviewed litterature:
The carbon intensity of each type of power plant takes into account emissions arising from the whole lifecyle of the plant (construction, fuel production, operational emissions, and decomissioning). Carbon-intensity factors used in the map are detailed in [co2eq-parameters.js](https://github.com/corradio/electricitymap/blob/master/config/co2eq_parameters.js). These numbers come from the following scientific peer reviewed litterature:
- IPCC 2014 Assessment Report is used as reference in most instances (see a summary in the [wikipedia entry](https://en.wikipedia.org/wiki/Life-cycle_greenhouse-gas_emissions_of_energy_sources#2014_IPCC.2C_Global_warming_potential_of_selected_electricity_sources))

Country-specific carbon-intensity factors:
Expand Down Expand Up @@ -140,31 +140,34 @@ Want to help? Join us on slack at [http://slack.tmrow.co](http://slack.tmrow.co)
### Adding a new country
It is very simple to add a new country. The Electricity Map backend runs a list of so-called *parsers* every 5min. Those parsers are responsible to fetch the generation mix for a given country (check out the existing list in the [parsers](https://github.com/corradio/electricitymap/tree/master/parsers) directory, or look at the [work in progress](https://github.com/tmrowco/electricitymap/issues?q=is%3Aissue+is%3Aopen+label%3Aparser)).

A parser is a python script that is expected to return the following datastructure:
A parser is a python script that is expected to define the method `fetch_production` which returns the production mix at current time, in the format:

```python
{
'countryCode': 'FR',
'datetime': '2017-01-01T00:00:00Z',
'production': {
'biomass': 0.0,
'coal': 0.0,
'gas': 0.0,
'hydro': 0.0,
'nuclear': null,
'oil': 0.0,
'solar': 0.0,
'wind': 0.0,
'geothermal': 0.0,
'unknown': 0.0
},
'storage': {
'hydro': -10.0,
},
'source': 'mysource.com'
}
def fetch_production(country_code='FR', session=None):
return {
'countryCode': 'FR',
'datetime': '2017-01-01T00:00:00Z',
'production': {
'biomass': 0.0,
'coal': 0.0,
'gas': 0.0,
'hydro': 0.0,
'nuclear': null,
'oil': 0.0,
'solar': 0.0,
'wind': 0.0,
'geothermal': 0.0,
'unknown': 0.0
},
'storage': {
'hydro': -10.0,
},
'source': 'mysource.com'
}
```

The `session` object is a python request session that you can re-use to make HTTP requests.

The production values should never be negative. Use `null`, or ommit the key, if a specific production mode is not known.
Storage values can be both positive (when storing energy) or negative (when the storage is emptied).

Expand Down
File renamed without changes.
File renamed without changes.
127 changes: 127 additions & 0 deletions config/zones.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"AL": {
"country_iso_a2": "AL"
},
"AT": {
"country_iso_a2": "AT"
},
"BA": {
"country_iso_a2": "BA"
},
"BE": {
"country_iso_a2": "BE"
},
"BG": {
"country_iso_a2": "BG"
},
"BY": {
"country_iso_a2": "BY"
},
"CH": {
"country_iso_a2": "CH"
},
"CZ": {
"country_iso_a2": "CZ"
},
"DE": {
"country_iso_a2": "DE"
},
"DK": {
"country_iso_a2": "DK"
},
"EE": {
"country_iso_a2": "EE"
},
"ES": {
"country_iso_a2": "ES"
},
"FI": {
"country_iso_a2": "FI"
},
"FR": {
"country_iso_a2": "FR"
},
"GB": {
"country_iso_a2": "GB",
"_comment": "Key should be GB-GBN (see https://en.wikipedia.org/wiki/ISO_3166-2:GB)"
},
"GB-NIR": {
"country_iso_a2": "GB",
"flag_file_name": "_Northern%20Ireland.png"
},
"GR": {
"country_iso_a2": "GR"
},
"HR": {
"country_iso_a2": "HR"
},
"HU": {
"country_iso_a2": "HU"
},
"IE": {
"country_iso_a2": "IE"
},
"IS": {
"country_iso_a2": "IS"
},
"IT": {
"country_iso_a2": "IT"
},
"LT": {
"country_iso_a2": "LT"
},
"LU": {
"country_iso_a2": "LU"
},
"LV": {
"country_iso_a2": "LV"
},
"MD": {
"country_iso_a2": "MD"
},
"ME": {
"country_iso_a2": "ME"
},
"MK": {
"country_iso_a2": "MK"
},
"MT": {
"country_iso_a2": "MT"
},
"NL": {
"country_iso_a2": "NL"
},
"NO": {
"country_iso_a2": "NO"
},
"PL": {
"country_iso_a2": "PL"
},
"PT": {
"country_iso_a2": "PT"
},
"RO": {
"country_iso_a2": "RO"
},
"RS": {
"country_iso_a2": "RS"
},
"RU": {
"country_iso_a2": "RU"
},
"SE": {
"country_iso_a2": "SE"
},
"SI": {
"country_iso_a2": "SI"
},
"SK": {
"country_iso_a2": "SK"
},
"TR": {
"country_iso_a2": "TR"
},
"UA": {
"country_iso_a2": "UA"
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ services:
- './web/views:/home/web/views'
- './web/webpack.config.js:/home/web/webpack.config.js'
- './web/locales:/home/web/locales'
- './config:/home/config'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
35 changes: 35 additions & 0 deletions parsers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Adding a new country
It is very simple to add a new country. The Electricity Map backend runs a list of so-called *parsers* every 5min. Those parsers are responsible to fetch the generation mix for a given country (check out the existing list in the [parsers](https://github.com/corradio/electricitymap/tree/master/parsers) directory, or look at the [work in progress](https://github.com/tmrowco/electricitymap/issues?q=is%3Aissue+is%3Aopen+label%3Aparser)).

A parser is a python script that is expected to define the method `fetch_production` which returns the production mix at current time, in the format:

```python
def fetch_production(country_code='FR', session=None):
return {
'countryCode': 'FR',
'datetime': '2017-01-01T00:00:00Z',
'production': {
'biomass': 0.0,
'coal': 0.0,
'gas': 0.0,
'hydro': 0.0,
'nuclear': null,
'oil': 0.0,
'solar': 0.0,
'wind': 0.0,
'geothermal': 0.0,
'unknown': 0.0
},
'storage': {
'hydro': -10.0,
},
'source': 'mysource.com'
}
```

The `session` object is a python request session that you can re-use to make HTTP requests.

The production values should never be negative. Use `null`, or ommit the key, if a specific production mode is not known.
Storage values can be both positive (when storing energy) or negative (when the storage is emptied).

The parser can also return an array of objects if multiple time values can be fetched. The backend will automatically update past values properly.
2 changes: 1 addition & 1 deletion web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ADD web/package.json /home/web/package.json
RUN npm install

ADD web /home/web
ADD shared /home/shared
ADD config /home/config

RUN npm run build-release

Expand Down
127 changes: 0 additions & 127 deletions web/app/configs/zones.json

This file was deleted.

4 changes: 2 additions & 2 deletions web/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var Tooltip = require('./tooltip');
var Wind = require('./wind');

// Configs
var capacities = require('json-loader!./configs/capacities.json');
var zones = require('json-loader!./configs/zones.json');
var capacities = require('json-loader!../../config/capacities.json');
var zones = require('json-loader!../../configs/zones.json');

// Constants
var REFRESH_TIME_MINUTES = 5;
Expand Down
2 changes: 1 addition & 1 deletion web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
function() {
this.plugin('emit', function(compilation, callback) {
compilation.fileDependencies.push(__dirname + '/public/css/styles.css');
glob(__dirname + '/../shared/**/*.js', function(err, files) {
glob(__dirname + '/../config/**/*.js', function(err, files) {
files.forEach(function(f) { compilation.fileDependencies.push(f); });
})
callback();
Expand Down

0 comments on commit bb2a4ab

Please sign in to comment.