Skip to content

Commit

Permalink
chore: optimize geodb query by select
Browse files Browse the repository at this point in the history
other minor fixes
  • Loading branch information
lubojr committed Jan 8, 2024
1 parent acaf8b0 commit bf36ca4
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 27 deletions.
4 changes: 1 addition & 3 deletions app/src/components/DataPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@

<script>
import {
mapGetters,
mapState,
} from 'vuex';
import { Wkt } from 'wicket';
Expand Down Expand Up @@ -366,8 +365,7 @@ export default {
let dataHref = 'data:text/csv;charset=utf-8,';
const exportKeys = [
'time', 'aoi', 'measurement',
'indicatorValue', 'referenceTime', /* 'referenceValue', */
'dataProvider', 'eoSensor', 'colorCode', 'inputData',
'indicatorValue', 'referenceTime', 'eoSensor', 'colorCode', 'inputData',
];
const header = `${exportKeys.join()}\n`;
let csv = header;
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/HighlightLocation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</template>
<script>
import { moveToHighlight } from '../utils';
import { moveToHighlight } from '@/utils';
export default {
props: {
Expand All @@ -38,7 +38,7 @@ export default {
methods: {
moveToHighlight(location) {
moveToHighlight(location);
}
},
},
};
</script>
42 changes: 34 additions & 8 deletions app/src/components/IndicatorFiltersDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ import {
mapMutations,
} from 'vuex';
import { Wkt } from 'wicket';
import { loadIndicatorData, loadFeatureData, moveToHighlight } from '@/utils';
const wkt = new Wkt();
export default {
data: () => ({
selectedItem: null,
Expand All @@ -117,8 +114,9 @@ export default {
const objectM = {
...ind,
...items[i],
}
};
if (poi !== 'World') {
// passing the aoiID into the merged object for POI indicator
objectM.aoiID = poi;
}
matched.push(objectM);
Expand All @@ -144,23 +142,51 @@ export default {
...mapMutations('indicators', {
setSelectedIndicator: 'SET_SELECTED_INDICATOR',
}),
...mapMutations('features', {
setSelectedFeature: 'SET_SELECTED_FEATURE',
}),
moveToHighlight(location) {
moveToHighlight(location);
},
async getIndicatorData(indicatorConfig) {
return await loadIndicatorData(
return loadIndicatorData(
this.baseConfig,
indicatorConfig,
);
},
async getFeatureData(currentFeatureObject) {
return await loadFeatureData(
return loadFeatureData(
this.baseConfig, currentFeatureObject.properties,
);
},
selectItem(item) {
this.setSelectedIndicator(item);
async selectItem(item) {
this.selectedItem = this.getLocationCode(item);
const val = item.poi;
const [poi] = val.split('-');
if (poi !== 'World') {
let indicatorObject = await loadIndicatorData(
this.baseConfig,
item,
);
const currentFeatureObject = indicatorObject.features.find(
(feat) => feat.id === item.aoiID,
);
// let currentFeatureData;
if (currentFeatureObject) {
// Merge info of feature object into indicator object as it overwrites some info
indicatorObject = {
...indicatorObject,
...currentFeatureObject.properties.indicatorObject,
};
const test = {
indicatorObject,
};
this.setSelectedIndicator(indicatorObject);
this.setSelectedFeature(test);
}
} else {
this.setSelectedIndicator(item);
}
if (item.dataLayerTime) {
setTimeout(() => {
this.centerMapVueComponent.dataLayerTime = {
Expand Down
3 changes: 2 additions & 1 deletion app/src/components/IndicatorFiltersPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default {
// not use styleOverride to reach them, commenting out this part of styleOverride now
// YET ANOTHER TODO: harmonize countries (currently both the alpha2 eg. AT are used and the full country names eg. Austria), I think we can not expect geodb values to get harmonized, so we should try to remedy in the client by preprocessing the values
let flags = ``;
// let flags = ``;
// [data-filter=countries] .title {
// display: flex;
// align-items: center;
Expand All @@ -263,6 +263,7 @@ export default {
// }
// `;
// });
const flags = '';
this.itemfilter.styleOverride = `
${this.itemFilterStyleOverride}
${flags}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/StacInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
methods: {
onStacInfoLoad() {
this.$nextTick(() => {
if (this.$vuetify.breakpoint.smAndUp && this.$refs.stacInfoEl?.shadowRoot.querySelector('main .description').children.length < 1) {
if (this.$vuetify.breakpoint.smAndUp && this.$refs.stacInfoEl?.shadowRoot.querySelector('main .description')?.children?.length < 1) {
// first parent is VExpantionPanelContent, second is VExpantionPanel
this.$parent.$parent.$el.style.display = 'none';
} else {
Expand Down
6 changes: 3 additions & 3 deletions app/src/components/UiPanelsLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export default {
heightPercentage: 100,
},
];
if (this.$route.name !== 'demo') {
leftPanels.push(layersTool);
} else {
if (this.$route.name === 'demo') {
rightPanels.push(layersTool);
} else {
leftPanels.push(layersTool);
}
this.panels.left = leftPanels;
this.panels.right = rightPanels;
Expand Down
12 changes: 7 additions & 5 deletions app/src/config/esa.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,19 @@ export const globalIndicators = [
// custom override of name + specialEnvTime
properties: {
indicatorObject: {
aoiID: 'WSF',
aoiID: 'World',
indicator: 'WSF',
display: [{
name: 'DLR WSF Evolution 1985-2015',
specialEnvTime: true,
attribution: '{ WSF Evolution Data are licensed under: <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank"> Attribution 4.0 International (CC BY 4.0) </a>; Contains modified Landsat-5/-7 data [1985-2015] }',
},
// {
// name: 'DLR WSF 2019 coverage',
// attribution: '{ WSF Evolution Data are licensed under: <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank"> Attribution 4.0 International (CC BY 4.0) </a>; Copyright DLR (2021);|Contains modified Copernicus Sentinel-1 and Sentinel-2 data [2019]}',
// }
{
url: 'https://a.geoservice.dlr.de/eoc/land/wms/',
layers: 'WSF_2019',
name: 'DLR WSF 2019 coverage',
attribution: '{ WSF Evolution Data are licensed under: <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank"> Attribution 4.0 International (CC BY 4.0) </a>; Copyright DLR (2021);|Contains modified Copernicus Sentinel-1 and Sentinel-2 data [2019]}',
},
],
},
},
Expand Down
16 changes: 12 additions & 4 deletions app/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,19 @@ export async function loadFeatureData(baseConfig, feature) {
const geodbUrl = baseConfig.geoDBFeatureParameters.url;
const geodbIndicatorId = indicatorObject.geoDBID
? indicatorObject.geoDBID : indicatorObject.indicator;
const url = `${geodbUrl}_${geodbIndicatorId}?aoi_id=eq.${indicatorObject.aoiID}`;
const selectQuery = 'site_name,city,color_code,time,aoi,measurement_value,indicator_value,reference_time,eo_sensor,reference_value,input_data';
const url = `${geodbUrl}_${geodbIndicatorId}?aoi_id=eq.${indicatorObject.aoiID}&select=${selectQuery}`;
// Fetch location data
const response = await axios.get(url, { credentials: 'same-origin' });
// specially fetch non-array like variables such as sub_aoi
// because they are huge and we do not expect it to change in array
const selectQueryNonArray = 'sub_aoi';
const urlNonArray = `${geodbUrl}_${geodbIndicatorId}?aoi_id=eq.${indicatorObject.aoiID}&select=${selectQueryNonArray}&limit=1`;
const responseNonArray = await axios.get(urlNonArray, { credentials: 'same-origin' });

if (response) {
const { data } = response;
const dataNonArray = responseNonArray.data;
// Set data to indicator object
// Convert data first
const mapping = {
Expand All @@ -344,12 +352,12 @@ export async function loadFeatureData(baseConfig, feature) {
mapping.siteNameNUTS = 'site_name';
}
// Try to extract sub_aoi geometry information
if (data && data.length > 0 && 'sub_aoi' in data[0]) {
if (dataNonArray && dataNonArray.length > 0 && 'sub_aoi' in dataNonArray[0]) {
let features = null;
if (data[0].sub_aoi !== '/' && data[0].sub_aoi !== '') {
if (dataNonArray[0].sub_aoi !== '/' && dataNonArray[0].sub_aoi !== '') {
// try to generate sub_aoi from geodb
try {
features = wkt.read(data[0].sub_aoi).toJson();
features = wkt.read(dataNonArray[0].sub_aoi).toJson();
} catch (error) {
console.log('Error parsing wkt sub_aoi');
}
Expand Down

0 comments on commit bf36ca4

Please sign in to comment.