コード例 #1
0
ファイル: JSONRace.cs プロジェクト: LukeStanislaus/SailingWeb
 public JSONRace(BoatsTidy boat, Calendar raceEvent, BoatLap lapNo, DateTime raceStart)
 {
     this.Boat      = boat;
     this.RaceEvent = raceEvent;
     this.LapNo     = lapNo;
     this.RaceStart = raceStart;
 }
コード例 #2
0
        public static int PlaceOf(BoatsTidy boat, Tuple <Calendar, Dictionary <BoatsTidy, List <BoatLap> >, DateTime> Race)
        {
            try
            {
                Dictionary <BoatsTidy, TimeSpan> places = new Dictionary <BoatsTidy, TimeSpan>();
                foreach (var x in Race.Item2)
                {
                    if (x.Value.Count != 0)
                    {
                        TimeSpan totaltime = new TimeSpan();
                        foreach (var y in x.Value)
                        {
                            totaltime += y.LapTime;
                        }
                        TimeSpan averageperlap = totaltime / x.Value.Count;
                        TimeSpan correctedTime = TimeSpan.FromSeconds((totaltime.TotalSeconds * NoOfLaps(Race) * 1000) / (x.Key.Py * x.Value.Count));

                        places.Add(x.Key, correctedTime);
                    }
                    else
                    {
                    }
                }
                var results = places.OrderBy(y => y.Value);
                var z       = results.Where(x => x.Key.Boat == boat.Boat &&
                                            x.Key.BoatNumber == boat.BoatNumber && x.Key.Crew == boat.Crew && x.Key.Name == boat.Name &&
                                            x.Key.Notes == boat.Notes && x.Key.Py == boat.Py);

                return(results.ToList().IndexOf(z.First()) + 1);
            }
            catch
            {
                return(0);
            }
        }
コード例 #3
0
ファイル: UnitTest.cs プロジェクト: LukeStanislaus/SailingWeb
        static void Act()
        {
            var      boat = new BoatsTidy("Luke Stanislaus", "Laser", "162872", "", 0, "");
            var      str1 = "2nd evening Series Race 9abc1232018-08-08 19:00:00".Split("abc123");
            Calendar cal  = new Calendar(str1[0], "", Convert.ToDateTime(str1[1]));

            Sql.RemoveBoats(boat, cal);
        }
コード例 #4
0
ファイル: SQL.cs プロジェクト: LukeStanislaus/SailingWeb
 public async static Task <IEnumerable <int> > NoOfLaps(BoatsTidy boat, Calendar cal)
 {
     using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal()))
     {
         return(await connection.QueryAsync <int>("select max(racelap) from races where name = @name and " +
                                                  "summary = @summary", new
         {
             name = boat.Name,
             summary = cal.Summary
         }));
     }
 }
コード例 #5
0
ファイル: SQL.cs プロジェクト: LukeStanislaus/SailingWeb
 public async static Task <int> RemoveLap(BoatsTidy boat, Calendar cal, int lapNo)
 {
     using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal()))
     {
         return(await connection.ExecuteAsync("delete from races where name = @name and " +
                                              "summary = @summary and racelap = @racelap and eventStart = @eventStart", new
         {
             name = boat.Name,
             summary = cal.Summary,
             racelap = lapNo,
             eventStart = cal.DateTime
         }));
     }
 }
コード例 #6
0
ファイル: SQL.cs プロジェクト: LukeStanislaus/SailingWeb
 public async static Task <int> NewLap(BoatsTidy boat, DateTime lapTime, Calendar cal)
 {
     using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal()))
     {
         return(await connection.ExecuteAsync("insert into races values(@name, @summary, @sailingClub," +
                                              " @racelap, @laptime)", new
         {
             name = boat.Name,
             summary = cal.Summary,
             sailingClub = "Whitefriars Sailing Club",
             racelap = NoOfLaps(boat, cal),
             laptime = lapTime
         }));
     }
 }
