public override TableDefinition Content(ReportData reportData, Dictionary <string, string> options)
        {
            var rowData = new List <string>();

            rowData.AddRange(new[] {
                " ",
                Labels.DebtRemoved + " (" + reportData.CurrencySymbol + ")",
                Labels.DebtAdded + " (" + reportData.CurrencySymbol + ")",
                Labels.Debt + " (" + reportData.CurrencySymbol + ")"
            });

            DataTable dtDates = new DataTable();

            dtDates.Columns.Add("Quarter", typeof(int));
            dtDates.Columns.Add("Year", typeof(int));
            dtDates.Columns.Add("RemovedTechnicalDebt", typeof(double));
            dtDates.Columns.Add("AddedTechnicalDebt", typeof(double));
            dtDates.Columns.Add("TotalTechnicalDebt", typeof(double));
            dtDates.AcceptChanges();

            #region Fetch SnapshotsPF

            if (reportData.Applications != null && reportData.Snapshots != null)
            {
                Snapshot[] _allSnapshots = reportData.Snapshots;

                int      generateQuater = 6;
                DateTime _dateNow       = DateTime.Now;
                int      currentYear    = _dateNow.Year;
                int      currentQuater  = DateUtil.GetQuarter(_dateNow);

                for (int i = generateQuater; i > 0; i--)
                {
                    DataRow dr = dtDates.NewRow();
                    dr["Quarter"] = currentQuater;
                    dr["Year"]    = currentYear;
                    dtDates.Rows.InsertAt(dr, 0);
                    currentYear   = DateUtil.GetPreviousQuarterYear(currentQuater, currentYear);
                    currentQuater = DateUtil.GetPreviousQuarter(currentQuater);
                }

                for (int i = 0; i < dtDates.Rows.Count; i++)
                {
                    double?_removedTechnicalDebt = 0;
                    double?_addedTechnicalDebt   = 0;
                    double?_totalTechnicalDebt   = 0;

                    if (_allSnapshots.Length > 0)
                    {
                        foreach (Snapshot snapshot in _allSnapshots.OrderBy(_ => _.Annotation.Date.DateSnapShot))
                        {
                            if (snapshot.Annotation.Date.DateSnapShot == null)
                            {
                                continue;
                            }
                            DateTime _snapshotDate = Convert.ToDateTime(snapshot.Annotation.Date.DateSnapShot.Value);

                            int intQuarter = Convert.ToInt32(dtDates.Rows[i]["Quarter"]);
                            int intYear    = Convert.ToInt32(dtDates.Rows[i]["Year"]);

                            int intSnapshotQuarter = DateUtil.GetQuarter(_snapshotDate);
                            int intSnapshotYear    = _snapshotDate.Year;

                            if (intQuarter != intSnapshotQuarter || intYear != intSnapshotYear)
                            {
                                continue;
                            }
                            _removedTechnicalDebt = _removedTechnicalDebt + MeasureUtility.GetRemovedTechDebtMetric(snapshot);
                            _addedTechnicalDebt   = _addedTechnicalDebt + MeasureUtility.GetAddedTechDebtMetric(snapshot);
                            _totalTechnicalDebt   = _totalTechnicalDebt + MeasureUtility.GetTechnicalDebtMetric(snapshot);
                        }
                    }

                    dtDates.Rows[i]["RemovedTechnicalDebt"] = _removedTechnicalDebt * -1;
                    dtDates.Rows[i]["AddedTechnicalDebt"]   = _addedTechnicalDebt;
                    dtDates.Rows[i]["TotalTechnicalDebt"]   = _totalTechnicalDebt;
                }

                for (int i = 0; i < dtDates.Rows.Count; i++)
                {
                    string strQuarter = dtDates.Rows[i]["Year"] + " Q" + dtDates.Rows[i]["Quarter"];
                    rowData.Add(strQuarter);
                    rowData.Add(dtDates.Rows[i]["RemovedTechnicalDebt"].ToString());
                    rowData.Add(dtDates.Rows[i]["AddedTechnicalDebt"].ToString());
                    rowData.Add(dtDates.Rows[i]["TotalTechnicalDebt"].ToString());
                }
            }
            #endregion Fetch SnapshotsPF

            TableDefinition resultTable = new TableDefinition
            {
                HasRowHeaders    = true,
                HasColumnHeaders = false,
                NbRows           = dtDates.Rows.Count + 1,
                NbColumns        = 4,
                Data             = rowData,
                GraphOptions     = null
            };
            return(resultTable);
        }
