create irradiance composite graph
This commit is contained in:
@@ -24,10 +24,10 @@ var api = express();
|
||||
|
||||
DB.sync().then(()=>{
|
||||
|
||||
routes(api);
|
||||
|
||||
api.use(bodyParser.json());
|
||||
api.use(bodyParser.urlencoded({ extended: false }));
|
||||
api.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
routes(api);
|
||||
|
||||
api.listen(API_PORT, () => {
|
||||
console.log(`API is now running on http://localhost:${API_PORT}`);
|
||||
|
||||
@@ -5,9 +5,14 @@ const NAME = 'EnergyController';
|
||||
class EnergyController{
|
||||
|
||||
static index(req, res){
|
||||
DB.EnergyDatum.exposeForHouseAtDates(req.query.house_id, req.query.dates).then((energy_data)=>{
|
||||
res.json({data: energy_data});
|
||||
});
|
||||
console.log ('EnergyController.index');
|
||||
console.log(JSON.stringify(req.body))
|
||||
console.log(JSON.stringify(req.params))
|
||||
console.log(JSON.stringify(req.query))
|
||||
DB.EnergyDatum.exposeForHouseAtDates(req.body)
|
||||
.then((energy_data)=>{
|
||||
res.json({data: energy_data});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,16 +32,27 @@ var EnergyDatum = DB.sequelize.define(NAME, {
|
||||
associate: ()=>{
|
||||
EnergyDatum.belongsTo(DB.House);
|
||||
},
|
||||
exposeForHouseAtDates: (house_id, dates)=>{
|
||||
var params = {house_id: house_id};
|
||||
extend(params, ApiHelper.datesParamToSequelize(dates, 'day'));
|
||||
exposeForHouseAtDates: (query)=>{
|
||||
var attributes = ['id', 'production', 'irradiance', 'consumption', 'day'],
|
||||
params = {};
|
||||
if (query.houses){
|
||||
attributes.push('house_id');
|
||||
params['$or'] = []
|
||||
query.houses.forEach((house_query)=>{
|
||||
var house_params = {house_id: house_query.house_id};
|
||||
extend(house_params, ApiHelper.datesParamToSequelize(house_query.dates, 'day'));
|
||||
params['$or'].push(house_params);
|
||||
});
|
||||
} else {
|
||||
params.house_id = query.house_id;
|
||||
extend(params, ApiHelper.datesParamToSequelize(query.dates, 'day'));
|
||||
}
|
||||
|
||||
return EnergyDatum.findAll({
|
||||
where: params,
|
||||
attributes: ['id', 'production', 'consumption', 'day']
|
||||
attributes: attributes
|
||||
}).then((energy_data)=>{
|
||||
return energy_data.map((energy_datum)=>{
|
||||
return energy_datum.dataValues;
|
||||
});
|
||||
return energy_data.map(energy_datum => energy_datum.dataValues);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user