2using System.Collections;
3using System.Collections.Generic;
17 internal float bestTime, averageTime;
18 private string selectedUsername =
"";
19 private readonly List<GameObject> spawnedObjects =
new List<GameObject>();
20 internal List<float> RecognitionList =
new List<float>();
21 internal List<float> TimeSpendList =
new List<float>();
22 internal List<float> PenaltyList =
new List<float>();
31 user.trainings.Clear();
32 user.trainings =
null;
39 selectedUsername = user.Username;
40 if (user.trainings ==
null || user.trainings.Count == 0)
43 empty.SetActive(
true);
44 foreach (var spawnedObject
in spawnedObjects)
46 Destroy(spawnedObject);
48 spawnedObjects.Clear();
54 empty.SetActive(
false);
55 foreach (var spawnedObject
in spawnedObjects)
57 Destroy(spawnedObject);
59 spawnedObjects.Clear();
62 var trainings =
new List<Trainings>();
64 foreach (var training
in user.trainings)
66 var first = trainings.FirstOrDefault(x => x.Name == training.Name);
67 if (first !=
default(Trainings))
69 first.successes.Add(training.Success);
70 first.times.Add(training.Time);
71 first.quizzes.AddQuizList(training.Quizzes);
75 trainings.Add(
new Trainings()
78 successes =
new List<bool>() {training.Success},
79 times =
new List<float>() {training.Time},
80 quizzes = Collector.ConvertQuiz(training.Quizzes)
85 foreach (var training
in trainings)
88 if (training.Name == trainingName)
92 spawnedObjects.Add(go);
94 go.SetText(
"Name", training.Name);
95 var notzerotimes = training.times.Where(x => x != 0.0f);
96 if (!notzerotimes.Any())
98 notzerotimes =
new List<float>(){3599.999f};
100 go.SetText(
"BestTime", TimeSpan.FromSeconds(notzerotimes.Min()).ToString(
"mm':'ss'.'fff"));
101 go.SetText(
"AverageTime", TimeSpan.FromSeconds(notzerotimes.Average()).ToString(
"mm':'ss'.'fff"));
102 go.SetText(
"LastTime", TimeSpan.FromSeconds(training.times.Last()).ToString(
"mm':'ss'.'fff"));
103 go.SetText(
"SuccessRate", ((
float)training.successes.Count(x => x) / training.successes.Count).ToString(
"P"));
105 var quizTransform = go.transform.Find(
"Quizzes");
108 if (training.quizzes.Count == 0)
110 Destroy(quizTransform.gameObject);
114 foreach (var trainingQuiz
in training.quizzes)
116 var qu = Instantiate(
QuizPrefab, quizTransform);
118 qu.SetText(
"Name", trainingQuiz.Name);
119 qu.SetText(
"BestTime", TimeSpan.FromSeconds(trainingQuiz.times.Min()).ToString(
"mm':'ss'.'fff"));
120 qu.SetText(
"SuccessRate", ((
float)trainingQuiz.successes.Count(x => x) / trainingQuiz.successes.Count).ToString(
"P"));
127 public void GetStats(
UserManager.
User user, out IEnumerable<float> notzerotimes , out IEnumerable<float> notzerotimesAll, out List<float> recognitionList , out List<float> timeSpendList, out List<float> penaltyList)
129 notzerotimes =
new List<float>();
130 notzerotimesAll =
new List<float>();
131 recognitionList =
new List<float>();
132 timeSpendList =
new List<float>();
133 penaltyList =
new List<float>();
134 var _trainings =
new List<Trainings>();
136 if (user.trainings ==
null || user.trainings.Count == 0)
141 var lastTraining = currentUserValue.trainings[currentUserValue.trainings.Count - 1];
149 foreach (var training
in user.trainings)
153 var first = _trainings.FirstOrDefault(x => x.Name == training.Name);
154 if (first !=
default(Trainings))
156 first.successes.Add(training.Success);
157 first.times.Add(training.Time);
158 first.quizzes.AddQuizList(training.Quizzes);
162 _trainings.Add(
new Trainings()
164 Name = training.Name,
165 successes =
new List<bool>() { training.Success },
166 times =
new List<float>() { training.Time },
167 quizzes = Collector.ConvertQuiz(training.Quizzes)
175 foreach (var training
in _trainings)
177 notzerotimes = training.times.Where(x => x != 0.0f);
178 if (!notzerotimes.Any())
180 notzerotimes =
new List<float>() { 3599.999f };
184 var allTrainings =
new List<Trainings>();
187 if (_user.trainings !=
null)
188 foreach (var userTraining
in _user.trainings)
192 var first = allTrainings.FirstOrDefault(x => x.Name == userTraining.Name);
193 if (first !=
default(Trainings))
195 first.successes.Add(userTraining.Success);
196 first.times.Add(userTraining.Time);
197 first.quizzes.AddQuizList(userTraining.Quizzes);
201 allTrainings.Add(
new Trainings()
203 Name = userTraining.Name,
204 successes =
new List<bool>() { userTraining.Success },
205 times =
new List<float>() { userTraining.Time },
214 foreach (var allTraining
in allTrainings)
216 notzerotimesAll = allTraining.times.Where(x => x != 0.0f);
217 if (!notzerotimesAll.Any())
219 notzerotimesAll =
new List<float>() { 3599.999f };
224 private class Trainings : Collector
226 public List<Collector> quizzes =
new List<Collector>();
228 internal class Collector
231 public List<float> times =
new List<float>();
232 public List<bool> successes =
new List<bool>();
234 public void AddTime(
float time)
238 public void AddSuccess(
bool value)
240 successes.Add(value);
243 public static List<Collector> ConvertQuiz(List<UserManager.Quiz> c)
245 var quiz =
new List<Collector>();
247 if (c ==
null || c.Count == 0)
254 quiz.Add(
new Collector()
257 successes =
new List<bool>(){q.Success},
258 times =
new List<float>() {q.Time}
267public static class CustomExtensions
269 internal static void SetText(
this GameObject go,
string text,
string value)
271 go.transform.Find(text)
273 .GetComponent<Text>()
277 internal static void AddQuizList(
this List<UserStatManager.Collector> collectors, List<UserManager.Quiz> value)
279 if (value ==
null || collectors ==
null || value.Count == 0)
283 foreach (var collector
in collectors)
285 foreach (var quiz
in value)
287 if (collector.Name != quiz.Name)
continue;
288 collector.AddTime(quiz.Time);
289 collector.AddSuccess(quiz.Success);
293 foreach (var quiz
in value)
295 if (collectors.All(x => x.Name != quiz.Name))
300 successes = new List<bool>(){ quiz.Success},
301 times =
new List<float>() {quiz.Time}
void ShowStats(UserManager.User user, string trainingName)
void GetStats(UserManager.User user, out IEnumerable< float > notzerotimes, out IEnumerable< float > notzerotimesAll, out List< float > recognitionList, out List< float > timeSpendList, out List< float > penaltyList)
GameObject TrainingPrefab
static UserStatManager Instance