Ejemplo n.º 1
0
        private static void CollectFileData(List <ISegmentWordCounter> counters, IWordCountBatchTaskSettings settings, CountTotal grandTotal, List <CountTotal> fileData)
        {
            foreach (var counter in counters)
            {
                var info = new CountTotal();

                AccumulateCountData(settings, counter, info);

                fileData.Add(info);
                grandTotal.Increment(info);
                grandTotal.UnlockedSpaceCountTotal += info.UnlockedSpaceCountTotal;
                grandTotal.LockedSpaceCountTotal   += info.LockedSpaceCountTotal;
            }
        }
Ejemplo n.º 2
0
        public void BuildTotalTable(CountTotal total, IWordCountBatchTaskSettings settings)
        {
            Contract.Requires <ArgumentNullException>(total != null);
            Contract.Requires <ArgumentNullException>(settings != null);

            string countType = GetCountType(total, settings);

            var parent = new XElement("GrandTotal",
                                      new XAttribute("CountType", countType));

            BuildTable(total, settings, parent);

            root.Add(parent);
        }
        public static string Generate(List <ISegmentWordCounter> counters, IWordCountBatchTaskSettings settings)
        {
            Contract.Requires <ArgumentNullException>(counters != null);
            Contract.Requires <ArgumentNullException>(settings != null);

            CountTotal        grandTotal = new CountTotal();
            List <CountTotal> fileData   = new List <CountTotal>();

            CollectFileData(counters, settings, grandTotal, fileData);

            grandTotal.CountMethod = fileData.First().CountMethod;
            grandTotal.FileName    = "Total";

            return(CreateReport(grandTotal, fileData, settings));
        }
Ejemplo n.º 4
0
        private static int CalculateLineCount(RateType type, IWordCountBatchTaskSettings settings, CountData countData, CountTotal total, ref int output, ref int totalChar)
        {
            if (!string.IsNullOrWhiteSpace(settings.CharactersPerLine))
            {
                if (int.TryParse(settings.CharactersPerLine, out output))
                {
                    if (type == RateType.Locked && settings.ReportLockedSeperately)
                    {
                        if (settings.IncludeSpaces)
                        {
                            totalChar = countData.Characters + total.LockedSpaceCountTotal;
                        }
                        else
                        {
                            totalChar = countData.Characters;
                        }
                    }
                    else
                    {
                        if (settings.IncludeSpaces)
                        {
                            if (settings.ReportLockedSeperately)
                            {
                                totalChar = countData.Characters + total.UnlockedSpaceCountTotal;
                            }
                            else
                            {
                                totalChar = countData.Characters + total.UnlockedSpaceCountTotal + total.LockedSpaceCountTotal;
                            }
                        }
                        else
                        {
                            totalChar = countData.Characters;
                        }
                    }

                    var num = Math.Round(Convert.ToDecimal(totalChar) / Convert.ToDecimal(output), MidpointRounding.AwayFromZero);
                    return(Convert.ToInt32(num));
                }
            }

            return(0);
        }
Ejemplo n.º 5
0
        private static void SetCountMethod(IWordCountBatchTaskSettings settings, ISegmentWordCounter counter, CountTotal info)
        {
            Language language = null;

            if (settings.UseSource)
            {
                language = counter.FileCountInfo.SourceInfo;
            }
            else
            {
                language = counter.FileCountInfo.TargetInfo;
            }

            if (language.UsesCharacterCounts)
            {
                info.CountMethod = CountUnit.Character;
            }
            else
            {
                info.CountMethod = CountUnit.Word;
            }
        }
Ejemplo n.º 6
0
 protected override void OnInitializeTask()
 {
     settings = GetSetting <WordCountBatchTaskSettings>();
 }
