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

Update batch list with mosaic name, move mosaic name function #142

Merged
merged 4 commits into from
Mar 11, 2024
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
9 changes: 1 addition & 8 deletions app/assets/scripts/components/compare-map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
PanelBlockBody,
} from '../common/panel-block';
import { getMosaicTileUrl } from '../../utils/mosaics';
import { composeMosaicName } from '../../utils/mosaics';

const { restApiEndpoint } = config;

Expand Down Expand Up @@ -117,14 +118,6 @@ const INITIAL_MAP_LAYERS = {
},
};

export const composeMosaicName = (start, end) =>
`${new Date(start).toLocaleString('default', {
month: 'short',
})} - ${new Date(end).toLocaleString('default', {
month: 'short',
year: 'numeric',
})}`;

function CompareMap() {
const { leftUUID, rightUUID } = useParams();
const [mapRef, setMapRef] = useState(null);
Expand Down
13 changes: 10 additions & 3 deletions app/assets/scripts/components/profile/project/batch-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import T from 'prop-types';
import styled from 'styled-components';
import { Button } from '@devseed-ui/button';
import { Heading } from '@devseed-ui/typography';
import tArea from '@turf/area';

import Table, { TableRow, TableCell } from '../../common/table';
import Paginator from '../../common/paginator';
Expand All @@ -17,14 +18,17 @@ import { formatDateTime } from '../../../utils/format';
import logger from '../../../utils/logger';
import useFetch from '../../../utils/use-fetch';
import { downloadGeotiff } from '../../../utils/share-link';
import { formatThousands } from '../../../utils/format';
import { composeMosaicName } from '../../../utils/mosaics';

const TABLE_PAGE_SIZE = 5;
const TABLE_HEADERS = [
'Id',
'AOI Name',
'AOI Size (KM2)',
'Started',
'Mosaic',
'Status',
'Started',
'Download',
];

Expand Down Expand Up @@ -104,7 +108,11 @@ const BatchRow = ({ batch, projectId }) => {
<TableRow key={id}>
<TableCell>{id}</TableCell>
<TableCell>{aoi?.name}</TableCell>
<TableCell>{mosaic?.name}</TableCell>
<TableCell>{formatThousands(tArea(aoi?.bounds) / 1e6)}</TableCell>
<TableCell>{formatDateTime(created)}</TableCell>
<TableCell>
{composeMosaicName(mosaic.mosaic_ts_start, mosaic.mosaic_ts_end)}
</TableCell>
<TableCell>
{status === 'Processing' ? (
<>
Expand All @@ -121,7 +129,6 @@ const BatchRow = ({ batch, projectId }) => {
status
)}
</TableCell>
<TableCell>{formatDateTime(created)}</TableCell>
<TableCell>
<DownloadAoiButton
aoi={aoi?.id}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/scripts/components/profile/project/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import copyTextToClipboard from '../../../utils/copy-text-to-clipboard';
import logger from '../../../utils/logger';
import BatchList from './batch-list';
import { downloadShareGeotiff } from '../../../utils/share-link';
import { composeMosaicName } from '../../compare-map';
import { composeMosaicName } from '../../../utils/mosaics';

// Controls the size of each page
const AOIS_PER_PAGE = 20;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/scripts/components/public-maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import copyTextToClipboard from '../../utils/copy-text-to-clipboard';
import toasts from '../common/toasts';
import { downloadShareGeotiff } from '../../utils/share-link';
import { StyledLink } from '../../styles/links';
import { composeMosaicName } from '../compare-map';
import { composeMosaicName } from '../../utils/mosaics';
import { useLocation } from 'react-router-dom';

const ITEMS_PER_PAGE = 20;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/scripts/components/share-map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MapContainer, TileLayer, FeatureGroup } from 'react-leaflet';

import { getMosaicTileUrl } from '../../utils/mosaics';
import { toTitleCase } from '../../utils/format';
import { composeMosaicName } from '../compare-map';
import { composeMosaicName } from '../../utils/mosaics';
import { Accordion, AccordionFold as BaseFold } from '@devseed-ui/accordion';
import ClassAnalyticsChart from '../project/sec-panel/class-analytics-chart';
import { round } from '../../utils/format';
Expand Down
15 changes: 15 additions & 0 deletions app/assets/scripts/utils/mosaics.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,18 @@ export async function generateSentinel2L2AMosaic({
mosaic_ts_end: endTime,
};
}

/**
* Print a formatted mosaic name
*
* @param {Date} start
* @param {Date} end
* @returns Formatted mosaic name
*/
export const composeMosaicName = (start, end) =>
`${new Date(start).toLocaleString('default', {
month: 'short',
})} - ${new Date(end).toLocaleString('default', {
month: 'short',
year: 'numeric',
})}`;
145 changes: 139 additions & 6 deletions cypress/e2e/project/batch.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,25 @@ describe('Batch predictions', () => {
project_id: 1,
created: new Date(Date.parse('2001-02-01')).setUTCDate(-i),
updated: new Date(Date.parse('2001-02-01')).setUTCDate(i + 1),
aoi: { id: i, name: `AOI ${i}` },
aoi: {
id: i,
name: `AOI ${i}`,
created: `2023-12-04T12:02:26.1792${i}`,
updated: `2023-12-04T12:02:26.1792${i}`,
bounds: {
type: 'Polygon',
crs: { type: 'name', properties: { name: 'EPSG:4326' } },
coordinates: [
[
[-100.08922576904298, 19.28910944501149],
[-99.9700927734375, 19.28910944501149],
[-99.9700927734375, 19.17954399635705],
[-100.08922576904298, 19.17954399635705],
[-100.08922576904298, 19.28910944501149],
],
],
},
},
mosaic: { id: i, name: `Mosaic ${i}` },
abort: false,
completed: i !== 1,
Expand Down Expand Up @@ -505,12 +523,13 @@ describe('Batch predictions', () => {

// Check available columns
cy.get('th')
.should('have.length', 6)
.should('have.length', 7)
.should('include.text', 'Id')
.should('include.text', 'AOI Name')
.should('include.text', 'AOI Size (KM2)')
.should('include.text', 'Started')
.should('include.text', 'Mosaic')
.should('include.text', 'Status')
.should('include.text', 'Started')
.should('include.text', 'Download');

// Check if page is well-formed
Expand Down Expand Up @@ -545,7 +564,45 @@ describe('Batch predictions', () => {
id: 1,
created: 1630056802895,
updated: 1630056976364,
aoi: 1,
aoi: {
id: 1,
name: `AOI 1`,
created: `2023-12-04T12:02:26.17921`,
updated: `2023-12-04T12:02:26.17921`,
bounds: {
type: 'Polygon',
crs: { type: 'name', properties: { name: 'EPSG:4326' } },
coordinates: [
[
[-100.08922576904298, 19.28910944501149],
[-99.9700927734375, 19.28910944501149],
[-99.9700927734375, 19.17954399635705],
[-100.08922576904298, 19.17954399635705],
[-100.08922576904298, 19.28910944501149],
],
],
},
},
mosaic: {
id: '3c694933cb850c3d76fa7651765ad9c2',
name: 'Sep 27, 2021 - Nov 27, 2021',
params: {
assets: ['B04', 'B03', 'B02', 'B08'],
rescale: '0,10000',
collection: 'sentinel-2-l2a',
},
imagery_source_id: 2,
created: '2024-02-14T11:18:58.106998',
updated: '2024-02-14T11:18:58.106998',
mosaic_ts_start: '2021-09-27T10:25:31',
mosaic_ts_end: '2021-11-27T11:25:31',
ui_params: {
assets: ['B04', 'B03', 'B02'],
collection: 'sentinel-2-l2a',
color_formula:
'Gamma+RGB+3.2+Saturation+0.8+Sigmoidal+RGB+25+0.35',
},
},
name: 'Wesley Heights',
abort: false,
completed: false,
Expand All @@ -555,7 +612,45 @@ describe('Batch predictions', () => {
id: 2,
created: 1630056802895,
updated: 1630056976364,
aoi: 1,
aoi: {
id: 2,
name: `AOI 2`,
created: `2023-12-04T12:02:26.17922`,
updated: `2023-12-04T12:02:26.17922`,
bounds: {
type: 'Polygon',
crs: { type: 'name', properties: { name: 'EPSG:4326' } },
coordinates: [
[
[-100.08922576904298, 19.28910944501149],
[-99.9700927734375, 19.28910944501149],
[-99.9700927734375, 19.17954399635705],
[-100.08922576904298, 19.17954399635705],
[-100.08922576904298, 19.28910944501149],
],
],
},
},
mosaic: {
id: '3c694933cb850c3d76fa7651765ad9c2',
name: 'Sep 27, 2021 - Nov 27, 2021',
params: {
assets: ['B04', 'B03', 'B02', 'B08'],
rescale: '0,10000',
collection: 'sentinel-2-l2a',
},
imagery_source_id: 2,
created: '2024-02-14T11:18:58.106998',
updated: '2024-02-14T11:18:58.106998',
mosaic_ts_start: '2021-09-27T10:25:31',
mosaic_ts_end: '2021-11-27T11:25:31',
ui_params: {
assets: ['B04', 'B03', 'B02'],
collection: 'sentinel-2-l2a',
color_formula:
'Gamma+RGB+3.2+Saturation+0.8+Sigmoidal+RGB+25+0.35',
},
},
name: 'Wesley Heights',
abort: true,
completed: false,
Expand All @@ -565,7 +660,45 @@ describe('Batch predictions', () => {
id: 3,
created: 1630056802895,
updated: 1630056976364,
aoi: 1,
aoi: {
id: 3,
name: `AOI 3`,
created: `2023-12-04T12:02:26.17923`,
updated: `2023-12-04T12:02:26.17923`,
bounds: {
type: 'Polygon',
crs: { type: 'name', properties: { name: 'EPSG:4326' } },
coordinates: [
[
[-100.08922576904298, 19.28910944501149],
[-99.9700927734375, 19.28910944501149],
[-99.9700927734375, 19.17954399635705],
[-100.08922576904298, 19.17954399635705],
[-100.08922576904298, 19.28910944501149],
],
],
},
},
mosaic: {
id: '3c694933cb850c3d76fa7651765ad9c2',
name: 'Sep 27, 2021 - Nov 27, 2021',
params: {
assets: ['B04', 'B03', 'B02', 'B08'],
rescale: '0,10000',
collection: 'sentinel-2-l2a',
},
imagery_source_id: 2,
created: '2024-02-14T11:18:58.106998',
updated: '2024-02-14T11:18:58.106998',
mosaic_ts_start: '2021-09-27T10:25:31',
mosaic_ts_end: '2021-11-27T11:25:31',
ui_params: {
assets: ['B04', 'B03', 'B02'],
collection: 'sentinel-2-l2a',
color_formula:
'Gamma+RGB+3.2+Saturation+0.8+Sigmoidal+RGB+25+0.35',
},
},
name: 'Wesley Heights',
abort: false,
completed: true,
Expand Down
Loading