Ejemplo n.º 1
0
    public void SetStats(metricType metric, string value)
    {
        switch (metric)
        {
        case metricType.play:
            if (playsText != null)
            {
                playsText.text = value;
            }
            break;

        case metricType.vote:
            if (votesText != null)
            {
                votesText.text = value;
            }
            break;

        case metricType.win:
            if (winsText != null)
            {
                winsText.text = value;
            }
            break;
        }
    }
Ejemplo n.º 2
0
    public static void AddBoardMetric(metricType metric)
    {
        if (State.gameBoardID == "" || State.gameBoardIdentityID == "")
        {
            return;
        }

        // Retrieve the ddbBoard
        BoardDDB ddbBoard = new BoardDDB();

        Context.LoadAsync <BoardDDB>(State.gameBoardIdentityID, State.gameBoardID, (result) =>
        {
            if (result.Exception == null)
            {
                ddbBoard = result.Result as BoardDDB;

                switch (metric)
                {
                case metricType.vote:
                    // votes will be negative so we can sort-descending with most-voted first
                    ddbBoard.Votes_D         = ddbBoard.Votes_D - 1;
                    ddbBoard.Votes_A         = ddbBoard.Votes_A + 1;
                    ddbBoard.VotesPlaysRatio = Math.Abs(ddbBoard.Votes_A) / (float)Math.Abs(ddbBoard.Plays_A);
                    break;

                case metricType.play:
                    // plays will be positive so we can sort-ascending with least-played first
                    ddbBoard.Plays_D         = ddbBoard.Plays_D - 1;
                    ddbBoard.Plays_A         = ddbBoard.Plays_A + 1;
                    ddbBoard.VotesPlaysRatio = Math.Abs(ddbBoard.Votes_A) / (float)Math.Abs(ddbBoard.Plays_A);
                    ddbBoard.WinsPlaysRatio  = Math.Abs(ddbBoard.Wins_A) / (float)Math.Abs(ddbBoard.Plays_A);
                    break;

                case metricType.win:
                    // wins will be positive so we can sort-ascending with least-won first
                    ddbBoard.Wins_D         = ddbBoard.Wins_D - 1;
                    ddbBoard.Wins_A         = ddbBoard.Wins_A - 1;
                    ddbBoard.WinsPlaysRatio = Math.Abs(ddbBoard.Wins_A) / (float)Math.Abs(ddbBoard.Plays_A);
                    break;
                }

                Context.SaveAsync <BoardDDB>(ddbBoard, (res) =>
                {
                    if (res.Exception == null)
                    {
                        Debug.Log("User board metric " + metric + " incremented.");
                    }
                });
            }
        });
    }
