private static List<ReportProject> MakeProjectList (List<ReportProjectJson> jsonList)
        {
            var projectList = new List<ReportProject> ();
            int colorIndex;

            foreach (var item in jsonList) {
                var p = new ReportProject () {
                    Project = item.Description.Project,
                    TotalTime = item.TotalTime,
                    Color = Int32.TryParse (item.Description.Color, out colorIndex) ? colorIndex : ProjectModel.HexColors.Length - 1
                };
                p.Items = new List<ReportTimeEntry> ();
                if (item.Items != null) {
                    foreach (var i in item.Items) {
                        p.Items.Add (new ReportTimeEntry () {
                            Rate = i.Rate,
                            Title = i.Description.Title,
                            Time = i.Time,
                            Sum = i.Sum
                        });
                    }
                }
                p.Currencies = new List<ReportCurrency> ();
                if (item.Currencies != null) {
                    foreach (var i in item.Currencies) {
                        p.Currencies.Add (new ReportCurrency () {
                            Amount = i.Amount,
                            Currency = i.Currency
                        });
                    }
                }
                projectList.Add (p);
            }
            return projectList;
        }
Beispiel #2
0
        private void SetProjectInfo(ReportProject selectedProject)
        {
            totalTimeLabel.Text = selectedProject.FormattedTotalTime;
            int currCount = selectedProject.Currencies.Count;

            if (currCount > 0)
            {
                totalTimeLabel.Center = new PointF(donutChart.PieCenter.X, donutChart.PieCenter.Y - 10);
                string moneyInfo = "";

                currCount = (selectedProject.Currencies.Count > 3) ? 3 : selectedProject.Currencies.Count;
                var projectCurrencies = selectedProject.Currencies.OrderBy(s => s.Amount.ToString().Length).Reverse <ReportCurrency> ().ToList <ReportCurrency>();
                for (int i = 0; i < currCount; i++)
                {
                    moneyInfo += projectCurrencies[i].Amount + " " + projectCurrencies[i].Currency + "\n";
                }

                moneyInfo        = moneyInfo.Substring(0, moneyInfo.Length - 1);
                moneyLabel.Alpha = 1.0f;
                moneyLabel.Text  = moneyInfo;
            }
            else
            {
                totalTimeLabel.Center = new PointF(donutChart.PieCenter.X, donutChart.PieCenter.Y);
                moneyLabel.Alpha      = 0.0f;
            }
            moneyLabel.SizeToFit();
        }
        private static List <ReportProject> MakeProjectList(List <ReportProjectJson> jsonList)
        {
            var projectList = new List <ReportProject> ();
            int colorIndex;

            foreach (var item in jsonList)
            {
                var p = new ReportProject()
                {
                    Project   = item.Description.Project,
                    TotalTime = item.TotalTime,
                    Color     = Int32.TryParse(item.Description.Color, out colorIndex) ? colorIndex : ProjectModel.HexColors.Length - 1
                };
                p.Items = new List <ReportTimeEntry> ();
                if (item.Items != null)
                {
                    foreach (var i in item.Items)
                    {
                        p.Items.Add(new ReportTimeEntry()
                        {
                            Rate  = i.Rate,
                            Title = i.Description.Title,
                            Time  = i.Time,
                            Sum   = i.Sum
                        });
                    }
                }
                p.Currencies = new List <ReportCurrency> ();
                if (item.Currencies != null)
                {
                    foreach (var i in item.Currencies)
                    {
                        p.Currencies.Add(new ReportCurrency()
                        {
                            Amount   = i.Amount,
                            Currency = i.Currency
                        });
                    }
                }
                projectList.Add(p);
            }
            return(projectList);
        }
