You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							60 lines
						
					
					
						
							1.9 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							60 lines
						
					
					
						
							1.9 KiB
						
					
					
				| import React from "react" | |
| import AsyncStorage from '@react-native-async-storage/async-storage' | |
| 
 | |
| import aerodynamicsQuestions from "../data/aerodynamics" | |
| import firstAidQuestions from "../data/firstAid" | |
| import flightSafetyQuestions from "../data/flightSafety" | |
| import instrumentsQuestions from "../data/instruments" | |
| import legislationQuestions from "../data/legislation" | |
| import materialsQuestions from "../data/materials" | |
| import meteorologyQuestions from "../data/meteorology" | |
| import physiopathologyQuestions from "../data/physiopathology" | |
| import pilotingTechniquesQuestions from "../data/pilotingTechniques" | |
| 
 | |
| import { examScheme } from "../components/Variables" | |
| 
 | |
| let tmpQuestions = [] | |
| 
 | |
| const allQuestions = { | |
|   aerodynamics: aerodynamicsQuestions, | |
|   firstAid: firstAidQuestions, | |
|   flightSafety: flightSafetyQuestions, | |
|   instruments: instrumentsQuestions, | |
|   legislation: legislationQuestions, | |
|   materials: materialsQuestions, | |
|   meteorology: meteorologyQuestions, | |
|   physiopathology: physiopathologyQuestions, | |
|   pilotingTechniques: pilotingTechniquesQuestions | |
| } | |
| 
 | |
| const generateQuestions = () => { | |
| 
 | |
|   AsyncStorage.getItem('setupData').then((value) => { | |
|     let setupData = {} | |
| 
 | |
|     if(!value) { | |
|       setupData = { | |
|         randomQuestions: true, | |
|         excludeDelta: true | |
|       } | |
|       AsyncStorage.setItem('setupData', JSON.stringify(setupData)) | |
|     } else { | |
|       setupData = JSON.parse(value) | |
|     } | |
| 
 | |
|     examScheme.forEach( (elem) => { | |
|       let currentSection = setupData.excludeDelta ? allQuestions[elem.section].filter(item => !item.delta) : allQuestions[elem.section] | |
|       for(let i=0; i<elem.questions; i++) { | |
|         const currentIndex = Math.floor(Math.random() * currentSection.length) | |
|         tmpQuestions.push(currentSection[currentIndex]) | |
|         currentSection = currentSection.filter( (item, index) => index != currentIndex) | |
|       } | |
|     }) | |
| 
 | |
|   })/*.then( (res) => {})*/ | |
| 
 | |
| } | |
| 
 | |
| generateQuestions() | |
| 
 | |
| export const examQuestions = tmpQuestions
 |