Skip to content

Commit

Permalink
add rownum
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Jul 23, 2020
1 parent 4dfbf88 commit 872caaa
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 27 deletions.
13 changes: 12 additions & 1 deletion dist/index.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.es.js.map

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions src/__tests__/CSISHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@
*/

import axios from 'axios';
import express from 'express';
import log from 'loglevel';

// Using ie9 polyfills as the "kitchen sink" of polyfills
// https://github.com/clarity-h2020/csis-helpers-js/issues/12
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

import { CSISHelpers as _CSISHelpers } from './../../dist/index.js';
// DON't use this. It imports just the default export which is the CSISHelpers class.
// import CSISHelpers from './../lib/CSISHelpers.js';
import * as CSISHelpers from './../lib/CSISHelpers.js';
import * as EMIKATHelpers from './../lib/EMIKATHelpers.js';
import { CSISHelpers as _CSISHelpers } from './../../dist/index.js';
import express from 'express';
import apiResponseStudy from './../__fixtures__/study.json';
import apiResponseDataPackage from './../__fixtures__/dataPackage.json';
import apiResponseResources from './../__fixtures__/resources.json';
import studyArea from './../__fixtures__/studyArea.json';
import resourceWithVariableMeanings from './../__fixtures__/resourceWithVariableMeanings.json';
import apiResponseStudy from './../__fixtures__/study.json';
import studyArea from './../__fixtures__/studyArea.json';



