public async Task <ProductScoreCard> GetProductScoreCard(string productCode)
        {
            var product = await _ctx.Products.FirstOrDefaultAsync(p => p.Code == productCode);

            if (product == null)
            {
                return(new ProductScoreCard(productCode, "NA", new ProductScoreCardRow[0]));
            }
            var functions = await _ctx.Nodes.Active().ByProductCode(product.Code)
                            .Select(p => new { p.Function.Id, p.Function.Name }).Distinct().ToDictionaryAsync(p => p.Id, p => p.Name);

            var list = new List <ProductScoreCardRow>();

            foreach (var function in functions.Keys)
            {
                var allByFunc = _ctx.Nodes.Active().ByFunction(productCode, function);
                if (await allByFunc.AnyAsync())
                {
                    var owners = await allByFunc.Select(p => p.Owner).Distinct().ToDictionaryAsync(p => p.Id, p => p);

                    foreach (var owner in owners.Keys)
                    {
                        var all = _ctx.Nodes.Active().ByFunction(productCode, function).ByOwner(owner);

                        var an    = all.Assigned();
                        var apn   = an.InPciScope();
                        var specs = await an.Select(p => p.BuildSpecificationId).Distinct().CountAsync();

                        var assigned = new ScoreCardPciCount(await apn.CountAsync(), await an.CountAsync());
                        var passing  = new ScoreCardPciCount(
                            await apn.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync(),
                            await an.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync());
                        var failing = new ScoreCardPciCount(
                            await apn.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync(),
                            await an.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync());
                        var notReporting = new ScoreCardPciCount(
                            await apn.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope()
                            .CountAsync(),
                            await an.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope()
                            .CountAsync());
                        var outOfChefScope = new ScoreCardPciCount(
                            await apn.OutOfChefScope()
                            .CountAsync(),
                            await an.OutOfChefScope()
                            .CountAsync());
                        var allNodes =
                            new ScoreCardPciCount(await all.InPciScope().CountAsync(), await all.CountAsync());

                        var row = new ProductScoreCardRow(function, functions[function], owners[owner].Id,
                                                          owners[owner].OwnerText(false), owners[owner].ReportingDirectorId,
                                                          owners[owner].ReportingDirector.OwnerText(false), specs, allNodes, assigned,
                                                          passing, failing, notReporting, outOfChefScope);
                        list.Add(row);
                    }
                }
            }

            return(new ProductScoreCard(product.Code, product.Name, list.ToArray()));
        }
