forked from electricitymaps/electricitymaps-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
561 changed files
with
161 additions
and
223 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,6 @@ | ||
.PHONY: server | ||
|
||
install: install-grib2json | ||
pip install -r requirements.txt | ||
pip install honcho==0.7.1 | ||
|
||
install-grib2json: | ||
git clone https://github.com/cambecc/grib2json | ||
cd grib2json && mvn package && tar -xvf target/grib2json-0.8.0-SNAPSHOT.tar.gz | ||
|
||
server: | ||
honcho start | ||
|
||
api: | ||
python -u server.py | ||
|
||
feeder: | ||
python -u backend/feeder.py | ||
|
||
db: | ||
mongod | ||
|
||
publish-gh-pages: | ||
git subtree split --prefix public -b gh-pages | ||
git subtree split --prefix static -b gh-pages | ||
git push -f origin gh-pages:gh-pages | ||
git branch -D gh-pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM node:4.5.0 | ||
WORKDIR /home | ||
EXPOSE 8000 | ||
ADD ./data/europe.topo.json /home/data/europe.topo.json | ||
ADD package.json /home/package.json | ||
RUN npm install | ||
ADD . /home | ||
CMD node index.js | ||
HEALTHCHECK CMD curl --fail http://localhost:8000/ || exit 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "electricitymap-api", | ||
"version": "0.0.1", | ||
"description": "", | ||
"dependencies": { | ||
"express": "^4.10.2", | ||
"mongodb": "^2.2.9", | ||
"node-statsd": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.10.2" | ||
}, | ||
"scripts": { | ||
"dev": "nodemon server.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var express = require('express'); | ||
var app = express(); | ||
var http = require('http').Server(app); | ||
var statsd = require('node-statsd'); | ||
var MongoClient = require('mongodb').MongoClient; | ||
|
||
// * Database | ||
var mongoCollection; | ||
MongoClient.connect(process.env['MONGO_URL'], function(err, db) { | ||
if (err) throw (err); | ||
console.log('Connected to database'); | ||
mongoCollection = db.collection('realtime'); | ||
// Create indexes | ||
mongoCollection.createIndexes( | ||
[ | ||
{ datetime: -1 }, | ||
{ countryCode: 1}, | ||
{ datetime: -1, countryCode: 1 } | ||
], | ||
null, | ||
function (err, indexName) { | ||
if (err) console.error(err); | ||
else console.log('Database indexes created'); | ||
} | ||
); | ||
http.listen(8000, function() { | ||
console.log('Listening on *:8000'); | ||
}); | ||
}); | ||
|
||
// * Metrics | ||
var statsdClient = new statsd.StatsD(); | ||
statsdClient.post = 8125; | ||
statsdClient.host = process.env['STATSD_HOST']; | ||
statsdClient.prefix = 'electricymap_api'; | ||
|
||
// * Routes | ||
app.use(express.static('static')); | ||
app.use(express.static('vendor')); | ||
app.get('/v1/wind', function(req, res) { | ||
statsdClient.increment('wind_GET'); | ||
res.header('Content-Encoding', 'gzip'); | ||
res.sendFile(__dirname + '/data/wind.json.gz'); | ||
}); | ||
app.get('/v1/solar', function(req, res) { | ||
statsdClient.increment('solar_GET'); | ||
res.header('Content-Encoding', 'gzip'); | ||
res.sendFile(__dirname + '/data/solar.json.gz'); | ||
}); | ||
app.get('/v1/production', function(req, res) { | ||
statsdClient.increment('production_GET'); | ||
var t0 = new Date().getTime(); | ||
mongoCollection.aggregate([ | ||
{'$sort': {'countryCode': 1, 'datetime': -1}}, | ||
{'$group': {'_id': '$countryCode', 'lastDocument': {'$first': '$$CURRENT'}}} | ||
], function (err, result) { | ||
if (err) { | ||
statsdClient.increment('production_GET_ERROR'); | ||
console.error(err); | ||
res.status(500).json({error: 'Unknown database error'}); | ||
} else { | ||
obj = {} | ||
result.forEach(function(d) { obj[d['_id']] = d.lastDocument; }); | ||
res.json({status: 'ok', data: obj}); | ||
statsdClient.timing('production', new Date().getTime() - t0); | ||
} | ||
}); | ||
}); | ||
app.get('/health', function(req, res) { | ||
statsdClient.increment('health_GET'); | ||
var EXPIRATION_SECONDS = 30 * 60.0; | ||
mongoCollection.findOne({}, {sort: [['datetime', -1]]}, function (err, doc) { | ||
if (err) { | ||
console.error(err); | ||
res.status(500).json({error: 'Unknown database error'}); | ||
} else { | ||
if (new Date().getTime() - new Date(doc.datetime).getTime() > EXPIRATION_SECONDS * 1000.0) | ||
res.status(500).json({error: 'Database is empty or last measurement is too old'}); | ||
else | ||
res.json({status: 'ok'}); | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
version: '2' | ||
services: | ||
web: | ||
extends: | ||
file: common.yml | ||
service: web | ||
api: | ||
build: api | ||
command: ./node_modules/.bin/nodemon server.js | ||
depends_on: [mongo] | ||
environment: [ENV=development, 'MONGO_URL=mongodb://mongo:27017/electricity'] | ||
ports: ['8000:8000'] | ||
volumes: | ||
- './public:/home/public' | ||
- './backend:/home/backend' | ||
- './server.py:/home/server.py' | ||
environment: [ENV=development, 'MONGO_URL=mongodb://mongo:27017'] | ||
- './static:/home/static' | ||
- './api/server.js:/home/server.js' | ||
- './api/data:/home/data' | ||
feeder: | ||
build: feeder | ||
depends_on: [mongo] | ||
environment: [ENV=development, 'MONGO_URL=mongodb://mongo:27017/electricity'] | ||
volumes: | ||
- './api/data:/home/data' | ||
mongo: | ||
image: mongo | ||
volumes: ['./mongodata/:/data/db'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM java:8 | ||
WORKDIR /home/ | ||
ENV LANG=en_US.UTF-8 | ||
ENV PYTHONIOENCODING=utf8 | ||
RUN apt-get update | ||
# Install python | ||
RUN apt-get install -y gcc make python-dev libxml2-dev libxslt-dev gzip | ||
RUN curl -s https://bootstrap.pypa.io/get-pip.py | python | ||
# Install pygrib dependencies manually | ||
RUN apt-get install -y maven | ||
RUN apt-get install -y libgrib-api-dev && pip install numpy==1.10.1 pyproj==1.9.4 | ||
RUN git clone https://github.com/cambecc/grib2json && \ | ||
cd grib2json && mvn package && tar -xvf target/grib2json-0.8.0-SNAPSHOT.tar.gz | ||
# Only add requirements to enable cached builds when it is unchanged | ||
ADD requirements.txt /home/requirements.txt | ||
RUN pip install -r requirements.txt | ||
# Add the rest | ||
ADD . /home/ | ||
CMD python -u feeder.py |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
arrow==0.5.0 | ||
Flask==0.11 | ||
Flask-Cors==2.1.2 | ||
pygrib==2.0.1 | ||
pymongo==3.2.2 | ||
requests==2.10.0 | ||
schedule==0.3.2 | ||
-e git+https://github.com/gaelenh/python-statsd-client.git#egg=statsd-client | ||
uwsgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.