public ActionResult Personal_Data(User user) { // Der Benutzer soll in der Datenbank gespeichert werden // 1. Verbindung zur Datenbank var db = new QuestDbContext(); if (ModelState.IsValid) { // das ist ein neuer User => gib ihm eine Id user.Id = Guid.NewGuid(); user.Created = DateTime.Now; // den neuen Benutzer zur Datenbank hinzufügen db.Users.Add(user); // Änderungen jetzt wirklich in der Datenbank speichern db.SaveChanges(); // jetzt das Quiz starten return(RedirectToAction("Index", "Quiz", new { id = user.Id })); } // wenn es nicht geklappt hat, dann hat der Benutzer wohl was falsches eingegeben // zeige den Dialog noch einmal return(View()); }
// GET: Quest/Analyse public ActionResult Index() { // 1. Verbindung zur Datenbank var db = new QuestDbContext(); // 2. Daten abfragen var model = db.Users.ToList(); return(View(model)); }
public static void EnsurePopulated(IApplicationBuilder app) { QuestDbContext context = (QuestDbContext)app.ApplicationServices.GetService(typeof(QuestDbContext)); context.Database.Migrate(); if (!context.Companies.Any()) { CompanyEntity[] companies = new CompanyEntity[] { new CompanyEntity { Name = "FearCorporation", Logo = "fear.jpg" }, new CompanyEntity { Name = "BlackBox", Logo = "box.jpg" }, }; context.AddRange(companies); QuestEntity[] quests = new QuestEntity[] { new QuestEntity { Name = "Escape from house", Company = companies[0], Address = "Dubno", Email = "*****@*****.**", Description = "Very scary", FearLevel = 5, HardLevel = 5, MaxPlayers = 10, MinAge = 21, MinPlayers = 3, Phone = "066-85-26-406", Raiting = 8.5, WalkTime = TimeSpan.FromMinutes(180) }, new QuestEntity { Name = "Find predmets in house", Company = companies[1], Address = "Rivne", Email = "*****@*****.**", Description = "Find predmets", FearLevel = 1, HardLevel = 3, MaxPlayers = 5, MinAge = 14, MinPlayers = 1, Phone = "095-32-21-109", Raiting = 9.2, WalkTime = TimeSpan.FromMinutes(160) }, }; context.AddRange(quests); ImageEntity[] images = new ImageEntity[] { new ImageEntity { Name = "Img1", Path = "1.jpg", Quest = quests[0] }, new ImageEntity { Name = "Img2", Path = "2.jpg", Quest = quests[0] }, new ImageEntity { Name = "Img3", Path = "3.jpg", Quest = quests[1] }, new ImageEntity { Name = "Img4", Path = "4.jpg", Quest = quests[1] }, }; context.AddRange(images); context.SaveChanges(); } }
public IHttpActionResult GetQuizGameResult(Guid?gameId, Guid?playerId) { var QuizDb = new QuestDbContext(); var result = new QuizGameResult(); if (gameId.HasValue && playerId.HasValue) { var game = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameId.Value); var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == playerId.Value); // Die Antwort if (game != null && player != null) { result.GameId = game.Id; result.PlayerId = player.Id; result.QuizId = game.Levels.First().Quiz.Id; var service = new GameStatisticsService(result.QuizId, player.UserId); var statistics = service.GetStatistics(game.Id); result.QuestionCount = statistics.TotalQuestionCount; result.CorrectAnswerCount = statistics.CorrectAnswerCount; result.PersonalRank = service.GetPersonalRank(result.CorrectAnswerCount); result.TotalRank = service.GetTotalRank(result.CorrectAnswerCount); result.Message = "OK"; } else { var sb = new StringBuilder(); if (game == null) { sb.Append("Spiel fehlt"); } if (player == null) { sb.Append("Spieler fehlt"); } result.Message = sb.ToString(); } } else { result.Message = "Falsche Parameter"; } return(Ok(result)); }
public IHttpActionResult GetLogAnswer(Guid?gameId, Guid?playerId, Guid?answerId) { var QuizDb = new QuestDbContext(); var result = new QuizGameAnswerResult(); if (gameId.HasValue && playerId.HasValue && answerId.HasValue) { var answer = QuizDb.Answers.SingleOrDefault(x => x.Id == answerId.Value); var game = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameId.Value); var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == playerId.Value); // Die Antwort if (answer != null && game != null && player != null) { var log = new GameLog(); log.Answer = answer; log.Game = game; log.Player = player; log.LogDateTime = DateTime.Now; QuizDb.GameLogs.Add(log); QuizDb.SaveChanges(); // Update var statService = new StatisticsService(QuizDb); statService.NotifyUpdates(); result.QuizId = game.Levels.First().Quiz.Id; result.AnswerId = answer.Id; result.IsCorrect = answer.IsCorrect; if (answer.IsCorrect) { result.Score = 1; } result.Message = "OK"; } else { var sb = new StringBuilder(); if (game == null) { sb.Append("Spiel fehlt"); } if (player == null) { sb.Append("Spieler fehlt"); } if (answer == null) { sb.Append("Antwort fehlt"); } result.Message = sb.ToString(); } } else { result.Message = "Falsche Parameter"; } return(Ok(result)); }
public StatisticsService(QuestDbContext db) { _dbContext = db; }
public ActionResult DownloadLogData() { var db = new QuestDbContext(); // 2. Daten abfragen var model = db.Users.ToList(); var ms = new MemoryStream(); var writer = new StreamWriter(ms, Encoding.Default); writer.Write("Datum;Geschlecht;Alter;Hochschulzugang;Fragen;Richtig;Falsch;NB;Zeit"); writer.Write(Environment.NewLine); foreach (var user in model) { var startTime = user.Created; var lastTime = user.Created; var q = user.Logs.Count; var correct = 0; var wrong = 0; var na = 0; writer.Write("{0};{1};{2};{3}", user.Created, user.Geschlecht, user.Altersgruppe, user.Hochschulzugangsberechtigung); foreach (var log in user.Logs.OrderBy(l => l.Question.Category.Reihenfolge).ThenBy(l => l.Question.Reihenfolge)) { if (log.Answer != null) { if (log.Answer.IsCorrect) { correct++; } else { wrong++; } } else { na++; } if (log.FirstView > lastTime) { lastTime = log.FirstView; } } writer.Write(";{0};{1};{2};{3}", q, correct, wrong, na); writer.Write(";{0}", (lastTime - startTime).TotalSeconds); writer.Write(Environment.NewLine); } writer.Flush(); writer.Dispose(); var sb = new StringBuilder(); sb.Append("WiQuestLog_"); sb.Append("_"); sb.Append(DateTime.Today.ToString("yyMMdd")); sb.Append(".csv"); return(File(ms.GetBuffer(), "text/csv", sb.ToString())); }
public GamePlayService(QuestDbContext db) { _quizDb = db; }
public GamePlayService() { _quizDb = new QuestDbContext(); }
public ActionResult Evaluation(Guid id) { // Alle Logeinträge des Benutzers var service = new QuestionService(); var user = service.GetUser(id); var db = new QuestDbContext(); var logs = db.QuestLogs.Where(l => l.User.Id == user.Id).ToList(); // Endergebnis für den ganzen Test var AnzahlFragen = logs.Count(); var IsCorrect = logs.Count(a => a.Answer != null && a.Answer.IsCorrect); var Result = (int)(IsCorrect / (double)AnzahlFragen * 100); ViewBag.AnzahlFragen = AnzahlFragen; ViewBag.IsCorrect = IsCorrect; ViewBag.Result = Result; // Ergebnis für Mathematik var AnzahlMatheFragen = logs.Count(m => m.Question.Category.Name.Equals("Mathematik")); var IsCorrectMathe = logs.Count(a => a.Answer != null && a.Answer.IsCorrect && a.Question.Category.Name.Equals("Mathematik")); var ResultMathe = (int)(IsCorrectMathe / (double)AnzahlMatheFragen * 100); ViewBag.ResultMathe = ResultMathe; // Ergebnis für Technik var AnzahlTechFragen = logs.Count(m => m.Question.Category.Name.Equals("Technik")); var IsCorrectTech = logs.Count(a => a.Answer != null && a.Answer.IsCorrect && a.Question.Category.Name.Equals("Technik")); var ResultTech = (int)(IsCorrectTech / (double)AnzahlTechFragen * 100); ViewBag.ResultTech = ResultTech; // Ergebnis für Wirtschaft var AnzahlWirtFragen = logs.Count(m => m.Question.Category.Name.Equals("Wirtschaft")); var IsCorrectWirt = logs.Count(a => a.Answer != null && a.Answer.IsCorrect && a.Question.Category.Name.Equals("Wirtschaft")); var ResultWirt = (int)(IsCorrectWirt / (double)AnzahlWirtFragen * 100); ViewBag.ResultWirt = ResultWirt; // Ergebnis für Naturwissenschaften var AnzahlNaturFragen = logs.Count(m => m.Question.Category.Name.Equals("Naturwissenschaften")); var IsCorrectNatur = logs.Count(a => a.Answer != null && a.Answer.IsCorrect && a.Question.Category.Name.Equals("Naturwissenschaften")); var ResultNatur = (int)(IsCorrectNatur / (double)AnzahlNaturFragen * 100); ViewBag.ResultNatur = ResultNatur; return(View(logs)); }
public FileResult ShowChart(Guid id) { Chart chart = new Chart(); chart.Width = 700; chart.Height = 300; chart.BackColor = Color.FromArgb(211, 223, 240); Series series = new Series("Default"); chart.Series.Add(series); chart.ChartAreas.Add("ChartArea1"); var service = new QuestionService(); var user = service.GetUser(id); var db = new QuestDbContext(); var logs = db.QuestLogs.Where(l => l.User.Id == user.Id).ToList(); var categories = logs.Select(d => d.Question.Category).Distinct().ToList(); double[] yValues = new double[categories.Count()]; string[] xValues = new string[categories.Count()]; var i = 0; foreach (var category in categories) { var AnzahlFragen = logs.Count(m => m.Question.Category.Id == category.Id); var IsCorrect = logs.Count(a => a.Answer != null && a.Answer.IsCorrect && a.Question.Category.Id == category.Id); var Result = IsCorrect / (double)AnzahlFragen * 100; yValues[i] = Result; xValues[i] = category.Name; i++; } // Populate series data //double[] yValues = {65.62, 75.54, 60.45, 34.73, 85.42, 55.9, 63.6, 55.2, 77.1}; //string[] xValues = {"France", "Canada", "Germany", "USA", "Italy", "Spain", "Russia", "Sweden", "Japan"}; chart.Series["Default"].Points.DataBindXY(xValues, yValues); // Set radar chart type chart.Series["Default"].ChartType = SeriesChartType.Radar; // Set radar chart style (Area, Line or Marker) chart.Series["Default"]["RadarDrawingStyle"] = "Area"; // Set circular area drawing style (Circle or Polygon) chart.Series["Default"]["AreaDrawingStyle"] = "Polygon"; // Set labels style (Auto, Horizontal, Circular or Radial) chart.Series["Default"]["CircularLabelsStyle"] = "Horizontal"; // Show as 3D chart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; MemoryStream ms = new MemoryStream(); chart.SaveImage(ms); return(File(ms.GetBuffer(), @"image/png")); }