Ejemplo n.º 7
0
        private static void AccumulateCountData(IWordCountBatchTaskSettings settings, ISegmentWordCounter counter, CountTotal info)
        {
            info.FileName = counter.FileName;

            SetCountMethod(settings, counter, info);

            foreach (var segInfo in counter.FileCountInfo.SegmentCounts)
            {
                var origin = segInfo.TranslationOrigin;

                if (origin == null)
                {
                    info.Increment(CountTotal.New, segInfo.CountData);
                }
                else
                {
                    if (settings.ReportLockedSeperately && segInfo.IsLocked)
                    {
                        info.Increment(CountTotal.Locked, segInfo.CountData);
                    }
                    else if (origin.OriginType == "document-match")
                    {
                        info.Increment(CountTotal.PerfectMatch, segInfo.CountData);
                    }
                    else if (origin.IsRepeated)
                    {
                        info.Increment(CountTotal.Repetitions, segInfo.CountData);
                    }
                    else if (origin.MatchPercent == 100)
                    {
                        if (origin.TextContextMatchLevel == Sdl.FileTypeSupport.Framework.NativeApi.TextContextMatchLevel.SourceAndTarget)
                        {
                            info.Increment(CountTotal.ContextMatch, segInfo.CountData);
                        }
                        else
                        {
                            info.Increment(CountTotal.OneHundredPercent, segInfo.CountData);
                        }
                    }
                    else if (origin.MatchPercent >= 95)
                    {
                        info.Increment(CountTotal.NinetyFivePercent, segInfo.CountData);
                    }
                    else if (origin.MatchPercent >= 85)
                    {
                        info.Increment(CountTotal.EightyFivePercent, segInfo.CountData);
                    }
                    else if (origin.MatchPercent >= 75)
                    {
                        info.Increment(CountTotal.SeventyFivePercent, segInfo.CountData);
                    }
                    else if (origin.MatchPercent >= 50)
                    {
                        info.Increment(CountTotal.FiftyPercent, segInfo.CountData);
                    }
                    else
                    {
                        info.Increment(CountTotal.New, segInfo.CountData);
                    }
                }

                if (!(settings.ReportLockedSeperately && segInfo.IsLocked))
                {
                    info.Increment(CountTotal.Total, segInfo.CountData);
                }

                if (segInfo.IsLocked)
                {
                    info.LockedSpaceCountTotal += segInfo.SpaceCount;
                }
                else
                {
                    info.UnlockedSpaceCountTotal += segInfo.SpaceCount;
                }
            }
        }
Ejemplo n.º 8
0
        private static string CreateReport(CountTotal grandTotal, List <CountTotal> fileData, IWordCountBatchTaskSettings settings)
        {
            var builder = new ReportBuilder();

            // Build grand total table
            builder.BuildTotalTable(grandTotal, settings);

            // Build individual file tables
            foreach (var data in fileData)
            {
                builder.BuildFileTable(data, settings);
            }

            return(builder.GetReport());
        }
Ejemplo n.º 9
0
 public SegmentWordCounter(string name, IWordCountBatchTaskSettings settings, WordCounter wordCounter)
 {
     FileName         = name;
     this.settings    = settings;
     this.wordCounter = wordCounter;
 }
Ejemplo n.º 10
0
        private XElement CreateXElement(string item, RateType type, CountTotal total, IWordCountBatchTaskSettings settings)
        {
            var countData = total.Totals[item];
            var count     = (total.CountMethod == CountUnit.Character) ? countData.Characters : countData.Words;
            var segments  = countData.Segments;

            var invoiceItem = settings.InvoiceRates[(int)type];

            decimal rate = 0M;

            if (!string.IsNullOrEmpty(invoiceItem.Rate))
            {
                rate = decimal.Parse(invoiceItem.Rate, System.Globalization.NumberStyles.Currency, CultureRepository.Cultures[settings.Culture]);
            }

            var amount    = count * rate;
            int output    = 0;
            int totalChar = 0;

            if (settings.UseLineCount)
            {
                count  = CalculateLineCount(type, settings, countData, total, ref output, ref totalChar);
                amount = count * rate;
            }

            totalAmount += amount;

            if (RateType.Total != type)
            {
                if (settings.UseLineCount)
                {
                    return(new XElement(item,
                                        new XAttribute("Segments", segments),
                                        new XAttribute("TotalCharacters", totalChar),
                                        new XAttribute("CharactersPerLine", output),
                                        new XAttribute("Count", count),
                                        new XAttribute("Rate", string.IsNullOrWhiteSpace(invoiceItem.Rate) ? "0" : invoiceItem.Rate),
                                        new XAttribute("Amount", amount.ToString("C2", CultureRepository.Cultures[settings.Culture]))));
                }
                else
                {
                    return(new XElement(item,
                                        new XAttribute("Segments", segments),
                                        new XAttribute("Count", count),
                                        new XAttribute("Rate", string.IsNullOrWhiteSpace(invoiceItem.Rate) ? "0" : invoiceItem.Rate),
                                        new XAttribute("Amount", amount.ToString("C2", CultureRepository.Cultures[settings.Culture]))));
                }
            }
            else
            {
                var t = totalAmount;
                totalAmount = 0M;

                if (settings.UseLineCount)
                {
                    return(new XElement(item,
                                        new XAttribute("Segments", segments),
                                        new XAttribute("TotalCharacters", totalChar),
                                        new XAttribute("CharactersPerLine", output),
                                        new XAttribute("Count", count),
                                        new XAttribute("Rate", string.IsNullOrWhiteSpace(invoiceItem.Rate) ? "0" : invoiceItem.Rate),
                                        new XAttribute("Amount", t.ToString("C2", CultureRepository.Cultures[settings.Culture]))));
                }
                else
                {
                    return(new XElement(item,
                                        new XAttribute("Segments", segments),
                                        new XAttribute("Count", count),
                                        new XAttribute("Rate", ""),
                                        new XAttribute("Amount", t.ToString("C2", CultureRepository.Cultures[settings.Culture]))));
                }
            }
        }