Browse Source

Merge branch 'feature/exam_simulation' into develop

master
Dslak 6 years ago
parent
commit
1c3f2435a1
  1. 43
      vds-app/App/components/ExamQuestions.js
  2. 49
      vds-app/App/components/Results.js
  3. 7
      vds-app/App/components/RowItem.js
  4. 14
      vds-app/App/components/Variables.js
  5. 12
      vds-app/App/index.js
  6. 164
      vds-app/App/screens/Exam.js
  7. 1
      vds-app/App/screens/Quiz.js
  8. 32
      vds-app/App/screens/QuizIndex.js

43
vds-app/App/components/ExamQuestions.js

@ -0,0 +1,43 @@
import testQuestions from "../data/test"
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 = () => {
examScheme.forEach( (elem) => {
let currentSection = allQuestions[elem.section]
for(let i=0; i<elem.questions; i++) {
const currentIndex = Math.floor(Math.random() * elem.questions)
//currentSection[currentIndex].question = elem.section + currentSection[currentIndex].question
tmpQuestions.push(currentSection[currentIndex])
currentSection = currentSection.filter( (item, index) => index != currentIndex)
}
})
}
generateQuestions()
export const examQuestions = tmpQuestions

49
vds-app/App/components/Results.js

@ -18,18 +18,28 @@ const styles = StyleSheet.create({
box: { box: {
backgroundColor: colors.green_alpha, backgroundColor: colors.green_alpha,
width: screen.width / 1.1, width: screen.width / 1.1,
height: screen.height / 2,
borderRadius: 5,
height: 320,
borderRadius: 15,
borderColor: colors.white_alpha, borderColor: colors.white_alpha,
borderWidth: 5, borderWidth: 5,
alignItems: "center", alignItems: "center",
justifyContent: "center" justifyContent: "center"
}, },
boxLooser: {
boxWrong: {
backgroundColor: colors.red_alpha, backgroundColor: colors.red_alpha,
width: screen.width / 1.1, width: screen.width / 1.1,
height: screen.height / 2,
borderRadius: 5,
height: 320,
borderRadius: 15,
borderColor: colors.white_alpha,
borderWidth: 5,
alignItems: "center",
justifyContent: "center"
},
boxUnsafe: {
backgroundColor: colors.orange,
width: screen.width / 1.1,
height: 320,
borderRadius: 15,
borderColor: colors.white_alpha, borderColor: colors.white_alpha,
borderWidth: 5, borderWidth: 5,
alignItems: "center", alignItems: "center",
@ -41,7 +51,7 @@ const styles = StyleSheet.create({
textAlign: "center", textAlign: "center",
letterSpacing: -0.02, letterSpacing: -0.02,
fontWeight: "500", fontWeight: "500",
lineHeight: 90
lineHeight: 50
}, },
textLabel: { textLabel: {
paddingHorizontal: 20, paddingHorizontal: 20,
@ -52,37 +62,30 @@ const styles = StyleSheet.create({
}, },
wrong: { wrong: {
color: colors.red color: colors.red
},
unsafe: {
color: colors.yellow
} }
}) })
export const Results = ({ correct, wrong, visible }) => {
export const Results = ({ total, correct, wrong, visible }) => {
if (!visible) return null if (!visible) return null
const total = wrong+correct
const percentage = (100/total) * correct
const boxStyle = percentage > 80 ? styles.box : styles.boxLooser
const percentStyle = percentage > 80 ? styles.correct : styles.wrong
const percentage = total ? (100/total) * correct : 0
const boxStyle = percentage >= 80 ? percentage >= 85 ? styles.box : styles.boxUnsafe : styles.boxWrong
const percentStyle = percentage >= 80 ? percentage >= 85 ? styles.correct : styles.unsafe : styles.wrong
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={boxStyle}> <View style={boxStyle}>
<Text style={styles.text}> <Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.corrects}: `}</Text>
<Text >
{`${correct}`}
</Text>
<Text style={styles.textLabel}>{`${texts.corrects}: ${correct}`}</Text>
</Text> </Text>
<Text style={styles.text}> <Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.wrongs}: `}</Text>
<Text>
{`${wrong}`}
</Text>
<Text style={styles.textLabel}>{`${texts.wrongs}: ${wrong}`}</Text>
</Text> </Text>
<Text style={styles.text}> <Text style={styles.text}>
<Text style={styles.textLabel}>{`${texts.percentage}: `}</Text>
<Text >
{`${Math.round(percentage)}%`}
</Text>
<Text style={styles.textLabel}>{`${texts.percentage}: ${Math.round(percentage)}%`}</Text>
</Text> </Text>
</View> </View>
</View> </View>

7
vds-app/App/components/RowItem.js

@ -7,8 +7,7 @@ const styles = StyleSheet.create({
paddingHorizontal: 15, paddingHorizontal: 15,
paddingVertical: 20, paddingVertical: 20,
backgroundColor: colors.blue, backgroundColor: colors.blue,
borderBottomColor: colors.dark_blue,
borderBottomWidth: 1
marginBottom: 1
}, },
text: { text: {
fontSize: 18, fontSize: 18,
@ -17,10 +16,10 @@ const styles = StyleSheet.create({
} }
}) })
export const RowItem = ({ onPress = () => {}, name, color }) => (
export const RowItem = ({ onPress = () => {}, name, color, textColor }) => (
<TouchableOpacity onPress={onPress} activeOpacity={0.8}> <TouchableOpacity onPress={onPress} activeOpacity={0.8}>
<View style={[styles.row, { backgroundColor: color }]}> <View style={[styles.row, { backgroundColor: color }]}>
<Text style={styles.text}>{name}</Text>
<Text style={[styles.text, { color: textColor }]}>{name}</Text>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
) )

