1
1
import axios from 'axios' ;
2
- import moment from 'moment' ;
3
2
4
- const REQUEST_URL = `${ process . env . GFW_API_HOST_PROD } ` ;
5
- const DATASET = process . env . GLAD_PRECALC_DATASET ;
3
+ const REQUEST_URL = process . env . GFW_API_HOST_PROD ;
4
+ const GLAD_ISO_DATASET = process . env . GLAD_ISO_DATASET ;
5
+ const GLAD_ADM1_DATASET = process . env . GLAD_ADM1_DATASET ;
6
+ const GLAD_ADM2_DATASET = process . env . GLAD_ADM2_DATASET ;
6
7
7
8
const QUERIES = {
8
- gladAlerts : '{location}?aggregate_values=true&aggregate_by={period}' ,
9
9
gladIntersectionAlerts :
10
- "SELECT iso, adm1, adm2, alerts as count, alert_date as date , area_ha, polyname FROM data WHERE {location} AND alert_date > '{dateBound}' AND polyname = '{polyname}'" ,
10
+ "SELECT iso, adm1, adm2, week, year, alerts as count , area_ha, polyname FROM data WHERE {location} AND polyname = '{polyname}'" ,
11
11
viirsAlerts :
12
12
'{location}?group=true&period={period}&thresh=0&geostore={geostore}'
13
13
} ;
@@ -20,26 +20,27 @@ const getLocation = (country, region, subRegion) =>
20
20
subRegion ? ` AND adm2 = ${ subRegion } ` : ''
21
21
} `;
22
22
23
- export const fetchGladAlerts = ( { country, region, subRegion, period } ) => {
24
- const url = `${ REQUEST_URL } /glad-alerts/admin/${ QUERIES . gladAlerts } `
25
- . replace ( '{location}' , getLocationQuery ( country , region , subRegion ) )
26
- . replace ( '{period}' , period || 'week' ) ;
23
+ export const fetchGladAlerts = ( { country, region, subRegion } ) => {
24
+ let glad_summary_table = GLAD_ISO_DATASET ;
25
+ if ( subRegion ) {
26
+ glad_summary_table = GLAD_ADM2_DATASET ;
27
+ } else if ( region ) {
28
+ glad_summary_table = GLAD_ADM1_DATASET ;
29
+ }
30
+ const url = `${ REQUEST_URL } /query/${ glad_summary_table } ?sql=${
31
+ QUERIES . gladIntersectionAlerts
32
+ } `
33
+ . replace ( '{location}' , getLocation ( country , region , subRegion ) )
34
+ . replace ( '{polyname}' , 'gadm28' ) ;
27
35
return axios . get ( url ) ;
28
36
} ;
29
37
30
38
export const fetchGladIntersectionAlerts = ( { country, region, indicator } ) => {
31
- const url = `${ REQUEST_URL } /query/${ DATASET } ?sql= ${
32
- QUERIES . gladIntersectionAlerts
33
- } `
39
+ const url = `${ REQUEST_URL } /query/${
40
+ region ? GLAD_ADM2_DATASET : GLAD_ADM1_DATASET
41
+ } ?sql= ${ QUERIES . gladIntersectionAlerts } `
34
42
. replace ( '{location}' , getLocation ( country , region ) )
35
- . replace ( '{polyname}' , indicator )
36
- . replace (
37
- '{dateBound}' ,
38
- moment
39
- . utc ( )
40
- . subtract ( 53 , 'weeks' )
41
- . format ( 'YYYY/MM/DD' )
42
- ) ;
43
+ . replace ( '{polyname}' , indicator ) ;
43
44
return axios . get ( url ) ;
44
45
} ;
45
46
0 commit comments