Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remove/add datasource from/to timeSync causing start/end timestamp which were not updated correctly #770

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/sweapi/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const config = {
toUrlUndefined: true
},
devServer: {
https: true,
https: false,
compress: false,
hot: true,
},
Expand Down
5 changes: 3 additions & 2 deletions source/core/datasource/TimeSeries.replay.datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ import {Mode} from './Mode';
*
*/
class TimeSeriesReplayDatasource extends DataSource {
constructor(name, properties) {
constructor(name = 'DataSource', properties) {
super(name, properties);

this.setMinTime(properties.startTime);
this.setMaxTime(properties.endTime);

this.properties.startTimestamp = new Date(properties.startTime).getTime();
this.properties.endTimestamp = new Date(properties.endTime).getTime();

assertDefined(properties, 'Some properties must be defined');
this.dataSynchronizer = undefined;

this.properties.version = 0;

}

getTimeTopicId() {
Expand Down
14 changes: 12 additions & 2 deletions source/core/timesync/replay/DataSynchronizer.replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ class DataSynchronizerReplay {
this.properties.minTimestamp = this.properties.startTimestamp = st;
this.properties.maxTimestamp = this.properties.endTimestamp = end;
}

if(this.properties.startTimestamp < this.properties.minTimestamp || this.properties.startTimestamp > this.properties.maxTimestamp) {
this.properties.startTimestamp = this.properties.minTimestamp;
}
if(this.properties.endTimestamp > this.properties.maxTimestamp || this.properties.endTimestamp < this.properties.minTimestamp) {
this.properties.endTimestamp = this.properties.maxTimestamp;
}
}

/**
Expand Down Expand Up @@ -324,7 +331,9 @@ class DataSynchronizerReplay {
// add dataSource to synchronizer algorithm
return this.synchronizerWorker.postMessageWithAck({
message: 'add',
dataSources: [dataSourceForWorker]
dataSources: [dataSourceForWorker],
startTimestamp: this.getStartTimeAsTimestamp(),
endTimestamp: this.getEndTimeAsTimestamp()
}).then(async () => {
if (await this.isConnected()) {
await dataSource.connect()
Expand Down Expand Up @@ -362,7 +371,8 @@ class DataSynchronizerReplay {
dataSourceIds: [dataSource.getId()],
startTimestamp: this.getStartTimeAsTimestamp(),
endTimestamp: this.getEndTimeAsTimestamp()
}).then(() => {
}).then(async () => {
await this.disconnect();
this.timeChanged();
this.onRemovedDataSource(dataSource.id);
});
Expand Down
15 changes: 11 additions & 4 deletions source/core/timesync/replay/DataSynchronizer.replay.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ async function handleMessage(event) {
} else if (event.data.message === 'add' && event.data.dataSources) {
console.log('Add datasource to synchronizer..')
addDataSources(event.data.dataSources);
if (dataSynchronizerAlgo instanceof DataSynchronizerAlgoReplay) {
dataSynchronizerAlgo.startTimestamp = event.data.startTimestamp;
dataSynchronizerAlgo.endTimestamp = event.data.endTimestamp;
}
reset();
} else if (event.data.message === 'connect') {
startMasterTimeInterval(masterTimeRefreshRate);
dataSynchronizerAlgo.checkStart();
Expand All @@ -73,8 +78,10 @@ async function handleMessage(event) {
console.log('Remove datasource from synchronizer algorithm..')
await removeDataSources(event.data.dataSourceIds);
if (dataSynchronizerAlgo instanceof DataSynchronizerAlgoReplay) {
dataSynchronizerAlgo.startTimestamp = event.data.startTimestamp;
dataSynchronizerAlgo.endTimestamp = event.data.endTimestamp;
}
reset();
} else if (event.data.message === 'current-time') {
data = dataSynchronizerAlgo.getCurrentTimestamp();
} else if (event.data.message === 'reset') {
Expand Down Expand Up @@ -191,14 +198,14 @@ function addDataSource(dataSource) {
*
* @param dataSourceIds
*/
async function removeDataSources(dataSourceIds) {
function removeDataSources(dataSourceIds) {
for(let dataSourceId of dataSourceIds) {
await removeDataSource(dataSourceId);
removeDataSource(dataSourceId);
}
}

async function removeDataSource(dataSourceId) {
await dataSynchronizerAlgo.removeDataSource(dataSourceId);
function removeDataSource(dataSourceId) {
dataSynchronizerAlgo.removeDataSource(dataSourceId);
// create a BC to push back the synchronized data into the DATA Stream.
console.log('deleting BC for datasource '+dataSourceId);
delete bcChannels[dataSourceId];
Expand Down
1 change: 0 additions & 1 deletion source/vue/components/RangeSlider.replay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export default {
}.bind(this);

this.dataSynchronizer.onAddedDataSource = function (dataSourceId) {
console.log('onAdded')
if (this.dataSynchronizer.getDataSources().length > 0 && isDefined(this.rangeSlider)) {
// To disable
this.rangeSlider.enable();
Expand Down
13 changes: 6 additions & 7 deletions source/vue/components/TimeController.replay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default {
return this.endTimestamp;
},
htmlCurrentTime() {
return this.parseTime(this.startTimestamp);
return this.parseTime(this.startTimestamp);
},
htmlEndTime() {
return this.parseTime(this.endTimestamp);
Expand All @@ -178,9 +178,9 @@ export default {
this.initComp();
},
methods: {
async initComp() {
initComp() {
assertDefined(this.getDataSourceObject(), 'either dataSource properties or dataSynchronizer must be defined');
await this.checkInit();
this.checkInit();
this.createTimeBc();

// listen for datasource status
Expand All @@ -196,12 +196,12 @@ export default {

if(isDefined(this.dataSynchronizer)) {
this.dataSynchronizer.onAddedDataSource = async () => {
await this.checkInit();
this.checkInit();
};
}

},
async checkInit() {
checkInit() {
if (!this.init && this.dataSourceObject.getDataSources().length > 0) {
try {
this.dataSourceObject.isConnected().then(value => this.connected = value);
Expand Down Expand Up @@ -304,8 +304,7 @@ export default {
this.rangeSliderInit = true;
// HAS BEEN REPLACED
}
}
,
},
doBackward() {
if (!this.interval) {
this.interval = setInterval(() => {
Expand Down