14
vds-app/App/components/Variables.js

@ -15,7 +15,7 @@ export const colors = {
export const texts = { export const texts = {
quizzes: "Seleziona un quiz", quizzes: "Seleziona un quiz",
exam: "Simulazione esame",
exam: "Simulazione esame (30 domande in 30min)",
corrects: "Corrette", corrects: "Corrette",
wrongs: "Sbagliate", wrongs: "Sbagliate",
percentage: "Percentuale", percentage: "Percentuale",
@ -29,3 +29,15 @@ export const texts = {
physiopathology: "Fisiopatologia del volo", physiopathology: "Fisiopatologia del volo",
piloting_techniques: "Tecniche di pilotaggio" piloting_techniques: "Tecniche di pilotaggio"
} }
export const examScheme = [
{section: "aerodynamics", questions: 8, points: 3},
{section: "firstAid", questions: 1, points: 2},
{section: "flightSafety", questions: 3, points: 4},
{section: "instruments", questions: 1, points: 2},
{section: "legislation", questions: 4, points: 3},
{section: "materials", questions: 1, points: 2},
{section: "meteorology", questions: 6, points: 4},
{section: "physiopathology", questions: 1, points: 2},
{section: "pilotingTechniques", questions: 5, points: 4}
]

12
vds-app/App/index.js

@ -2,6 +2,7 @@ import { createStackNavigator, createAppContainer } from "react-navigation"
import QuizIndex from "./screens/QuizIndex" import QuizIndex from "./screens/QuizIndex"
import Quiz from "./screens/Quiz" import Quiz from "./screens/Quiz"
import Exam from "./screens/Exam"
import { colors, texts} from "./components/Variables" import { colors, texts} from "./components/Variables"
const MainStack = createStackNavigator({ const MainStack = createStackNavigator({
@ -26,6 +27,17 @@ const MainStack = createStackNavigator({
borderBottomColor: navigation.getParam("color") borderBottomColor: navigation.getParam("color")
} }
}) })
},
Exam: {
screen: Exam,
navigationOptions: ({ navigation }) => ({
headerTitle: navigation.getParam("title"),
headerTintColor: colors.white,
headerStyle: {
backgroundColor: navigation.getParam("color"),
borderBottomColor: navigation.getParam("color")
}
})
} }
}) })

