Пример #1
0
        public static int DeltaWeek(DateTime top, List <CStats> stats, int gap)
        {
            if (stats.Count < 2)
            {
                return(0);
            }
            CStats now = stats[stats.Count - 1];

            if (Str2DT(now.Date) != top)
            {
                return(0);
            }
            CStats   prior = null;
            DateTime priorDate;
            int      offset = stats.Count - (gap + 1);

            if (offset > -1)
            {
                prior     = stats[offset];
                priorDate = Str2DT(prior.Date);
            }
            else
            {
                return(0);
            }
            int thisGap = -(priorDate - top).Days;

            if (thisGap > gap)
            {
                return(0);
            }
            int views = now.Views - prior.Views;

            return(views);
        }
Пример #2
0
        public static CStats Clone(CStats stats)
        {
            CStats thisS = new CStats();

            thisS.Date  = stats.Date;
            thisS.Views = stats.Views;
            return(thisS);
        }
Пример #3
0
        public static CStats Clone(DateTime dt, int views)
        {
            CStats thisS = new CStats();

            thisS.Date  = dt.ToString("yyyyMMdd");
            thisS.Views = views;
            return(thisS);
        }
Пример #4
0
 public CPhoto(string id, string title, string thumb, string large, CStats item)
 {
     ID       = id;
     Title    = title;
     ThumbURL = thumb;
     LargeURL = large;
     Stats    = new List <CStats>();
     Stats.Add(item);
 }
Пример #5
0
        public static int DeltaMonth(DateTime top, List <CStats> stats, int gap)
        {
            if (stats.Count < 2)
            {
                return(0);
            }
            CStats now = stats[stats.Count - 1];

            if (Str2DT(now.Date) != top)
            {
                return(0);
            }
            CStats   prior = null;
            DateTime priorDate;
            int      offset = stats.Count - (gap + 1);

            if (offset > -1)
            {
                prior     = stats[offset];
                priorDate = Str2DT(prior.Date);
            }
            else
            {
                return(0);
            }
            int thisGap = -(priorDate - top).Days;

            if (thisGap > gap)
            {
                return(0);
            }
            int views = now.Views - prior.Views;

            return(views);
            //CStats mostRecent = Find(top, stats);
            //if (mostRecent == null)
            //{
            //    return 0;
            //}
            //if (stats == null)
            //{
            //    return 0;
            //}
            //DateTime myTop = Str2DT(mostRecent.Date);
            //DateTime bottom = DTSub(top, gap);
            //CStats myBottom = FindFirstRecordOnOrAfter(bottom, stats);
            ////CStats myBottom = FindFirstRecordOnOrBefore(bottom, stats);
            //if (myBottom == null)
            //{
            //    return 0;
            //}
            ////if (myBottom.Date == DT2Str(bottom))
            ////{
            ////    return 0;
            ////}
            //return mostRecent.Views - myBottom.Views;
        }
Пример #6
0
        public bool KillDates(string date)
        {
            bool anyDup = false;

            foreach (CPhoto photo in db.Photos)
            {
                string dateSTR = string.Empty;
                bool   dupDate = false;
                foreach (CStats stats in photo.Stats)
                {
                    if (stats.Date == dateSTR)
                    {
                        dupDate = true;
                        break;
                    }
                    dateSTR = stats.Date;
                }
                if (dupDate)
                {
                    anyDup = true;
                    break;
                }
            }
            bool anychange = false;

            if (anyDup)
            {
                int    count    = 0;
                string killDate = "20140624";
                for (int ndx = 0; ndx != db.Photos.Count; ndx++)
                {
                    List <CStats> statsList = new List <CStats>();
                    count = 0;
                    for (int xdx = 0; xdx != db.Photos[ndx].Stats.Count; xdx++)
                    {
                        if (string.Compare(killDate, db.Photos[ndx].Stats[xdx].Date, true) == 0)
                        {
                            string y = db.Photos[ndx].Stats[xdx].Date;
                            count++;
                        }
                        else
                        {
                            statsList.Add(CStats.Clone(db.Photos[ndx].Stats[xdx]));
                        }
                    }
                    if (count != 0)
                    {
                        anychange            = true;
                        db.Photos[ndx].Stats = statsList;
                    }
                }
            }
            return(anychange);
        }
Пример #7
0
        public static int Delta(DateTime top, List <CStats> stats, int gap)
        {
            if (stats.Count < (gap + 1))
            {
                return(0);
            }
            CStats now   = stats[stats.Count - 1];
            CStats prior = stats[stats.Count - (gap + 1)];
            int    views = now.Views - prior.Views;

            return(views);
        }
Пример #8
0
        List <CStats> _Slim(CPhoto photo)
        {
            List <CStats> replacement = new List <CStats>();
            int           prior       = 0;

            foreach (CStats stat in photo.Stats)
            {
                if (stat.Views != prior)
                {
                    replacement.Add(CStats.Clone(stat));
                }
                prior = stat.Views;
            }
            if (replacement.Count != 0 & (replacement.Count != photo.Stats.Count))
            {
                return(replacement);
            }
            return(null);
        }
Пример #9
0
        List <CStats> _Trim(CPhoto photo, int max, DateTime dtLimit)
        {
            List <CStats> replacement = new List <CStats>();

            if (photo.Stats.Count > max)
            {
                foreach (CStats stat in photo.Stats)
                {
                    if (CWorker.Str2DT(stat.Date) > dtLimit)
                    {
                        replacement.Add(CStats.Clone(stat));
                    }
                }
            }
            if (replacement.Count != 0 & (replacement.Count != photo.Stats.Count))
            {
                return(replacement);
            }
            return(null);
        }
Пример #10
0
        //public List<CTotalViews> TotalViews()
        //{
        //    List<CTotalViews> output = new List<CTotalViews>();
        //    foreach (string date in MakeDateList())
        //    {
        //        output.Add(new CTotalViews(date));
        //    }
        //    foreach (CPhoto photo in Photos)
        //    {
        //        foreach (CTotalViews record in output)
        //        {
        //            CStats stat = _LookupStatRecord(photo, record.Date);
        //            if (stat != null)
        //            {
        //                ////debug test
        //                //if (stat.Date != record.Date)
        //                //{
        //                //    throw new ApplicationException("Bang");
        //                //}
        //                record.Views += stat.Views;
        //            }
        //        }
        //    }
        //    return output;
        //}

        public List <CTotalViews> TotalViews()
        {
            List <CTotalViews> output = new List <CTotalViews>();

            foreach (string date in MakeDateList())
            {
                output.Add(new CTotalViews(date));
            }
            foreach (CPhoto photo in Photos)
            {
                foreach (CTotalViews record in output)
                {
                    CStats stat = _LookupStatRecord(photo, record.Date);
                    if (stat != null)
                    {
                        record.Views += stat.Views;
                    }
                }
            }
            return(output);
        }
Пример #11
0
 public void SetStatistics(CStats last, CStats prior)
 {
     Views = last.Views - prior.Views;
     All   = last.Views;
 }