-
Notifications
You must be signed in to change notification settings - Fork 0
/
WizardStore.js
527 lines (522 loc) · 25.8 KB
/
WizardStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
import {defineStore} from 'pinia'
import {useDashboardStore} from './DashboardStore'
export const useWizardStore = defineStore('WizardStore', {
state: () => ({
dashboard: useDashboardStore(),
// stores the configuration values
configuration: {},
// the type of configuration being used (e.g. Guided, Custom)
activeConfigType: null,
// the index of the currently-selected form
activeFormIndex: 0,
// array of component names used within the ConfigurationView. Used to display by index
formOrder: ['Initial', 'Inhabitants', 'ECLSS', 'Greenhouse', 'Energy', 'Finalize'],
// which window on the reference side is active
activeReference: 'Layout', // see also resetConfigDefault below
// which entry is currently active within the reference
activeRefEntry: 'Welcome', // see also resetConfigDefault below
// true if the preset dropdown and the config form should be reset
resetConfig: false,
// the base url for the cached simdata
simdataLocation: 'https://simoc.space/download/simdata/',
// valid values and ranges for the form inputs
// TODO: the valid values should probably be defined and sent by the server
validValues: {
locations: ['mars', 'b2'],
startDate: {
min: '1991-01-01',
max: '1995-12-31',
},
duration_ranges: {
// limited to 2 earth years
hour: {min: 24, max: 8760*2},
day: {min: 1, max: 365*2},
year: {min: 1, max: 1*2},
},
duration_units: ['hour', 'day'],
humans: {min: 0, max: 10},
weeding: {min: 0, max: 16},
pestPicking: {min: 0, max: 16},
food: {min: 0, max: 8760},
eclss: {
amount: {min: 0, max: 10},
co2UpperLimit: {min: 0, max: 1},
co2Reserves: {min: 0, max: 1e6},
co2LowerLimit: {min: 0, max: 1},
o2Reserves: {min: 0, max: 1e6},
o2LowerLimit: {min: 0, max: 30},
},
crew_quarters_types: ['none', 'crew_habitat_small',
'crew_habitat_medium', 'crew_habitat_large',
'crew_habitat_sam', 'crew_habitat_b2'],
greenhouse_types: ['none', 'greenhouse_small',
'greenhouse_medium', 'greenhouse_large',
'greenhouse_sam', 'greenhouse_b2'],
// TODO: the list of plants is downloaded and should be cached
// the valid range for plants is calculated dinamically
concrete: {min: 0, max: 0.1},
generator_types: ['none', 'solar_pv_array_mars', 'b2_power_gen'],
generator: {min: 0, max: 5000},
storage: {min: 0, max: 10000},
},
defaultConfigs: {mars: 'one_human_radish', b2: 'b2_mission_1a'},
emptyMarsConfig: {
name: 'Default config',
simdata_file: '',
location: 'mars',
duration: {type: 'none', amount: null, units: 'day'},
humans: {type: 'human_agent', amount: null, units: ''},
food: {type: 'food_storage', amount: null, units: 'kg'},
eclss: {type: 'eclss', amount: null, units: ''},
powerGeneration: {type: 'solar_pv_array_mars', amount: null, units: ''},
powerStorage: {type: 'power_storage', amount: null, units: 'kWh'},
crewQuarters: {type: 'none', amount: 0, units: ''},
greenhouse: {type: 'none', amount: 0, units: ''},
plantSpecies: [{type: '', amount: ''}],
},
emptyB2Config: {
name: 'Default config Biosphere 2',
simdata_file: '',
location: 'b2',
startDate: '',
duration: {type: 'none', amount: null, units: 'day'},
humans: {type: 'human_agent', amount: null, units: '',
weeding: null, pestPicking: null},
food: {type: 'food_storage', amount: null, units: 'kg'},
crewQuarters: {type: 'crew_habitat_b2', amount: 0, units: ''},
biomes: {rainforest: 0, desert: 0, ocean: 0, savannah: 0},
eclss: {type: 'eclss', amount: null, units: '', o2Reserves: 0, o2LowerLimit: 0,
co2Reserves: 0, co2LowerLimit: 0, co2UpperLimit: 0},
powerGeneration: {type: 'b2_power_gen', amount: null, units: ''},
powerStorage: {type: 'power_storage', amount: null, units: 'kWh'},
greenhouse: {type: 'greenhouse_b2', amount: 0, units: ''},
plantSpecies: [{type: '', amount: ''}],
improvedCropManagement: false,
startWithM1EndingAtmosphere: false,
concrete: {amount: 0, carbonation: 0},
},
mars_presets: {
one_human: {
name: '1 Human + ECLSS',
simdata_file: 'simoc-simdata-1-human-preset.json',
location: 'mars',
duration: {type: 'none', amount: 10, units: 'day'},
humans: {type: 'human_agent', amount: 1, units: ''},
food: {type: 'food_storage', amount: 100, units: 'kg'},
crewQuarters: {type: 'crew_habitat_small', amount: 1, units: ''},
eclss: {type: 'eclss', amount: 1, units: ''},
powerGeneration: {type: 'solar_pv_array_mars', amount: 30, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'none', amount: 0, units: ''},
plantSpecies: [{type: '', amount: ''}],
},
one_human_radish: {
name: '1 Human + ECLSS + Radish',
simdata_file: 'simoc-simdata-1-human-radish-preset.json',
location: 'mars',
duration: {type: 'none', amount: 30, units: 'day'},
humans: {type: 'human_agent', amount: 1, units: ''},
food: {type: 'food_storage', amount: 100, units: 'kg'},
crewQuarters: {type: 'crew_habitat_small', amount: 1, units: ''},
eclss: {type: 'eclss', amount: 1, units: ''},
powerGeneration: {type: 'solar_pv_array_mars', amount: 70, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'greenhouse_small', amount: 1, units: ''},
plantSpecies: [{type: 'radish', amount: 40}],
},
four_humans: {
name: '4 Humans + ECLSS',
simdata_file: 'simoc-simdata-4-human-preset.json',
location: 'mars',
duration: {type: 'none', amount: 10, units: 'day'},
humans: {type: 'human_agent', amount: 4, units: ''},
food: {type: 'food_storage', amount: 100, units: 'kg'},
crewQuarters: {type: 'crew_habitat_small', amount: 1, units: ''},
eclss: {type: 'eclss', amount: 1, units: ''},
powerGeneration: {type: 'solar_pv_array_mars', amount: 30, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'none', amount: 0, units: ''},
plantSpecies: [{type: '', amount: ''}],
},
four_humans_garden: {
name: '4 Humans + ECLSS + Garden',
simdata_file: 'simoc-simdata-4-human-garden-preset.json',
location: 'mars',
duration: {type: 'none', amount: 100, units: 'day'},
humans: {type: 'human_agent', amount: 4, units: ''},
food: {type: 'food_storage', amount: 1200, units: 'kg'},
crewQuarters: {type: 'crew_habitat_medium', amount: 1, units: ''},
eclss: {type: 'eclss', amount: 1, units: ''},
powerGeneration: {type: 'solar_pv_array_mars', amount: 500, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'greenhouse_small', amount: 1, units: ''},
plantSpecies: [
{type: 'wheat', amount: 20},
{type: 'cabbage', amount: 30},
{type: 'strawberry', amount: 10},
{type: 'radish', amount: 50},
{type: 'red_beet', amount: 50},
{type: 'onion', amount: 50},
],
},
sam_one_human_garden: {
name: 'SAM: 1 Human + ECLSS + Garden',
simdata_file: 'simoc-simdata-sam-1-human-garden-preset.json',
location: 'mars',
duration: {type: 'none', amount: 100, units: 'day'},
humans: {type: 'human_agent', amount: 1, units: ''},
food: {type: 'food_storage', amount: 300, units: 'kg'},
crewQuarters: {type: 'crew_habitat_sam', amount: 1, units: ''},
eclss: {type: 'eclss', amount: 1, units: ''},
powerGeneration: {type: 'solar_pv_array_mars', amount: 100, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'greenhouse_sam', amount: 1, units: ''},
plantSpecies: [
{type: 'rice', amount: 2},
{type: 'cabbage', amount: 8},
{type: 'tomato', amount: 8},
{type: 'sweet_potato', amount: 5},
],
},
// these are disabled for now
/*
wheat: {
name: '2 Humans + Wheat (no ECLSS)',
simdata_file: "",
location: 'mars',
duration: {type:'none', amount:100, units:'day'},
humans: {type:'human_agent', amount:2, units:''},
food: {type:'food_storage', amount:300, units:'kg'},
crewQuarters: {type:'crew_habitat_small', amount:1, units:''},
eclss: {type:'eclss', amount:0, units:''},
powerGeneration: {type:'solar_pv_array_mars', amount:380, units:''},
powerStorage: {type:'power_storage', amount:1000, units:'kWh'},
greenhouse: {type:'greenhouse_small', amount:1, units:''},
plantSpecies: [{type:'wheat', amount:100}],
},
humansonly: {
name: '2 Humans',
simdata_file: "",
location: 'mars',
duration: {type:'none', amount:30, units:'day'},
humans: {type:'human_agent', amount:2, units:''},
food: {type:'food_storage', amount:10000, units:'kg'},
crewQuarters: {type:'crew_habitat_small', amount:0, units:''},
eclss: {type:'eclss', amount:1, units:''},
powerGeneration: {type:'solar_pv_array_mars', amount:2, units:''},
powerStorage: {type:'power_storage', amount:1000, units:'kWh'},
greenhouse: {type:'none', amount:0, units:''},
plantSpecies: [{type:'', amount:''}],
},
hybridthree: {
name: '2 Humans + Wheat (no ECLSS, more food)',
simdata_file: "",
location: 'mars',
duration: {type:'none', amount:90, units:'day'},
humans: {type:'human_agent', amount:2, units:''},
food: {type:'food_storage', amount:10000, units:'kg'},
crewQuarters: {type:'crew_habitat_small', amount:1, units:''},
eclss: {type:'eclss', amount:0, units:''},
powerGeneration: {type:'solar_pv_array_mars', amount:20, units:''},
powerStorage: {type:'power_storage', amount:1000, units:'kWh'},
greenhouse: {type:'greenhouse_small', amount:1, units:''},
plantSpecies: [{type:'wheat', amount:100}],
},*/
},
b2_presets: {
b2_mission_1a: {
name: 'Mission 1a',
simdata_file: 'simoc-simdata-b2-mission-1a.json',
location: 'b2',
startDate: '1991-09-26',
duration: {type: 'none', amount: 475, units: 'day'},
humans: {type: 'human_agent', amount: 8, units: '', weeding: null,
pestPicking: null},
food: {type: 'food_storage', amount: 500, units: 'kg'},
crewQuarters: {type: 'crew_habitat_b2', amount: 1, units: ''},
biomes: {rainforest: 2000, desert: 1400, ocean: 863, savannah: 1637},
eclss: {type: 'eclss', amount: 1, units: '',
o2Reserves: 0, // kg
o2LowerLimit: 20, // %
co2Reserves: 0, // kg
co2LowerLimit: 0, // %
co2UpperLimit: 0.25}, // %
powerGeneration: {type: 'b2_power_gen', amount: 1, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'greenhouse_b2', amount: 1, units: ''},
plantSpecies: [
{type: 'rice', amount: 530},
{type: 'wheat', amount: 370},
{type: 'sorghum', amount: 261},
{type: 'peanut', amount: 168},
{type: 'corn', amount: 488},
{type: 'dry_bean', amount: 222},
{type: 'sweet_potato', amount: 261},
{type: 'vegetables', amount: 348},
{type: 'soybean', amount: 326},
{type: 'orchard', amount: 646},
],
improvedCropManagement: false,
startWithM1EndingAtmosphere: false,
concrete: {amount: 15800, carbonation: 0.004}, // Actual: 0.00458
},
b2_mission_1b: {
name: 'Mission 1b',
simdata_file: 'simoc-simdata-b2-mission-1b.json',
location: 'b2',
startDate: '1993-01-12',
duration: {type: 'none', amount: 257, units: 'day'},
humans: {type: 'human_agent', amount: 8, units: ''},
food: {type: 'food_storage', amount: 500, units: 'kg'},
crewQuarters: {type: 'crew_habitat_b2', amount: 1, units: '',
o2: 1967, co2: 42, h2o: 120, n2: 11025},
biomes: {rainforest: 2000, desert: 1400, ocean: 863, savannah: 1637},
eclss: {type: 'eclss', amount: 1, units: '',
o2Reserves: 11288, // kg
o2LowerLimit: 20, // %
co2Reserves: 0, // kg
co2LowerLimit: 0, // %
co2UpperLimit: 0.25}, // %
powerGeneration: {type: 'b2_power_gen', amount: 1, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'greenhouse_b2', amount: 1, units: '',
o2: 6302, co2: 136, h2o: 381, n2: 35312},
plantSpecies: [
{type: 'rice', amount: 214},
{type: 'wheat', amount: 149},
{type: 'sorghum', amount: 105},
{type: 'peanut', amount: 68},
{type: 'corn', amount: 197},
{type: 'dry_bean', amount: 784},
{type: 'sweet_potato', amount: 784},
{type: 'vegetables', amount: 141},
{type: 'soybean', amount: 132},
{type: 'orchard', amount: 261},
{type: 'red_beet', amount: 784},
],
startWithM1EndingAtmosphere: true,
improvedCropManagement: false,
concrete: {amount: 15800, carbonation: 0.03}, // Actual: 0.02962
},
b2_mission_2: {
name: 'Mission 2',
simdata_file: 'simoc-simdata-b2-mission-2.json',
location: 'b2',
startDate: '1994-03-06',
duration: {type: 'none', amount: 185, units: 'day'},
humans: {type: 'human_agent', amount: 8, units: '', weeding: null,
pestPicking: null},
food: {type: 'food_storage', amount: 500, units: 'kg'},
crewQuarters: {type: 'crew_habitat_b2', amount: 1, units: ''},
biomes: {rainforest: 2000, desert: 1400, ocean: 863, savannah: 1637},
eclss: {type: 'eclss', amount: 1, units: '',
o2Reserves: 0, // kg
o2LowerLimit: 20, // %
co2Reserves: 0, // kg
co2LowerLimit: 0, // %
co2UpperLimit: 0.25}, // %
powerGeneration: {type: 'b2_power_gen', amount: 1, units: ''},
powerStorage: {type: 'power_storage', amount: 1000, units: 'kWh'},
greenhouse: {type: 'greenhouse_b2', amount: 1, units: ''},
plantSpecies: [
{type: 'rice', amount: 530},
{type: 'wheat', amount: 370},
{type: 'sorghum', amount: 261},
{type: 'peanut', amount: 168},
{type: 'corn', amount: 488},
{type: 'dry_bean', amount: 222},
{type: 'sweet_potato', amount: 261},
{type: 'vegetables', amount: 348},
{type: 'soybean', amount: 326},
{type: 'orchard', amount: 646},
],
startWithM1EndingAtmosphere: false,
improvedCropManagement: true,
concrete: {amount: 15800, carbonation: 0.04}, // Actual: 0.04099
},
},
}),
getters: {
// This method converts the total mission time to hours regardless of the units selected.
// As one step = one hour.
getActiveForm: state => state.formOrder[state.activeFormIndex],
getTotalMissionHours(state) {
let totalHours = 0
const durationLength = state.configuration.duration.amount
const durationUnits = state.configuration.duration.units
if (durationUnits === 'day') {
totalHours = durationLength * 24
} else if (durationUnits === 'year') {
totalHours = durationLength * 8760
} else {
totalHours = durationLength
}
return totalHours
},
// Returns a formatted configuration object in the format required by the backend.
getFormattedConfiguration(state) {
const config = state.configuration
// create formatted configuration
const fconfig = {
location: config.location,
start_time: config.startDate,
duration: {type: config.duration.units,
value: parseInt(config.duration.amount, 10)},
human_agent: {amount: parseInt(config.humans.amount, 10)},
food_storage: {ration: parseInt(config.food.amount, 10)},
eclss: config.eclss,
power_storage: {kwh: parseInt(config.powerStorage.amount, 10)},
nutrient_storage: {fertilizer: config.location === 'b2' ? 10000 : 300},
concrete: config.concrete,
single_agent: 1,
plants: [],
}
const pg = config.powerGeneration
fconfig[pg.type] = {amount: parseInt(pg.amount, 10)}
if ((state.configuration.greenhouse.type === 'none') &&
(state.configuration.crewQuarters.type === 'none')) {
throw new Error('Please select a value for the ' +
'Crew Quarters and/or the Greenhouse.')
}
if (state.configuration.greenhouse.type !== 'none') {
fconfig.greenhouse = config.greenhouse.type
}
if (state.configuration.crewQuarters.type !== 'none') {
fconfig.habitat = config.crewQuarters.type
}
if ('biomes' in state.configuration) {
fconfig.biomes = config.biomes
}
config.plantSpecies.forEach(element => {
// ignore plants if the plant type is not selected
if (element.type !== '') {
fconfig.plants.push({species: element.type,
amount: parseInt(element.amount, 10)})
}
})
// Flags, used to customize starting parameters in b2 sim
const flags = ['improvedCropManagement', 'startWithM1EndingAtmosphere']
flags.forEach(f => {
if (f in state.configuration) {
fconfig[f] = state.configuration[f]
}
})
return fconfig
},
getDefaultPresetName: state => location => state.defaultConfigs[location],
getDefaultPreset: state => location => {
// return a copy of the default preset for the given location
const preset_name = state.getDefaultPresetName(location)
return JSON.parse(JSON.stringify(state.getPresets(location)[preset_name]))
},
getPresets: state => location => {
// return an object with all the presets for the given location
const presets = location === 'b2' ? state.b2_presets : state.mars_presets
return presets
},
getEmptyConfig: state => location => {
// return a copy of the empty config for the given location
const emptyconfig = location === 'b2' ? state.emptyB2Config : state.emptyMarsConfig
return JSON.parse(JSON.stringify(emptyconfig))
},
},
actions: {
setConfiguration(value, location) {
// Make sure the config contains all required items:
// initialize with an empty config, then add
// all valid keys from "value" and report invalid ones.
const newvalue = JSON.parse(JSON.stringify(value))
const newconfig = this.getEmptyConfig(location)
const valid_keys = []
const invalid_keys = []
Object.keys(newvalue).forEach((key, i) => {
if (key in newconfig) {
newconfig[key] = newvalue[key]
valid_keys.push(key)
} else {
invalid_keys.push(key)
}
})
if (valid_keys.length === 0) {
throw new Error('invalid configuration file.')
}
if (invalid_keys.length > 0) {
console.log('* Ignoring invalid keys in the uploaded file:',
invalid_keys.join(', '))
}
this.configuration = newconfig
},
setPreset(name, location) {
const preset = this[`${location}_presets`][name]
this.setConfiguration(preset, location)
},
setLiveConfig(duration, location) {
this.setConfiguration(duration, location)
},
setInitial(value) {
const {startDate, duration} = value
this.configuration.startDate = startDate
this.configuration.duration = duration
},
setInhabitants(value) {
const {humans, food, crewQuarters} = value
this.configuration.humans = humans
this.configuration.food = food
this.configuration.crewQuarters = crewQuarters
if ('biomes' in value) {
const {biomes} = value
this.configuration.biomes = biomes
}
},
setECLSS(value) {
this.configuration.eclss = value
},
setGreenhouse(value) {
const {greenhouse} = value
this.configuration.greenhouse = greenhouse
},
setEnergy(value) {
const {powerGeneration, powerStorage} = value
this.configuration.powerGeneration = powerGeneration
this.configuration.powerStorage = powerStorage
},
// Adds an empty plant to the plant species array
addPlantSpecies() {
this.configuration.plantSpecies.push({type: '', amount: ''})
},
// Updates the plant at the index with the new values
updatePlantSpecies(value) {
const {index, plant} = value
plant.amount = parseInt(plant.amount, 10)
this.configuration.plantSpecies[index] = plant
},
// Removes the plant at the index
removePlantSpecies(value) {
const index = value
const arrLength = this.configuration.plantSpecies.length
if (arrLength > 1) {
this.configuration.plantSpecies.splice(index, 1)
} else if (arrLength === 1) {
// plantSpecies[0] = {type:"",amount:''} doesn't
// trigger the watchers, but this does
this.configuration.plantSpecies[0].type = ''
this.configuration.plantSpecies[0].amount = ''
}
},
setCropManagement(value) {
this.configuration.improvedCropManagement = value
},
setActiveRefEntry(value) {
// This is set here so I don't have to call it on every link.
// It is redundant for the table of contents navigation.
this.activeReference = 'Reference'
this.activeRefEntry = value
},
resetConfigDefault(location) {
this.configuration = this.getDefaultPreset(location)
this.activeFormIndex = 0
this.activeReference = location === 'mars' ? 'Layout' : 'Reference'
this.activeRefEntry = 'Welcome'
},
},
})