public void CalculateTimes(string name) { List <object> values = new List <object>(); values.Add(name); DataDump.Initialize(); calculateTimes(values); }
public void submitFeedback() { if (username == "") { username = "******"; } DataDump.Initialize(); List <object> surveyAnswers = new List <object>(); surveyAnswers.Add(username); surveyAnswers.Add(answers[0]); surveyAnswers.Add(answers[1]); for (int i = 0; i < 3; i++) { surveyAnswers.Add(textAnswers[i]); } DataDump.CreateEntry("A", "F", surveyAnswers, 1); CameraScript.Instance.CalculateTimes(username); }
public void GetLeaderboard() { if (!leaderboardCreated) { DataDump.Initialize(); IList <IList <object> > usernamesListDump = DataDump.ReadEntries("A3", "A20", 0); usernamesList.AddRange(from list in usernamesListDump from username in list select username as string); IList <IList <object> > timesListDump = DataDump.ReadEntries("R3", "R20", 0); timesList.AddRange(from list in timesListDump from time in list select time as string); foreach (string time in timesList) { var match = Regex.Match(time, @"([-+]?[0-9]*\.?[0-9]+)"); if (match.Success) { intTimesList.Add(Mathf.RoundToInt(System.Convert.ToSingle(match.Groups[1].Value))); } else { intTimesList.Add(-1); } } foreach (int time in intTimesList) { if (time == -1) { usernamesList.RemoveAt(intTimesList.IndexOf(-1)); intTimesList.Remove(-1); } } Debug.Log(intTimesList.Count); Debug.Log(usernamesList.Count); sortedIntTimesList = intTimesList.ToList().OrderBy(t => t).ToList(); if (sortedIntTimesList.Count > 9) { sortedIntTimesList = sortedIntTimesList.GetRange(0, 8).ToList(); } Debug.Log(sortedIntTimesList.Count); foreach (var time in sortedIntTimesList) { sortedUsernamesList.Add(usernamesList[intTimesList.IndexOf(time)]); intTimesList[intTimesList.IndexOf(time)] = -2; } int leaderboardLength = (sortedUsernamesList.Count <= sortedIntTimesList.Count ? sortedUsernamesList.Count : sortedIntTimesList.Count); for (int i = 0; i < leaderboardLength; i++) { usernames[i].text = sortedUsernamesList[i]; int minutes = Mathf.FloorToInt(sortedIntTimesList[i] / 60); int seconds = sortedIntTimesList[i] % 60; string secondsText = seconds.ToString(); while (secondsText.Length < 2) { secondsText = "0" + secondsText; } times[i].text = (minutes != 0 ? (minutes.ToString() + ":") : "0:") + secondsText; } if (leaderboardLength < usernames.Length) { for (int i = leaderboardLength; i < usernames.Length; i++) { usernames[i].text = ""; times[i].text = ""; } } leaderboardCreated = true; } }
private void calculateTimes(List <object> Values) { List <object> values = Values.ToList(); DataDump.Initialize(); bool completed = false; if (endTime != 0) { completed = true; } List <float> fillList(List <float> list) { List <float> tempList = list.ToList(); while (tempList.Count < 3) { tempList.Add(-1); } return(tempList); } void formatList(List <float> list) { List <float> tempList = list.ToList(); float temp = 0; for (int i = 0; i < 3; i++) { values.Add(tempList[i]); if (tempList[i] != -1) { temp += tempList[i]; } } values.Add(temp); } values.Add(completed.ToString()); List <float> _times = new List <float>(); times = fillList(times); for (int i = 0; i < 3; i++) { if (times[i] != -1) { if (i == 0) { _times.Add(Mathf.Abs(times[i] - startTime)); } else { if (times[i - 1] != -1) { _times.Add(Mathf.Abs(times[i] - times[i - 1])); } else { _times.Add(-1); } } } } formatList(_times); List <float> hintsList = fillList(hintsUsed.Select <int, float>(i => i).ToList()); formatList(hintsUsed.Select <int, float>(i => i).ToList()); penalties = fillList(penalties); formatList(penalties); formatList(_times.Zip(penalties, (x, y) => (x != -1 || y != -1 ? ((x != -1 ? x : 0) + (y != -1 ? y : 0)) : -1)).ToList()); if (times.Contains(-1)) { values[values.Count - 1] = -1; } DataDump.CreateEntry("A", "R", values, 0); }