示例#1
0
        public static ScheduleMatchData GetScheduleWeighting(redux_items redux, pips_programmes pips)
        {
            ScheduleMatchData data = new ScheduleMatchData();

            data.StartDistance = Math.Abs((redux.aired - pips.start_gmt).TotalSeconds);
            data.DurationDelta = Math.Abs(redux.duration - (pips.end_gmt - pips.start_gmt).TotalSeconds);
            DateTime maxstart = pips.start_gmt;

            if (redux.aired > pips.start_gmt)
            {
                maxstart = redux.aired;
            }

            DateTime minend = pips.end_gmt;

            if (redux.aired.AddSeconds(redux.duration) < minend)
            {
                minend = redux.aired.AddSeconds(redux.duration);
            }

            var overlap = minend - maxstart;

            if (overlap.TotalSeconds < 0)
            {
                data.OverlapWeight = 0.0;
            }
            else
            {
                data.OverlapWeight = 100.0 * (overlap.TotalSeconds / (double)redux.duration) + 100.0 * (overlap.TotalSeconds / (pips.end_gmt - pips.start_gmt).TotalSeconds);
            }
            return(data);
        }
示例#2
0
        public static bool IsPartialTitleMatchWithDescription(redux_items redux, pips_programmes pips)
        {
            if (redux == null || pips == null)
            {
                return(false);
            }
            string reduxtitle = GetCompleteTitle(redux);

            if (PartialMatch.IsPartialMatch(reduxtitle, pips.display_title))
            {
                return(true);
            }
            if (PartialMatch.IsPartialMatch(reduxtitle, pips.display_subtitle))
            {
                return(true);
            }
            string reduxdesc = redux.short_description;

            if (reduxdesc.Contains("] Followed by "))
            {
                reduxdesc = reduxdesc.Substring(0, reduxdesc.IndexOf("] Followed by "));
            }
            if (reduxdesc.Contains("] Then "))
            {
                reduxdesc = reduxdesc.Substring(0, reduxdesc.IndexOf("] Then "));
            }
            return(PartialMatch.IsPartialMatch(redux.programme_name + " " + reduxdesc, pips.display_title + " " + pips.display_subtitle + " " + pips.description));
        }
示例#3
0
        public static bool IsPartialTitleMatch(redux_items redux, pips_programmes pips)
        {
            if (redux == null || pips == null)
            {
                return(false);
            }
            string reduxtitle = GetCompleteTitle(redux);

            if (PartialMatch.IsPartialMatch(reduxtitle, pips.display_title))
            {
                return(true);
            }
            return(false);
        }
示例#4
0
 public static double GetSimpleWeighting(redux_items redux, pips_programmes pips)
 {
     if (IsGoodTitleMatch(redux, pips))
     {
         return(100.0);
     }
     if (IsPartialTitleMatch(redux, pips))
     {
         return(10.0);
     }
     if (IsPartialTitleMatchWithDescription(redux, pips))
     {
         return(1.0);
     }
     return(0.0);
 }
示例#5
0
        private static void MakeMatch(ReduxEntities ctx, UnmatchedItem item, pips_programmes p)
        {
            var rp = new redux_to_pips
            {
                duration_match = item.rp.duration_match,
                ischecked      = item.rp.ischecked,
                partial_match  = (item.r.programme_name == p.display_title) == false,
                pips_id        = p.id,
                redux_id       = item.rp.redux_id,
                start_match    = true,
                title_match    = (item.r.programme_name == p.display_title)
            };

            ctx.redux_to_pips.DeleteObject(item.rp);
            ctx.redux_to_pips.AddObject(rp);
            item.rp = rp;
            ctx.SaveChanges();
        }
