Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Elements changed before will now be displayed until then.
Browse files Browse the repository at this point in the history
  • Loading branch information
chirale committed Jan 14, 2020
1 parent 4ce5b5d commit 4e5d35e
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,25 @@ module.exports = function(app, apicache) {
* @param {[type]} allTimes [description]
* @return {Array} array of unchanged times
*/
function getOnlyUnchangedTimes (el, changedTimes, allTimes) {
let unchangedTimes = [];
function getTimesBeforeFirstChange (el, changedTimes, allTimes) {
// previously stored changed times
let ct = changedTimes[el.properties.wikidata];
if (typeof ct !== 'undefined') {
// get difference between all stored times from history
// and changed times
for (at of allTimes) {
if (ct.indexOf(at) === -1) {
unchangedTimes.push(at);
}
else {
// do not collect anymore unchangedTimes if is changed
// new result will be kept from now on
break;
}
}
console.log(el.properties.wikidata);
console.log(unchangedTimes);
return unchangedTimes;
let elChangedTimes = changedTimes[el.properties.wikidata];
let unchangedTimes = [];
if (typeof elChangedTimes !== 'undefined') {
let allTimeEndInd = allTimes.indexOf(elChangedTimes[0]);
unchangedTimes = allTimes.slice(0, allTimeEndInd);
}
else {
// this pin is never changed in History
return allTimes;
// never changed
unchangedTimes = allTimes;
}
// DEBUG
// if (DEBUG && elChangedTimes && el.properties.wikidata === 'Q3825655') {
// console.log('allTimes', allTimes);
// console.log('elChangedTimes', elChangedTimes);
// console.log('unchangedTimes', unchangedTimes);
// }
return unchangedTimes;
}

/**
Expand Down Expand Up @@ -335,7 +329,7 @@ module.exports = function(app, apicache) {
// from allTimeStartInd on
: allTimes.length;
// DEBUG
// if (el.properties.wikidata === 'Q15953347') {
// if (el.properties.wikidata === 'Q3825655') {
// console.log('allTimes', allTimes);
// console.log('elChangedTimes', elChangedTimes);
// console.log('changeTimeNext', changeTimeNext);
Expand All @@ -359,7 +353,8 @@ module.exports = function(app, apicache) {
let n;
for (n = 0; n < hists.length; n++) {
if (!hists[n].error) {
sparqlResultsFirstShotArray = JSON.parse(hists[0].json).data;
sparqlResultsFirstShotArray = JSON.parse(hists[n].json).data;
console.log('First timeshot is id: ' + hists[n].id);
break;
}
}
Expand All @@ -369,7 +364,7 @@ module.exports = function(app, apicache) {
for (histInd in hists.slice(n+1)) {
let hist = hists[histInd];
if (DEBUG) {
console.log('mapId', hist.mapId, 'published', hist.map.published, 'histInd (array)', histInd); // DEBUG
console.log('id', hist.id, 'mapId', hist.mapId, 'published', hist.map.published, 'histInd (array)', histInd); // DEBUG
}
// Ignore broken records, but keep them in History table
if (!hist.error) {
Expand Down Expand Up @@ -403,9 +398,9 @@ module.exports = function(app, apicache) {
// now as last time in array
// allTimes.push(now);
// first results: assign times only if are unchanged on all timeshots
for (fstel of sparqlResultsFirstShotArray) {
for (fstelInd in sparqlResultsFirstShotArray) {
// el.properties.time = now;
fstel.properties.times = getOnlyUnchangedTimes(fstel, changedTimes, allTimes);
sparqlResultsFirstShotArray[fstelInd].properties.times = getTimesBeforeFirstChange(sparqlResultsFirstShotArray[fstelInd], changedTimes, allTimes);
}
// create an array with old items changed at least one time, to be displayed as circle

Expand Down

0 comments on commit 4e5d35e

Please sign in to comment.