164
vds-app/App/screens/Exam.js

@ -0,0 +1,164 @@
import React from "react"
import { View, ScrollView, StyleSheet, StatusBar, Text, SafeAreaView } from "react-native"
import { Button, ButtonContainer } from "../components/Button"
import { Alert } from "../components/Alert"
import { Results } from "../components/Results"
import { colors } from "../components/Variables"
const styles = StyleSheet.create({
container: {
backgroundColor: colors.blue,
flex: 1,
paddingHorizontal: 20
},
text: {
color: colors.white,
fontSize: 20,
textAlign: "center",
fontWeight: "600",
paddingVertical: 20,
marginTop: 20,
},
timer: {
color: colors.white,
fontSize: 30,
textAlign: "center",
fontWeight: "600",
paddingVertical: 10,
marginTop: 10,
},
safearea: {
flex: 1,
marginTop: 20,
justifyContent: "space-between"
}
})
let interval = null
const maxTime = 10 // 1800
class Exam extends React.Component {
state = {
correctCount: 0,
wrongCount: 0,
totalCount: this.props.navigation.getParam("questions", []).length,
availableIds: this.props.navigation.getParam("questions", []).map(a => a.id),
activeQuestionId: this.props.navigation.getParam("questions", [])[
Math.floor(Math.random() * this.props.navigation.getParam("questions", []).length)
].id,
answered: false,
answerCorrect: false,
results: false,
timer: maxTime
}
answer = correct => {
this.setState(
state => {
const nextState = { answered: true }
if (correct) {
nextState.correctCount = state.correctCount + 1
nextState.answerCorrect = true
} else {
nextState.wrongCount = state.wrongCount + 1
nextState.answerCorrect = false
}
return nextState
},
() => {
setTimeout(() => this.nextQuestion(), 750)
}
)
}
nextQuestion = () => {
this.setState( (state) => {
const updatedIndexes = state.availableIds.filter( item => item != state.activeQuestionId)
const nextId = updatedIndexes[Math.floor(Math.random() * updatedIndexes.length)]
let resultsShow = this.state.timer <= 1 || false
if (!updatedIndexes.length) {
resultsShow = true
setTimeout( () => {
this.props.navigation.popToTop()
}, 5000)
}
return {
availableIds: updatedIndexes,
activeQuestionId: nextId,
answered: false,
results: resultsShow
}
})
}
render() {
const questions = this.props.navigation.getParam("questions", [])
const question = questions.filter(item => item.id == this.state.activeQuestionId)[0] || questions[0]
if(this.state.timer==maxTime) {
interval = setInterval( () => {
this.setState( (state) => {
return {
timer: this.state.timer-1,
results: this.state.timer <= 1 || false
}
})
}, 1000)
}
if(this.state.timer < 1) {
clearInterval(interval)
setTimeout( () => {
this.props.navigation.popToTop()
}, 5000)
}
return (
<ScrollView style={[
styles.container,
{ backgroundColor: this.props.navigation.getParam("color") }
]}
>
<StatusBar barStyle="light-content" />
<SafeAreaView style={styles.safearea}>
<Text style={styles.timer}>{new Date(this.state.timer * 1000).toISOString().substr(11, 8)}</Text>
<View>
<Text style={styles.text}>{question.question}</Text>
<ButtonContainer>
{question.answers.map(answer => (
<Button
key={answer.id}
text={answer.text}
onPress={() => this.answer(answer.correct)}
/>
))}
</ButtonContainer>
</View>
<Text style={styles.text}>
{`${this.state.correctCount+this.state.wrongCount}/${this.state.totalCount}`}
</Text>
</SafeAreaView>
<Alert
correct={this.state.answerCorrect}
visible={this.state.answered}
/>
<Results
total={this.state.totalCount}
correct={this.state.correctCount}
wrong={this.state.wrongCount}
visible={this.state.results}
/>
</ScrollView>
)
}
}
export default Exam