示例#6
0
        // This is a quick(ish) way to scan all the programmes in pips_programmes
        // and find all gaps in the schedule.
        // Note that this process will find all actual gaps where
        // the channel is not transmitting
        private void ScanGaps_Click(object sender, RoutedEventArgs e)
        {
            List <Gap> gaps = new List <Gap>();

            Task.Factory.StartNew(() =>
            {
                StringBuilder sql = new StringBuilder();
                sql.AppendLine("insert into gaps (programme_id, service_id, gapstart,gapend)");                        // VALUES(1234,1,"2007-06-28 03:00","2007-06-28 06:00")
                using (var data = new ReduxEntities())
                {
                    var programmes = (from prog in data.pips_programmes
                                      //orderby prog.ServiceId, prog.StartTime
                                      select prog).ToList();
                    programmes = (from prog in programmes
                                  orderby prog.service_id, prog.start_gmt
                                  select prog).ToList();
                    pips_programmes prev = null;
                    using (var newdata = new ReduxEntities())
                    {
                        foreach (var prog in programmes)
                        {
                            if (prev != null && prev.service_id == prog.service_id && prev.end_gmt < prog.start_gmt)
                            {
                                gap gap = new gap
                                {
                                    programme_id = prog.id,
                                    service_id   = prog.service_id,
                                    gapstart     = prev.end_gmt,
                                    gapend       = prog.start_gmt
                                };
                                newdata.gaps.AddObject(gap);
                                Dispatcher.Invoke((MyDelegate) delegate { gapLabel.Content = string.Format("{0}", gap.gapstart); });
                            }
                            if (prev == null || prog.service_id != prev.service_id || prog.end_gmt > prev.end_gmt)
                            {
                                prev = prog;
                            }
                        }
                        newdata.SaveChanges();
                    }
                    Dispatcher.Invoke((MyDelegate) delegate { gapGrid.ItemsSource = data.gaps; });
                }
            });
        }
示例#7
0
        public static bool IsGoodTitleMatch(redux_items redux, pips_programmes pips)
        {
            if (redux == null || pips == null)
            {
                return(false);
            }
            string reduxtitle = NormaliseTitle(GetCompleteTitle(redux));
            string pipstitle  = NormaliseTitle(pips.display_title);

            if (reduxtitle == pipstitle)
            {
                return(true);
            }
            if (reduxtitle == NormaliseTitle(pips.display_subtitle))
            {
                return(true);
            }
            return(false);
        }
示例#8
0
        private async void MissingGenres(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            Progress progress = new Progress();

            progress.Show();
            var itemStore = new ReduxEntities();
            var nogenres  = from p in itemStore.pips_programmes
                            join g in itemStore.genres on p.id equals g.pips_id into joined
                            from j in joined.DefaultIfEmpty()
                            where j == null
                            select p;
            var    ng  = nogenres.ToList();
            Random rnd = new Random();

            for (int i = ng.Count; i == 0; i--)
            {
                int             pos = rnd.Next(i);
                pips_programmes tmp = ng[i - 1];
                ng[i - 1] = ng[pos];
                ng[pos]   = tmp;
            }
            List <Task> tasks   = new List <Task>();
            Fetcher     fetcher = new Fetcher();

            foreach (var prog in ng)
            {
                tasks.Add(fetcher.AddGenresAsync(prog.pid, prog.id, progress, thumbnail));
                if (tasks.Count >= 16)
                {
                    await TaskEx.WhenAll(tasks);

                    tasks.Clear();
                    if (progress.IsCancelled)
                    {
                        break;
                    }
                }
            }
        }
示例#9
0
        public static double GetMatchWeighting(redux_items redux, pips_programmes pips)
        {
            var    titlematch   = Match(redux.programme_name, pips.display_title);
            var    partialmatch = Match(pips.display_title + " " + pips.display_subtitle + " " + pips.description, redux.programme_name + " " + redux.short_description);
            double weight       = 1;

            if (titlematch.PercentFirstInSecond > 0)
            {
                weight = weight * titlematch.PercentFirstInSecond * 2;
            }
            if (titlematch.PercentSecondInFirst > 0)
            {
                weight = weight * titlematch.PercentSecondInFirst * 2;
            }
            if (partialmatch.PercentFirstInSecond > 0)
            {
                weight = weight * partialmatch.PercentFirstInSecond;
            }
            if (partialmatch.PercentSecondInFirst > 0)
            {
                weight = weight * partialmatch.PercentSecondInFirst;
            }
            return(weight);
        }
示例#10
0
 public ReduxViewModel(redux_items redux, pips_programmes pips, redux_to_pips join)
 {
     ReduxItem        = redux;
     Programme        = pips;
     ReduxToProgramme = join;
 }