Ejemplo n.º 3
0
        /// <summary>
        /// This method return the name, type and result (grade or value) of the metric from getting it in the results of the snapshot
        /// The metric id can be a BC, TC, QR, sizing or background fact measure
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="snapshot"></param>
        /// <param name="metricId"></param>
        /// <param name="module"></param>
        /// <param name="technology"></param>
        /// <param name="format"></param> should be false for graph component
        /// <returns></returns>
        public static SimpleResult GetMetricNameAndResult(ReportData reportData, Snapshot snapshot, string metricId, Module module, string technology, bool format)
        {
            metricType type     = metricType.NotKnown;
            Result     bfResult = null;
            double?    result   = null;
            string     resStr   = string.Empty;

            string name = snapshot.BusinessCriteriaResults.Where(_ => _.Reference.Key == int.Parse(metricId)).Select(_ => _.Reference.Name).FirstOrDefault();

            if (name != null)
            {
                type = metricType.BusinessCriteria;
            }
            // if metricId is not a Business Criteria
            if (name == null)
            {
                name = snapshot.TechnicalCriteriaResults.Where(_ => _.Reference.Key == int.Parse(metricId)).Select(_ => _.Reference.Name).FirstOrDefault();
                if (name != null)
                {
                    type = metricType.TechnicalCriteria;
                }
            }
            // if metricId is not a technical criteria
            if (name == null)
            {
                name = snapshot.QualityRulesResults.Where(_ => _.Reference.Key == int.Parse(metricId)).Select(_ => _.Reference.Name).FirstOrDefault();
                if (name != null)
                {
                    type = metricType.QualityRule;
                }
            }
            // if metricId is not a quality rule
            if (name == null)
            {
                name = snapshot.SizingMeasuresResults.Where(_ => _.Reference.Key == int.Parse(metricId)).Select(_ => _.Reference.Name).FirstOrDefault();
                if (name != null)
                {
                    type = metricType.SizingMeasure;
                }
            }
            // if metricId is not a sizing measure, perhaps a background fact
            if (name == null)
            {
                bfResult = reportData.SnapshotExplorer.GetBackgroundFacts(snapshot.Href, metricId, true, true).FirstOrDefault();
                if (bfResult == null || !bfResult.ApplicationResults.Any())
                {
                    return(null);
                }
                name = bfResult.ApplicationResults[0].Reference.Name;
                if (name != null)
                {
                    type = metricType.BackgroundFact;
                }
            }
            // we don't know what is this metric
            if (name == null)
            {
                return(null);
            }

            switch (type)
            {
            case metricType.BusinessCriteria:
                if (module == null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.BusinessCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId))
                             .Select(_ => _.DetailResult.Grade).FirstOrDefault();
                }
                else if (module != null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.BusinessCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.DetailResult != null)?.DetailResult.Grade;
                }
                else if (module == null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.BusinessCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.TechnologyResult != null)
                             .SelectMany(_ => _.TechnologyResult)
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Grade;
                }
                else if (module != null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.BusinessCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.TechnologyResults != null)?.TechnologyResults
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Grade;
                }
                resStr = result?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                break;

            case metricType.TechnicalCriteria:
                if (module == null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.TechnicalCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId))
                             .Select(_ => _.DetailResult.Grade).FirstOrDefault();
                }
                else if (module != null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.TechnicalCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.DetailResult != null)?.DetailResult.Grade;
                }
                else if (module == null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.TechnicalCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.TechnologyResult != null)
                             .SelectMany(_ => _.TechnologyResult)
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Grade;
                }
                else if (module != null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.TechnicalCriteriaResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.TechnologyResults != null)?.TechnologyResults
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Grade;
                }
                resStr = result?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                break;

            case metricType.QualityRule:
                if (module == null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.QualityRulesResults?.Where(_ => _.Reference.Key == int.Parse(metricId))
                             .Select(_ => _.DetailResult.Grade).FirstOrDefault();
                }
                else if (module != null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.QualityRulesResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.DetailResult != null)?.DetailResult.Grade;
                }
                else if (module == null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.QualityRulesResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.TechnologyResult != null)
                             .SelectMany(_ => _.TechnologyResult)
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Grade;
                }
                else if (module != null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.QualityRulesResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.TechnologyResults != null)?.TechnologyResults
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Grade;
                }
                resStr = result?.ToString("N2") ?? (format ? Constants.No_Value : "0");

                break;

            case metricType.SizingMeasure:
                if (module == null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.SizingMeasuresResults?.Where(_ => _.Reference.Key == int.Parse(metricId))
                             .Select(_ => _.DetailResult.Value).FirstOrDefault();
                }
                else if (module != null && string.IsNullOrEmpty(technology))
                {
                    result = snapshot.SizingMeasuresResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.DetailResult != null)?.DetailResult.Value;
                }
                else if (module == null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.SizingMeasuresResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.TechnologyResult != null)
                             .SelectMany(_ => _.TechnologyResult)
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Value;
                }
                else if (module != null && !string.IsNullOrEmpty(technology))
                {
                    result = snapshot.SizingMeasuresResults?.Where(_ => _.Reference.Key == int.Parse(metricId) && _.ModulesResult != null)
                             .SelectMany(_ => _.ModulesResult)
                             .FirstOrDefault(_ => _.Module.Id == module.Id && _.TechnologyResults != null)?.TechnologyResults
                             .FirstOrDefault(_ => _.Technology == technology && _.DetailResult != null)?.DetailResult.Value;
                }
                resStr = format ? result?.ToString("N0") ?? Constants.No_Value : result?.ToString() ?? "0";
                break;

            case metricType.BackgroundFact:
                if (module == null && string.IsNullOrEmpty(technology))
                {
                    result = bfResult?.ApplicationResults[0].DetailResult.Value;
                }
                else if (module != null && string.IsNullOrEmpty(technology))
                {
                    result = bfResult?.ApplicationResults[0].ModulesResult.FirstOrDefault(_ => _.Module.Id == module.Id)?
                             .DetailResult.Value;
                }
                else if (module == null && !string.IsNullOrEmpty(technology))
                {
                    result = bfResult?.ApplicationResults[0].TechnologyResult.FirstOrDefault(_ => _.Technology == technology)?
                             .DetailResult.Value;
                }
                else if (module != null && !string.IsNullOrEmpty(technology))
                {
                    result = bfResult?.ApplicationResults[0].ModulesResult.FirstOrDefault(_ => _.Module.Id == module.Id)?
                             .TechnologyResults.FirstOrDefault(_ => _.Technology == technology)?
                             .DetailResult.Value;
                }
                resStr = format ? result?.ToString("N0") ?? Constants.No_Value : result?.ToString() ?? "0";
                break;

            case metricType.NotKnown:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (metricType.QualityRule == type)
            {
                name = name + " (" + metricId + ")";
            }
            SimpleResult res = new SimpleResult {
                name = name, type = type, result = result, resultStr = resStr
            };

            return(res);
        }
