/// <summary> /// Calculates z-scores for certain analytics compared to the rest of the data. /// </summary> /// <param name="all">Other team analyses to compare to</param> public void CalculateZScores(IEnumerable <TeamAnalysis> all) { IEnumerable <double> winrates = from ta in all select ta.WinRate; Distribution distWins = winrates.ToList().MakeDistribution(); WinRateZ = distWins.Model.ZScore(WinRate); IEnumerable <double> respRates = from ta in all select ta.ResponsivenessRate; Distribution distResp = winrates.ToList().MakeDistribution(); ResponsivenessRateZ = distResp.Model.ZScore(ResponsivenessRate); IEnumerable <Distribution> bigData = from ta in all select ta.ScoredPoints; ScoredPoints.CalculateZ(bigData); bigData = from ta in all select ta.FinalScore; FinalScore.CalculateZ(bigData); bigData = from ta in all select ta.Penalties; Penalties.CalculateZ(bigData); bigData = from ta in all select ta.Defense; Defense.CalculateZ(bigData); }
public override void Reset() { base.Reset(); Result = null; Penalties.Clear(); LoggerMarks.Clear(); }
public ActionResult <IEnumerable <string> > AddPenalties([FromBody] AddPenalties form) { string currentUserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var _clientid = Guid.Parse(currentUserId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var NewPenalties = new Penalties { Penalties_Date = form.Penalties_Date, Penalties_Enterid = _clientid, Penalties_Note = form.Penalties_Note, Penalties_Price = form.Penalties_Price, Employees_Id = form.Employees_Id, }; _context.Penalties.Add(NewPenalties); _context.SaveChanges(); return(Ok(new Response { Message = "Done !", Data = NewPenalties, Error = false })); }
void doLoop(CancellationToken token) { while (token.IsCancellationRequested == false) { bool changed = false; execute(() => { var rm = new List <int>(); foreach (var penalty in Penalties.Values) { if (penalty.Finished) { penalty.Unset(); rm.Add(penalty.Id); } } foreach (var x in rm) { Penalties.Remove(x); } changed = rm.Count > 0; }); if (changed) { OnSave(); } Thread.Sleep(5000); } }
static void Main(string[] args) { var penalties = new Penalties(); var now = DateTime.Now; // due = today // should print 0 Console.WriteLine(penalties.ComputeOverdueDaysPenalty(1234, new DateTime(now.Year, now.Month, now.Day))); // due = today plus 1 var dueDate = now.AddDays(1); // should print 0 again Console.WriteLine(penalties.ComputeOverdueDaysPenalty(1234, dueDate)); // due = today minus 1 dueDate = dueDate.Subtract(new TimeSpan(48, 0, 0)); // should print 1234 Console.WriteLine(penalties.ComputeOverdueDaysPenalty(1234, dueDate)); // due = today minus 2 dueDate = dueDate.Subtract(new TimeSpan(24, 0, 0)); // should print 2468 Console.WriteLine(penalties.ComputeOverdueDaysPenalty(1234, dueDate)); dueDate = DateTime.Parse("2016-10-02"); // should print 12340, as of 10/12/2016 Console.WriteLine(penalties.ComputeOverdueDaysPenalty(1234, dueDate)); Console.ReadKey(); }
public void RemovePenalty(int id) { execute(() => { if (Penalties.TryGetValue(id, out var penalty)) { penalty.Unset(); } Penalties.Remove(id); }); }
private void ParsePenalties(Penalties penalties) { ParsePenalty(MessageType.CheckHoldedPieceResponse, penalties.CheckForSham); ParsePenalty(MessageType.DestroyPieceResponse, penalties.DestroyPiece); ParsePenalty(MessageType.DiscoveryResponse, penalties.Discovery); ParsePenalty(MessageType.MoveResponse, penalties.Move); ParsePenalty(MessageType.PutPieceResponse, penalties.PutPiece); //TODO: //Temporary, because currently there is no PickPiece penalty ParsePenalty(MessageType.PickPieceResponse, penalties.DestroyPiece); _exchangePenalty = Int32.Parse(penalties.InformationExchange); }
public void checkAbsenceClass1() { var employees = _context.EmployessUsers.Where(x => x.IsDelete == false && x.IsDisplay == false).ToList(); var admininfo = _context.AdminUser.FirstOrDefault(); DateTime date = Convert.ToDateTime(DateTime.Now).Date; foreach (var i in employees) { var vacation = _context.EmployeeVacations.Where(x => x.EmployeeId == i.Id && x.StartDate.Date <= date && x.EndDate >= date).FirstOrDefault(); if (vacation == null) { var inemployee = _context.InOut.Where(x => x.In_Out_Date.Date == date && x.EmplyeeId == i.Id && x.In_Out_Status == 0).FirstOrDefault(); if (inemployee != null) { var inout = _context.InOut.Where(x => x.In_Out_Date.Date == date && x.EmplyeeId == i.Id && x.In_Out_Status == 1).FirstOrDefault(); if (inout == null) { var addabsence = new Absence { AbsenceDate = DateTime.Now, EmployeeId = i.Id, }; _context.Absence.Add(addabsence); var AddPenalties = new Penalties { Penalties_Date = DateTime.Now, Penalties_Note = "غياب - عدم وجود بصمة الخروج ", Penalties_Price = admininfo.Delay_penalty, Employees_Id = i.Id, Penalties_Enterid = Guid.Parse("3ef34045-bbbb-49e6-880e-7e7bcb9c9a16"), }; _context.Penalties.Add(AddPenalties); _context.SaveChanges(); } } } } }
private void btnCheckPenaltyStatistics_ItemClick(object sender, ItemClickEventArgs e) { ClearPanel(); ss = SaveSender.CheckAllPenalties; scMain.Panel2.Enabled = true; scMain.SplitterPosition = 0; Penalties p = new Penalties(ss); p.Dock = DockStyle.Fill; scMain.Panel2.Controls.Add(p); ClearCheckDoCheck(btnCheckPenaltyStatistics); rpgPenaltyTools.Visible = false; }
public bool Modify(int id, Action <Penalty> action) { var found = false; execute(() => { if (Penalties.TryGetValue(id, out var p)) { found = true; action(p); } }); return(found); }
public void Hack(MapTile tile) { if (tile.Modifier is Node) { WriteConsoleMessage("Node hacked"); tile.Modifier = new HackedNode(); tile.Discovered = true; BitCoin++; } else { WriteConsoleMessage("Error! No Node detected."); Penalties.Add(TracePenalty.HackError); tile.Modifier = new Corrupted(); ResolveTile(tile); } }
public void SetUp() { _database = Substitute.For <IMongoDatabase>(); _collection = Substitute.For <IMongoCollection <Match> >(); _matchDao = new MatchDao(_database, _collection); _team1 = new Team { Name = "test", Email = "test", ShortName = "test", Tla = "test", CrestUrl = "test", Address = "test", Phone = "test", Colors = "test", Venue = "test" }; _team2 = new Team { Name = "test", Email = "test", ShortName = "test", Tla = "test", CrestUrl = "test", Address = "test", Phone = "test", Colors = "test", Venue = "test" }; _fullTime = new FullTime { AwayTeam = 1, HomeTeam = 1 }; _halfTime = new HalfTime { AwayTeam = 1, HomeTeam = 1 }; _extraTime = new ExtraTime { AwayTeam = 1, HomeTeam = 1 }; _penalties = new Penalties { AwayTeam = 1, HomeTeam = 1 }; _score = new Score { Winner = "test", Duration = "test", ExtraTime = _extraTime, FullTime = _fullTime, Penalties = _penalties }; _match = new Match { Status = "test", LastUpdated = DateTime.Now, HomeTeam = _team1, AwayTeam = _team2, Score = _score }; }
public Penalty AddPenalty(Guid penaltyId, Decimal amount, String description) { if (amount < 0) { throw new ArgumentOutOfRangeException(nameof(amount), $"Positive number required, current value: {amount}"); } var penalty = Penalties.FirstOrDefault(_ => _.Id == Id); if (penalty == null) { penalty = new Penalty(penaltyId, this.Id, amount, description?.Trim()); Penalties.Add(penalty); return(penalty); } if (penalty.Amount == amount && penalty.Description == description) { return(penalty); } throw new PenaltyAlreadyExistsException(penalty); }
public static object SavePenalty(PenaltiesModel pinfo, List <int> penaltyWCModel = null) { var rowsAffected = 0; var response = new ResponseHandler(); try { object ValidateForm() { if (String.IsNullOrWhiteSpace(pinfo.penalty_code)) { response.Status = 0; response.Message = "Penalty code is required."; return(response); } if (pinfo.penalty_type.ToLower().Equals("rs") && penaltyWCModel.Count < 1) { response.Status = 0; response.Message = "Work collection should be added to a return submissioin penalty type."; return(response); } if (string.IsNullOrWhiteSpace(pinfo.penalty_desc)) { response.Status = 0; response.Message = "Penalty description is required."; return(response); } if (pinfo.ri_type_id == null || pinfo.ri_type_id == 0) { response.Status = 0; response.Message = "Return institution type is required."; return(response); } if (pinfo.penalty_type.ToLower().Equals("--choose one--") || pinfo.penalty_type == "") { response.Status = 0; response.Message = "Penalty type is required."; return(response); } if (string.IsNullOrWhiteSpace(pinfo.frequncy)) { response.Status = 0; response.Message = "Penalty frequency is required."; return(response); } if (string.IsNullOrWhiteSpace(pinfo.penalty_freq_unit.ToString())) { response.Status = 0; response.Message = "Penalty frequency unit is required."; return(response); } if (string.IsNullOrWhiteSpace(pinfo.penalty_value.ToString())) { response.Status = 0; response.Message = "Penalty value is required."; return(response); } if (pinfo.start_validity_date < DateTime.Now) { response.Status = 0; response.Message = "Penalty start validity date must be in the present or future date"; return(response); } return(response); }; ValidateForm(); var _penalties = new Penalties(); if (pinfo.penalty_type == SharedConst.PENALTY_TYPE_RS) { Dictionary <int, string> _selectedWorkCollections = new Dictionary <int, string>(); foreach (var li in penaltyWCModel) { if (li != null) { _selectedWorkCollections.Add(li, li.ToString()); } } var _penaltyWcModel = new PenaltyWorkCollectionModel(); _penaltyWcModel.penalty_code = pinfo.penalty_code; _penaltyWcModel.work_collection_id = _selectedWorkCollections; _penaltyWcModel.created_date = DateTime.Now; _penaltyWcModel.created_by = pinfo.created_by; rowsAffected = _penalties.SavePenalty(pinfo, _penaltyWcModel); } else { rowsAffected = _penalties.SavePenalty(pinfo); } if (rowsAffected > 0) { response.Status = rowsAffected; response.Message = $"Penalty records '{pinfo.penalty_code}' saved successfuly."; return(response); } else { response.Status = rowsAffected; response.Message = "Error while saving penalty details"; return(response); } } catch (SqlException sqlEx) { LogUtitlity.LogToText(sqlEx.ToString()); if (sqlEx.Number == 2627) { response.Status = 0; response.Message = "Penalty code already exists"; return(response); } } catch (Exception ex) { LogUtitlity.LogToText(ex.ToString()); response.Status = 0; response.Message = "Couldn't add penalty details"; return(response); } return(response); }
public async Task TestAcceptMessageStartGameShouldSetFields() { int agentID = 1; int leaderId = 1; Team teamId = Team.Red; int[] alliesId = new int[1] { 2 }; int[] enemiesId = new int[2] { 3, 4 }; BoardSize boardSize = new BoardSize { X = 3, Y = 3 }; int goalAreaSize = 1; NumberOfPlayers numberOfPlayers = new NumberOfPlayers { Allies = 2, Enemies = 2 }; int numberOfPieces = 2; int numberOfGoals = 2; Penalties penalties = new Penalties() { Move = 100, Ask = 100, Response = 100, Discovery = 100, Pickup = 100, CheckForSham = 100, PutPiece = 100, DestroyPiece = 100, }; float shanProbability = 0.5f; Position position = new Position { X = 1, Y = 1 }; // Arrange StartGamePayload startGamePayload = new StartGamePayload { AgentID = agentID, AlliesIDs = alliesId, LeaderID = leaderId, EnemiesIDs = enemiesId, TeamID = teamId, BoardSize = boardSize, GoalAreaSize = goalAreaSize, NumberOfPlayers = numberOfPlayers, NumberOfPieces = numberOfPieces, NumberOfGoals = numberOfGoals, Penalties = penalties, ShamPieceProbability = shanProbability, Position = position }; Message startMessage = new Message(MessageID.StartGame, agentID, startGamePayload); BufferBlock <Message> inputBuffer = new BufferBlock <Message>(); inputBuffer.Post(startMessage); PlayerConfiguration configuration = GenerateSampleConfiguration(); var player = new Player.Models.Player(configuration, inputBuffer, new TcpSocketClient <Message, Message>(logger), logger); // Act bool expectedisLeader = true; (int, int)expectedBoardSize = (boardSize.X, boardSize.Y); (int, int)expectedPosition = (position.X, position.Y); await player.AcceptMessage(CancellationToken.None); var agentIDResult = player.GetValue <Player.Models.Player, int>("id"); var leaderIdResult = player.LeaderId; var teamMatesResult = player.TeamMatesIds; var isLeaderResult = player.IsLeader; var teamResult = player.Team; var boardSizeResult = player.BoardSize; var penaltiesResult = player.PenaltiesTimes; var positionResult = player.Position; var enemiesResult = player.EnemiesIds; var goalAreaSizeResult = player.GoalAreaSize; var numOfPlayersResult = player.NumberOfPlayers; var numOfPiecesResult = player.NumberOfPieces; var numOfGoalsResult = player.NumberOfGoals; var shamProbabilityResult = player.ShamPieceProbability; // Assert Assert.Equal(agentID, agentIDResult); Assert.Equal(leaderId, leaderIdResult); Assert.Equal(alliesId, teamMatesResult); Assert.Equal(expectedisLeader, isLeaderResult); Assert.Equal(teamId, teamResult); Assert.Equal(expectedBoardSize, boardSizeResult); Assert.True(penalties.AreAllPropertiesTheSame(penaltiesResult), $"Penalties should be the same,\n expected: {penalties},\n actual {penaltiesResult}"); Assert.Equal(expectedPosition, positionResult); Assert.Equal(enemiesId, enemiesResult); Assert.Equal(goalAreaSize, goalAreaSizeResult); Assert.True(numberOfPlayers.Allies == numOfPlayersResult.Allies && numberOfPlayers.Enemies == numOfPlayersResult.Enemies); Assert.Equal(numberOfPieces, numOfPiecesResult); Assert.Equal(numberOfGoals, numOfGoalsResult); Assert.Equal(shanProbability, shamProbabilityResult); }
public ActionResult <IEnumerable <string> > AddIn([FromBody] AddInOut form) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var time = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now); var time1 = time.AddHours(3); string currentUserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var _clientid = Guid.Parse(currentUserId); //DateTime date = Convert.ToDateTime(DateTime.Now).Date; // var nextDay = form.In_Out_Date.AddDays(1); var employeeinfo = _context.EmployessUsers.Where(x => x.Id == _clientid).FirstOrDefault(); var admininfo = _context.AdminUser.FirstOrDefault(); var inoutinfo = _context.InOut.Where(x => x.EmplyeeId == _clientid && x.In_Out_Status == form.In_Out_Status && x.In_Out_Date.Date == time1.Date).ToList(); if (inoutinfo.Count != 0) { return(BadRequest(new Response { Message = "لقد قمت بالصمة سابقا", Data = "", Error = true })); } double sLatitude = Convert.ToDouble(admininfo.Company_Latitude); double sLongitude = Convert.ToDouble(admininfo.Company_Longitude); double eLatitude = Convert.ToDouble(form.Employee_Latitude); double eLongitude = Convert.ToDouble(form.Employee_Longitude); int distansm = 0; if ((sLatitude == eLatitude) && (sLongitude == eLongitude)) { distansm = 0; } else { double theta = sLongitude - eLongitude; double dist = Math.Sin(deg2rad(sLatitude)) * Math.Sin(deg2rad(eLatitude)) + Math.Cos(deg2rad(sLatitude)) * Math.Cos(deg2rad(eLatitude)) * Math.Cos(deg2rad(theta)); dist = Math.Acos(dist); dist = rad2deg(dist); dist = dist * 60 * 1.1515; var distans = ((dist * 1.609344).ToString()).Substring(0, 5); var ddistans = Convert.ToDouble(distans) * 1000; distansm = Convert.ToInt32(ddistans); } string time_fromDb = employeeinfo.Employee_In_Time; string fromDb = time1.Date.ToString("yyyy-MM-dd") + " " + time_fromDb; DateTime FromDB = DateTime.Parse(fromDb); DateTime DCurrent = DateTime.Parse(time1.ToString("yyyy-MM-dd HH:mm:ss")); TimeSpan diffResult = DCurrent.ToUniversalTime().Subtract(FromDB.ToUniversalTime()); string x = diffResult.ToString(); string nHour = x.Substring(0, 2); int xHour; if (!int.TryParse(nHour, out xHour)) { xHour = 0; } int xMinites = xHour * 60; string ntime = x.Substring(3, 2); int xTime; if (!int.TryParse(ntime, out xTime)) { xTime = 0; } xMinites += xTime; var late = _context.ScheduleDelayPenalties.ToList(); decimal PenaltiesPrice = 0; foreach (var i in late) { if ((i.formtime) <= xMinites && xMinites <= i.totime) { PenaltiesPrice = i.PenaltiesPrice; var AddPenalties = new Penalties { Penalties_Date = time1.Date, Penalties_Note = "تأخير" + xMinites + "دقيقة", Penalties_Price = PenaltiesPrice, Employees_Id = _clientid, Penalties_Enterid = Guid.Parse("3ef34045-bbbb-49e6-880e-7e7bcb9c9a16"), }; _context.Penalties.Add(AddPenalties); _context.SaveChanges(); } } var AddInOut = new InOut { distance = distansm, In_Out_Date = time1.Date, In_Out_Status = form.In_Out_Status, EmplyeeId = _clientid, Employee_Latitude = form.Employee_Latitude, Employee_Longitude = form.Employee_Longitude, In_Out_Time = time1.ToString("hh:mm tt"), }; _context.InOut.Add(AddInOut); _context.SaveChanges(); _context.SaveChanges(); return(Ok(new Response { Message = "Done !", Data = "Thanks", Error = false })); }
private void ApplySanction() { Penalties p = (Penalties)mf.scMain.Panel2.Controls[0]; p.ApplySanction(); }
public Penalizer(Penalties penalties) { ParsePenalties(penalties); }