1
vds-app/App/screens/Quiz.js

@ -121,6 +121,7 @@ class Quiz extends React.Component {
visible={this.state.answered} visible={this.state.answered}
/> />
<Results <Results
total={this.state.totalCount}
correct={this.state.correctCount} correct={this.state.correctCount}
wrong={this.state.wrongCount} wrong={this.state.wrongCount}
visible={this.state.results} visible={this.state.results}

32
vds-app/App/screens/QuizIndex.js

@ -14,86 +14,80 @@ import pilotingTechniquesQuestions from "../data/pilotingTechniques"
import { RowItem } from "../components/RowItem" import { RowItem } from "../components/RowItem"
import { colors, texts} from "../components/Variables" import { colors, texts} from "../components/Variables"
import { examQuestions } from "../components/ExamQuestions"
export default ({ navigation }) => ( export default ({ navigation }) => (
<ScrollView style={[{ backgroundColor: colors.dark_blue }]}> <ScrollView style={[{ backgroundColor: colors.dark_blue }]}>
<StatusBar barStyle="dark-content" /> <StatusBar barStyle="dark-content" />
<RowItem name={texts.aerodynamics} color={colors.blue} onPress={() =>
<RowItem name={texts.aerodynamics} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.aerodynamics, title: texts.aerodynamics,
questions: aerodynamicsQuestions, questions: aerodynamicsQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.first_aid} color={colors.blue} onPress={() =>
<RowItem name={texts.first_aid} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.first_aid, title: texts.first_aid,
questions: firstAidQuestions, questions: firstAidQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.flight_safety} color={colors.blue} onPress={() =>
<RowItem name={texts.flight_safety} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.flight_safety, title: texts.flight_safety,
questions: flightSafetyQuestions, questions: flightSafetyQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.instruments} color={colors.blue} onPress={() =>
<RowItem name={texts.instruments} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.instruments, title: texts.instruments,
questions: instrumentsQuestions, questions: instrumentsQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.legislation} color={colors.blue} onPress={() =>
<RowItem name={texts.legislation} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.legislation, title: texts.legislation,
questions: legislationQuestions, questions: legislationQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.materials} color={colors.blue} onPress={() =>
<RowItem name={texts.materials} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.materials, title: texts.materials,
questions: materialsQuestions, questions: materialsQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.meteorology} color={colors.blue} onPress={() =>
<RowItem name={texts.meteorology} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.meteorology, title: texts.meteorology,
questions: meteorologyQuestions, questions: meteorologyQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.physiopathology} color={colors.blue} onPress={() =>
<RowItem name={texts.physiopathology} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.physiopathology, title: texts.physiopathology,
questions: physiopathologyQuestions, questions: physiopathologyQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.piloting_techniques} color={colors.blue} onPress={() =>
<RowItem name={texts.piloting_techniques} color={colors.blue} textColor={colors.white} onPress={()=>
navigation.navigate("Quiz", { navigation.navigate("Quiz", {
title: texts.piloting_techniques, title: texts.piloting_techniques,
questions: pilotingTechniquesQuestions, questions: pilotingTechniquesQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name={texts.exam} color={colors.blue} onPress={() =>
navigation.navigate("Quiz", {
<RowItem name={texts.exam} color={colors.yellow} textColor={colors.black} onPress={() =>
navigation.navigate("Exam", {
title: texts.exam, title: texts.exam,
questions: pilotingTechniquesQuestions,
questions: examQuestions,
color: colors.blue color: colors.blue
})}/> })}/>
<RowItem name="TEST" color={colors.orange} onPress={() =>
navigation.navigate("Quiz", {
title: "TEST",
questions: testQuestions,
color: colors.orange
})}/>
</ScrollView> </ScrollView>
) )

Loading…
Cancel
Save