diff --git a/src/activities/calendar/ActivityInfo.qml b/src/activities/calendar/ActivityInfo.qml --- a/src/activities/calendar/ActivityInfo.qml +++ b/src/activities/calendar/ActivityInfo.qml @@ -37,4 +37,5 @@ credit: "" section: "math measures" createdInVersion: 9000 + levels: "1" } diff --git a/src/activities/calendar/CMakeLists.txt b/src/activities/calendar/CMakeLists.txt --- a/src/activities/calendar/CMakeLists.txt +++ b/src/activities/calendar/CMakeLists.txt @@ -1 +1 @@ -GCOMPRIS_ADD_RCC(activities/calendar *.qml *.svg *.js) +GCOMPRIS_ADD_RCC(activities/calendar *.qml *.svg *.js resource/* resource/*/*/*.qml) diff --git a/src/activities/calendar/Calendar.qml b/src/activities/calendar/Calendar.qml --- a/src/activities/calendar/Calendar.qml +++ b/src/activities/calendar/Calendar.qml @@ -57,15 +57,16 @@ property alias calendar: calendar property alias okButton: okButton property alias questionItem: questionItem + property var levels: activity.datasetLoader.item.data property alias score: score property alias answerChoices: answerChoices property alias questionDelay: questionDelay property alias okButtonParticles: okButtonParticles property bool horizontalLayout: background.width >= background.height * 1.5 property alias daysOfTheWeekModel: daysOfTheWeekModel } - onStart: { Activity.start(items, dataset) } + onStart: { Activity.start(items) } onStop: { Activity.stop() } Keys.onPressed: (answerChoices.visible) ? answerChoices.handleKeys(event) : handleKeys(event); diff --git a/src/activities/calendar/calendar.js b/src/activities/calendar/calendar.js --- a/src/activities/calendar/calendar.js +++ b/src/activities/calendar/calendar.js @@ -41,10 +41,9 @@ var correctAnswer var mode -function start(items_, dataset_) { +function start(items_) { items = items_ - dataset = dataset_.get() - numberOfLevel = dataset.length + numberOfLevel = items.levels.length currentLevel = 0 if(Qt.locale(GCompris.ApplicationSettings.locale).firstDayOfWeek == Qml.Locale.Monday) { @@ -59,7 +58,7 @@ function initLevel() { currentSubLevel = 1; items.bar.level = currentLevel + 1 - currentLevelConfig = dataset[currentLevel][0][0] + currentLevelConfig = items.levels[currentLevel] setCalendarConfigurations() initQuestion(); } @@ -92,20 +91,96 @@ monthSelected = currentLevelConfig["visibleMonth"] items.answerChoices.visible = (mode === "findDayOfWeek") ? true : false items.okButton.visible = !items.answerChoices.visible - currentDataSet = dataset[currentLevel][1] + currentDataSet = currentLevelConfig["questionAnswers"] currentDataSet = Core.shuffle(currentDataSet) items.score.numberOfSubLevels = currentDataSet.length items.score.currentSubLevel = currentSubLevel } +function isLeapYear(year) { + if(year % 100 == 0 && year % 400 != 0) { + return false + } else if(year % 4 == 0) { + return true + } else { + return false + } +} + +function generateRandomYearMonthDay(minimumDate, maximumDate) { + var daysInMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] + var minYear = Number(minimumDate.slice(0, 4)) + var maxYear = Number(maximumDate.slice(0, 4)) + var minMonth = Number(minimumDate.slice(5, 7)) + var maxMonth = Number(maximumDate.slice(5, 7)) + var minDate = Number(minimumDate.slice(8, 10)) + var maxDate = Number(maximumDate.slice(8, 10)) + var currentYear = minYear + Math.floor(Math.random() * Math.floor((maxYear - minYear))) + var currentMonth = minMonth + Math.floor(Math.random() * Math.floor((maxMonth - minMonth))) + var currentDate + daysInMonths[1] = (isLeapYear(currentYear)) ? 29 : 28; + currentDate = minDate + Math.floor(Math.random() * Math.floor((daysInMonths[currentMonth - 1] - minMonth))) + var maxOffset = (maxDate - minDate) + (maxMonth - minMonth) * 28 + (maxYear - minYear) * 365 + var offset = 1 + Math.floor(Math.random() * Math.floor(maxOffset)) + var currentOffset = offset; + currentOffset += currentDate + var answerDate = 1; + var answerMonth = currentMonth + var answerYear = currentYear + while(currentOffset > 0) { + if(currentOffset - daysInMonths[answerMonth - 1] > 0) { + currentOffset -= daysInMonths[answerMonth - 1] + answerMonth++; + } else { + answerDate = currentOffset; + currentOffset = 0 + } + if(answerMonth > 12) { + answerYear++; + answerMonth = 1; + } + } + + var question = "Find the date " + offset.toString() + "days after " + currentYear.toString() + "-" + + currentMonth.toString() + "-" + currentDate.toString(); + return { year: answerYear, month: answerMonth - 1, day: answerDate, offset: offset } +} + +function getTemplateQuestionText(mode, date) { + var questionText + if(mode == "findDayOfWeek") { + questionText = "Find the Week Day on " + date.day.toString() + } else if(mode == "findDay") { + questionText = "Select Day " + date.day.toString() + } else if(mode == "findMonthOnly") { + questionText = "Find the month" + date.month.toString() + } else { + "Find the date " + date.offset.toString() + "days after " + date.year.toString() + "-" + + date.month.toString() + "-" + date.day.toString(); + } + return questionText +} + function initQuestion() { if(currentDataSet.length < currentSubLevel) { items.bonus.good("lion") } else { - items.score.currentSubLevel = currentSubLevel - items.questionItem.text = currentDataSet[currentSubLevel-1]["question"] - correctAnswer = currentDataSet[currentSubLevel-1]["answer"] + if(!currentLevelConfig.questionsExplicitlyGiven) { + var randomDate = generateRandomYearMonthDay(currentLevelConfig.minimumDate, currentLevelConfig.maximumDate) + items.score.currentSubLevel = currentSubLevel + if(currentLevelConfig.mode == "findDayOfWeek") { + var selectedDate = new Date(randomDate.year, randomDate.month - 1, randomDate.day) + correctAnswer.dayOfWeek = Number(selectedDate.getDay()) + } else { + correctAnswer = randomDate + } + items.questionItem.text = getTemplateQuestionText(currentLevelConfig.mode, randomDate) + } else { + items.score.currentSubLevel = currentSubLevel + items.questionItem.text = currentDataSet[currentSubLevel-1]["question"] + correctAnswer = currentDataSet[currentSubLevel-1]["answer"] + } } } @@ -134,8 +209,14 @@ isCorrectAnswer = true } } + // For levels having question based on day only. + else if(mode === "findDay") { + if(daySelected === correctAnswer["day"]) { + isCorrectAnswer = true + } + } // For levels having questions based on dayOfWeek, month and year. - else if(mode !== "findDayOfWeek") { + else { if(monthSelected === correctAnswer["month"] && daySelected === correctAnswer["day"] && yearSelected === correctAnswer["year"]) { isCorrectAnswer = true } diff --git a/src/activities/calendar/calendar_dataset.js b/src/activities/calendar/calendar_dataset.js --- a/src/activities/calendar/calendar_dataset.js +++ b/src/activities/calendar/calendar_dataset.js @@ -38,7 +38,8 @@ "maximumDate": "2018-03-31", "visibleMonth": 2, "visibleYear": 2018, - "mode": "findDay" + "mode": "findDay", + "questionsExplicitly": false } ], [ // Level 1 Questions @@ -78,7 +79,8 @@ "maximumDate": "2018-03-31", "visibleMonth": 2, "visibleYear": 2018, - "mode": "findDayOfWeek" + "mode": "findDayOfWeek", + "questionsExplicitly": false } ], [ // Level 2 Questions @@ -121,7 +123,8 @@ "maximumDate": "2018-03-31", "visibleMonth": 2, "visibleYear": 2018, - "mode": "findDay" + "mode": "findDay", + "questionsExplicitly": false } ], @@ -165,7 +168,8 @@ "maximumDate": "2018-03-31", "visibleMonth": 2, "visibleYear": 2018, - "mode": "findDay" + "mode": "findDay", + "questionsExplicitly": false } ], [ // Level 4 Questions @@ -200,7 +204,8 @@ "maximumDate": "2018-12-31", "visibleMonth": 1, "visibleYear": 2018, - "mode": "findMonthOnly" + "mode": "findMonthOnly", + "questionsExplicitly": false } ], [ // Level 5 Questions @@ -231,11 +236,13 @@ [ // Level 6 Configurations { "navigationBarVisible" : true, - "minimumDate": "2017-01-01", - "maximumDate": "2019-12-31", - "visibleMonth": 2, + "minimumDate": "2018-09-01", + "maximumDate": "2019-01-31", + "visibleMonth": 10, "visibleYear": 2018, - "mode": "findYearMonthDay" + "mode": "findYearMonthDay", + "questionsExplicitly": true, + "maxOffset": 30, } ], @@ -287,7 +294,8 @@ "maximumDate": "2019-12-31", "visibleMonth": 1, "visibleYear": 2018, - "mode": "findYearMonthDay" + "mode": "findYearMonthDay", + "questionsExplicitly": true } ], [ // Level 7 Questions diff --git a/src/activities/calendar/resource/1/Data.qml b/src/activities/calendar/resource/1/Data.qml new file mode 100644 --- /dev/null +++ b/src/activities/calendar/resource/1/Data.qml @@ -0,0 +1,206 @@ +/* GCompris - Data.qml + * + * Copyright (C) 2018 Johnny Jazeix + * + * Authors: + * Johnny Jazeix + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +import QtQuick 2.6 +import GCompris 1.0 +import "../../../../core" + +Dataset { + objective: qsTr("Calendar Questions for a single mohth") + difficulty: 1 + data: [ + { + "navigationBarVisible" : false, + "minimumDate": "2018-03-01", + "maximumDate": "2018-03-31", + "visibleMonth": 2, + "visibleYear": 2018, + "mode": "findDay", + "questionsExplicitlyGiven": false, + "questionAnswers": { + "length": 5 + } + }, + { + "navigationBarVisible" : false, + "minimumDate": "2018-03-01", + "maximumDate": "2018-03-31", + "visibleMonth": 2, + "visibleYear": 2018, + "mode": "findDay", + "questionsExplicitlyGiven": true, + "questionAnswers": [ + { + "question": qsTr("Select day 23"), + "answer": {"year": 2018, "month": 2, "day": 23} + }, + { + "question": qsTr("Select day 1"), + "answer": {"year": 2018, "month": 2, "day": 1} + }, + { + "question": qsTr("Select day 16"), + "answer": {"year": 2018, "month": 2, "day": 16} + }, + { + "question": qsTr("Select day 28"), + "answer": {"year": 2018, "month": 2, "day": 28} + }, + { + "question": qsTr("Select day 11"), + "answer": {"year": 2018, "month": 2, "day": 11} + }, + { + "question": qsTr("Select day 20"), + "answer": {"year": 2018, "month": 2, "day": 20} + } + ] + }, + { + "navigationBarVisible" : false, + "minimumDate": "2018-03-01", + "maximumDate": "2018-03-31", + "visibleMonth": 2, + "visibleYear": 2018, + "mode": "findDayOfWeek", + "questionsExplicitlyGiven": false, + "questionAnswers": { + "length": 7 + } + }, + { + "navigationBarVisible" : false, + "minimumDate": "2018-03-01", + "maximumDate": "2018-03-31", + "visibleMonth": 2, + "visibleYear": 2018, + "mode": "findDayOfWeek", + "questionsExplicitlyGiven": true, + "questionAnswers": [ + { + "question": qsTr("What day of week is the 4th of given month?"), + "answer": {"dayOfWeek": 0} + }, + { + "question": qsTr("What day of the week is the 12th of given month?"), + "answer": {"dayOfWeek": 1} + }, + { + "question": qsTr("What day of the week is the 20th of given month?"), + "answer": {"dayOfWeek": 2} + }, + { + "question": qsTr("What day of the week is the 28th of given month?"), + "answer": {"dayOfWeek": 3} + }, + { + "question": qsTr("What day of the week is the 22nd of given month?"), + "answer": {"dayOfWeek": 4} + }, + { + "question": qsTr("What day of the week is the 16th of given month?"), + "answer": {"dayOfWeek": 5} + }, + { + "question": qsTr("What day of the week is the 10th of given month?"), + "answer": {"dayOfWeek": 6} + } + ] + }, + { + "navigationBarVisible": false, + "minimumDate": "2018-03-01", + "maximumDate": "2018-03-31", + "visibleMonth": 2, + "visibleYear": 2018, + "mode": "findDay", + "questionsExplicitlyGiven": true, + "questionAnswers": [ + { + "question": qsTr("Select a Monday between days 1 and 7 of given month"), + "answer": {"year": 2018, "month": 2, "day": 5} + }, + { + "question": qsTr("Select a Tuesday between days 8 and 16 of given month"), + "answer": {"year": 2018, "month": 2, "day": 13} + }, + { + "question": qsTr("Select a Wednesday between days 15 and 22 of given month"), + "answer": {"year": 2018, "month": 2, "day": 21} + }, + { + "question": qsTr("Select a Thursday between days 26 and 31 of given month"), + "answer": {"year": 2018, "month": 2, "day": 29} + }, + { + "question": qsTr("Select a Friday between days 20 and 25 of given month"), + "answer": {"year": 2018, "month": 2, "day": 23} + }, + { + "question": qsTr("Select a Saturday between days 13 and 23 of given month"), + "answer": {"year": 2018, "month": 2, "day": 17} + }, + { + "question": qsTr("Select a Sunday between days 5 and 17 of given month"), + "answer": {"year": 2018, "month": 2, "day": 11} + } + ] + }, + { + "navigationBarVisible" : false, + "minimumDate": "2018-03-01", + "maximumDate": "2018-03-31", + "visibleMonth": 2, + "visibleYear": 2018, + "mode": "findDay", + "questionsExplicitlyGiven": true, + "questionAnswers": [ + { + "question": qsTr("Select a Monday between days 1 and 7 of given month"), + "answer": {"year": 2018, "month": 2, "day": 5} + }, + { + "question": qsTr("Select a Tuesday between days 8 and 16 of given month"), + "answer": {"year": 2018, "month": 2, "day": 13} + }, + { + "question": qsTr("Select a Wednesday between days 15 and 22 of given month"), + "answer": {"year": 2018, "month": 2, "day": 21} + }, + { + "question": qsTr("Select a Thursday between days 26 and 31 of given month"), + "answer": {"year": 2018, "month": 2, "day": 29} + }, + { + "question": qsTr("Select a Friday between days 20 and 25 of given month"), + "answer": {"year": 2018, "month": 2, "day": 23} + }, + { + "question": qsTr("Select a Saturday between days 13 and 23 of given month"), + "answer": {"year": 2018, "month": 2, "day": 17} + }, + { + "question": qsTr("Select a Sunday between days 5 and 17 of given month"), + "answer": {"year": 2018, "month": 2, "day": 11} + } + ] + } + ] +}