<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CprBroker.Utilities;

namespace CprBroker.Tests.DBR.Comparison
{
    public class ReportGenerator
    {
        public string GenerateReport(Type comparisonType)
        {
            var types = comparisonType
                .Assembly
                .GetTypes()
                .Where(t => Reflection.IsTypeDerivedFromGenericType(t, comparisonType) && !t.IsGenericType)
                .ToArray();

            StringBuilder sb = new StringBuilder();
            foreach (var t in types)
            {
                var dprType = t.BaseType.GetGenericArguments().FirstOrDefault();
                if (DataLinq.IsTable(dprType))
                {
                    var cmpObj = Reflection.CreateInstance(t);
                    sb.Append(String.Format("* Type <{0}>, table <{1}>\r\n", dprType.Name, DataLinq.GetTableName(dprType)));
                    var props = DataLinq.GetColumnProperties(dprType);
                    var propNames = t.InvokeMember("ExcludedProperties", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty, null, cmpObj, null) as string[];
                    if (propNames.Length > 0)
                    {
                        foreach (var propName in propNames)
                        {
                            var prop = props.Where(p => p.Name.Equals(propName)).Single();
                            sb.Append(string.Format("** Property <{0}>, Column <{1}>\r\n", prop.Name, DataLinq.GetColumnName(prop)));
                        }
                    }
                    else
                    {
                        sb.Append("** (None)\r\n");
                    }
                }
            }
            return sb.ToString();
        }
    }
}<commit_msg>Generation of report for exclusion of row counts in DBR tests<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CprBroker.Utilities;

namespace CprBroker.Tests.DBR.Comparison
{
    public class ReportGenerator
    {
        public string GenerateReport(Type comparisonType)
        {
            var types = comparisonType
                .Assembly
                .GetTypes()
                .Where(t => Reflection.IsTypeDerivedFromGenericType(t, comparisonType) && !t.IsGenericType)
                .ToArray();

            return string.Format(
                "h3. Fields \r\n\r\n"
                + GenerateExclusionReport(types)
                + "\r\n"
                + "h3. Ignored count \r\n\r\n"
                + GenerateConutExclusionReport(types)
                );
        }

        public string GenerateExclusionReport(Type[] types)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var t in types)
            {
                var dprType = t.BaseType.GetGenericArguments().FirstOrDefault();
                if (DataLinq.IsTable(dprType))
                {
                    var cmpObj = Reflection.CreateInstance(t);
                    sb.Append(String.Format("* Type <{0}>, table <{1}>\r\n", dprType.Name, DataLinq.GetTableName(dprType)));
                    var props = DataLinq.GetColumnProperties(dprType);
                    var propNames = t.InvokeMember("ExcludedProperties", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty, null, cmpObj, null) as string[];
                    if (propNames.Length > 0)
                    {
                        foreach (var propName in propNames)
                        {
                            var prop = props.Where(p => p.Name.Equals(propName)).Single();
                            sb.Append(string.Format("** Property <{0}>, Column <{1}>\r\n", prop.Name, DataLinq.GetColumnName(prop)));
                        }
                    }
                    else
                    {
                        sb.Append("** (None)\r\n");
                    }
                }
            }
            return sb.ToString();
        }

        public String GenerateConutExclusionReport(Type[] types)
        {
            var ss = types
                .Select(t => new
                {
                    T = t,
                    Ign = (bool)t.InvokeMember(
                        "IgnoreCount",
                        System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetProperty,
                        null,
                        Reflection.CreateInstance(t),
                        null)
                })
                .Where(o => o.Ign)
                .Select(o => string.Format(
                    "* Type <{0}> table <{1}>",
                    o.T.BaseType.GetGenericArguments().FirstOrDefault().Name,
                    DataLinq.GetTableName(o.T.BaseType.GetGenericArguments().FirstOrDefault())
                    ))
                .ToArray();

            return string.Join("\r\n", ss);
        }
    }
}
{'fraction_non_alphanumeric': 0.10548851693265862, 'fraction_numerical': 0.0027247956403269754, 'mean_word_length': 1.3747689463955637, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4817282', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1257, 'n_words': 242}