示例#2
0
 public ExecutiveScoreCardRow(long employeeId, string name, int specCount, ScoreCardPciCount assignedNodes, ScoreCardPciCount totalNodesInInventory, ScoreCardPciCount passingNodes, ScoreCardPciCount failingNodes, ScoreCardPciCount notReportingNodes, ScoreCardPciCount outOfScopeNodes, int directReportCount)
 {
     EmployeeId            = employeeId;
     Name                  = name;
     SpecCount             = specCount;
     AssignedNodes         = assignedNodes;
     TotalNodesInInventory = totalNodesInInventory;
     PassingNodes          = passingNodes;
     FailingNodes          = failingNodes;
     NotReportingNodes     = notReportingNodes;
     OutOfScopeNodes       = outOfScopeNodes;
     DirectReportCount     = directReportCount;
 }
 public Status(ScoreCardPciCount passing, ScoreCardPciCount failingCompliance, ScoreCardPciCount unassigned, ScoreCardPciCount notReporting, ScoreCardPciCount unix, ScoreCardPciCount osOther, ScoreCardPciCount appliance, ScoreCardPciCount productExcluded)
 {
     Passing           = passing;
     FailingCompliance = failingCompliance;
     Unassigned        = unassigned;
     NotReporting      = notReporting;
     OutOfScope        = unix + osOther + appliance + productExcluded;
     Unix                  = unix;
     OsOther               = osOther;
     Applicance            = appliance;
     ProductExcluded       = productExcluded;
     TotalFailing          = FailingCompliance + NotReporting + Unassigned;
     InScope               = Passing + TotalFailing;
     PercentPassingInScope = Passing / InScope;
 }
 public ProductScoreCardRow(int functionId, string function, long ownerId, string owner, long?directorId, string director, int specCount, ScoreCardPciCount allNodes, ScoreCardPciCount assignedNodes, ScoreCardPciCount passingNodes, ScoreCardPciCount failingNodes, ScoreCardPciCount notReportingNodes, ScoreCardPciCount outOfChefScopeNodes)
 {
     FunctionId          = functionId;
     Function            = function;
     OwnerId             = ownerId;
     Owner               = owner;
     DirectorId          = directorId;
     Director            = director;
     SpecCount           = specCount;
     AllNodes            = allNodes;
     AssignedNodes       = assignedNodes;
     PassingNodes        = passingNodes;
     FailingNodes        = failingNodes;
     NotReportingNodes   = notReportingNodes;
     OutOfChefScopeNodes = outOfChefScopeNodes;
     UnassignedNodes     = allNodes - assignedNodes;
 }
        public async Task <DirectorScoreCard> GetDirectorScoreCard()
        {
            var directors = (await _ctx.Nodes.Active().Where(p => p.Owner.ReportingDirectorId != null)
                             .Select(p => p.Owner.ReportingDirector).Distinct()
                             .OrderBy(p => p.PreferredName ?? p.FirstName).ThenBy(p => p.LastName).ToArrayAsync())
                            .ToDictionary(p => p.Id, p => p);

            directors.Add(-1,
                          new Employee
            {
                Id            = -1,
                FirstName     = string.Empty,
                LastName      = string.Empty,
                PreferredName = "(Not Found)"
            });
            var list = new List <DirectorScoreCardRow>();

            foreach (var director in directors.Keys)
            {
                var owners = await _ctx.Nodes.ByDirector(director == -1?null : (int?)director).Select(p => p.Owner)
                             .Distinct().ToDictionaryAsync(p => p.Id, p => p);

                foreach (var owner in owners.Keys)
                {
                    var all = _ctx.Nodes.Active().ByOwner(owner).ProductIsNotExlcuded();
                    if (await all.AnyAsync())
                    {
                        var an    = all.Assigned();
                        var apn   = an.InPciScope();
                        var specs = await an.Select(p => p.BuildSpecificationId).Distinct().CountAsync();

                        var assigned = new ScoreCardPciCount(await apn.CountAsync(), await an.CountAsync());
                        var passing  = new ScoreCardPciCount(
                            await apn.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync(),
                            await an.ByComplianceStatus(ComplianceStatusConstant.Succeeded).InChefScope().CountAsync());
                        var failing = new ScoreCardPciCount(
                            await apn.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync(),
                            await an.ByComplianceStatus(ComplianceStatusConstant.Failed).InChefScope().CountAsync());
                        var notReporting = new ScoreCardPciCount(
                            await apn.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope()
                            .CountAsync(),
                            await an.ByComplianceStatus(ComplianceStatusConstant.NotFound).InChefScope()
                            .CountAsync());
                        var outOfChefScope = new ScoreCardPciCount(
                            await apn.OutOfChefScope()
                            .CountAsync(),
                            await an.OutOfChefScope()
                            .CountAsync());
                        var allNodes =
                            new ScoreCardPciCount(await all.InPciScope().CountAsync(), await all.CountAsync());

                        var row = new DirectorScoreCardRow(owners[owner].Id,
                                                           owners[owner].OwnerText(false), directors[director].Id,
                                                           directors[director].OwnerText(false), specs, assigned,
                                                           passing, failing, notReporting, outOfChefScope, allNodes);
                        list.Add(row);
                    }
                }
            }

            return(new DirectorScoreCard(list.ToArray()));
        }