25 | Oh snap :'( Something went wrong
26 | This on us, and we'll fix it as soon as possible
27 |
28 | Error: {this.state.error.message}
29 |
30 |
31 | ) : (
32 | // eslint-disable-next-line react/prop-types
33 | this.props.children
34 | );
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/assets/scripts/fsm/project/constants.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Session modes
3 | */
4 | export const SESSION_MODES = {
5 | LOADING: 'LOADING',
6 | PREDICT: 'PREDICT',
7 | RETRAIN: 'RETRAIN',
8 | };
9 |
10 | /**
11 | * Retrain map modes
12 | */
13 | export const RETRAIN_MAP_MODES = {
14 | BROWSE: 'BROWSE',
15 | ADD_POINT: 'ADD_POINT',
16 | ADD_POLYGON: 'ADD_POLYGON',
17 | ADD_FREEHAND: 'ADD_FREEHAND',
18 | REMOVE_SAMPLE: 'REMOVE_SAMPLE',
19 | DELETE_SAMPLES: 'DELETE_SAMPLES',
20 | };
21 |
--------------------------------------------------------------------------------
/app/assets/scripts/fsm/project/guards.js:
--------------------------------------------------------------------------------
1 | import config from '../../config';
2 |
3 | export const isLargeAoi = (context) => {
4 | const { currentAoi, apiLimits } = context;
5 | return currentAoi?.area > apiLimits?.live_inference;
6 | };
7 |
8 | export const retrainModeEnabled = (context) => {
9 | return !isLargeAoi(context) && context.currentTimeframe;
10 | };
11 |
12 | export const isRetrainReady = (context) => {
13 | return (
14 | context.retrainClasses?.length > 0 && context.retrainSamples?.length > 0
15 | );
16 | };
17 |
18 | export const isPredictionReady = (context) => {
19 | const {
20 | currentImagerySource,
21 | currentMosaic,
22 | currentModel,
23 | currentAoi,
24 | } = context;
25 |
26 | if (context.project.id === 'new') {
27 | return (
28 | !!currentAoi &&
29 | !!currentImagerySource &&
30 | !!currentMosaic &&
31 | !!currentModel
32 | );
33 | } else {
34 | return !!currentAoi && !!currentMosaic;
35 | }
36 | };
37 |
38 | export const isProjectNew = (c) => c.project.id === 'new';
39 | export const isFirstAoi = (c) => c.aoisList?.length === 0;
40 | export const isAoiNew = ({ currentAoi }) => !currentAoi || !currentAoi.id;
41 | export const isAuthenticated = (c) => c.isAuthenticated;
42 |
43 | export const isLivePredictionAreaSize = ({ currentAoi, apiLimits }) =>
44 | currentAoi &&
45 | currentAoi.area > config.minimumAoiArea &&
46 | currentAoi.area < apiLimits.live_inference;
47 |
48 | export const isBatchRunning = (c) => !!c.currentBatchPrediction;
49 |
50 | export const hasAois = (c) => c.aoisList?.length > 0;
51 |
52 | export const hasTimeframe = (c) => c.currentTimeframe;
53 |
--------------------------------------------------------------------------------
/app/assets/scripts/fsm/project/index.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect } from 'react';
2 | import T from 'prop-types';
3 | import { createActorContext } from '@xstate/react';
4 | import { projectMachine } from './machine';
5 | import { machineStateLogger } from '../../utils/machine-state-logger';
6 |
7 | import config from '../../config';
8 | const { environment } = config;
9 |
10 | export const ProjectMachineContext = createActorContext(projectMachine);
11 |
12 | export function ProjectMachineProvider(props) {
13 | return (
14 |