Exemple #1
0
        public async Task <bool> TryShowRowForUrn(SessionDetails sessionDetails, string systemName, string referenceVariableName, string urnValue, List <string> variableNames, TextWriter outputWriter)
        {
            FastStatsSystemService fastStatsSystemService = new FastStatsSystemService(connectorFactory, dataViewName);
            Variable referenceVariable = await fastStatsSystemService.GetVariable(sessionDetails, systemName, referenceVariableName);

            if (referenceVariable == null)
            {
                throw new Exception($"The variable {referenceVariableName} wasn't found in the system {systemName}");
            }

            Query query = BuildQueryForUrn(referenceVariable, urnValue);

            variableNames.Insert(0, referenceVariableName);
            List <Column> columns = BuildExportColumns(variableNames);

            ExportsService exportsService = new ExportsService(connectorFactory, dataViewName);
            List <string>  rows           = await exportsService.ExportData(systemName, sessionDetails, query, columns, 1, TimeSpan.FromMinutes(5));

            if (rows == null)
            {
                return(false);
            }

            foreach (string row in rows)
            {
                outputWriter.WriteLine(row);
            }

            return(true);
        }
Exemple #2
0
        public async Task <bool> TryShowCubeForVariables(SessionDetails sessionDetails, string systemName, string queryFilePath, List <string> variableNames, TextWriter outputWriter)
        {
            QueriesService queriesService = new QueriesService(connectorFactory, dataViewName);
            Query          query          = await queriesService.GetQueryDefinitionFromFile(systemName, sessionDetails, queryFilePath, TimeSpan.FromMinutes(5));

            if (query == null)
            {
                return(false);
            }

            if (query?.Selection?.TableName == null)
            {
                throw new Exception($"The query {queryFilePath} must have at least a selection with a table name");
            }

            FastStatsSystemService fastStatsSystemService = new FastStatsSystemService(connectorFactory, dataViewName);

            foreach (string variableName in variableNames)
            {
                Variable variable = await fastStatsSystemService.GetVariable(sessionDetails, systemName, variableName);

                if (variable == null)
                {
                    throw new Exception($"Couldn't find a variable with the name {variableName} in the system {systemName}");
                }

                if (variable.Type != Variable.TypeEnum.Selector)
                {
                    throw new Exception($"The DataAggregator can only build cubes with selector variables, but {variable.Description} is of type {variable.Type}");
                }
            }

            List <Dimension> dimensions = BuildDimensions(variableNames);
            List <Measure>   measures   = BuildMeasures(query.Selection.TableName);

            CubesService  cubesService = new CubesService(connectorFactory, dataViewName);
            List <string> rows         = await cubesService.CalculateCube(systemName, sessionDetails, query, dimensions, measures, TimeSpan.FromMinutes(5));

            if (rows == null)
            {
                return(false);
            }

            foreach (string row in rows)
            {
                outputWriter.WriteLine(row);
            }

            return(true);
        }
Exemple #3
0
        public async Task <bool> TryShowRowsForQuery(SessionDetails sessionDetails, string systemName, string queryFilePath, List <string> variableNames, int topNRows, TextWriter outputWriter)
        {
            QueriesService queriesService = new QueriesService(connectorFactory, dataViewName);
            Query          query          = await queriesService.GetQueryDefinitionFromFile(systemName, sessionDetails, queryFilePath, TimeSpan.FromMinutes(5));

            if (query == null)
            {
                return(false);
            }

            if (query?.Selection?.TableName == null)
            {
                throw new Exception($"The query {queryFilePath} must have at least a selection with a table name");
            }

            FastStatsSystemService fastStatsSystemService = new FastStatsSystemService(connectorFactory, dataViewName);
            Variable referenceVariable = await fastStatsSystemService.GetReferenceVariableForTable(sessionDetails, systemName, query.Selection.TableName);

            if (referenceVariable != null)
            {
                variableNames.Insert(0, referenceVariable.Name);
            }

            List <Column> columns = BuildExportColumns(variableNames);

            ExportsService exportsService = new ExportsService(connectorFactory, dataViewName);
            List <string>  rows           = await exportsService.ExportData(systemName, sessionDetails, query, columns, topNRows, TimeSpan.FromMinutes(5));

            if (rows == null)
            {
                return(false);
            }

            foreach (string row in rows)
            {
                outputWriter.WriteLine(row);
            }

            return(true);
        }
Exemple #4
0
        public async Task <bool> OutputStats(SessionDetails sessionDetails, TextWriter outputWriter)
        {
            FastStatsSystemService fastStatsSystemService = new FastStatsSystemService(connectorFactory, dataViewName);
            List <string>          systemNames            = await fastStatsSystemService.GetSystemNames(sessionDetails);

            if (systemNames == null || systemNames.Count == 0)
            {
                logger.LogError($"Couldn't find any FastStats systems in data view {dataViewName}");
                return(false);
            }

            foreach (string systemName in systemNames)
            {
                VariableStatistics stats = await fastStatsSystemService.GetVariableStatistics(systemName, sessionDetails);

                outputWriter.WriteLine(stats);
                outputWriter.WriteLine();
                outputWriter.WriteLine();
            }

            return(true);
        }