<commit_before>namespace ReamQuery.Services
{
    using System;
    using System.Diagnostics;
    using System.Reflection;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using ReamQuery.Api;
    using ReamQuery.Shared;
    using ReamQuery.Helpers;
    using System.Threading;

    public class QueryService
    {
        CompileService _compiler;
        DatabaseContextService _databaseContextService;
        SchemaService _schemaService;
        FragmentService _fragmentService;
        ClientService _clientService;
        int _sessionId = 0;

        public QueryService(CompileService compiler, DatabaseContextService databaseContextService,
            SchemaService schemaService, FragmentService fragmentService, ClientService clients)
        {
            _compiler = compiler;
            _databaseContextService = databaseContextService;
            _schemaService = schemaService;
            _fragmentService = fragmentService;
            _clientService = clients;
        }

        public async Task<QueryResponse> ExecuteQuery(QueryRequest input)
        {
            var queryId = Interlocked.Increment(ref _sessionId);
            var sw = new Stopwatch();
            sw.Start();
            var newInput = _fragmentService.Fix(input.Text);
            var contextResult = await _databaseContextService.GetDatabaseContext(input.ConnectionString, input.ServerType);
            if (contextResult.Code != Api.StatusCode.Ok)
            {
                return new QueryResponse { Code = contextResult.Code, Message = contextResult.Message };
            }
            var assmName = Guid.NewGuid().ToIdentifierWithPrefix("a");

            var programSource = _template
                .Replace("##SOURCE##", newInput.Text)
                .Replace("##NS##", assmName)
                .Replace("##SCHEMA##", "") // schema is linked
                .Replace("##DB##", contextResult.Type.ToString());

            var e1 = sw.Elapsed.TotalMilliseconds;
            sw.Reset();
            sw.Start();
            var compileResult = _compiler.LoadType(programSource, assmName, contextResult.Reference);
            var queryResponse = new QueryResponse
            {
                Id = Guid.NewGuid(),
                Created = DateTime.Now,
                Diagnostics = compileResult.Diagnostics,
                Code = compileResult.Code
            };

            if (compileResult.Code == Api.StatusCode.Ok)
            {
                var method = compileResult.Type.GetMethod("Run");
                var programInstance = Activator.CreateInstance(compileResult.Type);
                var e2 = sw.Elapsed.TotalMilliseconds;
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // TODO pass in real dump count !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                _clientService.AddEmitter(ReamQuery.Shared.Dumper.InitializeEmitter(queryId, 1));
                sw.Reset();
                sw.Start();
                try
                {
                    method.Invoke(programInstance, new object[] { queryId });
                }
                catch (System.Exception exn) 
                {<commit_msg>Use expression location count for dump counter<commit_after>namespace ReamQuery.Services
{
    using System;
    using System.Diagnostics;
    using System.Reflection;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using ReamQuery.Api;
    using ReamQuery.Shared;
    using ReamQuery.Helpers;
    using System.Threading;
    using System.Linq;

    public class QueryService
    {
        CompileService _compiler;
        DatabaseContextService _databaseContextService;
        SchemaService _schemaService;
        FragmentService _fragmentService;
        ClientService _clientService;
        int _sessionId = 0;

        public QueryService(CompileService compiler, DatabaseContextService databaseContextService,
            SchemaService schemaService, FragmentService fragmentService, ClientService clients)
        {
            _compiler = compiler;
            _databaseContextService = databaseContextService;
            _schemaService = schemaService;
            _fragmentService = fragmentService;
            _clientService = clients;
        }

        public async Task<QueryResponse> ExecuteQuery(QueryRequest input)
        {
            var queryId = Interlocked.Increment(ref _sessionId);
            var sw = new Stopwatch();
            sw.Start();
            var newInput = _fragmentService.Fix(input.Text);
            var contextResult = await _databaseContextService.GetDatabaseContext(input.ConnectionString, input.ServerType);
            if (contextResult.Code != Api.StatusCode.Ok)
            {
                return new QueryResponse { Code = contextResult.Code, Message = contextResult.Message };
            }
            var assmName = Guid.NewGuid().ToIdentifierWithPrefix("a");

            var programSource = _template
                .Replace("##SOURCE##", newInput.Text)
                .Replace("##NS##", assmName)
                .Replace("##SCHEMA##", "") // schema is linked
                .Replace("##DB##", contextResult.Type.ToString());

            var e1 = sw.Elapsed.TotalMilliseconds;
            sw.Reset();
            sw.Start();
            var compileResult = _compiler.LoadType(programSource, assmName, contextResult.Reference);
            var queryResponse = new QueryResponse
            {
                Id = Guid.NewGuid(),
                Created = DateTime.Now,
                Diagnostics = compileResult.Diagnostics,
                Code = compileResult.Code
            };

            if (compileResult.Code == Api.StatusCode.Ok)
            {
                var method = compileResult.Type.GetMethod("Run");
                var programInstance = Activator.CreateInstance(compileResult.Type);
                var e2 = sw.Elapsed.TotalMilliseconds;
                _clientService.AddEmitter(ReamQuery.Shared.Dumper.InitializeEmitter(queryId, newInput.ExpressionLocations.Count()));
                sw.Reset();
                sw.Start();
                try
                {
                    method.Invoke(programInstance, new object[] { queryId });
                }
                catch (System.Exception exn) 
                {
{'fraction_non_alphanumeric': 0.10541044776119403, 'fraction_numerical': 0.0010883084577114428, 'mean_word_length': 1.9893122676579926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5098026', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1470, 'n_words': 316}