Beispiel #4
0
        private void CalculateReportData()
        {
            var user = ServiceContainer.Resolve <AuthManager> ().User;

            long max = 0;

            foreach (var s in dataObject.Activity)
            {
                max = max < s.TotalTime ? s.TotalTime : max;
            }

            _maxTotal = (int)Math.Ceiling(max / 3600f / 5f) * 5;

            _chartRowLabels = new List <string> ();
            foreach (var row in dataObject.Activity)
            {
                _chartRowLabels.Add(LabelForDate(row.StartTime));
            }

            _chartTimeLabels = new List <string> ();
            for (int i = 1; i <= 5; i++)
            {
                _chartTimeLabels.Add(String.Format("{0} h", _maxTotal / 5 * i));
            }

            dataObject.Projects.Sort((x, y) => y.TotalTime.CompareTo(x.TotalTime));
            collapsedProjects = new List <ReportProject> ();
            projects          = new List <ReportProject> ();

            var containerProject = new ReportProject {
                Currencies = new List <ReportCurrency>(),
                Color      = ProjectModel.GroupedProjectColorIndex
            };

            const float minimunWeight = 0.01f; // minimum weight of project respect to total time
            var         totalValue    = Convert.ToSingle(dataObject.Projects.Sum(p => p.TotalTime));
            int         count         = ProjectModel.GroupedProjectColorIndex;

            // group projects on one single project
            foreach (var item in dataObject.Projects)
            {
                if (Convert.ToSingle(item.TotalTime) / totalValue > minimunWeight)
                {
                    collapsedProjects.Add(item);
                }
                else
                {
                    containerProject.BillableTime += item.BillableTime;
                    containerProject.TotalTime    += item.TotalTime;

                    // group currencies
                    foreach (var currencyItem in item.Currencies)
                    {
                        var index = containerProject.Currencies.FindIndex(c => c.Currency == currencyItem.Currency);
                        if (index != -1)
                        {
                            containerProject.Currencies [index] = new ReportCurrency {
                                Amount   = containerProject.Currencies [index].Amount + currencyItem.Amount,
                                Currency = currencyItem.Currency
                            }
                        }
                        ;
                        else
                        {
                            containerProject.Currencies.Add(currencyItem);
                        }
                    }
                    count++;
                }
            }

            // check if small projects exists and are enough to be a separeted slice
            if (containerProject.TotalTime > 0 && Convert.ToSingle(containerProject.TotalTime) / totalValue > minimunWeight)
            {
                containerProject.Project = count.ToString();
                collapsedProjects.Add(containerProject);
                projects = new List <ReportProject> (collapsedProjects);
            }
            else
            {
                projects = new List <ReportProject> (dataObject.Projects);
            }

            // format total and billable time
            FormatTimeData(collapsedProjects, user);
            FormatTimeData(projects, user);
            FormatTimeData(dataObject.Projects, user);
        }
        private void CalculateReportData()
        {
            var user = ServiceContainer.Resolve<AuthManager> ().User;

            long max = 0;
            foreach (var s in dataObject.Activity) {
                max = max < s.TotalTime ? s.TotalTime : max;
            }

            _maxTotal = (int)Math.Ceiling (max / 3600f / 5f) * 5;

            _chartRowLabels = new List<string> ();
            foreach (var row in dataObject.Activity) {
                _chartRowLabels.Add (LabelForDate (row.StartTime));
            }

            _chartTimeLabels = new List<string> ();
            for (int i = 1; i <= 5; i++) {
                _chartTimeLabels.Add (String.Format ("{0} h", _maxTotal / 5 * i));
            }

            dataObject.Projects.Sort ((x, y) => y.TotalTime.CompareTo ( x.TotalTime));
            collapsedProjects = new List<ReportProject> ();
            projects = new List<ReportProject> ();

            var containerProject = new ReportProject {
                Currencies = new List<ReportCurrency>(),
                Color = ProjectModel.GroupedProjectColorIndex
            };

            const float minimunWeight = 0.01f; // minimum weight of project respect to total time
            var totalValue = Convert.ToSingle ( dataObject.Projects.Sum (p => p.TotalTime));
            int count = ProjectModel.GroupedProjectColorIndex;

            // group projects on one single project
            foreach (var item in dataObject.Projects) {
                if (Convert.ToSingle (item.TotalTime) / totalValue > minimunWeight) {
                    collapsedProjects.Add (item);
                } else {
                    containerProject.BillableTime += item.BillableTime;
                    containerProject.TotalTime += item.TotalTime;

                    // group currencies
                    foreach (var currencyItem in item.Currencies) {
                        var index = containerProject.Currencies.FindIndex (c => c.Currency == currencyItem.Currency);
                        if (index != -1)
                            containerProject.Currencies [index] = new ReportCurrency {
                            Amount = containerProject.Currencies [index].Amount + currencyItem.Amount,
                            Currency = currencyItem.Currency
                        };
                        else {
                            containerProject.Currencies.Add ( currencyItem);
                        }
                    }
                    count++;
                }
            }

            // check if small projects exists and are enough to be a separeted slice
            if (containerProject.TotalTime > 0 && Convert.ToSingle (containerProject.TotalTime) / totalValue > minimunWeight) {
                containerProject.Project = count.ToString();
                collapsedProjects.Add (containerProject);
                projects = new List<ReportProject> (collapsedProjects);
            } else {
                projects = new List<ReportProject> (dataObject.Projects);
            }

            // format total and billable time
            FormatTimeData (collapsedProjects, user);
            FormatTimeData (projects, user);
            FormatTimeData (dataObject.Projects, user);
            FormatActivityTimeData (dataObject.Activity, user);
        }
Beispiel #6
0
 private bool AreEquals(ReportProject a, ReportProject b)
 {
     return(false || a.TotalTime == b.TotalTime && string.Compare(a.Project, b.Project, StringComparison.Ordinal) == 0 && a.Color == b.Color);
 }