diff --git a/.gitignore b/.gitignore index f92c8cc..3af4703 100644 --- a/.gitignore +++ b/.gitignore @@ -193,3 +193,5 @@ App/functions/MinutePaper/__pycache__ App/functions/MinutePaper/.pytest_cache App/android/app/release/ +App/functions/.runtimeconfig.json +App/ios/TLS/GoogleService-Info.plist diff --git a/App/Components/Feedback/FeedbackStudentPage.js b/App/Components/Feedback/FeedbackStudentPage.js index cd0bb96..ea09fc4 100644 --- a/App/Components/Feedback/FeedbackStudentPage.js +++ b/App/Components/Feedback/FeedbackStudentPage.js @@ -26,6 +26,9 @@ export default class FeedbackStudentPage extends Component { error: null, loading: true, kind: null, + firstOpen: 0, + date: '', + opens: 0, }; this.getTopics = this.getTopics.bind(this); this.studentResponses = this.studentResponses.bind(this); @@ -74,16 +77,31 @@ export default class FeedbackStudentPage extends Component { }); } + getStartTime = async () => { + const feedback = new Feedback(); + await feedback + .getFeedbackDetails(this.state.course.passCode) + .then(value => { + console.log('Output line 82 FeedbackStudent.js' + value['startTime']); + this.setState({ + date: value['startTime'], + }); + }); + }; + submitFeedback = async () => { var {responses} = this.state; var err = false; + let msg = ""; console.log("Submit Feedback ",responses); if (this.state.responses === -1 || !responses) { + err = true; - msg = "Please enter a response"; + msg = 'Please enter a response'; } if (this.state.kind == 2) { + responses = [...this.state.responses]; if(Array.isArray(this.state.responses)){ if (!responses[0] || !responses[1] ) { @@ -114,12 +132,42 @@ export default class FeedbackStudentPage extends Component { if (!err) { Toast.show('Responses have been recorded!'); const feedbackResponse = new FeedbackResponses(); - const timestamp = moment.utc(database().getServerTime()).format( - 'DD/MM/YYYY HH:mm:ss', - ); + const timestamp = moment + .utc(database().getServerTime()) + .format('DD/MM/YYYY HH:mm:ss'); console.log(timestamp); + + await this.getStartTime(); + + let temp = moment.utc(this.state.date, 'DD/MM/YYYY HH:mm:ss'); + let temp1 = moment.utc(this.state.firstOpen, 'DD/MM/YYYY HH:mm:ss'); + let temp3 = moment.utc(timestamp, 'DD/MM/YYYY HH:mm:ss'); + + console.log('Printing line-> 130, FeedbackStudentPage.js'); + console.log(temp1, temp); + + let date1 = new Date(temp); + let date2 = new Date(temp1); + let date3 = new Date(temp3) + + + const difference = date3.getTime() - date1.getTime(); + const differenceOpen = date2.getTime() - date1.getTime(); + + let feedback_response_time = (difference / 60000) * 60; + feedback_response_time = feedback_response_time.toFixed(2); + console.log('Response Time added'); + console.log(feedback_response_time); + + let first_open_time = (differenceOpen / 60000) * 60; + first_open_time = first_open_time.toFixed(2); + console.log('Printing line-> 136, FeedbackStudentPage.js'); + console.log(first_open_time); + + console.log(this.state.responses); const studentResponses = this.state.responses; + await feedbackResponse .getFeedbackResponse(this.state.user.url, this.state.course.passCode) .then(url => { @@ -131,6 +179,8 @@ export default class FeedbackStudentPage extends Component { this.state.user.email, studentResponses, timestamp, + first_open_time, + feedback_response_time, ) .then(r => { console.log('create'); @@ -144,6 +194,8 @@ export default class FeedbackStudentPage extends Component { studentResponses, timestamp, url, + first_open_time, + feedback_response_time, ) .then(r => { console.log('update'); @@ -177,6 +229,18 @@ export default class FeedbackStudentPage extends Component { render() { if (!this.state.loading) { + + if (this.props.currentFeedback && this.state.opens === 0) { + console.log('Printing line-> 202, FeedbackStudentPage.js'); + const timestamp_first = moment + .utc(database().getServerTime()) + .format('DD/MM/YYYY HH:mm:ss'); + + this.setState({firstOpen: timestamp_first}); + this.setState({opens: this.state.opens + 1}); + console.log(this.state.firstOpen); + } + return ( {this.props.currentFeedback === false ? ( diff --git a/App/Components/Navigation/QuizStack.js b/App/Components/Navigation/QuizStack.js index 80f7422..e2b5450 100644 --- a/App/Components/Navigation/QuizStack.js +++ b/App/Components/Navigation/QuizStack.js @@ -1,6 +1,7 @@ import {createStackNavigator} from '@react-navigation/stack'; import React, {Component} from 'react'; import QuizHomePage from '../Quiz/QuizHomePage'; +import {useRoute} from '@react-navigation/native'; const Stack = createStackNavigator(); diff --git a/App/Components/Quiz/QuizHomePage.js b/App/Components/Quiz/QuizHomePage.js index 975f0a5..b89dff3 100644 --- a/App/Components/Quiz/QuizHomePage.js +++ b/App/Components/Quiz/QuizHomePage.js @@ -34,11 +34,7 @@ export default class QuizHomePage extends Component{ .on('value', snapshot => { if (snapshot.val()){ const values = Object.values(snapshot.val())[0] - // console.log("Non moment") console.log("serverTime: "+database().getServerTime()) - // console.log(moment.utc(database().getServerTime())) - // console.log("startTime"+values['startTime']) - // console.log("endTime"+ values['endTime']) const curr = moment.utc(database().getServerTime()) const startTime = moment.utc(values['startTime'], "DD/MM/YYYY HH:mm:ss") const endTime = moment.utc(values['endTime'], "DD/MM/YYYY HH:mm:ss") diff --git a/App/Components/Quiz/QuizStudentPage.js b/App/Components/Quiz/QuizStudentPage.js index f980cd1..1fca25e 100644 --- a/App/Components/Quiz/QuizStudentPage.js +++ b/App/Components/Quiz/QuizStudentPage.js @@ -1,5 +1,13 @@ import React, {Component} from 'react'; -import {SafeAreaView, ScrollView, StyleSheet, View, TextInput, ActivityIndicator} from 'react-native'; +import { + SafeAreaView, + ScrollView, + StyleSheet, + View, + TextInput, + ActivityIndicator, + AppState, +} from 'react-native'; import {Text, Button} from 'react-native-elements'; import moment from 'moment'; import Options from './Options'; @@ -8,337 +16,486 @@ import CountDown from 'react-native-countdown-component'; import QuizResultGraph from './QuizResultGraph'; import Quiz from '../../Databases/Quiz'; import Toast from 'react-native-simple-toast'; -import database from "@react-native-firebase/database"; +import database from '@react-native-firebase/database'; import MultiCorrectOptions from './MultiCorrectOptions'; export default class QuizStudentPage extends Component { - constructor(props) { - super(props); - this.state = { - course : this.props.course, - user : this.props.user, - option : "", - icon : "", - error : null, - correctAnswer : "", - quizResults : false, - date : "", - results :"", - loading : true - }; - this.setOption = this.setOption.bind(this); - this.quizresultData = this.quizresultData.bind(this); - } + constructor(props) { + super(props); + this.state = { + course: this.props.course, + user: this.props.user, + option: '', + icon: '', + error: null, + correctAnswer: '', + quizResults: false, + date: '', + results: '', + loading: true, + appState: AppState.currentState, + opens: 0, + firstOpen: 0, + duration: '', + }; + this.setOption = this.setOption.bind(this); + this.quizresultData = this.quizresultData.bind(this); + } - quizresultData(resultData, quizNumber) { - this.setState({ - results: resultData - }) - } + componentDidMount() { + this.appStateSubscription = AppState.addEventListener( + 'change', + nextAppState => { + if ( + this.state.appState.match(/inactive|background/) && + nextAppState === 'active' && + this.props.currentQuiz + ) { + console.log('Quiz has come to the foreground for First time!'); + this.setState({opens: this.state.opens + 1}); + console.log(this.state.opens); + } + this.setState({appState: nextAppState}); + }, + ); + } + + componentWillUnmount() { + this.appStateSubscription = AppState.removeEventListener('change', () => { + console.log('componentHasUnmounted'); + }); + } + + quizresultData(resultData, quizNumber) { + this.setState({ + results: resultData, + }); + } + + setOption(value) { + this.setState({ + option: value, + icon: value, + }); + } + + getCorrectAnswer = async () => { + const Kbc = new Quiz(); + Kbc.getTiming(this.state.course.passCode).then(value => { + this.setState({ + correctAnswer: value['correctAnswer'], + date: value['startTime'], + }); + }); + }; + + getDuration = async () =>{ + const Kbc = new Quiz() + await Kbc.getTiming(this.state.course.passCode).then(value => { + console.log("Printing duration finally") + console.log(value); + console.log(value['duration']); - setOption(value){ this.setState({ - option : value, - icon : value, + duration: value['duration'], }) - } + }) +} - getCorrectAnswer = async () =>{ - const Kbc = new Quiz() - Kbc.getTiming(this.state.course.passCode).then(value => { - this.setState({ - correctAnswer : value["correctAnswer"], - date : value["startTime"] - }) - }) + getStartTime = async () => { + const Kbc = new Quiz(); + await Kbc.getTiming(this.state.course.passCode).then(value => { + console.log('Output line 92 QuizStudentPage.js' + value['startTime']); + this.setState({ + date: value['startTime'], + }); + }); + }; + + submitResponse = async () => { + const {option} = this.state; + + if (option === '') { + this.setState({ + error: 'Please answer', + }); + } else if (this.props.quizType === 'numeric' && isNaN(parseFloat(option))) { + this.setState({ + error: 'Please Input a Numerical Response', + }); + } else { + this.setState({ + error: null, + }); } - submitResponse = async () => { + Toast.show('Answer has been recorded!'); + const kbcresponse = new QuizResponses(); + const timestamp = moment + .utc(database().getServerTime()) + .format('DD/MM/YYYY HH:mm:ss'); - const {option} = this.state; + console.log('Printing Output from QuizStudentpage.js in line 117'); + await this.getStartTime(); - if (option === '') { - this.setState({ - error: "Please answer" - }) - } - else if(this.props.quizType==="numeric" && isNaN(parseFloat(option))) - { - this.setState({ - error: "Please Input a Numerical Response" - }) - } - else { - this.setState({ - error:null - }) - Toast.show('Answer has been recorded!'); - const kbcresponse = new QuizResponses() - const timestamp = moment.utc(database().getServerTime()).format("DD/MM/YYYY HH:mm:ss") + console.log( + 'Printing Output from QuizStudentpage.js in line 119 ->' + + this.state.date, + ); - await kbcresponse.getResponse(this.state.user.url, this.state.course.passCode) - .then((url) => { - if (url === null) { - kbcresponse.createResponse( - this.state.course.passCode, - this.state.user.url, - this.state.user.email, - option, - timestamp, - this.state.user.name - ).then(r => { - console.log("update") - }) - } else { - kbcresponse.setResponse( - this.state.course.passCode, - this.state.user.url, - this.state.user.email, - option, - timestamp, - this.state.user.name, - url - ).then(r => { - console.log("create") - }) + await this.getDuration(); - } - }) + console.log(this.state.date); - } - } + let temp1 = moment.utc(timestamp, 'DD/MM/YYYY HH:mm:ss'); + let temp = moment.utc(this.state.date, 'DD/MM/YYYY HH:mm:ss'); + let temp2 = moment.utc(this.state.firstOpen,'DD/MM/YYYY HH:mm:ss'); + let date3 = new Date(temp2) + let date1 = new Date(temp); + let date2 = new Date(temp1); + + // console.log('The dates are as follows ->'); + // console.log(date1,date2); - render() { - if(!this.state.loading) - { - console.log("Debugging"); - console.log(this.props.quizType); - return( - - { this.props.currentQuiz === false - ? - this.state.quizResults === false - ? - - Wohoo! No current quiz! - - : - - - - - - : - + const difference = date2.getTime() - date1.getTime(); + const differenceOpen = date3.getTime() - date1.getTime(); + // console.log("The difference is"+ difference); + let quiz_response_time = (difference / 60000) * 60; + let first_open_time = (differenceOpen / 60000) * 60; + quiz_response_time = quiz_response_time.toFixed(2); + first_open_time = first_open_time.toFixed(2); + console.log('Response Time added'); + console.log(quiz_response_time); + console.log(first_open_time); - In-Class Quiz + console.log("Printing duration of Quiz") + console.log(this.state.duration); + var duration_seconds=parseInt(this.state.duration); + console.log(duration_seconds); - { - this.setState({ - quizResults : true, - option: "", - icon: "", - error: null - }) - this.props.setQuizState() - this.getCorrectAnswer().then(r=>{console.log("")}) - }} - digitStyle={{backgroundColor: 'white'}} - digitTxtStyle={{color: 'tomato'}} - timeToShow={['M', 'S']} - timeLabels={{m: 'Min', s: 'Sec'}} - /> - {this.props.quizType==="mcq" - ? - - - - {this.state.error ? - - {this.state.error} - : - } - -