Ejemplo n.º 1
0
        private void GenerateGanttChartFromGraphCompilation()
        {
            lock (m_Lock)
            {
                GanttChart = null;
                IList <IDependentActivity <int, int> > dependentActivities =
                    GraphCompilation.DependentActivities
                    .Select(x => (IDependentActivity <int, int>)x.CloneObject())
                    .ToList();

                if (!HasCompilationErrors &&
                    dependentActivities.Any())
                {
                    List <IDependentActivity <int, int> > orderedActivities =
                        dependentActivities.OrderBy(x => x.EarliestStartTime)
                        .ThenBy(x => x.Duration)
                        .ToList();

                    ArrowGraphSettingsModel arrowGraphSettings = ArrowGraphSettings;
                    ResourceSeriesSetModel  resourceSeriesSet  = ResourceSeriesSet;

                    if (arrowGraphSettings != null &&
                        resourceSeriesSet != null)
                    {
                        GanttChart = new GanttChartModel
                        {
                            DependentActivities = m_Mapper.Map <List <IDependentActivity <int, int> >, List <DependentActivityModel> >(orderedActivities),
                            ResourceSeriesSet   = resourceSeriesSet,
                            IsStale             = false,
                        };
                    }
                }
            }
            PublishGanttChartDataUpdatedPayload();
        }
Ejemplo n.º 2
0
        public CostsModel CalculateProjectCosts(ResourceSeriesSetModel resourceSeriesSet)
        {
            if (resourceSeriesSet == null)
            {
                throw new ArgumentNullException(nameof(resourceSeriesSet));
            }

            var costs = new CostsModel();

            if (resourceSeriesSet.Combined.Any())
            {
                costs.DirectCost = resourceSeriesSet.Combined
                                   .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.Direct)
                                   .Sum(x => x.Values.Sum(y => y * x.UnitCost));
                costs.IndirectCost = resourceSeriesSet.Combined
                                     .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.Indirect)
                                     .Sum(x => x.Values.Sum(y => y * x.UnitCost));
                costs.OtherCost = resourceSeriesSet.Combined
                                  .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.None)
                                  .Sum(x => x.Values.Sum(y => y * x.UnitCost));
            }

            costs.TotalCost = costs.DirectCost + costs.IndirectCost + costs.OtherCost;
            return(costs);
        }
        private void GenerateGanttChart()
        {
            GanttChartAreaCtrl.ClearGantt();
            GanttChartModel ganttChart = ViewModel.GanttChart;

            if (ganttChart != null)
            {
                IList <DependentActivityModel> dependentActivities = ganttChart.DependentActivities;
                ResourceSeriesSetModel         resourceSeriesSet   = ganttChart.ResourceSeriesSet;

                m_DateTimeCalculator.UseBusinessDays(ViewModel.UseBusinessDays);

                DateTime projectStart = ViewModel.ProjectStart;

                DateTime minDate = DatePicker.SelectedDate ?? projectStart;
                DateTime maxDate = minDate.AddDays(DaysSelect.Value.GetValueOrDefault());
                GanttChartAreaCtrl.Initialize(minDate, maxDate);

                // Create timelines and define how they should be presented.
                GanttChartAreaCtrl.CreateTimeLine(new PeriodYearSplitter(minDate, maxDate), FormatYear);
                GanttChartAreaCtrl.CreateTimeLine(new PeriodMonthSplitter(minDate, maxDate), FormatMonth);
                TimeLine gridLineTimeLine = GanttChartAreaCtrl.CreateTimeLine(new PeriodDaySplitter(minDate, maxDate), FormatDay);
                //GanttChartAreaCtrl.CreateTimeLine(new PeriodDaySplitter(minDate, maxDate), FormatDayName);

                // Attach gridlines.
                GanttChartAreaCtrl.SetGridLinesTimeline(gridLineTimeLine, DetermineBackground);

                // Prep formatting helpers.
                SlackColorFormatLookup  colorFormatLookup  = null;
                ArrowGraphSettingsModel arrowGraphSettings = ViewModel.ArrowGraphSettings;

                if (arrowGraphSettings?.ActivitySeverities != null)
                {
                    colorFormatLookup = new SlackColorFormatLookup(arrowGraphSettings.ActivitySeverities);
                }

                if (GroupByResource.IsChecked.GetValueOrDefault())
                {
                    BuildGanttChart(dependentActivities.Select(x => x.Activity), resourceSeriesSet, projectStart, colorFormatLookup);
                }
                else
                {
                    BuildGanttChart(dependentActivities.Select(x => x.Activity), projectStart, colorFormatLookup);
                }
            }
        }
