Пример #1
0
        public List <List <string> > LongestTask(string email)
        {
            var list = new List <LongTask>();

            var user = _userRepositories.Get(email);


            foreach (var act in user.Activities)
            {
                TimeSpan sum = new TimeSpan();


                foreach (var parts in act.PartsOfActivity)
                {
                    sum += parts.Duration;
                }
                LongTask strLongTask = new LongTask();
                strLongTask.dur  = sum;
                strLongTask.name = act.Task.Name;


                list.Add(strLongTask);
            }

            var orderList = list.OrderByDescending(x => x.dur).ToList();

            if (orderList.Count == 0)
            {
                return(null);
            }

            var max = orderList[0].dur.TotalSeconds;

            var returned = new List <List <string> >();

            foreach (var item in orderList)
            {
                var tmp     = item.dur.ToString();
                var tmpPerc = (item.dur.TotalSeconds / max) * 100;
                var tmp3    = Math.Round(tmpPerc, 0);
                var cos     = new List <string>();

                cos.Add(tmp);
                cos.Add(item.name);
                cos.Add(tmp3.ToString());

                returned.Add(cos);
            }

            return(returned);
        }
Пример #2
0
        public List <LongTask> ActivityFromBase(string email)
        {
            //------------------Geslerowa---------------------------

            var Period     = DateTime.Now.AddDays(-30);
            var user       = _userRepositories.Get(email);
            var listOfAct  = new List <DAL.DTOModels.ActivityDto>();
            var tabUserAct = user.Activities;

            var notPlaned = tabUserAct.Where(a => a.State != State.Planned);


            foreach (var cos in notPlaned)
            {
                foreach (var part in cos.PartsOfActivity)
                {
                    if ((part.Stop > Period) && (part.Start < DateTime.Now))
                    {
                        listOfAct.Add(cos);
                        break;
                    }
                }
            }
            //--------------------------------------------------------


            var list = new List <LongTask>();



            foreach (var act in listOfAct)
            {
                TimeSpan sum = new TimeSpan();


                foreach (var parts in act.PartsOfActivity)
                {
                    sum += parts.Duration;
                }
                LongTask strLongTask = new LongTask();
                strLongTask.dur  = sum;
                strLongTask.name = act.Task.Name;

                list.Add(strLongTask);
            }

            var list2 = new List <LongTask>();



            foreach (var element in list)
            {
                var tmpName = element.name;
                var tmpDur  = TimeSpan.Zero;
                var obi     = new LongTask()
                {
                    dur  = tmpDur,
                    name = tmpName
                };

                if (!list2.Any(a => a.name.Equals(tmpName)))
                {
                    list2.Add(obi);
                }
            }


            var list3 = new List <LongTask>();


            foreach (var el2 in list2)
            {
                var tmpName = el2.name;
                var tmpDur  = el2.dur;
                var obi2    = new LongTask()
                {
                    dur  = tmpDur,
                    name = tmpName
                };


                foreach (var element in list)
                {
                    if (el2.name.Equals(element.name))
                    {
                        tmpDur += element.dur;
                    }
                }

                LongTask strLongTask = new LongTask();
                strLongTask.name     = tmpName;
                strLongTask.dur      = tmpDur;
                strLongTask.totalDur = Math.Round(tmpDur.TotalSeconds, 0);
                list3.Add(strLongTask);
            }



            return(list3);
        }
Пример #3
0
        public List <List <string> > LongestTaskToChart(string email, int days)
        {
            var list = new List <LongTask>();



            var date7DaysAgo = DateTime.Now.AddDays(-days);
            var user         = _userRepositories.Get(email);
            var listOfAct    = new List <DAL.DTOModels.ActivityDto>();

            var result = new List <List <string> >();

            var tabUserAct = user.Activities;
            var notPlaned  = tabUserAct.Where(a => a.State != State.Planned);


            foreach (var cos in notPlaned)
            {
                foreach (var part in cos.PartsOfActivity)
                {
                    if ((part.Stop > date7DaysAgo) && (part.Start < DateTime.Now))
                    {
                        listOfAct.Add(cos);
                        break;
                    }
                }
            }


            foreach (var act in listOfAct)
            {
                TimeSpan sum = new TimeSpan();


                foreach (var parts in act.PartsOfActivity)
                {
                    sum += parts.Duration;
                }
                LongTask strLongTask = new LongTask();
                strLongTask.dur  = sum;
                strLongTask.name = act.Task.Name;

                list.Add(strLongTask);
            }
            var max       = 1.0;
            var orderList = list.OrderByDescending(x => x.dur).ToList();

            try
            {
                max = orderList[0].dur.TotalSeconds;
            }
            catch
            {
                max = 1;
            }


            var returned = new List <List <string> >();

            foreach (var item in orderList)
            {
                var tmp     = item.dur.ToString();
                var tmpPerc = (item.dur.TotalSeconds / max) * 100;
                var tmp3    = Math.Round(tmpPerc, 0);
                var cos     = new List <string>();

                cos.Add(tmp);
                cos.Add(item.name);
                cos.Add(tmp3.ToString());

                returned.Add(cos);
            }

            return(returned);
        }