const app = express();
var server;
Expand Down Expand Up @@ -251,6 +250,7 @@ test('[DEV] WMS URL with mapped PARAMETERS', () => {
maxx: 30,
maxy: -30,
emikat_id: undefined,
rownum: 999,
data_format: 'data',
study_variant: 'BASELINE',
time_period: 'Baseline',
Expand All @@ -269,10 +269,10 @@ test('[DEV] WMS URL with mapped PARAMETERS', () => {
resourceWithVariableMeanings.included
);

expect(parametersMap.size).toEqual(5);
expect(parametersMap.size).toEqual(6);

/**
* @type{String[]}
* @type{String}
*/
const transformedUrl = CSISHelpers.addTemplateParameters(urlTemplate, parametersMap);

Expand Down Expand Up @@ -309,6 +309,7 @@ test('[PROD] WMS URL with mapped PARAMETERS', () => {
maxx: 30,
maxy: -30,
emikat_id: undefined,
rownum:999,
data_format: 'data',
study_variant: 'BASELINE',
time_period: 'Baseline',
Expand All @@ -324,7 +325,7 @@ test('[PROD] WMS URL with mapped PARAMETERS', () => {
resourceWithVariableMeanings.included
);

expect(parametersMap.size).toEqual(5);
expect(parametersMap.size).toEqual(6);

const transformedUrl = _CSISHelpers.addTemplateParameters(urlTemplate, parametersMap);

Expand Down
26 changes: 15 additions & 11 deletions src/__tests__/EMIKATHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
*/

import axios from 'axios';

// import {create, router, defaults, rewriter} from 'json-server';
import express from 'express';
// Using ie9 polyfills as the "kitchen sink" of polyfills
// https://github.com/clarity-h2020/csis-helpers-js/issues/12
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

import * as EMIKATHelpers from './../lib/EMIKATHelpers.js';
import { EMIKATHelpers as _EMIKATHelpers } from './../../dist/index.js';
import * as EMIKATHelpers from './../lib/EMIKATHelpers.js';
import populationExposure from './../__fixtures__/tab.CLY_EL_POPULATION_INTERPOLATED.2016.json';




// import {create, router, defaults, rewriter} from 'json-server';
import express from 'express'
import populationExposure from './../__fixtures__/tab.CLY_EL_POPULATION_INTERPOLATED.2016.json';

const app = express();
var server;

beforeAll(() => {
// respond with "hello world" when a GET request is made to the homepage
app.get('/EmiKatTst/api/scenarios/2846/feature/tab.CLY_EL_POPULATION_INTERPOLATED.2016/table/data', function (req, res) {
app.get('/EmiKatTst/api/scenarios/2846/feature/tab.CLY_EL_POPULATION_INTERPOLATED.2016/table/data', function (_req, res) {
res.json(populationExposure);
})

Expand Down Expand Up @@ -168,18 +168,19 @@ test('[DEV] Table URL with EMIKAT PARAMETERS', () => {
/**
* @type {String}
*/
const urlTemplate = `https://service.emikat.at/EmiKatTst/api/scenarios/${EMIKATHelpers.EMIKAT_STUDY_ID}/feature/view.2975/table/${EMIKATHelpers.DATA_FORMAT}?rownum=1000&filter=STUDY_VARIANT=%27${EMIKATHelpers.STUDY_VARIANT}%27&filter=TIME_PERIOD=%27${EMIKATHelpers.TIME_PERIOD}%27&filter=EMISSIONS_SCENARIO=%27${EMIKATHelpers.EMISSIONS_SCENARIO}%27&filter=EVENT_FREQUENCY=%27${EMIKATHelpers.EVENT_FREQUENCY}%27`;
const urlTemplate = `https://service.emikat.at/EmiKatTst/api/scenarios/${EMIKATHelpers.EMIKAT_STUDY_ID}/feature/view.2975/table/${EMIKATHelpers.DATA_FORMAT}?rownum=${EMIKATHelpers.ROWNUM}&filter=STUDY_VARIANT=%27${EMIKATHelpers.STUDY_VARIANT}%27&filter=TIME_PERIOD=%27${EMIKATHelpers.TIME_PERIOD}%27&filter=EMISSIONS_SCENARIO=%27${EMIKATHelpers.EMISSIONS_SCENARIO}%27&filter=EVENT_FREQUENCY=%27${EMIKATHelpers.EVENT_FREQUENCY}%27`;

/**
* @type {String}
*/
const url = 'https://service.emikat.at/EmiKatTst/api/scenarios/2846/feature/view.2975/table/csv?rownum=1000&filter=STUDY_VARIANT=%27BASELINE%27&filter=TIME_PERIOD=%27Baseline%27&filter=EMISSIONS_SCENARIO=%27Baseline%27&filter=EVENT_FREQUENCY=%27Rare%27';
const url = 'https://service.emikat.at/EmiKatTst/api/scenarios/2846/feature/view.2975/table/csv?rownum=666&filter=STUDY_VARIANT=%27BASELINE%27&filter=TIME_PERIOD=%27Baseline%27&filter=EMISSIONS_SCENARIO=%27Baseline%27&filter=EVENT_FREQUENCY=%27Rare%27';

/**
* @type{Map<String, any>}
*/
const parametersMap = new Map([
[EMIKATHelpers.EMIKAT_STUDY_ID, 2846],
[EMIKATHelpers.ROWNUM, 666],
[EMIKATHelpers.STUDY_VARIANT, 'BASELINE'],
[EMIKATHelpers.TIME_PERIOD, 'Baseline'],
[EMIKATHelpers.EMISSIONS_SCENARIO, 'Baseline'],
Expand All @@ -194,6 +195,7 @@ test('[DEV] Table URL with EMIKAT PARAMETERS', () => {

expect(urlTemplate).not.toEqual(transformedUrl);
expect(transformedUrl.includes('$')).toBeFalsy;
expect(transformedUrl.includes('666'));
expect(transformedUrl.includes('csv'));
expect(transformedUrl.includes('2846'));
expect(transformedUrl.includes('BASELINE'));
Expand All @@ -206,18 +208,19 @@ test('[PROD] Table URL with EMIKAT PARAMETERS', () => {
/**
* @type {String}
*/
const urlTemplate = `https://service.emikat.at/EmiKatTst/api/scenarios/${_EMIKATHelpers.EMIKAT_STUDY_ID}/feature/view.2975/table/${_EMIKATHelpers.DATA_FORMAT}?rownum=1000&filter=STUDY_VARIANT=%27${_EMIKATHelpers.STUDY_VARIANT}%27&filter=TIME_PERIOD=%27${_EMIKATHelpers.TIME_PERIOD}%27&filter=EMISSIONS_SCENARIO=%27${_EMIKATHelpers.EMISSIONS_SCENARIO}%27&filter=EVENT_FREQUENCY=%27${_EMIKATHelpers.EVENT_FREQUENCY}%27`;
const urlTemplate = `https://service.emikat.at/EmiKatTst/api/scenarios/${_EMIKATHelpers.EMIKAT_STUDY_ID}/feature/view.2975/table/${_EMIKATHelpers.DATA_FORMAT}?rownum=${EMIKATHelpers.ROWNUM}&filter=STUDY_VARIANT=%27${_EMIKATHelpers.STUDY_VARIANT}%27&filter=TIME_PERIOD=%27${_EMIKATHelpers.TIME_PERIOD}%27&filter=EMISSIONS_SCENARIO=%27${_EMIKATHelpers.EMISSIONS_SCENARIO}%27&filter=EVENT_FREQUENCY=%27${_EMIKATHelpers.EVENT_FREQUENCY}%27`;

/**
* @type {String}
*/
const url = 'https://service.emikat.at/EmiKatTst/api/scenarios/2846/feature/view.2975/table/csv?rownum=1000&filter=STUDY_VARIANT=%27BASELINE%27&filter=TIME_PERIOD=%27Baseline%27&filter=EMISSIONS_SCENARIO=%27Baseline%27&filter=EVENT_FREQUENCY=%27Rare%27';
const url = 'https://service.emikat.at/EmiKatTst/api/scenarios/2846/feature/view.2975/table/csv?rownum=666&filter=STUDY_VARIANT=%27BASELINE%27&filter=TIME_PERIOD=%27Baseline%27&filter=EMISSIONS_SCENARIO=%27Baseline%27&filter=EVENT_FREQUENCY=%27Rare%27';

/**
* @type{Map<String, any>}
*/
const parametersMap = new Map([
[_EMIKATHelpers.EMIKAT_STUDY_ID, 2846],
[EMIKATHelpers.ROWNUM, 666],
[_EMIKATHelpers.STUDY_VARIANT, 'BASELINE'],
[_EMIKATHelpers.TIME_PERIOD, 'Baseline'],
[_EMIKATHelpers.EMISSIONS_SCENARIO, 'Baseline'],
Expand All @@ -232,6 +235,7 @@ test('[PROD] Table URL with EMIKAT PARAMETERS', () => {

expect(urlTemplate).not.toEqual(transformedUrl);
expect(transformedUrl.includes('$')).toBeFalsy;
expect(transformedUrl.includes('666'));
expect(transformedUrl.includes('csv'));
expect(transformedUrl.includes('2846'));
expect(transformedUrl.includes('BASELINE'));
Expand Down
6 changes: 4 additions & 2 deletions src/lib/CSISHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* ***************************************************
*/

import Wkt from 'wicket';
import log from 'loglevel';

import Wkt from 'wicket';
import * as EMIKATHelpers from './EMIKATHelpers.js';


/**
* Be aware of the difference between default and named exports. It is a common source of mistakes.
* We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component).
Expand Down Expand Up @@ -61,6 +61,7 @@ export default class CSISHelpers {
maxx: 30, // deprecated
maxy: -30, // deprecated
emikat_id: undefined, // this is the emikat study id
rownum: 1000,
data_format: EMIKATHelpers.DATA_FORMAT_VALUES[0],
study_variant: EMIKATHelpers.STUDY_VARIANT_VALUES[0],
time_period: EMIKATHelpers.TIME_PERIOD_VALUES[0],
Expand Down Expand Up @@ -636,6 +637,7 @@ export const LAYERS = CSISHelpers.LAYERS;
*
*/
export const QUERY_PARAMS = EMIKATHelpers.QUERY_PARAMS;
export const ROWNUM = EMIKATHelpers.ROWNUM;
export const DATA_FORMAT = EMIKATHelpers.DATA_FORMAT;
export const DATA_FORMAT_VALUES = EMIKATHelpers.DATA_FORMAT_VALUES;
export const EMISSIONS_SCENARIO = EMIKATHelpers.EMISSIONS_SCENARIO;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/EMIKATHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export const STUDY_VARIANT_VALUES = [ 'BASELINE', 'ADAPTATION-01' ];
*/
export const TIME_PERIOD = '${time_period}';


/**
* ROWNUM = number of rows returned
*
* @type {String}
*/
export const ROWNUM = '${rownum}';


/**
* DATA_FORMAT = 'data' (JSON), 'csv' or 'geojson'
*
Expand Down Expand Up @@ -96,6 +105,7 @@ export const DATA_FORMAT_VALUES = [ 'data', 'csv', 'geojson' ];
*/
export const QUERY_PARAMS = new Map([
[ EMIKAT_STUDY_ID, 'emikat_id' ],
[ ROWNUM, 'rownum' ],
[ DATA_FORMAT, 'data_format' ],
[ STUDY_VARIANT, 'study_variant' ],
[ TIME_PERIOD, 'time_period' ],
Expand Down

0 comments on commit 872caaa

Please sign in to comment.