Пример #2
0
        protected override TableDefinition Content(ReportData reportData, Dictionary <string, string> options)
        {
            int count = 0;

            var rowData = new List <String>();

            rowData.AddRange(new string[] {
                " ",
                Labels.DebtRemoved + " (" + reportData.CurrencySymbol + ")",
                Labels.DebtAdded + " (" + reportData.CurrencySymbol + ")",
                Labels.Debt + " (" + reportData.CurrencySymbol + ")"
            });

            #region Fetch Snapshots
            int nbSnapshots = (reportData != null && reportData.Application != null) ? reportData.Application.Snapshots.Count() : 0;
            if (nbSnapshots > 0)
            {
                foreach (Snapshot snapshot in reportData.Application.Snapshots.OrderBy(_ => _.Annotation.Date.DateSnapShot))
                {
                    double?prevDoubleSnapshotDate   = snapshot.Annotation.Date.DateSnapShot.HasValue ? snapshot.Annotation.Date.DateSnapShot.Value.ToOADate() : 0;
                    double?prevRemovedTechDebtValue = MeasureUtility.GetRemovedTechDebtMetric(snapshot);
                    double?prevAddedTechDebtValue   = MeasureUtility.GetAddedTechDebtMetric(snapshot);
                    double?prevTotalTechDebtValue   = MeasureUtility.GetTechnicalDebtMetric(snapshot);
                    rowData.AddRange(new string[] {
                        prevDoubleSnapshotDate.GetValueOrDefault().ToString(),
                        prevRemovedTechDebtValue.GetValueOrDefault().ToString(),
                        prevAddedTechDebtValue.GetValueOrDefault().ToString(),
                        prevTotalTechDebtValue.GetValueOrDefault().ToString(),
                    });
                }
                count = nbSnapshots;
            }
            #endregion Previous Snapshots

            #region just 1 snapshot
            if (reportData.Application != null &&
                reportData.Application.Snapshots != null &&
                nbSnapshots == 1 &&
                reportData.CurrentSnapshot != null)
            {
                double?prevDoubleSnapshotDate   = reportData.CurrentSnapshot.Annotation.Date.DateSnapShot.HasValue ? reportData.CurrentSnapshot.Annotation.Date.DateSnapShot.Value.ToOADate() : 0;
                double?prevRemovedTechDebtValue = MeasureUtility.GetRemovedTechDebtMetric(reportData.CurrentSnapshot);
                double?prevAddedTechDebtValue   = MeasureUtility.GetAddedTechDebtMetric(reportData.CurrentSnapshot);
                double?prevTotalTechDebtValue   = MeasureUtility.GetTechnicalDebtMetric(reportData.CurrentSnapshot);
                rowData.AddRange(new string[] {
                    prevDoubleSnapshotDate.GetValueOrDefault().ToString(),
                    prevRemovedTechDebtValue.GetValueOrDefault().ToString(),
                    prevAddedTechDebtValue.GetValueOrDefault().ToString(),
                    prevTotalTechDebtValue.GetValueOrDefault().ToString(),
                });
                count = count + 1;
            }
            #endregion just 1 snapshot



            TableDefinition resultTable = new TableDefinition {
                HasRowHeaders    = true,
                HasColumnHeaders = false,
                NbRows           = count + 1,
                NbColumns        = 4,
                Data             = rowData,
                GraphOptions     = null
            };
            return(resultTable);
        }
        protected override TableDefinition Content(ReportData reportData, Dictionary <string, string> options)
        {
            var rowData = new List <String>();

            rowData.AddRange(new string[] {
                " ",
                Labels.DebtRemoved + " (" + reportData.CurrencySymbol + ")",
                Labels.DebtAdded + " (" + reportData.CurrencySymbol + ")",
                Labels.Debt + " (" + reportData.CurrencySymbol + ")"
            });

            DataTable dtDates = new DataTable();

            dtDates.Columns.Add("Quarter", typeof(int));
            dtDates.Columns.Add("Year", typeof(int));
            dtDates.Columns.Add("RemovedTechnicalDebt", typeof(double));
            dtDates.Columns.Add("AddedTechnicalDebt", typeof(double));
            dtDates.Columns.Add("TotalTechnicalDebt", typeof(double));
            dtDates.AcceptChanges();

            #region Fetch SnapshotsPF

            if (reportData != null && reportData.Applications != null && reportData.snapshots != null)
            {
                DateTime DateNow = DateTime.Now;
                //DateTime DateNow = Convert.ToDateTime("03 01 2014");
                Application[] AllApps        = reportData.Applications;
                Snapshot[]    AllSnapshots   = reportData.snapshots;
                int           generateQuater = 6;
                int           currentYear    = DateNow.Year;
                int           currentQuater  = GetQuarter(DateNow);
                for (int i = generateQuater; i > 0; i--)
                {
                    DataRow dr = dtDates.NewRow();
                    dr["Quarter"] = currentQuater;
                    dr["Year"]    = currentYear;
                    dtDates.Rows.InsertAt(dr, 0);
                    //dtDates.Rows.Add(currentQuater, currentYear);
                    if (--currentQuater == 0)
                    {
                        currentQuater = 4;
                        currentYear--;
                    }
                }

                double?RemovedTechnicalDebt = 0;
                double?AddedTechnicalDebt   = 0;
                double?TotalTechnicalDebt   = 0;

                for (int i = 0; i < dtDates.Rows.Count; i++)
                {
                    RemovedTechnicalDebt = 0;
                    AddedTechnicalDebt   = 0;
                    TotalTechnicalDebt   = 0;

                    if (AllSnapshots.Count() > 0)
                    {
                        foreach (Snapshot snapshot in AllSnapshots.OrderBy(_ => _.Annotation.Date.DateSnapShot))
                        {
                            DateTime SnapshotDate = Convert.ToDateTime(snapshot.Annotation.Date.DateSnapShot.Value);

                            int intQuarter = Convert.ToInt32(dtDates.Rows[i]["Quarter"]);
                            int intYear    = Convert.ToInt32(dtDates.Rows[i]["Year"]);

                            int intSnapshotQuarter = GetQuarter(SnapshotDate);
                            int intSnapshotYear    = SnapshotDate.Year;

                            if (intQuarter == intSnapshotQuarter && intYear == intSnapshotYear)
                            {
                                RemovedTechnicalDebt = RemovedTechnicalDebt + MeasureUtility.GetRemovedTechDebtMetric(snapshot);
                                AddedTechnicalDebt   = AddedTechnicalDebt + MeasureUtility.GetAddedTechDebtMetric(snapshot);
                                TotalTechnicalDebt   = TotalTechnicalDebt + MeasureUtility.GetTechnicalDebtMetric(snapshot);
                            }
                        }
                    }

                    if (RemovedTechnicalDebt > 0)
                    {
                        RemovedTechnicalDebt = RemovedTechnicalDebt * -1;
                    }

                    if (RemovedTechnicalDebt != null)
                    {
                        dtDates.Rows[i]["RemovedTechnicalDebt"] = RemovedTechnicalDebt;
                    }
                    else
                    {
                        dtDates.Rows[i]["RemovedTechnicalDebt"] = 0.0;
                    }

                    if (AddedTechnicalDebt != null)
                    {
                        dtDates.Rows[i]["AddedTechnicalDebt"] = AddedTechnicalDebt;
                    }
                    else
                    {
                        dtDates.Rows[i]["AddedTechnicalDebt"] = 0.0;
                    }

                    if (TotalTechnicalDebt != null)
                    {
                        dtDates.Rows[i]["TotalTechnicalDebt"] = TotalTechnicalDebt;
                    }
                    else
                    {
                        dtDates.Rows[i]["TotalTechnicalDebt"] = 0.0;
                    }
                }

                for (int i = 0; i < dtDates.Rows.Count; i++)
                {
                    string strQuarter = dtDates.Rows[i]["Year"].ToString() + " Q" + dtDates.Rows[i]["Quarter"].ToString();
                    rowData.AddRange(new string[] {
                        strQuarter,
                        dtDates.Rows[i]["RemovedTechnicalDebt"].ToString(),
                        dtDates.Rows[i]["AddedTechnicalDebt"].ToString(),
                        dtDates.Rows[i]["TotalTechnicalDebt"].ToString(),
                    });
                }
            }
            #endregion Fetch SnapshotsPF



            TableDefinition resultTable = new TableDefinition
            {
                HasRowHeaders    = true,
                HasColumnHeaders = false,
                NbRows           = dtDates.Rows.Count + 1,
                NbColumns        = 4,
                Data             = rowData,
                GraphOptions     = null
            };
            return(resultTable);
        }