Ejemplo n.º 4
0
        public static SimpleResult GetAggregatedMetric(ReportData reportData, Dictionary <Application, Snapshot> lastSnapshotList, string metricId, string techno, string aggregator, bool format)
        {
            List <SimpleResult> results = new List <SimpleResult>();

            foreach (Application application in reportData.Applications)
            {
                Snapshot appCurSnap;
                try
                {
                    appCurSnap = lastSnapshotList[application];
                }
                catch (KeyNotFoundException)
                {
                    appCurSnap = null;
                }
                SimpleResult appRes = GetMetricNameAndResult(reportData, appCurSnap, metricId, null, techno, format);
                results.Add(appRes);
            }

            string metName = results.FirstOrDefault()?.name;

            if (metName == null)
            {
                return(null);
            }

            metricType metType = results.FirstOrDefault()?.type ?? metricType.NotKnown;

            double?curResult = 0;

            if (string.IsNullOrEmpty(aggregator))
            {
                switch (metType)
                {
                case metricType.QualityRule:
                case metricType.TechnicalCriteria:
                case metricType.BusinessCriteria:
                    aggregator = "AVERAGE";
                    break;

                case metricType.SizingMeasure:
                case metricType.BackgroundFact:
                    aggregator = "SUM";
                    break;
                }
            }

            switch (aggregator)
            {
            case "SUM":
                foreach (var _result in results)
                {
                    curResult = _result.result != null ? curResult + _result.result : curResult;
                }
                break;

            case "AVERAGE":
                int nbCurRes = 0;
                foreach (var _result in results)
                {
                    if (_result.result == null)
                    {
                        continue;
                    }
                    curResult = curResult + _result.result;
                    nbCurRes++;
                }
                curResult = nbCurRes != 0 ? curResult / nbCurRes : null;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // format curResult and prevResult in case of metricType
            string res;

            switch (metType)
            {
            case metricType.BusinessCriteria:
            case metricType.TechnicalCriteria:
            case metricType.QualityRule:
                res = curResult?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                break;

            case metricType.SizingMeasure:
            case metricType.BackgroundFact:
                res = format ? curResult?.ToString("N0") ?? Constants.No_Value : curResult?.ToString() ?? "0";
                break;

            case metricType.NotKnown:
                res = curResult?.ToString() ?? (format ? Constants.No_Value : "0");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new SimpleResult
            {
                name = metName,
                type = metType,
                resultStr = res
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This method return the evolution of a metric between 2 snapshots results (name, type, current result, previous result, absolute evolution and percent evolution
        /// The metric id can be a BC, TC, QR, sizing or background fact measure
        /// </summary>
        /// <param name="reportData"></param>
        /// <param name="curSnapshot"></param>
        /// <param name="prevSnapshot"></param>
        /// <param name="metricId"></param>
        /// <param name="evol"></param>
        /// <param name="module"></param>
        /// <param name="technology"></param>
        /// <param name="format"></param> format is true for table component and false for graph component
        /// <returns></returns>
        public static EvolutionResult GetMetricEvolution(ReportData reportData, Snapshot curSnapshot, Snapshot prevSnapshot, string metricId, bool evol, Module module, string technology, bool format)
        {
            SimpleResult curResult  = null;
            SimpleResult prevResult = null;

            if (curSnapshot != null)
            {
                curResult = GetMetricNameAndResult(reportData, curSnapshot, metricId, module, technology, format);
            }
            if (prevSnapshot != null)
            {
                prevResult = GetMetricNameAndResult(reportData, prevSnapshot, metricId, module, technology, format);
            }
            if (!evol && (curResult?.result != null || prevResult?.result != null))
            {
                string     name    = curResult?.name ?? prevResult?.name ?? Constants.No_Value;
                metricType type    = curResult?.type ?? prevResult?.type ?? metricType.NotKnown;
                string     curRes  = format ? Constants.No_Value : "0";
                string     prevRes = format ? Constants.No_Value : "0";
                switch (type)
                {
                case metricType.BusinessCriteria:
                case metricType.TechnicalCriteria:
                case metricType.QualityRule:
                    curRes  = curResult?.result?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                    prevRes = prevResult?.result?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                    break;

                case metricType.SizingMeasure:
                case metricType.BackgroundFact:
                    if (format)
                    {
                        curRes  = curResult?.result?.ToString("N0") ?? Constants.No_Value;
                        prevRes = prevResult?.result?.ToString("N0") ?? Constants.No_Value;
                    }
                    else
                    {
                        curRes  = curResult?.result?.ToString() ?? "0";
                        prevRes = prevResult?.result?.ToString() ?? "0";
                    }
                    break;

                case metricType.NotKnown:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                return(new EvolutionResult
                {
                    name = name,
                    type = type,
                    curResult = curRes,
                    prevResult = prevRes,
                    evolution = format ? Constants.No_Value : "0",
                    evolutionPercent = format ? Constants.No_Value : "0"
                });
            }

            if (curResult?.result == null || prevResult?.result == null)
            {
                string     name    = curResult?.name ?? prevResult?.name ?? Constants.No_Value;
                metricType type    = curResult?.type ?? prevResult?.type ?? metricType.NotKnown;
                string     curRes  = format ? Constants.No_Value : "0";
                string     prevRes = format ? Constants.No_Value : "0";
                switch (type)
                {
                case metricType.BusinessCriteria:
                case metricType.TechnicalCriteria:
                case metricType.QualityRule:
                    curRes  = curResult?.result?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                    prevRes = prevResult?.result?.ToString("N2") ?? (format ? Constants.No_Value : "0");
                    break;

                case metricType.SizingMeasure:
                case metricType.BackgroundFact:
                    if (format)
                    {
                        curRes  = curResult?.result?.ToString("N0") ?? Constants.No_Value;
                        prevRes = prevResult?.result?.ToString("N0") ?? Constants.No_Value;
                    }
                    else
                    {
                        curRes  = curResult?.result?.ToString() ?? "0";
                        prevRes = prevResult?.result?.ToString() ?? "0";
                    }
                    break;

                case metricType.NotKnown:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                return(new EvolutionResult
                {
                    name = name,
                    type = type,
                    curResult = curRes,
                    prevResult = prevRes,
                    evolution = format ? Constants.No_Value : "0",
                    evolutionPercent = format ? Constants.No_Value : "0"
                });
            }

            string evolution;
            string evolPercent;
            string finalCurRes;
            string finalPrevRes;
            double?evp;

            switch (curResult.type)
            {
            case metricType.BusinessCriteria:
            case metricType.TechnicalCriteria:
            case metricType.QualityRule:
                if (curResult.result != null && prevResult.result != null)
                {
                    finalCurRes  = curResult.result.Value.ToString("N2");
                    finalPrevRes = prevResult.result.Value.ToString("N2");
                    evolution    = (curResult.result - prevResult.result).Value.ToString("N2");
                    evp          = Math.Abs((double)prevResult.result) > 0.0 ? (curResult.result - prevResult.result) / prevResult.result : null;
                    evolPercent  = evp != null?evp.FormatPercent() : format ? Constants.No_Value : "0";
                }
                else
                {
                    finalCurRes  = format ? Constants.No_Value : "0";
                    finalPrevRes = format ? Constants.No_Value : "0";
                    evolution    = format ? Constants.No_Value : "0";
                    evolPercent  = format ? Constants.No_Value : "0";
                }
                break;

            case metricType.SizingMeasure:
            case metricType.BackgroundFact:
                if (curResult.result != null && prevResult.result != null)
                {
                    if (format)
                    {
                        finalCurRes  = curResult.result.Value.ToString("N0");
                        finalPrevRes = prevResult.result.Value.ToString("N0");
                        evolution    = (curResult.result - prevResult.result).Value.ToString("N0");
                    }
                    else
                    {
                        finalCurRes  = curResult.result.ToString();
                        finalPrevRes = prevResult.result.ToString();
                        evolution    = (curResult.result - prevResult.result).ToString();
                    }
                    evp         = Math.Abs((double)prevResult.result) > 0.0 ? (curResult.result - prevResult.result) / prevResult.result : null;
                    evolPercent = evp != null?evp.FormatPercent() : format ? Constants.No_Value : "0";
                }
                else
                {
                    finalCurRes  = format ? Constants.No_Value : "0";
                    finalPrevRes = format ? Constants.No_Value : "0";
                    evolution    = format ? Constants.No_Value : "0";
                    evolPercent  = format ? Constants.No_Value : "0";
                }
                break;

            case metricType.NotKnown:
                finalCurRes  = format ? Constants.No_Value : "0";
                finalPrevRes = format ? Constants.No_Value : "0";
                evolution    = format ? Constants.No_Value : "0";
                evolPercent  = format ? Constants.No_Value : "0";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new EvolutionResult
            {
                name = curResult.name,
                type = curResult.type,
                curResult = finalCurRes,
                prevResult = finalPrevRes,
                evolution = evolution,
                evolutionPercent = evolPercent
            });
        }