Ejemplo n.º 4
0
        private void BuildGanttChart(
            IEnumerable <ActivityModel> activities,
            ResourceSeriesSetModel resourceSeriesSet,
            DateTime projectStart,
            SlackColorFormatLookup colorFormatLookup)
        {
            if (activities == null || resourceSeriesSet?.Scheduled == null)
            {
                return;
            }

            IDictionary <int, ActivityModel> activityLookup = activities.ToDictionary(x => x.Id);

            foreach (ResourceSeriesModel resourceSeries in resourceSeriesSet.Scheduled)
            {
                ResourceScheduleModel resourceSchedule = resourceSeries.ResourceSchedule;

                if (resourceSchedule != null)
                {
                    GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup(resourceSeries.Title);

                    foreach (ScheduledActivityModel scheduledctivity in resourceSchedule.ScheduledActivities)
                    {
                        if (activityLookup.TryGetValue(scheduledctivity.Id, out ActivityModel activity))
                        {
                            string   name = string.IsNullOrWhiteSpace(scheduledctivity.Name) ? scheduledctivity.Id.ToString(CultureInfo.InvariantCulture) : scheduledctivity.Name;
                            GanttRow row  = GanttChartAreaCtrl.CreateGanttRow(rowGroup, name);

                            if (activity.EarliestStartTime.HasValue &&
                                activity.EarliestFinishTime.HasValue)
                            {
                                CheckRowErrors(activity, row);

                                GanttChartAreaCtrl.AddGanttTask(
                                    row,
                                    CreateGanttTask(projectStart, activity, colorFormatLookup));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private DataTable BuildResourceChartDataTable()
        {
            lock (m_Lock)
            {
                var table = new DataTable();
                ResourceSeriesSetModel resourceSeriesSet = ResourceSeriesSet;

                if (resourceSeriesSet != null)
                {
                    IEnumerable <ResourceSeriesModel> combinedResourceSeries = resourceSeriesSet.Combined.OrderBy(x => x.DisplayOrder);

                    if (combinedResourceSeries.Any())
                    {
                        table.Columns.Add(new DataColumn(Resource.ProjectPlan.Properties.Resources.Label_TimeAxisTitle));

                        // Create the column titles.
                        foreach (ResourceSeriesModel resourceSeries in combinedResourceSeries)
                        {
                            var column = new DataColumn(resourceSeries.Title, typeof(int));
                            table.Columns.Add(column);
                        }

                        m_DateTimeCalculator.UseBusinessDays(UseBusinessDays);

                        // Pivot the series values.
                        int valueCount = combinedResourceSeries.Max(x => x.Values.Count);
                        for (int timeIndex = 0; timeIndex < valueCount; timeIndex++)
                        {
                            var rowData = new List <object>
                            {
                                ChartHelper.FormatScheduleOutput(timeIndex, ShowDates, ProjectStart, m_DateTimeCalculator)
                            };
                            rowData.AddRange(combinedResourceSeries.Select(x => x.Values[timeIndex] * (ExportResourceChartAsCosts ? x.UnitCost : 1)).Cast <object>());
                            table.Rows.Add(rowData.ToArray());
                        }
                    }
                }

                return(table);
            }
        }
Ejemplo n.º 6
0
        private void CalculateResourceChartPlotModel()
        {
            lock (m_Lock)
            {
                ResourceSeriesSetModel resourceSeriesSet = ResourceSeriesSet;
                PlotModel plotModel = null;

                if (resourceSeriesSet != null)
                {
                    IEnumerable <ResourceSeriesModel> combinedResourceSeries = resourceSeriesSet.Combined.OrderBy(x => x.DisplayOrder);

                    if (combinedResourceSeries.Any())
                    {
                        plotModel = new PlotModel();
                        plotModel.Axes.Add(BuildResourceChartXAxis());
                        plotModel.Axes.Add(BuildResourceChartYAxis());
                        plotModel.LegendPlacement = LegendPlacement.Outside;
                        plotModel.LegendPosition  = LegendPosition.RightMiddle;

                        var total = new List <int>();
                        m_DateTimeCalculator.UseBusinessDays(UseBusinessDays);

                        foreach (ResourceSeriesModel series in combinedResourceSeries)
                        {
                            if (series != null)
                            {
                                var areaSeries = new AreaSeries
                                {
                                    //Smooth = false,
                                    StrokeThickness = 0.0,
                                    Title           = series.Title,
                                    Color           = OxyColor.FromArgb(
                                        series.ColorFormat.A,
                                        series.ColorFormat.R,
                                        series.ColorFormat.G,
                                        series.ColorFormat.B)
                                };
                                for (int i = 0; i < series.Values.Count; i++)
                                {
                                    int j = series.Values[i];
                                    if (i >= total.Count)
                                    {
                                        total.Add(0);
                                    }
                                    areaSeries.Points.Add(
                                        new DataPoint(ChartHelper.CalculateChartTimeXValue(i, ShowDates, ProjectStart, m_DateTimeCalculator),
                                                      total[i]));
                                    total[i] += j;
                                    areaSeries.Points2.Add(
                                        new DataPoint(ChartHelper.CalculateChartTimeXValue(i, ShowDates, ProjectStart, m_DateTimeCalculator),
                                                      total[i]));
                                }
                                plotModel.Series.Add(areaSeries);
                            }
                        }
                    }
                }
                ResourceChartPlotModel = plotModel;
            }
            RaiseCanExecuteChangedAllCommands();
        }
Ejemplo n.º 7
0
        public ResourceSeriesSetModel CalculateResourceSeriesSet(
            IEnumerable <ResourceScheduleModel> resourceSchedules,
            IEnumerable <ResourceModel> resources,
            double defaultUnitCost)
        {
            if (resourceSchedules == null)
            {
                throw new ArgumentNullException(nameof(resourceSchedules));
            }
            if (resources == null)
            {
                throw new ArgumentNullException(nameof(resources));
            }

            var resourceSeriesSet = new ResourceSeriesSetModel
            {
                Scheduled   = new List <ResourceSeriesModel>(),
                Unscheduled = new List <ResourceSeriesModel>(),
                Combined    = new List <ResourceSeriesModel>(),
            };
            var resourceLookup = resources.ToDictionary(x => x.Id);

            if (resourceSchedules.Any())
            {
                IDictionary <int, ColorFormatModel> colorFormatLookup = resources.ToDictionary(x => x.Id, x => x.ColorFormat);
                int finishTime         = resourceSchedules.Max(x => x.FinishTime);
                int spareResourceCount = 1;

                // Scheduled resource series.
                // These are the series that apply to scheduled activities (whether allocated to named or unnamed resources).
                var scheduledSeriesSet            = new List <ResourceSeriesModel>();
                var scheduledResourceSeriesLookup = new Dictionary <int, ResourceSeriesModel>();

                foreach (ResourceScheduleModel resourceSchedule in resourceSchedules)
                {
                    var series = new ResourceSeriesModel
                    {
                        ResourceSchedule            = resourceSchedule,
                        Values                      = resourceSchedule.ActivityAllocation.Select(x => x ? 1 : 0).ToList(),
                        InterActivityAllocationType = InterActivityAllocationType.None,
                    };

                    var stringBuilder = new StringBuilder();

                    if (resourceSchedule.Resource != null &&
                        resourceLookup.TryGetValue(resourceSchedule.Resource.Id, out ResourceModel resource))
                    {
                        int resourceId = resource.Id;
                        series.ResourceId = resourceId;
                        series.InterActivityAllocationType = resource.InterActivityAllocationType;
                        if (string.IsNullOrWhiteSpace(resource.Name))
                        {
                            stringBuilder.Append($@"{Resource.ProjectPlan.Resources.Label_Resource} {resourceId}");
                        }
                        else
                        {
                            stringBuilder.Append($@"{resource.Name}");
                        }
                        series.ColorFormat  = colorFormatLookup.ContainsKey(resourceId) ? colorFormatLookup[resourceId].CloneObject() : Randomize(new ColorFormatModel());
                        series.UnitCost     = resource.UnitCost;
                        series.DisplayOrder = resource.DisplayOrder;
                        scheduledResourceSeriesLookup.Add(resourceId, series);
                    }
                    else
                    {
                        stringBuilder.Append($@"{Resource.ProjectPlan.Resources.Label_Resource} {spareResourceCount}");
                        spareResourceCount++;
                        series.ColorFormat  = Randomize(new ColorFormatModel());
                        series.UnitCost     = defaultUnitCost;
                        series.DisplayOrder = 0;
                    }

                    series.Title = stringBuilder.ToString();
                    scheduledSeriesSet.Add(series);
                }

                // Unscheduled resource series.
                // These are the series that apply to named resources that need to be included, even if they are not
                // scheduled to specific activities.
                var unscheduledSeriesSet            = new List <ResourceSeriesModel>();
                var unscheduledResourceSeriesLookup = new Dictionary <int, ResourceSeriesModel>();

                IEnumerable <ResourceModel> unscheduledResources = resources
                                                                   .Where(x => x.InterActivityAllocationType == InterActivityAllocationType.Indirect);

                foreach (ResourceModel resource in unscheduledResources)
                {
                    int resourceId = resource.Id;
                    var series     = new ResourceSeriesModel
                    {
                        ResourceId = resourceId,
                        InterActivityAllocationType = resource.InterActivityAllocationType,
                        Values      = new List <int>(Enumerable.Repeat(1, finishTime)),
                        ColorFormat = resource.ColorFormat != null?resource.ColorFormat.CloneObject() : Randomize(new ColorFormatModel()),
                                          UnitCost     = resource.UnitCost,
                                          DisplayOrder = resource.DisplayOrder,
                    };

                    var stringBuilder = new StringBuilder();
                    if (string.IsNullOrWhiteSpace(resource.Name))
                    {
                        stringBuilder.Append($@"{Resource.ProjectPlan.Resources.Label_Resource} {resourceId}");
                    }
                    else
                    {
                        stringBuilder.Append($@"{resource.Name}");
                    }
                    series.Title = stringBuilder.ToString();

                    unscheduledSeriesSet.Add(series);
                    unscheduledResourceSeriesLookup.Add(resourceId, series);
                }

                // Combined resource series.
                // The intersection of the scheduled and unscheduled series.
                var combinedScheduled = new List <ResourceSeriesModel>();
                var unscheduledSeriesAlreadyIncluded = new HashSet <int>();

                foreach (ResourceSeriesModel scheduledSeries in scheduledSeriesSet)
                {
                    var values = new List <int>(Enumerable.Repeat(0, finishTime));
                    if (scheduledSeries.ResourceId.HasValue)
                    {
                        int resourceId = scheduledSeries.ResourceId.GetValueOrDefault();
                        if (unscheduledResourceSeriesLookup.TryGetValue(resourceId, out ResourceSeriesModel unscheduledResourceSeries))
                        {
                            values = scheduledSeries.Values.Zip(unscheduledResourceSeries.Values, (x, y) => Math.Max(x, y)).ToList();
                            unscheduledSeriesAlreadyIncluded.Add(resourceId);
                        }
                        else
                        {
                            values = scheduledSeries.Values.ToList();
                        }
                    }
                    else
                    {
                        values = scheduledSeries.Values.ToList();
                    }

                    scheduledSeries.Values = values;

                    combinedScheduled.Add(scheduledSeries);
                }

                // Finally, add the unscheduled series that have not already been included above.

                // Prepend so that they might be displayed first after sorting.
                List <ResourceSeriesModel> combined = unscheduledSeriesSet
                                                      .Where(x => !unscheduledSeriesAlreadyIncluded.Contains(x.ResourceId.GetValueOrDefault()))
                                                      .ToList();

                combined.AddRange(combinedScheduled);

                resourceSeriesSet.Scheduled.AddRange(scheduledSeriesSet);
                resourceSeriesSet.Unscheduled.AddRange(unscheduledSeriesSet);
                resourceSeriesSet.Combined.AddRange(combined.OrderBy(x => x.DisplayOrder));
            }

            return(resourceSeriesSet);
        }