/** * @@param * ScoresInfo scoresInfo - information to be printed */ public void PrintScoreInfo(ScoresInfo scoresInfo, bool normalMode = true) { if (scoresInfo == null) { Console.WriteLine("No scores \n"); return; } Console.WriteLine("Team Name " + scoresInfo.teamName); Console.WriteLine("Players Info "); foreach (String p in scoresInfo.playerNames) { if (p != null) { Console.WriteLine("Player: " + p); } } Console.WriteLine("Team Score " + scoresInfo.teamScore); Console.WriteLine("Time Played " + scoresInfo.timePlayed); if (scoresInfo.rank != -1) { Console.WriteLine("Rank " + scoresInfo.rank); } Console.WriteLine(); }
public ScoresInfo CreateScoresInfo(ScoresPacket sPacket) { // make the information for the scores object List <String> players = sPacket.playerNames; while (players.Count < 4) { players.Add(null); } ScoresInfo scores = new ScoresInfo(sPacket.teamName, players, sPacket.teamScore, sPacket.timePlayed); return(scores); }
public void ScoreInfoWithThreePlayers() { String d = "{\"teamName\":\"Team1\",\"playerNames\":[\"Player1\", \"Player2\", \"Player3\"],\"teamScore\":3,\"timePlayed\":50}"; ScoresPacket sPacket = JsonConvert.DeserializeObject <ScoresPacket>(d); ScoresInfo scoresInfo = scoresManager.CreateScoresInfo(sPacket); Assert.That(scoresInfo.playerNames.Count, Is.EqualTo(4)); Assert.That(scoresInfo.teamName, Is.EqualTo("Team1")); Assert.That(scoresInfo.teamScore, Is.EqualTo(3)); Assert.That(scoresInfo.timePlayed, Is.EqualTo(50)); Assert.That(scoresInfo.playerNames[0], Is.EqualTo("Player1")); Assert.That(scoresInfo.playerNames[1], Is.EqualTo("Player2")); Assert.That(scoresInfo.playerNames[2], Is.EqualTo("Player3")); Assert.That(scoresInfo.playerNames[3], Is.EqualTo(null)); }
protected ManyScoresPacket PutScores(ScoresInfo scores) { // add the scores to the database and retrieve the team information including the current team SQLConnection.AddTeamScore(scores); Tuple <List <ScoresInfo>, ScoresInfo> retrievedInfo = SQLConnection.GetTopTeamsAndCurrentTeam(scores.teamName); // make into json a packet with the top teams info and current team info to return back ManyScoresPacket multipleScoresPacket = new ManyScoresPacket(); multipleScoresPacket.topTeamInfos = retrievedInfo.Item1; multipleScoresPacket.currentTeamInfo = retrievedInfo.Item2; var convertedInfo = JsonConvert.SerializeObject(multipleScoresPacket); Send(convertedInfo); return(multipleScoresPacket); }
/** * #function SQLConnection::AddTeamScore | * @author JavaComSci | * @desc Connects to the database in order to add the team information about scores | * @param String teamName: Name of team | * @param List<String> playerNames: Players of team | * @param int score: Score of team | * @param int timeInSeconds: Time played of team | */ public static void AddTeamScore(ScoresInfo scoresInfo) { // create connection MySqlConnection conn = new MySqlConnection(connString); // id of the team that has just inserted // long imageId = -1; try { // open connection conn.Open(); // create new command MySqlCommand command = conn.CreateCommand(); // text for command with parameterization command.CommandText = "REPLACE INTO Scores(TeamName, Player1, Player2, Player3, Player4, TeamScore, TimePlayed) VALUES(@teamName, @player1, @player2, @player3, @player4, @teamScore, @timePlayed)"; // add all the params command.Parameters.AddWithValue("@teamName", scoresInfo.teamName); command.Parameters.AddWithValue("@player1", scoresInfo.playerNames[0]); command.Parameters.AddWithValue("@player2", scoresInfo.playerNames[1] ?? (object)DBNull.Value); command.Parameters.AddWithValue("@player3", scoresInfo.playerNames[2] ?? (object)DBNull.Value); command.Parameters.AddWithValue("@player4", scoresInfo.playerNames[3] ?? (object)DBNull.Value); command.Parameters.AddWithValue("@teamScore", scoresInfo.teamScore); command.Parameters.AddWithValue("@timePlayed", scoresInfo.timePlayed); // execute the query command.ExecuteNonQuery(); // get the id of the last inserted score for the team that has just placed in the scores // imageId = command.LastInsertedId; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // close the connection conn.Close(); // // return the image id that has just been inserted // return imageId; }
/** * #function SQLConnection::UpdateTeamScore | * @author JavaComSci | * @desc Connects to the database in order to update a team information about scores | * @param String teamName: Name of team | * @param List<String> playerNames: Players of team | * @param int score: Score of team | * @param int timeInSeconds: Time played of team | */ public static long UpdateTeamScore(ScoresInfo scoresInfo, long imageId) { // create connection MySqlConnection conn = new MySqlConnection(connString); try { // open connection conn.Open(); // create new command MySqlCommand command = conn.CreateCommand(); // text for command with parameterization command.CommandText = "UPDATE Scores SET TeamName = @teamName, Player1 = @player1, Player2 = @player2, Player3 = @player3, Player4 = @player4, TeamScore = @teamScore, TimePlayed = @timePlayed WHERE Id = @id"; // add all the params command.Parameters.AddWithValue("@teamName", scoresInfo.teamName); command.Parameters.AddWithValue("@player1", scoresInfo.playerNames[0]); command.Parameters.AddWithValue("@player2", scoresInfo.playerNames[1] ?? (object)DBNull.Value); command.Parameters.AddWithValue("@player3", scoresInfo.playerNames[2] ?? (object)DBNull.Value); command.Parameters.AddWithValue("@player4", scoresInfo.playerNames[3] ?? (object)DBNull.Value); command.Parameters.AddWithValue("@teamScore", scoresInfo.teamScore); command.Parameters.AddWithValue("@timePlayed", scoresInfo.timePlayed); command.Parameters.AddWithValue("@id", imageId); // execute the query command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // close the connection conn.Close(); // return the image id that has just been updated return(imageId); }
public void ShareInfo1() { String d = "{\"teamName\":\"Team1\",\"playerNames\":[\"Player1\", \"Player2\", \"Player3\", \"Player4\"],\"teamScore\":3,\"timePlayed\":50}"; ScoresPacket sPacket = JsonConvert.DeserializeObject <ScoresPacket>(d); ScoresInfo scoresInfo = scoresManager.CreateScoresInfo(sPacket); List <ScoresInfo> scoresList = new List <ScoresInfo>(); // Bitmap bitmap = new System.Drawing.Bitmap("canvas.bmp"); // var encoded = shareManager.CreateDetails(Tuple.Create<List<ScoresInfo>, ScoresInfo>(scoresList, scoresInfo), null); PointF firstLocation = new PointF(320f, 400f); PointF secondLocation = new PointF(320f, 490f); Bitmap bitmap = new Bitmap(200, 100); using (Graphics graphics = Graphics.FromImage(bitmap)) { using (Font arialFont = new Font("Arial", 50)) { graphics.DrawString("teamName", arialFont, Brushes.Red, firstLocation); graphics.DrawString("500", arialFont, Brushes.Blue, secondLocation); } } Bitmap bImage = bitmap; System.IO.MemoryStream ms = new MemoryStream(); bImage.Save(ms, ImageFormat.Jpeg); byte[] byteImage = ms.ToArray(); var encodedImage = Convert.ToBase64String(byteImage); // Assert.That(encodedImage, Is.Not.Contains(" ") ); }
/** * #function SQLConnection::GetTopTeamsAndCurrentTeam | * @author JavaComSci | * @desc Connects to the database in order to obtain team results | */ public static List <ScoresInfo> GetTopTeams() { // create connection MySqlConnection conn = new MySqlConnection(connString); // scoresInfo list for the top teams List <ScoresInfo> topTeams = new List <ScoresInfo>(); try { // open connection conn.Open(); // create new command MySqlCommand command = conn.CreateCommand(); // text for command with top teams command.CommandText = "SELECT * FROM Scores ORDER BY TeamScore DESC LIMIT 10"; // create a reader to read the high scores MySqlDataReader reader1 = command.ExecuteReader(); if (reader1.HasRows == true) { while (reader1.Read()) { // put the information read into the score info object int teamId = Convert.ToInt32(reader1[0]); String t = Convert.ToString(reader1[1]); List <String> playerNames = new List <String>(); if (reader1[2] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[2])); } if (reader1[3] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[3])); } if (reader1[4] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[4])); } if (reader1[5] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[5])); } int teamScore = Convert.ToInt32(reader1[6]); int timePlayed = Convert.ToInt32(reader1[7]); // add the top team to the list of top teams ScoresInfo team = new ScoresInfo(t, playerNames, teamScore, timePlayed); topTeams.Add(team); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // close the connection conn.Close(); // return the topteams return(topTeams); }
/** * #function SQLConnection::GetTopTeamsAndCurrentTeam | * @author JavaComSci | * @desc Connects to the database in order to obtain team results | * @param long teamId: Id of team | */ public static Tuple <List <ScoresInfo>, ScoresInfo> GetTopTeamsAndCurrentTeam(string teamName) { // create connection MySqlConnection conn = new MySqlConnection(connString); // scoresInfo list for the top teams List <ScoresInfo> topTeams = new List <ScoresInfo>(); // information for current team ScoresInfo currentTeam = null; try { // open connection conn.Open(); // create new command MySqlCommand command = conn.CreateCommand(); // text for command with top teams // command.CommandText = "SELECT * FROM Scores ORDER BY TeamScore DESC LIMIT 10"; command.CommandText = "SELECT * FROM (SELECT *, rank() OVER (ORDER BY TeamScore DESC) as Ranking FROM Scores) AS ScoresRanked WHERE Ranking < 11 OR TeamName = @TeamName"; command.Parameters.AddWithValue("@TeamName", teamName); // create a reader to read the high scores MySqlDataReader reader1 = command.ExecuteReader(); // team counter int teamCount = 0; if (reader1.HasRows == true) { while (reader1.Read()) { teamCount += 1; int teamId = Convert.ToInt32(reader1[0]); String t = Convert.ToString(reader1[1]); List <String> playerNames = new List <String>(); if (reader1[2] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[2])); } if (reader1[3] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[3])); } if (reader1[4] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[4])); } if (reader1[5] != DBNull.Value) { playerNames.Add(Convert.ToString(reader1[5])); } int teamScore = Convert.ToInt32(reader1[6]); int timePlayed = Convert.ToInt32(reader1[7]); int ranking = Convert.ToInt32(reader1[8]); // add the top team to the list of top teams ScoresInfo team = new ScoresInfo(t, playerNames, teamScore, timePlayed); team.rank = ranking; // current team looking at if (teamName.Equals(t)) { // current team currentTeam = team; } // add to the top teams if (teamCount < 11) { topTeams.Add(team); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } // close the connection conn.Close(); // return the tuple return(Tuple.Create(topTeams, currentTeam)); }
public string CreateDetails(Tuple <List <ScoresInfo>, ScoresInfo> filledInfo, Bitmap b) { ScoresInfo myTeam = filledInfo.Item2; string teamName = myTeam.teamName; int score = myTeam.teamScore; string scoreInfo = "Best achieving score: " + score; PointF firstLocation = new PointF(320f, 400f); PointF secondLocation = new PointF(320f, 490f); Bitmap bitmap; if (b == null) { bitmap = new System.Drawing.Bitmap("canvas.png"); } else { bitmap = b; } using (Graphics graphics = Graphics.FromImage(bitmap)) { using (Font arialFont = new Font("Arial", 50)) { graphics.DrawString(teamName, arialFont, Brushes.Red, firstLocation); int i = teamName.Length; graphics.DrawString(scoreInfo, arialFont, Brushes.Blue, secondLocation); } } // string imageFilePath = "canvas.bmp"; // string outputFileName = imageFilePath; // using (MemoryStream memory = new MemoryStream()) // { // using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite)) // { // bitmap.Save(memory, ImageFormat.Jpeg); // byte[] bytes = memory.ToArray(); // fs.Write(bytes, 0, bytes.Length); // } // } Bitmap bImage = bitmap; System.IO.MemoryStream ms = new MemoryStream(); bImage.Save(ms, ImageFormat.Jpeg); byte[] byteImage = ms.ToArray(); var encodedImage = Convert.ToBase64String(byteImage); // Console.WriteLine("ENCODED IMAGE " + encodedImage); ImgPacket imgPacket = new ImgPacket(); imgPacket.data = encodedImage; var convertedInfo = JsonConvert.SerializeObject(imgPacket); Send(convertedInfo); return(encodedImage); }
public async Task <IActionResult> Put(int id, [FromBody] ScoresInfo model) { try { Score Score = _context.Score.SingleOrDefault(m => m.ScoreId == id); //Score.CourseId = model.CourseId; //Score.Color = model.Color; //Score.ScoreDate = model.ScoreDate; //Score.EnteredById = model.EnteredBy.MemberId; Score.Hole01 = model.Hole01; Score.Hole02 = model.Hole02; Score.Hole03 = model.Hole03; Score.Hole04 = model.Hole04; Score.Hole05 = model.Hole05; Score.Hole06 = model.Hole06; Score.Hole07 = model.Hole07; Score.Hole08 = model.Hole08; Score.Hole09 = model.Hole09; Score.Hole10 = model.Hole10; Score.Hole11 = model.Hole11; Score.Hole12 = model.Hole12; Score.Hole13 = model.Hole13; Score.Hole14 = model.Hole14; Score.Hole15 = model.Hole15; Score.Hole16 = model.Hole16; Score.Hole17 = model.Hole17; Score.Hole18 = model.Hole18; Score.HoleIn = model.HoleIn; Score.HoleOut = model.HoleOut; Score.HoleTotal = model.HoleTotal; Score.Round = model.Round; Score.MatchGrp = model.MatchGrp; Score.MatchPlayerNum = model.MatchPlayerNum; Score.MatchPoints = model.MatchPoints; int holesPlayed = 0; if (Score.Hole01 > 0) { holesPlayed++; } if (Score.Hole02 > 0) { holesPlayed++; } if (Score.Hole03 > 0) { holesPlayed++; } if (Score.Hole04 > 0) { holesPlayed++; } if (Score.Hole05 > 0) { holesPlayed++; } if (Score.Hole06 > 0) { holesPlayed++; } if (Score.Hole07 > 0) { holesPlayed++; } if (Score.Hole08 > 0) { holesPlayed++; } if (Score.Hole09 > 0) { holesPlayed++; } if (Score.Hole10 > 0) { holesPlayed++; } if (Score.Hole11 > 0) { holesPlayed++; } if (Score.Hole12 > 0) { holesPlayed++; } if (Score.Hole13 > 0) { holesPlayed++; } if (Score.Hole14 > 0) { holesPlayed++; } if (Score.Hole15 > 0) { holesPlayed++; } if (Score.Hole16 > 0) { holesPlayed++; } if (Score.Hole17 > 0) { holesPlayed++; } if (Score.Hole18 > 0) { holesPlayed++; } int lastHolePlayed = 0; lastHolePlayed = setLastHolePlayed(lastHolePlayed, 1, model.Hole01); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 2, model.Hole02); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 3, model.Hole03); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 4, model.Hole04); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 5, model.Hole05); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 6, model.Hole06); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 7, model.Hole07); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 8, model.Hole08); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 9, model.Hole09); if (lastHolePlayed == 0 || lastHolePlayed >= 9) { lastHolePlayed = setLastHolePlayed(lastHolePlayed, 10, model.Hole10); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 11, model.Hole11); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 12, model.Hole12); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 13, model.Hole13); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 14, model.Hole14); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 15, model.Hole15); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 16, model.Hole16); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 17, model.Hole17); lastHolePlayed = setLastHolePlayed(lastHolePlayed, 18, model.Hole18); } Score.LastHolePlayed = lastHolePlayed; //Score.TourEvent = model.TourEvent; //Score.TourId = model.TourId; //if (model.AboutGame == null) model.AboutGame = ""; //Score.AboutGame = model.AboutGame; Score.NetScore = 199; Score.TourScore = 199; float HcpAllowPct = 100.0F; float MultiAdj = 0.0F; Tour Tour; Handicap Handicap = _handicap.getHandicapForDate(Score.MemberId, Score.ScoreDate); CourseDetail CourseDetail = _courseDetail.get(Score.CourseId, Score.Color); Course Course = _courseData.get(Score.CourseId); if (Score.TourEvent == true && (Tour = _tourInfo.getTour(Score.TourId)) != null) { HcpAllowPct = Tour.HcpAllowPct; if (Tour.AllowMultiTee == true) { CourseDetail BaseCourse = _courseDetail.get(Course.CourseId, Tour.BaseColor.ToString()); MultiAdj = (float)(BaseCourse.Rating - CourseDetail.Rating); } } if (Handicap != null && Handicap.HcpIndex > 0) { float courseHandicap = Handicap.HcpIndex * CourseDetail.Slope / 113; float courseHandicapT = (Handicap.HcpIndex * CourseDetail.Slope / 113 - MultiAdj) * (HcpAllowPct / 100); Score.NetScore = (int)Math.Round(model.HoleTotal - courseHandicap * holesPlayed / 18.0); Score.TourScore = (int)Math.Round(model.HoleTotal - courseHandicapT * holesPlayed / 18.0); } else { float courseHandicap = getS36Hcp(Score, Course) * CourseDetail.Slope / 113; float courseHandicapT = getS36Hcp(Score, Course) * (HcpAllowPct / 100) * CourseDetail.Slope / 113; Score.NetScore = (int)Math.Round(model.HoleTotal - courseHandicap * holesPlayed / 18.0); Score.TourScore = (int)Math.Round(model.HoleTotal - courseHandicapT * holesPlayed / 18.0); } countScores(Score, Course); Score.Tiebreaker = _scoreInfo.getTiebreaker(Score); //Score.LastUpdatedBy = User.Identity.Name; Score.LastUpdatedBy = "Live Score"; Score.LastUpdatedTs = DateTime.Now; _context.Update(Score); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ScoreExists(model.ScoreId)) { return(NotFound()); } else { throw; } } return(Ok()); }