public void InningsSummaryTextRendersCorrectly() { var data = this.FormContent().ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var innings = new Models.Score { BattingScorecard = Parse.parseBattingScorecard(data["BattingScorecard"]).ToArray(), BowlingScorecard = Parse.parseBowlingScorecard(data["BowlingScorecard"]).ToArray(), Declared = false, Extras = int.Parse(data["Extras"]), FallOfWicketScorecard = Parse.parseFallOfWicketScorecard(data["FallOfWicketScorecard"]).ToArray(), Innings = int.Parse(data["Innings"]), Team = data["Team"] }; // check basic case Assert.AreEqual("164-5", innings.RenderBattingScore()); // check parses declarations innings.Declared = true; Assert.AreEqual("164-5d", innings.RenderBattingScore()); // check doesn't count 'not outs' in dismissals innings.BattingScorecard.First().Dismissal = Models.Enums.Dismissal.NotOut; Assert.AreEqual("164-4d", innings.RenderBattingScore()); // check 'all out' renders correctly innings.Declared = false; innings.BattingScorecard = innings.BattingScorecard .Concat(Enumerable.Repeat(innings.BattingScorecard.Last(), NumberOfPlayers - innings.BattingScorecard.Length)) .ToArray(); Assert.AreEqual("278 all out", innings.RenderBattingScore()); }
public ScoresNewPage() { InitializeComponent(); Data = new Models.Score { Name = "New Score", Description = "This is a new Score", Id = Guid.NewGuid().ToString(), ImageURI = "https://i.imgur.com/DeFwZPA.png" }; BindingContext = this; }
public async Task <Models.Score> ScorePackage(PackageContext context) { var score = new Models.Score(); score.ScoreReport = new ScoreReport { FollowsNuGetConventions = await FollowsNuGetConventionsAsync(context), ProvidesDocumentation = await ProvidesDocumentationAsync(context), PassStaticAnalysis = await PassStaticAnalysisAsync(context), SupportsMultiplePlatforms = await SupportsMultiplePlatformsAsync(context), SupportUpToDateDependencies = await SupportUpToDateDependenciesAsync(context) }; return(score); }
public async Task <IActionResult> AddHighScore([FromBody] Models.Score score) { int userId; if (!HttpContext.User.Identity.IsAuthenticated) { return(StatusCode(400)); } try { int.TryParse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value, out userId); } catch { return(StatusCode(400)); } score.UserID = userId; _context.Scores.Add(score); await _context.SaveChangesAsync(); return(StatusCode(201)); }
// public static void EnsurePopulated(IApplicationBuilder app) public static async Task EnsurePopulated(IApplicationBuilder app) { ApplicationDbContext context = app.ApplicationServices.GetRequiredService <ApplicationDbContext>(); //#region UserRolesRegion if (!context.Members.Any()) { #region Identity string adminRole = "Admin"; string memberRole = "Member"; UserManager <Member> userManager = app.ApplicationServices.GetRequiredService <UserManager <Member> >(); RoleManager <IdentityRole> roleManager = app.ApplicationServices.GetRequiredService <RoleManager <IdentityRole> >(); if (await roleManager.FindByNameAsync(adminRole) == null) { await roleManager.CreateAsync(new IdentityRole(adminRole)); } if (await roleManager.FindByNameAsync(memberRole) == null) { await roleManager.CreateAsync(new IdentityRole(memberRole)); } #region works adds net user admin role // Add one user. string username = "******"; string email = "*****@*****.**"; string password = "******"; Member user = await userManager.FindByNameAsync(username); if (user == null) { user = new Member { UserName = username, Email = email, Password = password }; IdentityResult result = await userManager.CreateAsync(user, password); if (result.Succeeded) { await userManager.AddToRoleAsync(user, adminRole); } } #endregion context.Members.AddRange( new Member() { Name = "Fred William", Email = "*****@*****.**", Password = "******" }, new Member() { Name = "Fry Burger", Email = "*****@*****.**", Password = "******" }, new Member() { Name = "Bill Nye", Email = "*****@*****.**", Password = "******" } ); #endregion #region SeedDataRegion var member1 = new Member { Name = "Member0ne", Email = "*****@*****.**", Password = "******" }; context.Members.Add(member1); var Score1 = new Models.Score { ScoreNum = 1, Body = "Big Moma jokes are hurtful", Date = DateTime.Now, From = member1, Topic = "stuff she says" }; context.Scores.Add(Score1); var member2 = new Member { Name = "Membertw0", Email = "*****@*****.**", Password = "******" }; context.Members.Add(member2); var Score2 = new Models.Score { ScoreNum = 4, Body = "Big Moma jokes are hurtful", Date = DateTime.Now, From = member2, Topic = "Topic 2" }; context.Scores.Add(Score2);//working / score is int var member3 = new Member { Name = "Memberthree", Email = "*****@*****.**", Password = "******" }; context.Members.Add(member3); var Score3 = new Models.Score { ScoreNum = 3, Body = "Big Dad jokes are hurtful", Date = DateTime.Now, From = member3, Topic = "Topic 3" }; context.Scores.Add(Score3); var member4 = new Member { Name = "MemberFour", Email = "*****@*****.**", Password = "******" }; context.Members.Add(member4); var Score4 = new Models.Score { ScoreNum = 4, Body = "Big Moma jokes are hurtful", Date = DateTime.Now, From = member4, Topic = "Topic 4" }; context.Scores.Add(Score4); var member5 = new Member { Name = "MemberFive", Email = "*****@*****.**", Password = "******" }; context.Members.Add(member5); var Score5 = new Models.Score { ScoreNum = 5, Body = "Dad", Date = DateTime.Now, From = member5, Topic = "Stop" }; context.Scores.Add(Score5); var member6 = new Member { Name = "BillNewy", Email = "*****@*****.**", Password = "******" }; context.Members.Add(member5); var Score6 = new Score { ScoreNum = 5, Body = "we win!", Date = DateTime.Now, From = member6, Topic = "stuff ontop od f stuff" }; context.Scores.Add(Score6); #endregion } //await EnsurePopulated(app); context.SaveChanges(); }
public static void DumpScore(Models.Score score) { AnsiConsole.Render(new FigletText(".NET SCORE").Centered().Color(Color.Purple)); //Score -> ScoreReport -> 5 List<ScoreSections> (Iterate) -> ScoreSection (Tree & Nodes & Table) var nugetConventionsTable = new Table(); nugetConventionsTable .Collapse() .Border(TableBorder.Rounded) .AddColumn(new TableColumn("[u]Follows NuGet Conventions[/]").Footer("[bold u].NET Score[/]")) .AddColumn(new TableColumn("[u]Score[/]").Footer($"[bold u]{score.ScoreReport.FollowsNuGetConventions.Sum(x => x.CurrentScore)}[/]")) .AddColumn(new TableColumn("[u]Total Score[/]").Footer($"[bold u]{score.ScoreReport.FollowsNuGetConventions.Sum(x => x.MaxScore)}[/]")); if (score?.ScoreReport != null) { foreach (var scoreSection in score.ScoreReport?.FollowsNuGetConventions) { //If the scoreSection has no issues, just do the tree markup, otherwise add issues / resolution var scoreSectionTree = new Tree(new Markup($"[bold]{scoreSection.Title}[/]")); if (scoreSection.Summaries != null) { foreach (var scoreSectionSummary in scoreSection?.Summaries) { var issueNode = scoreSectionTree.AddNode($"[yellow]{scoreSectionSummary.Issue}[/]"); issueNode.AddNode( $"[red]{scoreSectionSummary.Resolution}[/]"); } } nugetConventionsTable .AddRow(scoreSectionTree, new Markup($"{scoreSection.CurrentScore}"), new Markup($"[bold]{scoreSection.MaxScore}[/]")); } AnsiConsole.Render(nugetConventionsTable); //Add a BreakdownChart() when 1.0.0 is released in Spectre.Console. var providesDocumentationTable = new Table(); providesDocumentationTable .Collapse() .Border(TableBorder.Rounded) .AddColumn(new TableColumn("[u]Provides Documentation[/]").Footer("[bold u].NET Score[/]")) .AddColumn(new TableColumn("[u]Score[/]").Footer($"[bold u]{score.ScoreReport.ProvidesDocumentation.Sum(x => x.CurrentScore)}[/]")) .AddColumn(new TableColumn("[u]Total Score[/]").Footer($"[bold u]{score.ScoreReport.ProvidesDocumentation.Sum(x => x.MaxScore)}[/]")); if (score?.ScoreReport != null) { foreach (var scoreSection in score.ScoreReport?.ProvidesDocumentation) { //If the scoreSection has no issues, just do the tree markup, otherwise add issues / resolution var scoreSectionTree = new Tree(new Markup($"[bold]{scoreSection.Title}[/]")); if (scoreSection.Summaries != null) { foreach (var scoreSectionSummary in scoreSection?.Summaries) { var issueNode = scoreSectionTree.AddNode($"[yellow]{scoreSectionSummary.Issue}[/]"); issueNode.AddNode( $"[red]{scoreSectionSummary.Resolution}[/]"); } } providesDocumentationTable .AddRow(scoreSectionTree, new Markup($"{scoreSection.CurrentScore}"), new Markup($"[bold]{scoreSection.MaxScore}[/]")); } AnsiConsole.Render(providesDocumentationTable); var supportsMultiplePlatformsTable = new Table(); supportsMultiplePlatformsTable .Collapse() .Border(TableBorder.Rounded) .AddColumn(new TableColumn("[u]Supports Multiple Platforms[/]").Footer("[bold u].NET Score[/]")) .AddColumn(new TableColumn("[u]Score[/]").Footer($"[bold u]{score.ScoreReport.SupportsMultiplePlatforms.Sum(x => x.CurrentScore)}[/]")) .AddColumn(new TableColumn("[u]Total Score[/]").Footer($"[bold u]{score.ScoreReport.SupportsMultiplePlatforms.Sum(x => x.MaxScore)}[/]")); if (score?.ScoreReport != null) { foreach (var scoreSection in score.ScoreReport?.SupportsMultiplePlatforms) { //If the scoreSection has no issues, just do the tree markup, otherwise add issues / resolution var scoreSectionTree = new Tree(new Markup($"[bold]{scoreSection.Title}[/]")); if (scoreSection.Summaries != null) { foreach (var scoreSectionSummary in scoreSection?.Summaries) { var issueNode = scoreSectionTree.AddNode($"[yellow]{scoreSectionSummary.Issue}[/]"); issueNode.AddNode( $"[red]{scoreSectionSummary.Resolution}[/]"); } } supportsMultiplePlatformsTable .AddRow(scoreSectionTree, new Markup($"{scoreSection.CurrentScore}"), new Markup($"[bold]{scoreSection.MaxScore}[/]")); } AnsiConsole.Render(supportsMultiplePlatformsTable); // var passStaticAnalysisTable = new Table(); // passStaticAnalysisTable // .Expand() // .Border(TableBorder.Minimal) // .AddColumn(new TableColumn("[u]Pass Static Analysis[/]")) // .AddColumn(new TableColumn("[u]Score[/]")) // .AddColumn(new TableColumn("[u]Total Score[/]")); // // if (score?.ScoreReport != null) // { // foreach (var scoreSection in score.ScoreReport?.PassStaticAnalysis) // { // //If the scoreSection has no issues, just do the tree markup, otherwise add issues / resolution // var scoreSectionTree = new Tree(new Markup(scoreSection.Title)); // // if (scoreSection.Summaries != null) // foreach (var scoreSectionSummary in scoreSection?.Summaries) // { // var issueNode = // scoreSectionTree.AddNode($"[yellow]{scoreSectionSummary.Issue}[/]"); // issueNode.AddNode( // $"[red]{scoreSectionSummary.Resolution}[/]"); // } // // passStaticAnalysisTable // .AddRow(scoreSectionTree, new Markup($"{scoreSection.CurrentScore}"), // new Markup($"[bold]{scoreSection.MaxScore}[/]")); // } // // AnsiConsole.Render(passStaticAnalysisTable); var upToDateDependenciesTable = new Table(); upToDateDependenciesTable .Collapse() .Border(TableBorder.Rounded) .AddColumn(new TableColumn("[u]Up-to-date Dependencies[/]").Footer("[bold u].NET Score[/]")) .AddColumn(new TableColumn("[u]Score[/]").Footer($"[bold u]{score.ScoreReport.SupportUpToDateDependencies.Sum(x => x.CurrentScore)}[/]")) .AddColumn(new TableColumn("[u]Total Score[/]").Footer($"[bold u]{score.ScoreReport.SupportUpToDateDependencies.Sum(x => x.MaxScore)}[/]")); if (score?.ScoreReport != null) { foreach (var scoreSection in score.ScoreReport?.SupportUpToDateDependencies) { //If the scoreSection has no issues, just do the tree markup, otherwise add issues / resolution var scoreSectionTree = new Tree(new Markup($"[bold]{scoreSection.Title}[/]")); if (scoreSection.Summaries != null) { foreach (var scoreSectionSummary in scoreSection?.Summaries) { var issueNode = scoreSectionTree.AddNode($"[yellow]{scoreSectionSummary.Issue}[/]"); issueNode.AddNode( $"[red]{scoreSectionSummary.Resolution}[/]"); } } upToDateDependenciesTable .AddRow(scoreSectionTree, new Markup($"{scoreSection.CurrentScore}"), new Markup($"[bold]{scoreSection.MaxScore}[/]")); } AnsiConsole.Render(upToDateDependenciesTable); } } } } }
public void OnGet() { var student = JsonConvert.DeserializeObject <Models.Student>( User.Claims.First(claim => claim.Type == "Information").Value); var kuasAp = new Services.KUASAPService(); var sysValueList = kuasAp.GetOptionValueList(student: student); var scores = new List <Models.Score>(); var subject = new Dictionary <string, List <Models.Score> >() { { "Get", new List <Models.Score>() }, { "Miss", new List <Models.Score>() } }; var generalEducation = new Dictionary <string, List <Models.Score> >() { { "Core", new List <Models.Score>() }, { "Extend", new List <Models.Score>() } }; for (int i = 0, countOfEmpty = 0; countOfEmpty < 10; i++) { var tmpScores = kuasAp.GetScores(student: student, year: sysValueList[i].SysYear, semester: sysValueList[i].SysSemester).Scores; if (tmpScores.Count <= 0) { countOfEmpty++; } else { scores.AddRange(tmpScores); countOfEmpty = 0; } } if (scores.Count > 0) { foreach (Models.Score score in scores) { if (!string.IsNullOrEmpty(score.SemesterScore)) { if (score.SemesterScore == "合格") { subject["Get"].Add(score); } else if (score.SemesterScore.Contains("*") && score.IsRequired) { subject["Miss"].Add(score); } else if (score.SemesterScore.Contains("不合格") && score.IsRequired) { subject["Miss"].Add(score); } else if (float.Parse(score.SemesterScore) < 60) { subject["Miss"].Add(score); } else { subject["Get"].Add(score); if (score.SubjectChineseName.Contains("核心通識")) { generalEducation["Core"].Add(score); } else if (score.SubjectChineseName.Contains("延伸通識")) { generalEducation["Extend"].Add(score); } } } } } // 刪除課程中的通識課程 subject["Get"].RemoveAll(x => x.SubjectChineseName.Contains("通識")); subject["Miss"].RemoveAll(x => x.SubjectChineseName.Contains("通識")); // 刪除重複已失去課程 foreach (Models.Score score in subject["Miss"].ToArray()) { // 建立暫存課程 Models.Score temp = score; // 尋找是否有重複 (2 個以上) 項目 if (subject["Miss"].FindAll(x => x.SubjectChineseName == temp.SubjectChineseName && x.PropertiesCredit == temp.PropertiesCredit && x.PropertiesRequiredOrElective == temp.PropertiesRequiredOrElective).Count > 1) { // 若有則全數移除並重新加入 subject["Miss"].RemoveAll(x => x.SubjectChineseName == temp.SubjectChineseName && x.PropertiesCredit == temp.PropertiesCredit && x.PropertiesRequiredOrElective == temp.PropertiesRequiredOrElective); subject["Miss"].Add(temp); } } // 重修已及格修正 foreach (Models.Score score in subject["Get"].ToArray()) { if (subject["Miss"].FindAll(x => x.SubjectChineseName == score.SubjectChineseName && x.PropertiesCredit == score.PropertiesCredit && x.PropertiesRequiredOrElective == score.PropertiesRequiredOrElective).Count > 0) { subject["Miss"].RemoveAll(x => x.SubjectChineseName == score.SubjectChineseName && x.PropertiesCredit == score.PropertiesCredit && x.PropertiesRequiredOrElective == score.PropertiesRequiredOrElective); } } // 對 subject 做排序 foreach (string key in subject.Keys.ToArray()) { subject[key] = subject[key].OrderBy(x => float.Parse(x.PropertiesCredit)) .ThenBy(x => x.SubjectChineseName) .ThenBy(x => float.Parse(x.TeachTime)) .ThenBy(x => x.PropertiesRequiredOrElective) .ThenBy(x => x.ClassType) .ThenBy(x => x.MidtermScore) .ThenBy(x => x.SemesterScore) .ThenBy(x => x.Remark).ToList(); } // 對 generalEducation 以自定義做排序 foreach (string key in generalEducation.Keys.ToArray()) { generalEducation[key].Sort((x, y) => new OrderBySubjectChtName().Compare(x.SubjectChineseName, y.SubjectChineseName)); } Credits = new Models.Credits() { Subject = subject, GeneralEducation = generalEducation }; // 已取得所有學分 GetCredits = (int)subject["Get"].Sum(x => float.Parse(x.PropertiesCredit)); // 已取得必修學分 GetRequiredCredits = (int)subject["Get"].FindAll(x => x.IsRequired).Sum(x => float.Parse(x.PropertiesCredit)); // 已取得選修學分 GetNotRequiredCredits = (int)subject["Get"].FindAll(x => !x.IsRequired).Sum(x => float.Parse(x.PropertiesCredit)); // 已失去必修學分 MissRequiredCredits = (int)subject["Miss"].Sum(x => float.Parse(x.PropertiesCredit)); }