-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Tsay <[email protected]>
- Loading branch information
1 parent
a4fe8dd
commit 65d264f
Showing
67 changed files
with
1,105 additions
and
13,455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ npm-debug.log | |
# auto-env files for those that use them. | ||
.env | ||
dist | ||
package-lock.json | ||
test_data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import ExportDataTask from './ExportDataTask'; | ||
|
||
/** | ||
* Implements the "Export Data" action, allowing data for Channels, EVRs, | ||
* or grouped containers of these to be exported as CSV using ES6 class syntax. | ||
* | ||
* @param {openmct} openmct instance | ||
* @memberof vista/export | ||
*/ | ||
class ExportDataAction { | ||
constructor(openmct, validTypes) { | ||
this.name = 'Export Historical Data'; | ||
this.key = 'vista.export'; | ||
this.description = 'Export channel or EVR data as CSV'; | ||
this.cssClass = 'icon-download'; | ||
this.group = 'view'; | ||
this.priority = 1; | ||
this.validTypes = validTypes; | ||
|
||
this.openmct = openmct; | ||
} | ||
|
||
appliesTo(objectPath) { | ||
const domainObject = objectPath[0]; | ||
|
||
if (this.isValidType(domainObject)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
async invoke(objectPath) { | ||
const domainObject = objectPath[0]; | ||
const progressDialog = this.openmct.notifications.progress('Exporting CSV', 'unknown'); | ||
|
||
try { | ||
await this.exportData(domainObject); | ||
} catch (error) { | ||
console.error(error); | ||
this.openmct.notifications.error('Error exporting CSV'); | ||
} finally { | ||
progressDialog.dismiss(); | ||
} | ||
} | ||
|
||
async exportData(domainObject) { | ||
if (this.hasHistoricalTelemetry(domainObject)) { | ||
await this.runExportTask([domainObject]); | ||
} else { | ||
await this.exportCompositionData(domainObject); | ||
} | ||
} | ||
|
||
async exportCompositionData(domainObject) { | ||
const compositionCollection = this.openmct.composition.get(domainObject); | ||
const composition = await compositionCollection.load(); | ||
const filteredComposition = composition.filter(obj => | ||
this.isValidType(obj) && this.hasHistoricalTelemetry(obj) | ||
); | ||
|
||
if (filteredComposition.length > 0) { | ||
await this.runExportTask(filteredComposition); | ||
} else { | ||
this.openmct.notifications.info('No historical data to export'); | ||
} | ||
} | ||
|
||
runExportTask(domainObjects) { | ||
const task = new ExportDataTask(this.openmct, domainObjects[0].name, domainObjects); | ||
|
||
return task.invoke(); | ||
} | ||
|
||
isValidType(domainObject) { | ||
return this.validTypes.includes(domainObject?.type); | ||
} | ||
|
||
hasHistoricalTelemetry(domainObject) { | ||
return this.openmct.telemetry.isTelemetryObject(domainObject) && !domainObject.telemetry.realtimeOnly; | ||
} | ||
} | ||
|
||
export default ExportDataAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import CSV from 'comma-separated-values'; | ||
import {saveAs} from 'saveAs'; | ||
|
||
export default class ExportDataTask { | ||
/** | ||
* Exports telemetry data to CSV for a group of domain objects. | ||
* Used to support the "Export Data" action. | ||
* @see {vista/export.ExportDataAction} | ||
* @param {DomainObject[]} domainObjects the domain object for which | ||
* telemetry data should be exported | ||
*/ | ||
constructor(openmct, filename, domainObjects) { | ||
this.openmct = openmct; | ||
this.filename = filename; | ||
this.domainObjects = domainObjects; | ||
} | ||
|
||
/** | ||
* Query for telemetry data and export it to CSV. | ||
* @returns {Promise} a promise which will resolve when the export is | ||
* successfully completed, or be rejected if an error occurs | ||
*/ | ||
async invoke() { | ||
const telemetryData = await this.fetchAllTelemetryData(); | ||
const headers = this.extractHeaders(telemetryData); | ||
const allTelemetry = telemetryData.flat(); | ||
|
||
return this.exportAsCSV(allTelemetry, headers); | ||
} | ||
|
||
async fetchAllTelemetryData() { | ||
return Promise.all(this.domainObjects.map(async (domainObject) => { | ||
return this.openmct.telemetry.request(domainObject, { strategy: 'comprehensive' }); | ||
})); | ||
} | ||
|
||
extractHeaders(telemetryData) { | ||
const headerSet = new Set(); | ||
telemetryData.forEach(data => { | ||
const datum = data[0] || {}; | ||
Object.keys(datum).forEach(key => headerSet.add(key)); | ||
}); | ||
return Array.from(headerSet); | ||
} | ||
|
||
exportAsCSV(rows, headers) { | ||
const options = { | ||
headers: headers, | ||
filename: this.filename | ||
}; | ||
return this.exportCSV(rows, options); | ||
} | ||
|
||
exportCSV(rows, options) { | ||
const headers = options.headers || Object.keys((rows[0] || {})).sort(); | ||
const filename = `${options.filename || 'export'}.csv`; | ||
const csvText = new CSV(rows, { header: headers }).encode(); | ||
const blob = new Blob([csvText], { type: "text/csv" }); | ||
saveAs(blob, filename); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import ExportDataAction from './ExportDataAction'; | ||
|
||
export default function (validTypes) { | ||
return function (openmct) { | ||
openmct.actions.register(new ExportDataAction(openmct, validTypes)); | ||
}; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.