diff --git a/vds-app/App/components/ExamQuestions.js b/vds-app/App/components/ExamQuestions.js new file mode 100644 index 0000000..2f2ab63 --- /dev/null +++ b/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 index != currentIndex) + } + }) +} + +generateQuestions() + +export const examQuestions = tmpQuestions diff --git a/vds-app/App/components/Results.js b/vds-app/App/components/Results.js index 6e95233..238c897 100644 --- a/vds-app/App/components/Results.js +++ b/vds-app/App/components/Results.js @@ -18,18 +18,28 @@ const styles = StyleSheet.create({ box: { backgroundColor: colors.green_alpha, 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" }, - boxLooser: { + boxWrong: { backgroundColor: colors.red_alpha, 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, borderWidth: 5, alignItems: "center", @@ -41,7 +51,7 @@ const styles = StyleSheet.create({ textAlign: "center", letterSpacing: -0.02, fontWeight: "500", - lineHeight: 90 + lineHeight: 50 }, textLabel: { paddingHorizontal: 20, @@ -52,37 +62,30 @@ const styles = StyleSheet.create({ }, wrong: { color: colors.red + }, + unsafe: { + color: colors.yellow } }) -export const Results = ({ correct, wrong, visible }) => { +export const Results = ({ total, correct, wrong, visible }) => { 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 ( - {`${texts.corrects}: `} - - {`${correct}`} - + {`${texts.corrects}: ${correct}`} - {`${texts.wrongs}: `} - - {`${wrong}`} - + {`${texts.wrongs}: ${wrong}`} - {`${texts.percentage}: `} - - {`${Math.round(percentage)}%`} - + {`${texts.percentage}: ${Math.round(percentage)}%`} diff --git a/vds-app/App/components/RowItem.js b/vds-app/App/components/RowItem.js index 4930195..7c3009e 100644 --- a/vds-app/App/components/RowItem.js +++ b/vds-app/App/components/RowItem.js @@ -7,8 +7,7 @@ const styles = StyleSheet.create({ paddingHorizontal: 15, paddingVertical: 20, backgroundColor: colors.blue, - borderBottomColor: colors.dark_blue, - borderBottomWidth: 1 + marginBottom: 1 }, text: { fontSize: 18, @@ -17,10 +16,10 @@ const styles = StyleSheet.create({ } }) -export const RowItem = ({ onPress = () => {}, name, color }) => ( +export const RowItem = ({ onPress = () => {}, name, color, textColor }) => ( - {name} + {name} ) diff --git a/vds-app/App/components/Variables.js b/vds-app/App/components/Variables.js index a3200ab..ec0a0d0 100644 --- a/vds-app/App/components/Variables.js +++ b/vds-app/App/components/Variables.js @@ -15,7 +15,7 @@ export const colors = { export const texts = { quizzes: "Seleziona un quiz", - exam: "Simulazione esame", + exam: "Simulazione esame (30 domande in 30min)", corrects: "Corrette", wrongs: "Sbagliate", percentage: "Percentuale", @@ -29,3 +29,15 @@ export const texts = { physiopathology: "Fisiopatologia del volo", 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} +] diff --git a/vds-app/App/index.js b/vds-app/App/index.js index eff7a1a..3734f9f 100644 --- a/vds-app/App/index.js +++ b/vds-app/App/index.js @@ -2,6 +2,7 @@ import { createStackNavigator, createAppContainer } from "react-navigation" import QuizIndex from "./screens/QuizIndex" import Quiz from "./screens/Quiz" +import Exam from "./screens/Exam" import { colors, texts} from "./components/Variables" const MainStack = createStackNavigator({ @@ -26,6 +27,17 @@ const MainStack = createStackNavigator({ 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") + } + }) } }) diff --git a/vds-app/App/screens/Exam.js b/vds-app/App/screens/Exam.js new file mode 100644 index 0000000..eb0a1e2 --- /dev/null +++ b/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 ( + + + + {new Date(this.state.timer * 1000).toISOString().substr(11, 8)} + + {question.question} + + + {question.answers.map(answer => ( +