Exemple #1
0
        /// <summary>
        /// Determine starter for specified lineup slot.
        /// </summary>
        /// <param name="slot">The slot.</param>
        /// <returns>
        /// The starter.
        /// </returns>
        private Player DetermineStarter(LineupItem slot)
        {
            Player starter = null;

            // Get all starters for the position
            var potentialStarters = this.bench.GetStartersForPosition(slot.Position);

            // Get the total starts for all players
            Int32 totalStarts = (from player in potentialStarters
                                 select player.FieldingStarts.Find(slot.Position).Starts).Sum();

            // Build a dictionary with player and their starting percentage
            var   potentialDictionary = new Dictionary <Player, Int32>();
            Int32 totalPercent        = 0;

            foreach (var potential in potentialStarters)
            {
                // Get the # of games this player started at the current position
                var fieldingStart = potential.FieldingStarts.Find(slot.Position);

                // Determine percent of games this player played (at this position)
                var percent = (Int32)Math.Round(fieldingStart.Starts == 0 ? 0 :
                                                ((double)fieldingStart.Starts / (double)totalStarts * 100));

                totalPercent += percent;

                potentialDictionary.Add(potential, totalPercent);
            }

            // Pick a random number
            var randomValue = this.random.Next(0, 99);

            // See which player was chosen
            foreach (var key in potentialDictionary.Keys)
            {
                // Get the percent
                var percent = potentialDictionary[key];

                // Is this the player?
                if (randomValue <= percent)
                {
                    // We got our starter
                    starter = key;
                    break;
                }
                else
                {
                }
            }

            return(starter);
        }
Exemple #2
0
        private static ChannelItemInfo CreateFolderChannelItemInfo(LineupItem show)
        {
            var folderId = FolderId.CreateShowFolderId(show.Url);

            return(new ChannelItemInfo
            {
                FolderType = ChannelFolderType.Container,
                Id = folderId.ToString(),
                ImageUrl = show.ImageUrl,
                Name = show.Title,
                Type = ChannelItemType.Folder
            });
        }
Exemple #3
0
 private ChannelItemInfo CreateChannelItemInfo(LineupItem episode, string season)
 {
     return(new ChannelItemInfo
     {
         Id = episode.Url,
         ImageUrl = episode.ImageUrl,
         MediaType = ChannelMediaType.Video,
         Name = string.Format("{0}: {1}", season, episode.Title),
         Overview = episode.Details.Description,
         ProductionYear = GetProductionYear(episode.Details.ProductionYear),
         People = ConvertPeople(episode.Details.Persons),
         Type = ChannelItemType.Media
     });
 }
        public static async Task <IEnumerable <LineupItem> > ChannelsToHdhrLineup(string deviceId, IEnumerable <Channel> channels)
        {
            await Task.Yield();

            var items = new List <LineupItem>();

            foreach (var channel in channels)
            {
                var item      = new LineupItem();
                var frequency = $"{channel.Frequency:#.000000}".Replace(".", "");

                item.GuideNumber = channel.DisplayChannel;
                item.GuideName   = channel.Name;
                item.Url         = $"hdhomerun://{deviceId}/ch{frequency}-{channel.ProgramId:d}";

                items.Add(item);
            }

            return(items);
        }
        /// <summary>
        /// Parses the specified lines.
        /// </summary>
        /// <param name="lines">The lines.</param>
        /// <returns>The team.</returns>
        private static Team Parse(String[] lines)
        {
            var team = new Team();

            // Extract team name (with year)
            team.Name = lines[0].Substring(10, 18).TrimEnd(' ');

            // Add batting order
            for (Int32 loopCounter = 0; loopCounter < 9; loopCounter++)
            {
                if (lines[loopCounter + 1].Length > 8)
                {
                    String text   = lines[loopCounter + 1];
                    var    player = ParseBatter(text);

                    player.Identifier = String.Format("{0}-{1}-{2}", player.LastName, player.FirstName, team.Name);

                    team.Players.Add(player);

                    // Add to default lineup
                    String position = text.Substring(6, 2);
                    var    item     = new LineupItem();
                    item.Player   = player;
                    item.Order    = loopCounter + 1;
                    item.Position = Convert.ToInt32(position);
                    team.DefaultLineup.Add(item);
                }
            }

            // Add pitchers
            Int32   lineIndex    = 11;
            Int32   benchIndex   = 11;
            Boolean done         = false;
            Int32   pitcherOrder = 1;

            while (!done)
            {
                if (lines[lineIndex].StartsWith("*Bench"))
                {
                    benchIndex = lineIndex + 1;
                    done       = true;
                }
                else
                {
                    // Add the pitcher
                    var player = ParsePitcher(lines[lineIndex]);
                    player.Identifier = String.Format("{0}-{1}-{2}", player.LastName, player.FirstName, team.Name);
                    team.Players.Add(player);

                    // Add pitcher to rotation?
                    if (pitcherOrder <= 5)
                    {
                        var item = new RotationItem();
                        item.Player = player;
                        item.Order  = pitcherOrder;
                        team.Rotation.Add(item);
                    }

                    pitcherOrder++;

                    lineIndex++;
                }
            }

            // Add bench
            done = false;
            while (!done)
            {
                if (lines[benchIndex].StartsWith("*") == false && lines[benchIndex] != String.Empty)
                {
                    var player = ParseBatter(lines[benchIndex]);
                    team.Players.Add(player);
                }

                benchIndex++;

                if (benchIndex >= lines.Length)
                {
                    done = true;
                }
            }

            return(team);
        }
Exemple #6
0
 private static bool IsValidItem(LineupItem item)
 {
     return(item.IsActive && item.IsFree && (item.Template.Contains("-content") || item.Template == "program"));
 }