Skip to content

Commit

Permalink
minor tweaks to timeseries chart csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim committed Nov 21, 2024
1 parent 872597f commit 6e9523f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</button>
<mat-menu #menu="matMenu">
<div class="chart-config-menu-panel">
<button mat-button (click)="onExportCSV()">{{'EXPORT' | translate}} {{ 'CSV' | translate }}</button>
<button mat-button (click)="onExportCSV()">{{'EXPORT' | translate}} CSV</button>
</div>
</mat-menu>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class TimeseriesChartComponent implements OnInit, OnDestroy {
});

if (result.state.checked) {
const series_key = `series ${result.state.seriesNumber}`
const series_key = result.state.seriesNumber.toString()
if (!!!this.exportableData[series_key]) {
this.exportableData[series_key] = []
}
Expand Down
10 changes: 2 additions & 8 deletions src/app/services/netcdf-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NetcdfService {
private descendingCache = {}
private totalKeys = [];
private maxCacheSize = 10;
private csvHeaders = 'series, longitude, latitude, date (mm/dd/yr), short wavelength displacement, source file'
private csvHeaders = 'name, geometry, date (mm/dd/yr), short wavelength displacement, source file'

constructor(
private http: HttpClient,
Expand Down Expand Up @@ -129,19 +129,13 @@ export class NetcdfService {
// series 1, 1.0, 2.0, 05/14/2020, 0.500, granule1.nc
// ...
public toCSV(seriesData: { [index:string]: {}[]}): string {
const reg = /-?\d*\.\d+|\d+/g
let output = `${this.csvHeaders}\n`
const sortedSeriesKeys = Object.keys(seriesData).sort((s1, s2) => s1 < s2 ? -1 : 1)
for (const seriesNumber of sortedSeriesKeys) {

let points = seriesData[seriesNumber][0]['wkt'].match(reg)
const lon = points[0]
const lat = points[1]

for (const timestep of seriesData[seriesNumber]) {
if (timestep !== 'aoi') {
let dateDisplay = ''
// const sample = data.data[timestep]
if (timestep !== 'mean') {

const d = new Date(timestep['date'])
Expand All @@ -158,7 +152,7 @@ export class NetcdfService {
}
dateDisplay = `${monthDisplay}/${dayDisplay}/${d.getUTCFullYear()}`
}
output += `${seriesNumber}, ${lon}, ${lat}, ${dateDisplay}, ${timestep['short_wavelength_displacement']}, ${timestep['fileName']}\n`
output += `Series ${seriesNumber}, ${timestep['wkt']}, ${dateDisplay}, ${timestep['short_wavelength_displacement']}, ${timestep['fileName']}\n`
}
}
}
Expand Down

0 comments on commit 6e9523f

Please sign in to comment.