211 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			211 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Collections.ObjectModel;
 | |
| using System.Text.Json.Serialization;
 | |
| 
 | |
| namespace Adaptation.FileHandlers.Priority;
 | |
| 
 | |
| #nullable enable
 | |
| 
 | |
| public class WorkItem
 | |
| {
 | |
| 
 | |
|     [JsonConstructor]
 | |
|     public WorkItem(double? costOfDelay,
 | |
|                     Aggregation? businessValue,
 | |
|                     Aggregation? effort,
 | |
|                     int id,
 | |
|                     int? sortBeforeId,
 | |
|                     int? sortPriority,
 | |
|                     int? sortPriorityGroup,
 | |
|                     Aggregation? riskReductionOpportunityEnablement,
 | |
|                     string? site,
 | |
|                     int? sortOrder,
 | |
|                     Aggregation? timeCriticality,
 | |
|                     double? weightedShortestJobFirst)
 | |
|     {
 | |
|         CostOfDelay = costOfDelay;
 | |
|         BusinessValue = businessValue;
 | |
|         Effort = effort;
 | |
|         Id = id;
 | |
|         Site = site;
 | |
|         SortBeforeId = sortBeforeId;
 | |
|         SortPriority = sortPriority;
 | |
|         SortPriorityGroup = sortPriorityGroup;
 | |
|         RiskReductionOpportunityEnablement = riskReductionOpportunityEnablement;
 | |
|         SortOrder = sortOrder;
 | |
|         TimeCriticality = timeCriticality;
 | |
|         WeightedShortestJobFirst = weightedShortestJobFirst;
 | |
|     }
 | |
| 
 | |
|     const string _PageEffort = "effort";
 | |
|     const string _PageTimeCriticality = "time";
 | |
|     const string _PageBusinessValue = "business";
 | |
|     const string _PageRiskReductionOpportunityEnablement = "risk";
 | |
| 
 | |
|     public double? CostOfDelay { get; } // [JsonPropertyName("CostOfDelay")]
 | |
|     public Aggregation? BusinessValue { get; } // [JsonPropertyName("BusinessValue")]
 | |
|     public Aggregation? Effort { get; } // [JsonPropertyName("Effort")]
 | |
|     public int Id { get; } // [JsonPropertyName("Id")]
 | |
|     public string? Site { get; } // [JsonPropertyName("Site")]
 | |
|     public int? SortBeforeId { get; } // [JsonPropertyName("SortBeforeId")]
 | |
|     public int? SortPriority { get; } // [JsonPropertyName("SortPriority")]
 | |
|     public int? SortPriorityGroup { get; } // [JsonPropertyName("SortPriorityGroup")]
 | |
|     public Aggregation? RiskReductionOpportunityEnablement { get; } // [JsonPropertyName("RiskReductionOpportunityEnablement")]
 | |
|     public int? SortOrder { get; } // [JsonPropertyName("SortOrder")]
 | |
|     public Aggregation? TimeCriticality { get; } // [JsonPropertyName("TimeCriticality")]
 | |
|     public double? WeightedShortestJobFirst { get; } // [JsonPropertyName("WeightedShortestJobFirst")]
 | |
| 
 | |
|     internal static WorkItem GetWorkItem(WorkItem workItem, int i, int? sortBeforeId, int? sortPriority, int? sortPriorityGroup) =>
 | |
|         new(workItem.CostOfDelay,
 | |
|             workItem.BusinessValue,
 | |
|             workItem.Effort,
 | |
|             workItem.Id,
 | |
|             sortBeforeId,
 | |
|             sortPriority,
 | |
|             sortPriorityGroup,
 | |
|             workItem.RiskReductionOpportunityEnablement,
 | |
|             workItem.Site,
 | |
|             i,
 | |
|             workItem.TimeCriticality,
 | |
|             workItem.WeightedShortestJobFirst);
 | |
| 
 | |
|     private static string? GetSite(Aggregation? effort, Aggregation? businessValue, Aggregation? timeCriticality, Aggregation? riskReductionOpportunityEnablement)
 | |
|     {
 | |
|         string? result = null;
 | |
|         if (result is null && effort is not null)
 | |
|         {
 | |
|             foreach (Notification notification in effort.Notifications)
 | |
|             {
 | |
|                 if (notification.Site is not null)
 | |
|                 {
 | |
|                     result = notification.Site;
 | |
|                     break;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         if (result is null && businessValue is not null)
 | |
|         {
 | |
|             foreach (Notification notification in businessValue.Notifications)
 | |
|             {
 | |
|                 if (notification.Site is not null)
 | |
|                 {
 | |
|                     result = notification.Site;
 | |
|                     break;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         if (result is null && timeCriticality is not null)
 | |
|         {
 | |
|             foreach (Notification notification in timeCriticality.Notifications)
 | |
|             {
 | |
|                 if (notification.Site is not null)
 | |
|                 {
 | |
|                     result = notification.Site;
 | |
|                     break;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         if (result is null && riskReductionOpportunityEnablement is not null)
 | |
|         {
 | |
|             foreach (Notification notification in riskReductionOpportunityEnablement.Notifications)
 | |
|             {
 | |
|                 if (notification.Site is not null)
 | |
|                 {
 | |
|                     result = notification.Site;
 | |
|                     break;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         return result;
 | |
|     }
 | |
| 
 | |
|     internal static ReadOnlyDictionary<int, WorkItem?> GetWorkItems(Settings settings, ReadOnlyDictionary<string, ReadOnlyDictionary<int, Aggregation>> keyValuePairs)
 | |
|     {
 | |
|         Dictionary<int, WorkItem?> results = new();
 | |
|         string? site;
 | |
|         WorkItem? workItem;
 | |
|         double? costOfDelay;
 | |
|         Aggregation? effort;
 | |
|         List<int> ids = new();
 | |
|         Aggregation? businessValue;
 | |
|         Aggregation? timeCriticality;
 | |
|         double? weightedShortestJobFirst;
 | |
|         Aggregation? riskReductionOpportunityEnablement;
 | |
|         Dictionary<int, Aggregation?> effortCollection = new();
 | |
|         Dictionary<int, Aggregation?> businessValueCollection = new();
 | |
|         Dictionary<int, Aggregation?> timeCriticalityCollection = new();
 | |
|         Dictionary<int, Aggregation?> riskReductionOpportunityEnablementCollection = new();
 | |
|         foreach (KeyValuePair<string, ReadOnlyDictionary<int, Aggregation>> keyValuePair in keyValuePairs)
 | |
|         {
 | |
|             foreach (KeyValuePair<int, Aggregation> keyValue in keyValuePair.Value)
 | |
|             {
 | |
|                 if (!ids.Contains(keyValue.Key))
 | |
|                     ids.Add(keyValue.Key);
 | |
|                 if (keyValuePair.Key == _PageEffort)
 | |
|                     effortCollection.Add(keyValue.Key, keyValue.Value);
 | |
|                 else if (keyValuePair.Key == _PageTimeCriticality)
 | |
|                     timeCriticalityCollection.Add(keyValue.Key, keyValue.Value);
 | |
|                 else if (keyValuePair.Key == _PageBusinessValue)
 | |
|                     businessValueCollection.Add(keyValue.Key, keyValue.Value);
 | |
|                 else if (keyValuePair.Key == _PageRiskReductionOpportunityEnablement)
 | |
|                     riskReductionOpportunityEnablementCollection.Add(keyValue.Key, keyValue.Value);
 | |
|                 else
 | |
|                     throw new NotImplementedException();
 | |
|             }
 | |
|         }
 | |
|         foreach (int id in ids)
 | |
|         {
 | |
|             if (!effortCollection.TryGetValue(id, out effort))
 | |
|                 effort = null;
 | |
|             if (!businessValueCollection.TryGetValue(id, out businessValue))
 | |
|                 businessValue = null;
 | |
|             if (!timeCriticalityCollection.TryGetValue(id, out timeCriticality))
 | |
|                 timeCriticality = null;
 | |
|             if (!riskReductionOpportunityEnablementCollection.TryGetValue(id, out riskReductionOpportunityEnablement))
 | |
|                 riskReductionOpportunityEnablement = null;
 | |
|             site = GetSite(effort, businessValue, timeCriticality, riskReductionOpportunityEnablement);
 | |
|             costOfDelay = businessValue is null
 | |
|                 || timeCriticality is null
 | |
|                 || riskReductionOpportunityEnablement is null ? null : businessValue.FibonacciAverage
 | |
|                 + timeCriticality.FibonacciAverage
 | |
|                 + riskReductionOpportunityEnablement.FibonacciAverage;
 | |
|             weightedShortestJobFirst = costOfDelay is null || effort is null ? null : Math.Round(costOfDelay.Value / effort.FibonacciAverage, settings.Digits);
 | |
|             workItem = new(costOfDelay: costOfDelay,
 | |
|                            businessValue: businessValue,
 | |
|                            effort: effort,
 | |
|                            id: id,
 | |
|                            sortBeforeId: null,
 | |
|                            sortPriority: null,
 | |
|                            sortPriorityGroup: null,
 | |
|                            riskReductionOpportunityEnablement: riskReductionOpportunityEnablement,
 | |
|                            site: site,
 | |
|                            sortOrder: null,
 | |
|                            timeCriticality: timeCriticality,
 | |
|                            weightedShortestJobFirst: weightedShortestJobFirst);
 | |
|             results.Add(id, workItem);
 | |
|         }
 | |
|         return new(results);
 | |
|     }
 | |
| 
 | |
|     internal static ReadOnlyDictionary<int, WorkItem?> GetKeyValuePairs(Settings settings)
 | |
|     {
 | |
|         ReadOnlyDictionary<int, WorkItem?> results;
 | |
|         ReadOnlyDictionary<string, ReadOnlyDictionary<int, Aggregation>> keyValuePairs = Aggregation.GetKeyValuePairsAndWriteFiles(settings);
 | |
|         results = GetWorkItems(settings, keyValuePairs);
 | |
|         return results;
 | |
|     }
 | |
| 
 | |
| }
 | |
| 
 | |
| [JsonSourceGenerationOptions(WriteIndented = true)]
 | |
| [JsonSerializable(typeof(Dictionary<int, WorkItem>))]
 | |
| internal partial class WorkItemDictionarySourceGenerationContext : JsonSerializerContext
 | |
| {
 | |
| }
 | |
| 
 | |
| [JsonSourceGenerationOptions(WriteIndented = true)]
 | |
| [JsonSerializable(typeof(KeyValuePair<string, WorkItem>))]
 | |
| internal partial class KeyValuePairStringWorkItemSourceGenerationContext : JsonSerializerContext
 | |
| {
 | |
| } |