コード例 #7
0
ファイル: SQL.cs プロジェクト: LukeStanislaus/SailingWeb
        /// <summary>
        /// Removes boats, knows if they are crew or not.
        /// </summary>
        /// <param name="boat"></param>
        public static void RemoveBoats(BoatsTidy boat, Calendar race)
        {
            using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal()))
            {
                // Creates query.

                string str = "delete from signonlists where (name = @name and summary = @summary " +
                             "and dateTime = @dateTime and sailingClub = @sailingClub)";
                connection.Query(str, new {
                    name        = boat.Name,
                    summary     = race.Summary,
                    dateTime    = race.DateTime,
                    sailingClub = "Whitefriars Sailing Club"
                });
            }
        }
コード例 #8
0
ファイル: SQL.cs プロジェクト: LukeStanislaus/SailingWeb
 /// <summary>
 /// Inserts sailor into a named race.
 /// </summary>
 /// <param name="boat">Boat data of person to add.</param>
 /// <param name="crew">Are they crew?</param>
 public async static Task <int> SetBoats(BoatsTidy boat, Calendar race)
 {
     using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal()))
     {
         string str = "insert into signonlists values(@name, @boatName, @boatNumber, @crew, " +
                      "@py, @notes, @summary, @dateTime, @sailingClub)";
         return(await connection.ExecuteAsync(str, new {
             name = boat.Name,
             boatName = boat.Boat,
             boatNumber = boat.BoatNumber,
             crew = boat.Crew == null? "" : boat.Crew,
             py = boat.Py,
             notes = boat.Notes == null ? "" : boat.Crew,
             summary = race.Summary,
             dateTime = race.DateTime,
             sailingClub = "Whitefriars Sailing Club"
         }));
     }
 }
コード例 #9
0
        public async void SetBoats(BoatsTidy boats)
        {
            string[] str = Race.Split("abc123");
            Calendar cal = new Calendar(str[0], null,
                                        Convert.ToDateTime(str[1]));

            try
            {
                var result = await Sql.SetBoats(boats, cal);

                Program.Exit(boats, cal);
                Program.Globals.Racename = new Calendar(Race, "", new DateTime());
            }
            catch
            {
                Program.Globals.Removeboat = boats;
                Program.Globals.Alerttext  = "You are already added to the race, would you like to remove yourself?";
                Program.Globals.Racename   = cal;
            }
        }
コード例 #10
0
        public static TimeSpan CorrectedTime(BoatsTidy boat, Tuple <Calendar, Dictionary <BoatsTidy, List <BoatLap> >, DateTime> Race)
        {
            try
            {
                var x = Race.Item2[boat];

                TimeSpan totaltime = new TimeSpan();
                foreach (var y in x)
                {
                    totaltime += y.LapTime;
                }
                TimeSpan averageperlap = totaltime / x.Count;
                TimeSpan correctedTime = TimeSpan.FromSeconds((totaltime.TotalSeconds * NoOfLaps(Race) * 1000) / (boat.Py * x.Count));
                return(correctedTime);
            }
            catch
            {
                return(new TimeSpan());
            }
        }
コード例 #11
0
ファイル: UnitTest.cs プロジェクト: LukeStanislaus/SailingWeb
        public void EnterRace()
        {
            CreateModel cm = new CreateModel();

            var boat = new BoatsTidy("Luke Stanislaus", "Laser", "162872", "", 0, "");

            cm.Boats         = boat;
            cm.Boatandnumber = "Laser, 162872";

            var str = "2nd evening Series Race 9abc1232018-08-08 19:00:00";

            cm.Race = str;
            Assert.IsTrue(cm.OnPost().IsCompletedSuccessfully);
            var      str1 = str.Split("abc123");
            Calendar cal  = new Calendar(str1[0], "", Convert.ToDateTime(str1[1]));



            Action act = new Action(Act);

            Assert.IsFalse(Assert.ThrowsException <Exception>(act) != new Exception());
        }