void Start() { crudscore = GetComponent <CRUDScores>(); studentscore = new StudentScores(); world = "world1"; chap = "chap1"; difficulty = "easy"; invalidworld = "testingworld123"; userid = "userid1159"; userid2 = "user1"; studentscore.attempt = 1; studentscore.name = "Sam"; studentscore.scores = 123; GameOwneruserid = "student1"; InvalidGameOwneruserid = "testinguser1234"; UniqueQuestionId = "3405934"; Test_getLeaderBoard_WithValidValue(world, chap, difficulty); Test_getLeaderBoard_WithInvalidValue(invalidworld, chap, difficulty); Test_getUserScores_WithValidValue(world, chap, difficulty, userid); Test_getUserScores_WithInvalidValue(invalidworld, chap, difficulty, userid); Test_getUserScoreForStudentGame_WithValidValue(GameOwneruserid, userid2, UniqueQuestionId); Test_getUserScoreForStudentGame_WithInvalidValue(InvalidGameOwneruserid, userid2, UniqueQuestionId); }
public void getUserScore(string world, string chap, string difficulty, string userid, System.Action <StudentScores, string, string, string> callback) { Debug.Log(world + chap + difficulty + userid); FirebaseDatabase.DefaultInstance .GetReference("scores").Child(world).Child(chap).Child(difficulty).Child(userid) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.Log("Failed to connect"); // Handle the error... } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; StudentScores studentScore = new StudentScores(); studentScore = JsonUtility.FromJson <StudentScores>(snapshot.GetRawJsonValue()); // Debug.Log("here1"); // Debug.Log(studentScore.scores); //Debug.Log("here2"); //need to check whether it exist in database if (studentScore == null) { // Debug.Log("it's null"); callback(null, null, null, null); } else { // Debug.Log("attemp:" + studentScore.attempt + " , name is: " + studentScore.name + " , score: " + studentScore.scores); callback(studentScore, world, chap, difficulty); } } }); }
public void leaderboardCallback(StudentScores[] scoresList, int listSize) { StudentScores[] OrderedScoreList = new StudentScores[11]; for (int i = 0; i < 11; i++) { OrderedScoreList[i] = new StudentScores(); } //Debug.Log(index); // StudentScores[] OrderedScoreList = new StudentScores[index]; for (int i = 0; i < 11 && i < listSize; i++) { OrderedScoreList[i] = scoresList[listSize - i - 1]; //Debug.Log("Score: " + OrderedScoreList[i].name); } leaderboardData = OrderedScoreList; // foreach (StudentScores s in scoresList) // { // Debug.Log(s.name); // Debug.Log(s.scores); // if(s.name == StaticVariable.UserID){ // selfname.text = s.name; // selfscore.text = s.scores.ToString(); // } // Debug.Log("here"); // } Debug.Log("hi4"); getLeaderboard = true; }
public void RandomlyGenerateScores(string world) { StudentScores newScore = new StudentScores(); for (int k = 0; k < 20; k++) { newScore.name = "student" + Random.Range(0, 10000); newScore.scores = Random.Range(0, 100000); newScore.attempt = Random.Range(1, 3); AddNewScores(world, "chap1", "easy", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap1", "normal", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap1", "hard", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap2", "easy", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap2", "normal", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap2", "hard", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap3", "easy", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap3", "normal", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap3", "hard", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap4", "easy", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap4", "normal", "userid" + Random.Range(0, 10000), newScore); AddNewScores(world, "chap4", "hard", "userid" + Random.Range(0, 10000), newScore); } }
public void getUserScoreForStudentGame(string GameOwneruserid, string userid, string UniqueQuestionId, System.Action <StudentScores> callback) { FirebaseDatabase.DefaultInstance .GetReference("studentGame").Child(GameOwneruserid).Child(UniqueQuestionId).Child("scores").Child(userid) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.Log("Failed to connect"); // Handle the error... } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; StudentScores studentScore = new StudentScores(); studentScore = JsonUtility.FromJson <StudentScores>(snapshot.GetRawJsonValue()); //need to check whether it exist in database if (studentScore == null) { //Debug.Log("it's null"); callback(null); } else { //Debug.Log("attemp:" + studentScore.attempt + " , name is: " + studentScore.name + " , score: " + studentScore.scores); callback(studentScore); } } }); }
public void callback(StudentScores[] scores, int index) { OrderedScoreList = new StudentScores[11]; for (int i = 0; i < 11; i++) { OrderedScoreList[i] = new StudentScores(); } for (int i = 0; i < 11 && i < index; i++) { OrderedScoreList[i] = scores[index - i - 1]; //Debug.Log("Score: " + OrderedScoreList[i].name); } for (int i = 0; i < index; i++) { if (scores[index - i - 1].name == username) { userrank = (i + 1).ToString(); break; } } gotData = true; Debug.Log(gotData); }
public void getUserScoreCallback(StudentScores myScore, string world, string chap, string difficulty) { Debug.Log("call back executed"); username = myScore.name; userscore = myScore.scores.ToString(); dbClass.getLeaderBoard(world, chapter, mode, callback); gotUserScore = true; }
private void PeriodPicker_SelectedIndexChanged(object sender, EventArgs e) { StudentScores.DataSource = OgrenciDAO.GetScoresForStudent(ogrenci.Id, Convert.ToInt32(PeriodPicker.Text)); StudentScores.AutoResizeColumns(); for (int i = 1; i < StudentScores.ColumnCount; i++) { StudentScores.Columns[i].ReadOnly = true; } }
public void RandomlyGenerateStudentGameScores() { StudentScores newScore = new StudentScores(); for (int k = 0; k < 5; k++) { newScore.name = "student" + Random.Range(0, 10000); newScore.scores = Random.Range(0, 100000); newScore.attempt = Random.Range(1, 3); AddStudentGameNewScores("student3", newScore.name, "84356", newScore); } }
/// <summary> /// Returns the number of students assignments /// </summary> /// <returns>int length</returns> public int GetStudentAssignmentsCount() { try { return(StudentScores.GetLength(1)); } catch (Exception ex) { //This is the top level method so we want to handle the exception throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } }
public void getStudentGameLeaderBoard(string gameID, System.Action <StudentScores[], int> callback) { FirebaseDatabase.DefaultInstance .GetReference("studentGame") .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.Log("Failed to connect"); // Handle the error... } else if (task.IsCompleted) { // Debug.Log("Code Runs"); DataSnapshot snapshot = task.Result; int Scoreindex = 0; StudentScores[] scoresList = new StudentScores[100]; foreach (DataSnapshot s in snapshot.Children) { foreach (DataSnapshot ss in s.Children) { if (gameID == ss.Key) { foreach (DataSnapshot sss in ss.Child("scores").Children) { scoresList[Scoreindex] = new StudentScores(); scoresList[Scoreindex++] = JsonUtility.FromJson <StudentScores>(sss.GetRawJsonValue()); //Debug.Log("StudentName: " + scoresList[Scoreindex-1].name + " , Student Score: " + scoresList[Scoreindex-1].scores); } break; } } } if (Scoreindex == 0) { callback(null, 0); } else { callback(scoresList, Scoreindex); } //Debug.Log("Code End"); } }); }
public IActionResult Profile() { string login = HttpContext.Session.GetString("Login"); if (string.IsNullOrWhiteSpace(login)) { return(RedirectToAction("Login")); } var allStudentScores = _dbContext.StudentScores; List <Lecture> lectures = _dbContext.Lecture.ToList(); if (login == "Lecturer") { var lecturerProfileModel = new LecturerProfileViewModel { Lectures = new List <string>(), AllStudentScores = new Dictionary <string, List <int> >() }; foreach (var lec in lectures) { lecturerProfileModel.Lectures.Add(lec.Name); } foreach (var stud in allStudentScores) { lecturerProfileModel.AllStudentScores.Add(stud.StudentName, stud.GetScoresAsCollection().ToList()); } return(View("LecturerProfile", lecturerProfileModel)); } else { StudentScores studentScores = allStudentScores.FirstOrDefault(i => i.StudentName == login); var profileViewModel = new ProfileViewModel { UserName = studentScores.StudentName, Scores = new List <int>(), Lectures = new List <string>() }; foreach (var lec in lectures) { profileViewModel.Lectures.Add(lec.Name); } var studentScoresResult = studentScores.GetScoresAsCollection(); for (int i = 0; i < lectures.Count(); ++i) { profileViewModel.Scores.Add(studentScoresResult.ElementAt(i)); } return(View("Profile", profileViewModel)); } }
/// <summary> /// 取得學生學期成績 /// </summary> /// <param name="utilCache"></param> /// <returns></returns> private Dictionary <string, StudentScores> GetStudentScores(Dictionary <string, HistoryUtil> utilCache) { Dictionary <string, StudentScores> scores = new Dictionary <string, StudentScores>(); foreach (JHSemesterScoreRecord scoreRecord in JHSemesterScore.SelectByStudentIDs(AllStudentID)) { if (!scores.ContainsKey(scoreRecord.RefStudentID)) { StudentScores studentScores = new StudentScores(utilCache[scoreRecord.RefStudentID]); scores.Add(scoreRecord.RefStudentID, studentScores); } scores[scoreRecord.RefStudentID].Add(scoreRecord); } return(scores); }
public void myCallbackFunction(StudentScores myScore, string world, string chap, string difficulty) { Debug.Log("call back executed"); if (myScore == null) { Debug.Log("false"); } else { this.studentScores = myScore; _chap = chap; _world = world; _difficulty = difficulty; Debug.Log(studentScores.scores); getStudentScores(_world, _chap, userid, _difficulty); } callbackdone = true; }
// Start is called before the first frame update void Awake() { // Set this before calling into the realtime database. /*FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://ssadpancake.firebaseio.com/");*/ FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://ssad-c9270.firebaseio.com/"); // Get the root reference location of the database. mDatabaseRef = FirebaseDatabase.DefaultInstance.RootReference; ////////////////////////////This function will add a new score in the database////////////////////////////////////// ///Specify which world, chap and difficulty level of the question, student and the scores of the student into the function StudentScores sample = new StudentScores(); sample.name = "Johnny pean"; sample.scores = Random.Range(0, 100000); sample.attempt = Random.Range(1, 3); AddNewScores("world1", "chap1", "easy", "myuserid", sample); }
public void getLeaderBoard(string world, string chap, string difficulty, System.Action <StudentScores[], int> callback) { FirebaseDatabase.DefaultInstance .GetReference("scores").Child(world).Child(chap).Child(difficulty).OrderByChild("scores") .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.Log("Failed to connect"); // Handle the error... } else if (task.IsCompleted) { // Debug.Log("Code Runs"); DataSnapshot snapshot = task.Result; int index = 0; //currently order is ascending StudentScores[] scoresList = new StudentScores[200]; foreach (DataSnapshot s in snapshot.Children) { //Debug.Log(index+s.GetRawJsonValue()); scoresList[index] = new StudentScores(); scoresList[index++] = JsonUtility.FromJson <StudentScores>(s.GetRawJsonValue()); } //Debug.Log(index); // StudentScores[] OrderedScoreList = new StudentScores[index]; if (index == 0) { callback(null, 0); } else { callback(scoresList, index); } //Debug.Log("Code End"); } }); }
// Start is called before the first frame update void Start() { crudscore = GetComponent <CRUDScores>(); crudUser = GetComponent <AddUser>(); studentscore = new StudentScores(); world = "testworld"; chap = "chap1"; difficulty = "easy"; userid = "user1"; studentscore.attempt = 1; studentscore.name = "Sam"; studentscore.scores = 123; GameOwneruserid = "student1"; UniqueQuestionId = "3405934"; AddNewScores(world, chap, difficulty, userid, studentscore); getUserScores(world, chap, difficulty, userid); updateUserScore(world, chap, difficulty, userid, studentscore); AddStudentGameNewScores(GameOwneruserid, userid, UniqueQuestionId, studentscore); getUserScoreForStudentGame(GameOwneruserid, userid, UniqueQuestionId); }
public void callbackFunc(StudentScores scList) { scoreList = scList; call = true; }
public void AddNewScores(string world, string chap, string difficulty, string userid, StudentScores studentscore) { string json = JsonUtility.ToJson(studentscore); mDatabaseRef.Child("scores").Child(world).Child(chap).Child(difficulty).Child(userid).SetRawJsonValueAsync(json); }
public bool AddNewScores(string world, string chap, string difficulty, string userid, StudentScores studentscore) { if (world != null && chap != null && difficulty != null && userid != null && studentscore != null) { return(true); } return(false); }
public bool AddStudentGameNewScores(string GameOwneruserid, string userid, string UniqueQuestionId, StudentScores studentscore) { if (GameOwneruserid != null && UniqueQuestionId != null && userid != null && studentscore != null) { return(true); } return(false); }
public void AddStudentGameNewScores(string GameOwneruserid, string userid, string UniqueQuestionId, StudentScores studentscore) { Debug.Log("Add student's game user score into database"); Debug.Log("Call Score manager to add data"); crudscore.AddStudentGameNewScores(GameOwneruserid, userid, UniqueQuestionId, studentscore); crudscore.getUserScoreForStudentGame(GameOwneruserid, userid, UniqueQuestionId, printSuccessMsg); }
public void updateUserScore(string world, string chap, string difficulty, string userid, StudentScores studentscore) { Debug.Log("Update user score"); Debug.Log("Call Score manager to update data"); crudscore.updateUserScore(world, chap, difficulty, userid, studentscore); crudscore.getUserScore(world, chap, difficulty, userid, printSuccessMsg); }
public void printSuccessMsg(StudentScores sc) { Debug.Log("CRUD called"); }
public void AddNewScores(string world, string chap, string difficulty, string userid, StudentScores studentscore) { Debug.Log("Add user score into database"); Debug.Log("Call Score manager to add data"); crudscore.AddNewScores(world, chap, difficulty, userid, studentscore); crudscore.getUserScore(world, chap, difficulty, userid, printSuccessMsg); }
public void CallBackFunction_WithFalse(StudentScores sc) { assert((sc != null), false); }
public void CallBackFunction_WithTrue(StudentScores sc) { assert((sc != null), true); }
IEnumerator GenerateQuestions() { var getTask = FirebaseDatabase.DefaultInstance .GetReference("question").Child(world).Child(chap).Child(difficulty) .GetValueAsync(); yield return(new WaitUntil(() => getTask.IsCompleted || getTask.IsFaulted)); DataSnapshot snapshot = null; if (getTask.IsCompleted) { snapshot = getTask.Result; } if (difficulty == "easy") { NumQuestions = 10; } else if (difficulty == "normal") { NumQuestions = 15; } else { NumQuestions = 20; } int totalQuestion = int.Parse(snapshot.ChildrenCount.ToString()); if (NumQuestions > totalQuestion) //If not enough questions from the database { question.text = "The lecturer has not set enough question for this chapter."; Time.timeScale = 0; } else { GetQuestion[] questionList = new GetQuestion[snapshot.ChildrenCount]; int index = 0; //Get question list foreach (DataSnapshot s in snapshot.Children) { questionList[index] = new GetQuestion(); questionList[index].UniqueKey = s.Key; questionList[index++].question = JsonUtility.FromJson <UploadQuestion>(s.GetRawJsonValue()); } GetQuestion[] randomQuestion = new GetQuestion[NumQuestions]; for (int i = 0; i < NumQuestions; i++) { randomQuestion[i] = questionList[i]; while (randomQuestion[i] == null) { int random = Random.Range(0, NumQuestions - 1); if (questionList[random] != null) { randomQuestion[i] = questionList[random]; questionList[random] = null; } } } int rightOption = 0; for (int i = 0; i < NumQuestions; i++) { question.text = randomQuestion[i].question.question; int random = Random.Range(1, 4); if (random == 1) { answer1.text = randomQuestion[i].question.ans1; answer2.text = randomQuestion[i].question.ans2; answer3.text = randomQuestion[i].question.ans3; answer4.text = randomQuestion[i].question.ans4; } else if (random == 2) { answer1.text = randomQuestion[i].question.ans2; answer2.text = randomQuestion[i].question.ans3; answer3.text = randomQuestion[i].question.ans1; answer4.text = randomQuestion[i].question.ans4; } else if (random == 3) { answer1.text = randomQuestion[i].question.ans3; answer2.text = randomQuestion[i].question.ans2; answer3.text = randomQuestion[i].question.ans4; answer4.text = randomQuestion[i].question.ans1; } else { answer1.text = randomQuestion[i].question.ans3; answer2.text = randomQuestion[i].question.ans1; answer3.text = randomQuestion[i].question.ans4; answer4.text = randomQuestion[i].question.ans2; } string rightAnswer = randomQuestion[i].question.correctAns; if (rightAnswer == answer1.text) { rightOption = 1; } else if (rightAnswer == answer2.text) { rightOption = 2; } else if (rightAnswer == answer3.text) { rightOption = 3; } else if (rightAnswer == answer4.text) { rightOption = 4; } yield return(new WaitForSeconds(4.2f)); if (rightOption == userChoice) { score++; Score.text = score.ToString(); point.Play(); // playSound(); yield return(new WaitForSeconds(1.8f)); } else { setCharacterMovement(character, true); fail.Play(); yield return(new WaitForSeconds(0.6f)); setCharacterMovement(character, false); yield return(new WaitForSeconds(1.2f)); } } // GETTING attempt from scores int latestAttempt = 0; /* var task = FirebaseDatabase.DefaultInstance * .GetReference("scores").Child(world).Child(chap).Child(difficulty).Child(userID) * .GetValueAsync(); * * yield return new WaitUntil(() => task.IsCompleted || task.IsFaulted); * * * if (task.IsFaulted) * { * Debug.Log("Failed to connect"); * // Handle the error... * } * else if (task.IsCompleted) * { * * Debug.Log("Code Runs"); * snapshot = task.Result; * * * index = 0; * * //currently order is ascending * StudentScores[] scoresList = new StudentScores[snapshot.ChildrenCount]; * * foreach (DataSnapshot s in snapshot.Children) * { * scoresList[index] = new StudentScores(); * scoresList[index++] = JsonUtility.FromJson<StudentScores>(s.GetRawJsonValue()); * } * * Debug.Log("Total record found " + snapshot.ChildrenCount); * * * foreach (var item in scoresList) * { * if (item != null) * { * //get the student name here * if (item.attempt > latestAttempt) * { * latestAttempt = item.attempt; * } * * if (item.scores > score) * { * score = item.scores; * } * } * } * //}*/ // To Insert student score into DB Debug.Log(scoreList.scores); if (scoreList != null) { if (scoreList.scores > score) { score = scoreList.scores; } latestAttempt = scoreList.attempt; } crudscore.getUserScore(world, chap, difficulty, userID, callbackFunc); StudentScores sc = new StudentScores(); sc.name = ""; sc.attempt = latestAttempt + 1; sc.scores = score; crudscore.updateUserScore(world, chap, difficulty, userID, sc); Time.timeScale = 0; question.text = "Game Completed! Click back to attempt another game!"; } }
/// <summary> /// Generates a string to display all the student's scores /// </summary> /// <param name="preDisplay">Header string</param> /// <returns>String display</returns> public String GenerateDisplay(String preDisplay) { String display = preDisplay; try { for (int i = 0; i < StudentNames.Length; ++i) { double sum = 0; display += Environment.NewLine; display += StudentNames[i] + "\t\t"; for (int j = 0; j < StudentScores.GetLength(1); ++j) { display += StudentScores[i, j] + "\t"; sum += StudentScores[i, j]; } double average = (sum / StudentScores.GetLength(1)); display += average + "\t"; String letterGrade; if (average >= 93) { letterGrade = "A"; } else if (average >= 90) { letterGrade = "A-"; } else if (average >= 87) { letterGrade = "B+"; } else if (average >= 83) { letterGrade = "B"; } else if (average >= 80) { letterGrade = "B-"; } else if (average >= 77) { letterGrade = "C="; } else if (average >= 73) { letterGrade = "C"; } else if (average >= 70) { letterGrade = "C-"; } else if (average >= 67) { letterGrade = "D+"; } else if (average >= 63) { letterGrade = "D"; } else if (average >= 60) { letterGrade = "D-"; } else { letterGrade = "F"; } display += letterGrade; } } catch (Exception ex) { //This is the top level method so we want to handle the exception throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message); } return(display); }
public void printggetUserScoreForStudentGameTime(StudentScores dummy) { Debug.Log("Getting getUserScoreForStudentGame data at: " + System.DateTime.Now); }