public IndividualValuesCache ImportFrom(string populationFileFullPath, IImportLogger logger, PathCache <IParameter> allParameters = null)
        {
            try
            {
                foreach (var delimiter in ALLOWED_DELIMITERS)
                {
                    var individualValuesCache = individualValuesCacheFrom(populationFileFullPath, delimiter);
                    //we found at least one individual, this is a valid file for the delimiter and we can exit
                    if (individualValuesCache?.Count > 0)
                    {
                        return(withPathsContainingUnitsUpdated(individualValuesCache, allParameters, logger));
                    }
                }

                //no match. Log
                logger.AddError(Warning.PopulationFileFormatIsNotSupported);
                return(new IndividualValuesCache());
            }
            catch (Exception e)
            {
                logger.AddError(e.FullMessage());
                return(new IndividualValuesCache());
            }
        }
Ejemplo n.º 2
0
        public IndividualPropertiesCache ImportFrom(string fileFullPath, IImportLogger logger)
        {
            try
            {
                foreach (var delimiter in ALLOWED_DELIMITERS)
                {
                    var individualPropertyCache = individualPropertiesCacheFrom(fileFullPath, delimiter);
                    //we found at least one individual, this is a valid file for the delimiter and we can exit
                    if (individualPropertyCache?.Count > 0)
                    {
                        return(individualPropertyCache);
                    }
                }

                //no match. Log
                logger.AddError(PKSimConstants.Warning.PopulationFileFormatIsNotSupported);
                return(new IndividualPropertiesCache());
            }
            catch (Exception e)
            {
                logger.AddError(e.FullMessage());
                return(new IndividualPropertiesCache());
            }
        }
Ejemplo n.º 3
0
        public IReadOnlyList <PKParameterSensitivity> ImportFrom(string fileFullPath, IModelCoreSimulation simulation, IImportLogger logger)
        {
            try
            {
                foreach (var delimiter in ALLOWED_DELIMITERS)
                {
                    var pkParameterSensitivities = pkParameterSensitivitiesFrom(fileFullPath, delimiter);
                    //we found at least one individual, this is a valid file for the delimiter and we can exit
                    if (pkParameterSensitivities.Any())
                    {
                        return(pkParameterSensitivities);
                    }
                }

                //no match. Log
                logger.AddError(Warning.SensitivityAnalysisFileFormatIsNotSupported);
                return(Array.Empty <PKParameterSensitivity>());
            }
            catch (Exception e)
            {
                logger.AddError(e.FullMessage());
                return(Array.Empty <PKParameterSensitivity>());
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <QuantityPKParameter> ImportPKParameters(string fileFullPath, IImportLogger logger)
        {
            try
            {
                _importedPK = new Cache <string, QuantityPKParameter>(x => x.Id);
                //cache containing a list of tupe<individual Id, value in core unit>
                _valuesCache = new Cache <QuantityPKParameter, List <Tuple <int, float> > >();
                using (var reader = new CsvReaderDisposer(fileFullPath))
                {
                    var csv     = reader.Csv;
                    var headers = csv.GetFieldHeaders();
                    validateFileFormat(headers);
                    while (csv.ReadNextRecord())
                    {
                        var pkParameter = retrieveOrCreatePKParameterFor(csv);
                        addValues(pkParameter, csv);
                    }
                }

                foreach (var keyValue in _valuesCache.KeyValues)
                {
                    var pkParameter = keyValue.Key;
                    var values      = keyValue.Value;
                    //0-based id
                    var maxIndividualId = values.Select(x => x.Item1).Max();
                    pkParameter.SetNumberOfIndividuals(maxIndividualId + 1);

                    foreach (var value in values)
                    {
                        pkParameter.SetValue(value.Item1, value.Item2);
                    }
                }

                return(_valuesCache.Keys.ToList());
            }
            catch (Exception e)
            {
                logger.AddError(e.FullMessage());
                return(Enumerable.Empty <QuantityPKParameter>());
            }
            finally
            {
                _importedPK.Clear();
                _valuesCache.Clear();
            }
        }
        public IEnumerable <IndividualResults> ImportFrom(string fileFullPath, IModelCoreSimulation simulation, IImportLogger logger)
        {
            //do not define this variables as member variable to be thread safe
            var cacheQuantitiesValues = new Cache <QuantityValues, List <float> >();
            var cacheTimeValues       = new Cache <IndividualResults, List <float> >();

            try
            {
                var individualResults = new Cache <int, IndividualResults>(x => x.IndividualId);
                using (var reader = new CsvReaderDisposer(fileFullPath))
                {
                    var csv     = reader.Csv;
                    var headers = csv.GetFieldHeaders();
                    validateHeaders(headers);

                    //skip the first two indexes that are individual id and time
                    var allQuantityPaths = retrieveQuantityPathsFromHeader(headers, simulation);

                    while (csv.ReadNextRecord())
                    {
                        int individualId = retrieveParameterId(csv);
                        if (!individualResults.Contains(individualId))
                        {
                            individualResults.Add(createIndividualResults(individualId, cacheTimeValues));
                        }

                        addRecordToIndividualResults(individualResults[individualId], allQuantityPaths, csv, cacheTimeValues, cacheQuantitiesValues);
                    }
                }

                updateResults(cacheTimeValues, cacheQuantitiesValues);
                return(individualResults);
            }
            catch (Exception e)
            {
                logger.AddError(e.FullMessage());
                return(Enumerable.Empty <IndividualResults>());
            }
            finally
            {
                cacheQuantitiesValues.Clear();
                cacheTimeValues.Clear();
            }
        }
Ejemplo n.º 6
0
        public IndividualPropertiesCache ImportFrom(string fileFullPath, IImportLogger logger)
        {
            try
            {
                foreach (var delimiter in _allowedDelimiters)
                {
                    var individualPropertyCache = individualPropertiesCacheFrom(fileFullPath, logger, delimiter);
                    //we found at least one individual, this is a valid file for the delimiter and we can exit
                    if (individualPropertyCache.Count > 0)
                    {
                        return(individualPropertyCache);
                    }
                }

                return(new IndividualPropertiesCache());
            }
            catch (Exception e)
            {
                logger.AddError(e.FullMessage());
                return(new IndividualPropertiesCache());
            }
        }