示例#11
0
        private async void RunMatcherClick(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnails = new Thumbnail();

            thumbnails.Show();
            Progress progress = new Progress();

            progress.Show();
            ReduxEntities ctx = new ReduxEntities();
            //DateTime cutoff = new DateTime(2010, 5, 1);
            var unmatched = (from r in ctx.redux_items
                             from rp in ctx.redux_to_pips
                             where r.id == rp.redux_id && rp.pips_id == 0
                             //&& r.aired >= cutoff
                             select r).ToList();;
            int count = 0;

            foreach (var unmatcheditem in unmatched)
            {
                if (progress.IsCancelled)
                {
                    break;
                }

                var item = new UnmatchedItem(unmatcheditem, ctx.redux_to_pips.FirstOrDefault(rp => rp.redux_id == unmatcheditem.id));
                if (item.rp == null || item.rp.pips_id > 0)
                {
                    continue;
                }

                var rangestart  = item.r.aired.AddMinutes(-5);
                var rangeend    = item.r.aired.AddMinutes(5);
                var pipsmatches = await TaskEx.Run <List <pips_programmes> >(() =>
                {
                    return((from p in ctx.pips_programmes
                            where p.start_gmt == item.r.aired &&
                            p.service_id == item.r.service_id
                            select p).ToList());
                });

                string matchedpid  = null;
                bool   isMatchMade = false;
                if (pipsmatches.Count == 0)
                {
                    //progress.WriteLine("Unmatched: {0} {1} {2}", item.r.disk_reference, item.r.programme_name, item.r.aired);
                }
                else if (pipsmatches.Count == 1)
                {
                    var p = pipsmatches.First();
                    if (PartialMatch.GetSimpleWeighting(item.r, p) > 0)
                    {
                        MakeMatch(ctx, item, p);
                        matchedpid  = p.pid;
                        isMatchMade = true;
                        //progress.WriteLine("Matched: {0} {1} {2} -> {3} {4} {5}", item.r.disk_reference, item.r.programme_name, item.r.aired, p.pid, p.display_title, p.start_gmt);
                    }
                }
                else
                {
                    //progress.WriteLine("Matched: {0} {1} {2} ->", item.r.disk_reference, item.r.programme_name, item.r.aired);
                    //foreach (var pipsmatch in pipsmatches)
                    //{
                    //    var p = pipsmatch;
                    //    progress.WriteLine("         -> {0} {1} {2}", p.pid, p.display_title, p.start_gmt);
                    //}
                    //matchedpid = pipsmatches.First().pid;
                }

                if (isMatchMade == false)
                {
                    pipsmatches = await TaskEx.Run <List <pips_programmes> >(() =>
                    {
                        DateTime fiveminutesbefore = item.r.aired.AddMinutes(-5);
                        DateTime fiveminutesafter  = item.r.aired.AddMinutes(5);
                        return((from p in ctx.pips_programmes
                                join rp in ctx.redux_to_pips on p.id equals rp.pips_id into joined
                                from j in joined.DefaultIfEmpty()
                                where j == null && p.start_gmt >= fiveminutesbefore &&
                                p.start_gmt <= fiveminutesafter &&
                                p.service_id == item.r.service_id
                                select p).ToList());
                    });

                    var suitable = pipsmatches.Where(p => PartialMatch.GetSimpleWeighting(item.r, p) > 0)
                                   .OrderByDescending(p => PartialMatch.GetSimpleWeighting(item.r, p))
                                   .OrderBy(p => Math.Abs((p.start_gmt - item.r.aired).TotalSeconds))
                                   .OrderBy(p => Math.Abs(p.duration - item.r.duration))
                                   .ToList();
                    if (suitable.Count > 0)
                    {
                        pips_programmes matchedpips = suitable.First();
                        MakeMatch(ctx, item, matchedpips);
                        isMatchMade = true;
                        matchedpid  = matchedpips.pid;
                    }
                }

                if (matchedpid != null)
                {
                    thumbnails.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + matchedpid + "_314_176.jpg");
                }
                if (isMatchMade == false)
                {
                    progress.WriteLine("Failed to match {0} {1} {2}", item.r.programme_name, item.r.disk_reference, item.r.aired);
                }
            }
            MessageBox.Show("Finished matching unmatched items");
        }