<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sequencing.AppChainsSample.SQAPI;

namespace Sequencing.AppChainsSample
{
    /// <summary>
    /// High level wrapper for accessing appchains functionality
    /// </summary>
    public class AppChains
    {
        /// <summary>
        /// Security token supplied by the client
        /// </summary>
        private string token;

        /// <summary>
        /// Service facade for SQAPI
        /// </summary>
        private readonly BackendServiceFacade backendFacade;

        /// <summary>
        /// Service facade for beacons
        /// </summary>
        private readonly BeaconFacade beaconFacade;

        /// <summary>
        /// Timeout to wait between tries to update Job status in seconds
        /// </summary>
        private const int DEFAULT_REPORT_RETRY_TIMEOUT = 1;

        /// <summary>
        /// Constructor that should be called in order to work  with methods that require authentication (i.e. GetReport)
        /// </summary>
        /// <param name="token">OAuth security token</param>
        /// <param name="chainsUrl">hostname to call</param>
        /// <param name="beaconsUrl"></param>
        public AppChains(string token, string chainsUrl, string beaconsUrl) : this(beaconsUrl)
        {
            backendFacade = new BackendServiceFacade(token, chainsUrl);
        }

        /// <summary>
        /// Constructor that should be called in order to work with methods that doesn't require authentication (i.e. GetBeacon)
        /// </summary>
        /// <param name="beaconsUrl"></param>
        public AppChains(string beaconsUrl)
        {
            beaconFacade = new BeaconFacade(beaconsUrl);
        }

        /// <summary>
        /// High level public API. Requests report.
        /// </summary>
        /// <param name="applicationMethodName">report/application specific identifier (i.e. MelanomaDsAppv)</param>
        /// <param name="datasourceId">resource with data to use for report generation</param>
        /// <returns></returns>
        public Report GetReport(string applicationMethodName, string datasourceId)
        {
            var _startApp = backendFacade.StartApp(new AppStartParams
            {
                AppCode = applicationMethodName,
                Pars = { new NewJobParameter("dataSourceId", datasourceId) }
            });
            return GetReportImpl(_startApp);
        }

        public Dictionary<string, Report> GetReportBatch(Dictionary<string, string> appChainsParams)
        {
            List<AppStartParams> paramsList = new List<AppStartParams>(appChainsParams.Count);

            foreach (var appParameter in appChainsParams)
                paramsList.Add(new AppStartParams
                {
                    AppCode = appParameter.Key,
                    Pars = { new NewJobParameter("dataSourceId", appParameter.Value) }
                });
            var startAppBatch = backendFacade.StartAppBatch(new BatchAppStartParams() { Pars = paramsList });

            Dictionary<string, Report> reportAppResults = new Dictionary<string, Report>(startAppBatch.Count);
            foreach (var appResult in startAppBatch)
            {
                
                reportAppResults[appResult.Key] = GetReportImpl(appResult.Value);
            }                
            return reportAppResults;
        }

        /// <summary>
        /// Returns sequencing beacon
        /// </summary>
        /// <param name="chrom"></param>
        /// <param name="pos"></param>
        /// <param name="allele"></param>
        /// <returns></returns>
        public string GetSequencingBeacon(int chrom, int pos, string allele)
        {
            return beaconFacade.GetSequencingBeacon(chrom, pos, allele);
        }

        /// <summary>
        /// Returns public beacon
        /// </summary>
        /// <param name="chrom"></param><commit_msg>Code refactoring<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sequencing.AppChainsSample.SQAPI;

namespace Sequencing.AppChainsSample
{
    /// <summary>
    /// High level wrapper for accessing appchains functionality
    /// </summary>
    public class AppChains
    {
        /// <summary>
        /// Security token supplied by the client
        /// </summary>
        private string token;

        /// <summary>
        /// Service facade for SQAPI
        /// </summary>
        private readonly BackendServiceFacade backendFacade;

        /// <summary>
        /// Service facade for beacons
        /// </summary>
        private readonly BeaconFacade beaconFacade;

        /// <summary>
        /// Timeout to wait between tries to update Job status in seconds
        /// </summary>
        private const int DEFAULT_REPORT_RETRY_TIMEOUT = 1;

        /// <summary>
        /// Constructor that should be called in order to work  with methods that require authentication (i.e. GetReport)
        /// </summary>
        /// <param name="token">OAuth security token</param>
        /// <param name="chainsUrl">hostname to call</param>
        /// <param name="beaconsUrl"></param>
        public AppChains(string token, string chainsUrl, string beaconsUrl) : this(beaconsUrl)
        {
            backendFacade = new BackendServiceFacade(token, chainsUrl);
        }

        /// <summary>
        /// Constructor that should be called in order to work with methods that doesn't require authentication (i.e. GetBeacon)
        /// </summary>
        /// <param name="beaconsUrl"></param>
        public AppChains(string beaconsUrl)
        {
            beaconFacade = new BeaconFacade(beaconsUrl);
        }

        /// <summary>
        /// High level public API. Requests report.
        /// </summary>
        /// <param name="applicationMethodName">report/application specific identifier (i.e. MelanomaDsAppv)</param>
        /// <param name="datasourceId">resource with data to use for report generation</param>
        /// <returns></returns>
        public Report GetReport(string applicationMethodName, string datasourceId)
        {
            var _startApp = backendFacade.StartApp(new AppStartParams
            {
                AppCode = applicationMethodName,
                Pars = { new NewJobParameter("dataSourceId", datasourceId) }
            });
            return GetReportImpl(_startApp);
        }

        public Dictionary<string, Report> GetReportBatch(Dictionary<string, string> appChainsParams)
        {
            List<AppStartParams> paramsList = new List<AppStartParams>(appChainsParams.Count);

            foreach (var appParameter in appChainsParams)
                paramsList.Add(new AppStartParams
                {
                    AppCode = appParameter.Key,
                    Pars = { new NewJobParameter("dataSourceId", appParameter.Value) }
                });
            var startAppBatch = backendFacade.StartAppBatch(new BatchAppStartParams() { Pars = paramsList });

            Dictionary<string, Report> reportAppResults = new Dictionary<string, Report>(startAppBatch.Count);
            foreach (var appResult in startAppBatch)
                reportAppResults[appResult.Key] = GetReportImpl(appResult.Value);       

            return reportAppResults;
        }

        /// <summary>
        /// Returns sequencing beacon
        /// </summary>
        /// <param name="chrom"></param>
        /// <param name="pos"></param>
        /// <param name="allele"></param>
        /// <returns></returns>
        public string GetSequencingBeacon(int chrom, int pos, string allele)
        {
            return beaconFacade.GetSequencingBeacon(chrom, pos, allele);
        }

        /// <summary>
        /// Returns public beacon
        /// </summary>
        /// <param name="chrom"></param>
{'fraction_non_alphanumeric': 0.11001766338632349, 'fraction_numerical': 0.00025233409033560434, 'mean_word_length': 1.974484052532833, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, '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': '1875214', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1960, 'n_words': 514}