mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 06:03:08 +00:00
Merge pull request #637 from nasa/rems_data
[Examples] Rems data integration
This commit is contained in:
commit
a73f1ebbbd
11
app.js
11
app.js
@ -14,7 +14,8 @@
|
|||||||
options = require('minimist')(process.argv.slice(2)),
|
options = require('minimist')(process.argv.slice(2)),
|
||||||
express = require('express'),
|
express = require('express'),
|
||||||
app = express(),
|
app = express(),
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
request = require('request');
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
options.port = options.port || options.p || 8080;
|
options.port = options.port || options.p || 8080;
|
||||||
@ -61,6 +62,14 @@
|
|||||||
res.send(JSON.stringify(bundles));
|
res.send(JSON.stringify(bundles));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use('/proxyUrl', function proxyRequest(req, res, next) {
|
||||||
|
console.log('Proxying request to: ', req.query.url);
|
||||||
|
req.pipe(request({
|
||||||
|
url: req.query.url,
|
||||||
|
strictSSL: false
|
||||||
|
}).on('error', next)).pipe(res);
|
||||||
|
});
|
||||||
|
|
||||||
// Expose everything else as static files
|
// Expose everything else as static files
|
||||||
app.use(express['static']('.'));
|
app.use(express['static']('.'));
|
||||||
|
|
||||||
|
20
example/msl/README.md
Normal file
20
example/msl/README.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
To use this bundle, add the following paths to /main.js -
|
||||||
|
'./platform/features/conductor/bundle',
|
||||||
|
'./example/msl/bundle',
|
||||||
|
|
||||||
|
An example plugin that integrates with public data from the Curiosity rover.
|
||||||
|
The data shown used by this plugin is published by the Centro de
|
||||||
|
Astrobiología (CSIC-INTA) at http://cab.inta-csic.es/rems/
|
||||||
|
|
||||||
|
Fetching data from this source requires a cross-origin request which will
|
||||||
|
fail on most modern browsers due to restrictions on such requests. As such,
|
||||||
|
it is proxied through a local proxy defined in app.js. In order to use this
|
||||||
|
example you will need to run app.js locally.
|
||||||
|
|
||||||
|
This example shows integration with an historical telemetry source, as
|
||||||
|
opposed to a real-time data source that is streaming back current information
|
||||||
|
about the state of a system. This example is atypical of a historical data
|
||||||
|
source in that it fetches all data in one request. The server infrastructure
|
||||||
|
of an historical telemetry source should ideally allow queries bounded by
|
||||||
|
time and other data attributes.
|
||||||
|
|
118
example/msl/bundle.js
Normal file
118
example/msl/bundle.js
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define([
|
||||||
|
"./src/RemsTelemetryServerAdapter",
|
||||||
|
"./src/RemsTelemetryInitializer",
|
||||||
|
"./src/RemsTelemetryModelProvider",
|
||||||
|
"./src/RemsTelemetryProvider",
|
||||||
|
'legacyRegistry',
|
||||||
|
"module"
|
||||||
|
], function (
|
||||||
|
RemsTelemetryServerAdapter,
|
||||||
|
RemsTelemetryInitializer,
|
||||||
|
RemsTelemetryModelProvider,
|
||||||
|
RemsTelemetryProvider,
|
||||||
|
legacyRegistry
|
||||||
|
) {
|
||||||
|
"use strict";
|
||||||
|
legacyRegistry.register("example/notifications", {
|
||||||
|
"name" : "Mars Science Laboratory Data Adapter",
|
||||||
|
"extensions" : {
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"name":"Mars Science Laboratory",
|
||||||
|
"key": "msl.curiosity",
|
||||||
|
"glyph": "o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Instrument",
|
||||||
|
"key": "msl.instrument",
|
||||||
|
"glyph": "o",
|
||||||
|
"model": {"composition": []}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Measurement",
|
||||||
|
"key": "msl.measurement",
|
||||||
|
"glyph": "T",
|
||||||
|
"model": {"telemetry": {}},
|
||||||
|
"telemetry": {
|
||||||
|
"source": "rems.source",
|
||||||
|
"domains": [
|
||||||
|
{
|
||||||
|
"name": "Time",
|
||||||
|
"key": "timestamp",
|
||||||
|
"format": "utc"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"constants": [
|
||||||
|
{
|
||||||
|
"key": "REMS_WS_URL",
|
||||||
|
"value": "/proxyUrl?url=http://cab.inta-csic.es/rems/wp-content/plugins/marsweather-widget/api.php"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"roots": [
|
||||||
|
{
|
||||||
|
"id": "msl:curiosity",
|
||||||
|
"priority" : "preferred",
|
||||||
|
"model": {
|
||||||
|
"type": "msl.curiosity",
|
||||||
|
"name": "Mars Science Laboratory",
|
||||||
|
"composition": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"key":"rems.adapter",
|
||||||
|
"implementation": RemsTelemetryServerAdapter,
|
||||||
|
"depends": ["$q", "$http", "$log", "REMS_WS_URL"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"runs": [
|
||||||
|
{
|
||||||
|
"implementation": RemsTelemetryInitializer,
|
||||||
|
"depends": ["rems.adapter", "objectService"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"provides": "modelService",
|
||||||
|
"type": "provider",
|
||||||
|
"implementation": RemsTelemetryModelProvider,
|
||||||
|
"depends": ["rems.adapter"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"provides": "telemetryService",
|
||||||
|
"type": "provider",
|
||||||
|
"implementation": RemsTelemetryProvider,
|
||||||
|
"depends": ["rems.adapter", "$q"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
1
example/msl/data/rems.json
Normal file
1
example/msl/data/rems.json
Normal file
File diff suppressed because one or more lines are too long
79
example/msl/src/MSLDataDictionary.js
Normal file
79
example/msl/src/MSLDataDictionary.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
/**
|
||||||
|
* A data dictionary describes the telemetry available from a data
|
||||||
|
* source and its data types. The data dictionary will be parsed by a custom
|
||||||
|
* server provider for this data source (in this case
|
||||||
|
* {@link RemsTelemetryServerAdapter}).
|
||||||
|
*
|
||||||
|
* Typically a data dictionary would be made available alongside the
|
||||||
|
* telemetry data source itself.
|
||||||
|
*/
|
||||||
|
function () {
|
||||||
|
return {
|
||||||
|
"name": "Mars Science Laboratory",
|
||||||
|
"identifier": "msl",
|
||||||
|
"instruments": [
|
||||||
|
{
|
||||||
|
"name":"rems",
|
||||||
|
"identifier": "rems",
|
||||||
|
"measurements": [
|
||||||
|
{
|
||||||
|
"name": "Min. Air Temperature",
|
||||||
|
"identifier": "min_temp",
|
||||||
|
"units": "degrees",
|
||||||
|
"type": "float"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Max. Air Temperature",
|
||||||
|
"identifier": "max_temp",
|
||||||
|
"units": "degrees",
|
||||||
|
"type": "float"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Atmospheric Pressure",
|
||||||
|
"identifier": "pressure",
|
||||||
|
"units": "pascals",
|
||||||
|
"type": "float"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Min. Ground Temperature",
|
||||||
|
"identifier": "min_gts_temp",
|
||||||
|
"units": "degrees",
|
||||||
|
"type": "float"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Max. Ground Temperature",
|
||||||
|
"identifier": "max_gts_temp",
|
||||||
|
"units": "degrees",
|
||||||
|
"type": "float"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
71
example/msl/src/RemsTelemetryInitializer.js
Normal file
71
example/msl/src/RemsTelemetryInitializer.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
function (){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var TAXONOMY_ID = "msl:curiosity",
|
||||||
|
PREFIX = "msl_tlm:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function that is executed on application startup and populates
|
||||||
|
* the navigation tree with objects representing the MSL REMS
|
||||||
|
* telemetry points. The tree is populated based on the data
|
||||||
|
* dictionary on the provider.
|
||||||
|
*
|
||||||
|
* @param {RemsTelemetryServerAdapter} adapter The server adapter
|
||||||
|
* (necessary in order to retrieve data dictionary)
|
||||||
|
* @param objectService the ObjectService which allows for lookup of
|
||||||
|
* objects by ID
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function RemsTelemetryInitializer(adapter, objectService) {
|
||||||
|
function makeId(element) {
|
||||||
|
return PREFIX + element.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeTaxonomy(dictionary) {
|
||||||
|
function getTaxonomyObject(domainObjects) {
|
||||||
|
return domainObjects[TAXONOMY_ID];
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateModel (taxonomyObject) {
|
||||||
|
return taxonomyObject.useCapability(
|
||||||
|
"mutation",
|
||||||
|
function (model) {
|
||||||
|
model.name = dictionary.name;
|
||||||
|
model.composition = dictionary.instruments.map(makeId);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
objectService.getObjects([TAXONOMY_ID])
|
||||||
|
.then(getTaxonomyObject)
|
||||||
|
.then(populateModel);
|
||||||
|
}
|
||||||
|
initializeTaxonomy(adapter.dictionary);
|
||||||
|
}
|
||||||
|
return RemsTelemetryInitializer;
|
||||||
|
}
|
||||||
|
);
|
87
example/msl/src/RemsTelemetryModelProvider.js
Normal file
87
example/msl/src/RemsTelemetryModelProvider.js
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
function (){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var PREFIX = "msl_tlm:",
|
||||||
|
FORMAT_MAPPINGS = {
|
||||||
|
float: "number",
|
||||||
|
integer: "number",
|
||||||
|
string: "string"
|
||||||
|
};
|
||||||
|
|
||||||
|
function RemsTelemetryModelProvider(adapter){
|
||||||
|
|
||||||
|
function isRelevant(id) {
|
||||||
|
return id.indexOf(PREFIX) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeId(element){
|
||||||
|
return PREFIX + element.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildTaxonomy(dictionary){
|
||||||
|
var models = {};
|
||||||
|
|
||||||
|
function addMeasurement(measurement){
|
||||||
|
var format = FORMAT_MAPPINGS[measurement.type];
|
||||||
|
models[makeId(measurement)] = {
|
||||||
|
type: "msl.measurement",
|
||||||
|
name: measurement.name,
|
||||||
|
telemetry: {
|
||||||
|
key: measurement.identifier,
|
||||||
|
ranges: [{
|
||||||
|
key: "value",
|
||||||
|
name: measurement.units,
|
||||||
|
units: measurement.units,
|
||||||
|
format: format
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function addInstrument(subsystem) {
|
||||||
|
var measurements = (subsystem.measurements || []);
|
||||||
|
models[makeId(subsystem)] = {
|
||||||
|
type: "msl.instrument",
|
||||||
|
name: subsystem.name,
|
||||||
|
composition: measurements.map(makeId)
|
||||||
|
};
|
||||||
|
measurements.forEach(addMeasurement);
|
||||||
|
}
|
||||||
|
|
||||||
|
(dictionary.instruments || []).forEach(addInstrument);
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getModels: function (ids) {
|
||||||
|
return ids.some(isRelevant) ? buildTaxonomy(adapter.dictionary) : {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return RemsTelemetryModelProvider;
|
||||||
|
}
|
||||||
|
);
|
83
example/msl/src/RemsTelemetryProvider.js
Normal file
83
example/msl/src/RemsTelemetryProvider.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define */
|
||||||
|
define (
|
||||||
|
['./RemsTelemetrySeries'],
|
||||||
|
function (RemsTelemetrySeries) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var SOURCE = "rems.source";
|
||||||
|
|
||||||
|
function RemsTelemetryProvider(adapter, $q) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
this.$q = $q;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve telemetry from this telemetry source.
|
||||||
|
* @memberOf example/msl
|
||||||
|
* @param {Array<TelemetryRequest>} requests An array of all request
|
||||||
|
* objects (which needs to be filtered to only those relevant to this
|
||||||
|
* source)
|
||||||
|
* @returns {Promise} A {@link Promise} resolved with a {@link RemsTelemetrySeries}
|
||||||
|
* object that wraps the telemetry returned from the telemetry source.
|
||||||
|
*/
|
||||||
|
RemsTelemetryProvider.prototype.requestTelemetry = function (requests) {
|
||||||
|
var packaged = {},
|
||||||
|
relevantReqs,
|
||||||
|
adapter = this.adapter;
|
||||||
|
|
||||||
|
function matchesSource(request) {
|
||||||
|
return (request.source === SOURCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addToPackage(history) {
|
||||||
|
packaged[SOURCE][history.id] =
|
||||||
|
new RemsTelemetrySeries(history.values);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleRequest(request) {
|
||||||
|
return adapter.history(request).then(addToPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
relevantReqs = requests.filter(matchesSource);
|
||||||
|
packaged[SOURCE] = {};
|
||||||
|
|
||||||
|
return this.$q.all(relevantReqs.map(handleRequest))
|
||||||
|
.then(function () {
|
||||||
|
return packaged;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This data source does not support real-time subscriptions
|
||||||
|
*/
|
||||||
|
RemsTelemetryProvider.prototype.subscribe = function (callback, requests) {
|
||||||
|
return function() {};
|
||||||
|
};
|
||||||
|
RemsTelemetryProvider.prototype.unsubscribe = function (callback, requests) {
|
||||||
|
return function() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
return RemsTelemetryProvider;
|
||||||
|
}
|
||||||
|
);
|
84
example/msl/src/RemsTelemetrySeries.js
Normal file
84
example/msl/src/RemsTelemetrySeries.js
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define */
|
||||||
|
define(
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} RemsTelemetryValue
|
||||||
|
* @memberOf example/msl
|
||||||
|
* @property {number} date The date/time of the telemetry value. Constitutes the domain value of this value pair
|
||||||
|
* @property {number} value The value of this telemetry datum.
|
||||||
|
* A floating point value representing some observable quantity (eg.
|
||||||
|
* temperature, air pressure, etc.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A representation of a collection of telemetry data. The REMS
|
||||||
|
* telemetry data is time ordered, with the 'domain' value
|
||||||
|
* constituting the time stamp of each data value and the
|
||||||
|
* 'range' being the value itself.
|
||||||
|
*
|
||||||
|
* TelemetrySeries will typically wrap an array of telemetry data,
|
||||||
|
* and provide an interface for retrieving individual an telemetry
|
||||||
|
* value.
|
||||||
|
* @memberOf example/msl
|
||||||
|
* @param {Array<RemsTelemetryValue>} data An array of telemetry values
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function RemsTelemetrySeries(data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {number} A count of the number of data values available in
|
||||||
|
* this series
|
||||||
|
*/
|
||||||
|
RemsTelemetrySeries.prototype.getPointCount = function() {
|
||||||
|
return this.data.length;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* The domain value at the given index. The Rems telemetry data is
|
||||||
|
* time ordered, so the domain value is the time stamp of each data
|
||||||
|
* value.
|
||||||
|
* @param index
|
||||||
|
* @returns {number} the time value in ms since 1 January 1970
|
||||||
|
*/
|
||||||
|
RemsTelemetrySeries.prototype.getDomainValue = function(index) {
|
||||||
|
return this.data[index].date;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The range value of the REMS data set is the value of the thing
|
||||||
|
* being measured, be it temperature, air pressure, etc.
|
||||||
|
* @param index The datum in the data series to return the range
|
||||||
|
* value of.
|
||||||
|
* @returns {number} A floating point number
|
||||||
|
*/
|
||||||
|
RemsTelemetrySeries.prototype.getRangeValue = function(index) {
|
||||||
|
return this.data[index].value;
|
||||||
|
};
|
||||||
|
|
||||||
|
return RemsTelemetrySeries;
|
||||||
|
}
|
||||||
|
);
|
142
example/msl/src/RemsTelemetryServerAdapter.js
Normal file
142
example/msl/src/RemsTelemetryServerAdapter.js
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define*/
|
||||||
|
/*jslint es5: true */
|
||||||
|
|
||||||
|
define(
|
||||||
|
[
|
||||||
|
"./MSLDataDictionary",
|
||||||
|
"module"
|
||||||
|
],
|
||||||
|
function (MSLDataDictionary, module) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var TERRESTRIAL_DATE = "terrestrial_date",
|
||||||
|
LOCAL_DATA = "../data/rems.json";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches historical data from the REMS instrument on the Curiosity
|
||||||
|
* Rover.
|
||||||
|
* @memberOf example/msl
|
||||||
|
* @param $q
|
||||||
|
* @param $http
|
||||||
|
* @param REMS_WS_URL The location of the REMS telemetry data.
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function RemsTelemetryServerAdapter($q, $http, $log, REMS_WS_URL) {
|
||||||
|
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
|
||||||
|
this.deferreds = {};
|
||||||
|
this.REMS_WS_URL = REMS_WS_URL;
|
||||||
|
this.$q = $q;
|
||||||
|
this.$http = $http;
|
||||||
|
this.$log = $log;
|
||||||
|
this.cache = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The data dictionary for this data source.
|
||||||
|
* @type {MSLDataDictionary}
|
||||||
|
*/
|
||||||
|
RemsTelemetryServerAdapter.prototype.dictionary = MSLDataDictionary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches historical data from source, and associates it with the
|
||||||
|
* given request ID.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
RemsTelemetryServerAdapter.prototype.requestHistory = function(request) {
|
||||||
|
var self = this,
|
||||||
|
id = request.key,
|
||||||
|
deferred = this.$q.defer();
|
||||||
|
|
||||||
|
function processResponse(response){
|
||||||
|
var data = [];
|
||||||
|
/*
|
||||||
|
* Currently all data is returned for entire history of the mission. Cache response to avoid unnecessary re-queries.
|
||||||
|
*/
|
||||||
|
self.cache = response;
|
||||||
|
/*
|
||||||
|
* History data is organised by Sol. Iterate over sols...
|
||||||
|
*/
|
||||||
|
response.data.soles.forEach(function(solData){
|
||||||
|
/*
|
||||||
|
* Check that valid data exists
|
||||||
|
*/
|
||||||
|
if (!isNaN(solData[id])) {
|
||||||
|
/*
|
||||||
|
* Append each data point to the array of values
|
||||||
|
* for this data point property (min. temp, etc).
|
||||||
|
*/
|
||||||
|
data.unshift({
|
||||||
|
date: Date.parse(solData[TERRESTRIAL_DATE]),
|
||||||
|
value: solData[id]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fallbackToLocal() {
|
||||||
|
self.$log.warn("Loading REMS data failed, probably due to" +
|
||||||
|
" cross origin policy. Falling back to local data");
|
||||||
|
return self.$http.get(self.localDataURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Filter results to match request parameters
|
||||||
|
function filterResults(results) {
|
||||||
|
return results.filter(function(result){
|
||||||
|
return result.date >= (request.start || Number.MIN_VALUE) &&
|
||||||
|
result.date <= (request.end || Number.MAX_VALUE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function packageAndResolve(results){
|
||||||
|
deferred.resolve({id: id, values: results});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.$q.when(this.cache || this.$http.get(this.REMS_WS_URL))
|
||||||
|
.catch(fallbackToLocal)
|
||||||
|
.then(processResponse)
|
||||||
|
.then(filterResults)
|
||||||
|
.then(packageAndResolve);
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests historical telemetry for the named data attribute. In
|
||||||
|
* the case of REMS, this data source exposes multiple different
|
||||||
|
* data variables from the REMS instrument, including temperature
|
||||||
|
* and others
|
||||||
|
* @param id The telemetry data point key to be queried.
|
||||||
|
* @returns {Promise | Array<RemsTelemetryValue>} that resolves with an Array of {@link RemsTelemetryValue} objects for the request data key.
|
||||||
|
*/
|
||||||
|
RemsTelemetryServerAdapter.prototype.history = function(request) {
|
||||||
|
var id = request.key;
|
||||||
|
return this.requestHistory(request);
|
||||||
|
};
|
||||||
|
|
||||||
|
return RemsTelemetryServerAdapter;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -4,7 +4,8 @@
|
|||||||
"description": "The Open MCT Web core platform",
|
"description": "The Open MCT Web core platform",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.13.1",
|
"express": "^4.13.1",
|
||||||
"minimist": "^1.1.1"
|
"minimist": "^1.1.1",
|
||||||
|
"request": "^2.69.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bower": "^1.7.7",
|
"bower": "^1.7.7",
|
||||||
|
Loading…
Reference in New Issue
Block a user