CodeForAfrica / sensors.AFRICA-api

The sensors.AFRICA API receiving, storing, and processing data received from sensors across the continentent. Accessible at https://api.sensors.africa/
https://api.sensors.africa/
18 stars 7 forks source link

Optimize stats #17

Closed karimkawambwa closed 5 years ago

karimkawambwa commented 5 years ago

Description

Calculating stats for each call is expensive. This will therefore store indexed filters and pre calculated data stats for faster access.

Had to match exact number values because production data consists of some dirty values:

[{
    'value': '57n20',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '8s.90',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '85n20',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '67>47',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '231.5p',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '1 .43',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '%0.40',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '14n30',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '2.1p',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '15.6?',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '6,03',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '19.4?',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '21>77',
    'sensordata__location__city': 'Dar es Salaam'
}, {
    'value': '>99.40',
    'sensordata__location__city': 'Dar es Salaam'
}]

Type of change

Please delete options that are not relevant.

Checklist:

karimkawambwa commented 5 years ago

@kilemensi 👀

kilemensi commented 5 years ago

Just had a quick glance @karimkawambwa, and I've only seen the calculate stats command, does that mean you've gone the route of having an external trigger for calculating averages?

karimkawambwa commented 5 years ago

I run a cronjob daily to calculate the stats @kilemensi