예제 #1
0
 private static void quantize(KISTimeSpan span, float quantizer)
 {
     if ((span.getMinutes() % quantizer) > quantizer / 2)
     {
         span.setQuantizedMinutes((int)(Math.Ceiling(span.getMinutes() / quantizer) * quantizer));
     }
     else
     {
         span.setQuantizedMinutes((int)(Math.Floor(span.getMinutes() / quantizer) * quantizer));
     }
 }
예제 #2
0
        private void quantizeKisTimeSpansToQuarter(List <KISTimeSpan> timeSpans, TimeSpan totalWorktime)
        {
            const float quantizer = 15;

            var totalWorktimeTmp = new KISTimeSpan(totalWorktime, "Fake Total timespan");

            quantize(totalWorktimeTmp, quantizer);
            var totalWorktimeTargetMins = totalWorktimeTmp.getQuantizedMinutes();

            //first round: quantize
            //TODO LINQ
            foreach (var span in timeSpans)
            {
                quantize(span, quantizer);
            }

            //check if we reached exactly the target
            //TODO LINQ
            var countMins = 0;

            foreach (var span in timeSpans)
            {
                countMins += span.getQuantizedMinutes();
            }
            if (countMins != totalWorktimeTargetMins)
            {
                //second round: make adaptions so we fit the target by adapting the most sensible projects (i.e. the ones with the biggest deviations)
                //TODO linq
                var errorList = new Dictionary <string, KISTimeSpan>(); // key = projectname
                foreach (var pq in timeSpans)
                {
                    errorList.Add(pq.ProjectTrackerProject, pq);
                }

                var errorListSorted = errorList.OrderByDescending(x => Math.Abs(x.Value.getQuantizationErrorInMins()));

                foreach (var pql in errorListSorted)
                {
                    if (countMins > totalWorktimeTargetMins)
                    {
                        errorList[pql.Key].setQuantizedMinutes(errorList[pql.Key].getQuantizedMinutes() - (int)quantizer); //TODO wäh
                        countMins -= (int)quantizer;
                    }
                    else if (countMins < totalWorktimeTargetMins)
                    {
                        errorList[pql.Key].setQuantizedMinutes(errorList[pql.Key].getQuantizedMinutes() + (int)quantizer); //TODO wäh
                        countMins += (int)quantizer;
                    }
                }
            }
        }