@@ -12,7 +12,7 @@ import {
12
12
savingExpansionSet ,
13
13
} from '../stores/expansion' ;
14
14
import { createModelError , createPlanError , creatingModel , creatingPlan , models , plan } from '../stores/plan' ;
15
- import { resources } from '../stores/resources' ;
15
+ import { simulationResources } from '../stores/resources' ;
16
16
import { schedulingStatus , selectedSpecId } from '../stores/scheduling' ;
17
17
import { simulation , simulationStatus } from '../stores/simulation' ;
18
18
import { view } from '../stores/views' ;
@@ -21,8 +21,9 @@ import { parseFloatOrNull, setQueryParam, sleep } from './generic';
21
21
import gql from './gql' ;
22
22
import { showConfirmModal } from './modal' ;
23
23
import { reqGateway , reqHasura } from './requests' ;
24
+ import { sampleProfiles } from './resources' ;
24
25
import { Status } from './status' ;
25
- import { getDoyTime , getDoyTimeFromDuration , getDurationInMs , getIntervalFromDoyRange , getUnixEpochTime } from './time' ;
26
+ import { getDoyTime , getDoyTimeFromDuration , getIntervalFromDoyRange } from './time' ;
26
27
import { showFailureToast , showSuccessToast } from './toast' ;
27
28
28
29
/**
@@ -750,65 +751,6 @@ const effects = {
750
751
}
751
752
} ,
752
753
753
- async getSampledResourcesForPlan ( planId : number ) : Promise < Resource [ ] > {
754
- try {
755
- const data = await reqHasura < ProfilesForPlanResponse > ( gql . GET_PROFILES_FOR_PLAN , { planId } ) ;
756
- const { plan } = data ;
757
- const { duration, simulations, start_time } = plan ;
758
- const [ { datasets } ] = simulations ;
759
- const [ { dataset } ] = datasets ;
760
- const { profiles } = dataset ;
761
-
762
- const planStart = getUnixEpochTime ( getDoyTime ( new Date ( start_time ) ) ) ;
763
- const planDuration = getDurationInMs ( duration ) ;
764
- const sampledResources : Resource [ ] = [ ] ;
765
-
766
- for ( const profile of profiles ) {
767
- const { name, profile_segments, type : profileType } = profile ;
768
- const { type } = profileType ;
769
- const values : ResourceValue [ ] = [ ] ;
770
- const schema = profileType ?. schema ?? ( profileType as ValueSchema ) ;
771
-
772
- for ( let i = 0 ; i < profile_segments . length ; ++ i ) {
773
- const segment = profile_segments [ i ] ;
774
- const nextSegment = profile_segments [ i + 1 ] ;
775
-
776
- const segmentOffset = getDurationInMs ( segment . start_offset ) ;
777
- const nextSegmentOffset = nextSegment ? getDurationInMs ( nextSegment . start_offset ) : planDuration ;
778
-
779
- const { dynamics } = segment ;
780
-
781
- if ( type === 'discrete' ) {
782
- values . push ( {
783
- x : planStart + segmentOffset ,
784
- y : dynamics ,
785
- } ) ;
786
- values . push ( {
787
- x : planStart + nextSegmentOffset ,
788
- y : dynamics ,
789
- } ) ;
790
- } else if ( type === 'real' ) {
791
- values . push ( {
792
- x : planStart + segmentOffset ,
793
- y : dynamics . initial ,
794
- } ) ;
795
- values . push ( {
796
- x : planStart + nextSegmentOffset ,
797
- y : dynamics . initial + dynamics . rate * ( nextSegmentOffset / 1000 ) ,
798
- } ) ;
799
- }
800
- }
801
-
802
- sampledResources . push ( { name, schema, values } ) ;
803
- }
804
-
805
- return sampledResources ;
806
- } catch ( e ) {
807
- console . log ( e ) ;
808
- return [ ] ;
809
- }
810
- } ,
811
-
812
754
async getSchedulingGoal ( id : number | null | undefined ) : Promise < SchedulingGoal | null > {
813
755
if ( id !== null && id !== undefined ) {
814
756
try {
@@ -852,6 +794,22 @@ const effects = {
852
794
}
853
795
} ,
854
796
797
+ async getSimulationResources ( planId : number ) : Promise < Resource [ ] > {
798
+ try {
799
+ const data = await reqHasura < ProfilesSimulationResponse > ( gql . GET_PROFILES_SIMULATION , { planId } ) ;
800
+ const { plan } = data ;
801
+ const { duration, simulations, start_time } = plan ;
802
+ const [ { datasets } ] = simulations ;
803
+ const [ { dataset } ] = datasets ;
804
+ const { profiles } = dataset ;
805
+ const resources : Resource [ ] = sampleProfiles ( profiles , start_time , duration ) ;
806
+ return resources ;
807
+ } catch ( e ) {
808
+ console . log ( e ) ;
809
+ return [ ] ;
810
+ }
811
+ } ,
812
+
855
813
async getTsFilesActivityType (
856
814
activityTypeName : string | null | undefined ,
857
815
modelId : number | null | undefined ,
@@ -1114,8 +1072,8 @@ const effects = {
1114
1072
activitiesMap . set ( keyBy ( newActivities , 'id' ) ) ;
1115
1073
1116
1074
// Resources.
1117
- const sampledResources : Resource [ ] = await effects . getSampledResourcesForPlan ( planId ) ;
1118
- resources . set ( sampledResources ) ;
1075
+ const resources : Resource [ ] = await effects . getSimulationResources ( planId ) ;
1076
+ simulationResources . set ( resources ) ;
1119
1077
1120
1078
checkConstraintsStatus . set ( Status . Dirty ) ;
1121
1079
simulationStatus . update ( Status . Complete ) ;
0 commit comments