/[xmltv_parser]/trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs
ViewVC logotype

Diff of /trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/15 17:33:15	165
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/16 13:16:42	166
@@ -17,7 +17,7 @@
         List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
         List<SQLLITE.ICHANNEL> Channels { get; }
         IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
-        List<SQLLITE.IPROGRAMME> FilterProgramsByDateRange(List<SQLLITE.IPROGRAMME> programs, IDateTimeRange range, out List<SQLLITE.IPROGRAMME> removed_programs);
+        List<SQLLITE.IPROGRAMME> GetValidPrograms(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> removed_programs);
 
     }
     public class SQLLITE : ISQLLITE
@@ -293,34 +293,60 @@
             return range;
         }
 
-        public List<SQLLITE.IPROGRAMME> FilterProgramsByDateRange(List<SQLLITE.IPROGRAMME> programs, IDateTimeRange range, out List<SQLLITE.IPROGRAMME> removed_programs)
+        public List<SQLLITE.IPROGRAMME> GetValidPrograms(List<SQLLITE.IPROGRAMME> gbpvr_programs, List<libxmltv.Interfaces.IProgramDefinition> xmltv_programs, out List<SQLLITE.IPROGRAMME> source_invalid)
         {
-            removed_programs = new List<IPROGRAMME>();
-            List<SQLLITE.IPROGRAMME> list = new List<IPROGRAMME>(programs.ToArray());
-            list = list.OrderBy(s => s.start_time).ToList();
-            List<SQLLITE.IPROGRAMME> list2 = new List<IPROGRAMME>();
-            if (range == null)
-            {
-                gLog.Warn.WriteLine("The DateTimeRange passed in is null...returning the original program list");
-                return list;
-            }
+            source_invalid = new List<IPROGRAMME>();
+            List<SQLLITE.IPROGRAMME> source = new List<IPROGRAMME>(gbpvr_programs.ToArray());
+            source = source.OrderBy(s => s.start_time).ToList();
+            List<SQLLITE.IPROGRAMME> source_valid = new List<IPROGRAMME>();
+            //if (range == null)
+            //{
+            //    gLog.Warn.WriteLine("The DateTimeRange passed in is null...returning the original program list");
+            //    return list;
+            //}
             //gLog.Warn.WriteLine("FilterProgramsByDateRange has not been implemented");
-           
-            foreach (var program in list)
-            {
-                if (program.start_time >= range.Start &&
-                    program.start_time <= range.End)
+
+            double total = source.Count;
+            double index = 0;
+            double progress = 0;
+            foreach (var program in source)
+            {
+                //if (program.start_time >= range.Start &&
+                //    program.start_time <= range.End)
+                //{
+                //    list2.Add(program);
+                //}
+                //else
+                //{
+                //    removed_programs.Add(program);
+                //}   
+                progress = 100.0 * (index / total);
+                gLog.ReportProgress(this, new ReportProgressEventArgs((int)progress, string.Format("SQLLITE: Filtering GBPVR Programs: {1:00}%", progress)));
+                var xmltv_entry = program.AsXMLTVProgramDefinition(this);
+                if (xmltv_programs.Contains(xmltv_entry))
                 {
-                    list2.Add(program);
+                    source_valid.Add(program);
                 }
                 else
                 {
-                    removed_programs.Add(program);
+                    source_invalid.Add(program);
                 }
+                index++;
             }
-            list2 = list2.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
-            removed_programs = removed_programs.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
-            return list2;
+
+            //for (int i = 0; i < programs.Count(); i++)
+            //{
+            //    var gbpvr_entry = gbpvr[i];
+            //    var xmltv_entry = gbpvr_entry.AsXMLTVProgramDefinition(sqlite);
+            //    if (!xmltv[i].Equals(xmltv_entry))
+            //    {
+            //        gLog.Warn.WriteLine("Warning GBPVR Program oid: {0} might be invalid", gbpvr_entry.oid);
+            //    }
+            //}
+
+            source_valid = source_valid.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
+            source_invalid = source_invalid.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
+            return source_valid;
         }
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22