public static ICache <string, T> ToCache <T>(this IEnumerable <T> elements, Func <T, string> getKey) where T : class { var cache = new Cache <string, T>(getKey, x => null); cache.AddRange(elements); return(cache); }
private DataRepository synchronize(DataRepository oldResultsToUpdate, DataRepository newResults) { var newResultsCache = new Cache <QuantityInfo, DataColumn>(col => col.QuantityInfo); newResultsCache.AddRange(newResults); //remove column that do not exist in the new results removeDeletedColumns(oldResultsToUpdate, newResultsCache); //first update base grid columns var baseGridColumns = oldResultsToUpdate.Where(col => col.IsBaseGrid()); baseGridColumns.Each(baseGrid => updateColumnValues(baseGrid, newResultsCache)); //then update non base grid columnds var columns = oldResultsToUpdate.AllButBaseGrid(); columns.Each(col => updateColumnValues(col, newResultsCache)); //finally for all new columns, create a copy with the accurate base grid reference var oldResultsCache = new Cache <QuantityInfo, DataColumn>(col => col.QuantityInfo); oldResultsCache.AddRange(oldResultsToUpdate); var newColumns = newResults.Where(col => !oldResultsCache.Contains(col.QuantityInfo)); newColumns.Each(col => oldResultsToUpdate.Add(cloneColumn(oldResultsCache, col))); return(oldResultsToUpdate); }
private ICache <int, FlatSpeciesContainer> speciesSubContainers(string species, int parentContainerId) { var result = new Cache <int, FlatSpeciesContainer>(flatContainer => flatContainer.Id); result.AddRange(_speciesContainerRepo.AllSubContainer(species, parentContainerId)); return(result); }
private void adjustParameterVisibility() { if (!Formulation.IsParticleDissolution) { return; } var cache = new Cache <string, IParameter>(p => p.Name); cache.AddRange(_formulationDTO.Parameters); cache.Each(p => p.Visible = true); var particleDisperseSystem = cache[CoreConstants.Parameter.PARTICLE_DISPERSE_SYSTEM]; var particleDistribution = cache[CoreConstants.Parameter.PARTICLE_SIZE_DISTRIBUTION]; var parameterToHide = new List <string>(); if (particleDisperseSystem.Value == CoreConstants.Parameter.MONODISPERSE) { parameterToHide.AddRange(CoreConstants.Parameter.HiddenParameterForMonodisperse); } else if (particleDistribution.Value == CoreConstants.Parameter.PARTICLE_SIZE_DISTRIBUTION_NORMAL) { parameterToHide.AddRange(CoreConstants.Parameter.HiddenParameterForPolydisperseNormal); } else { parameterToHide.AddRange(CoreConstants.Parameter.HiddenParameterForPolydisperseLogNormal); } parameterToHide.Each(p => cache[p].Visible = false); }
private ICache <int, FlatPopulationContainer> populationSubContainers(SpeciesPopulation population, FlatContainer parentContainer) { var result = new Cache <int, FlatPopulationContainer>(x => x.Id); result.AddRange(_populationContainerRepo.AllSubContainerFor(population.Name, parentContainer.Id)); return(result); }
private ICache <string, INeighborhood> createNeighborhoodCache(IModel model) { var cloneNeighborhoods = new Cache <string, INeighborhood>(nh => nh.Name); cloneNeighborhoods.AddRange(model.Neighborhoods.GetChildren <INeighborhood>()); return(cloneNeighborhoods); }
private Cache <string, UsedBuildingBlock> ofType(IEnumerable <UsedBuildingBlock> usedBuildingBlocks, PKSimBuildingBlockType buildingBlockType) { var cache = new Cache <string, UsedBuildingBlock>(x => x.Name, x => null); cache.AddRange(usedBuildingBlocks.Where(x => x.BuildingBlockType.Is(buildingBlockType))); return(cache); }
public ResidualsResult Calculate(IReadOnlyList <SimulationRunResults> simulationsResults, IReadOnlyList <OutputMapping> allOutputMappings) { if (simulationsResults.Any(x => !x.Success)) { return(residualResultWithErrorFrom(simulationsResults)); } var simulationColumnsCache = new Cache <string, DataColumn>(x => x.PathAsString, x => null); simulationsResults.Select(x => x.Results).Each(repo => simulationColumnsCache.AddRange(repo.AllButBaseGrid())); var residualResult = new ResidualsResult(); foreach (var outputMapping in allOutputMappings) { var simulationColumn = simulationColumnsCache[outputMapping.FullOutputPath]; if (simulationColumn == null) { residualResult.ExceptionOccured = true; residualResult.ExceptionMessage = Error.CannotFindSimulationResultsForOutput(outputMapping.FullOutputPath); return(residualResult); } var outputResiduals = calculateOutputResiduals(simulationColumn, outputMapping); residualResult.AddOutputResiduals(outputMapping.FullOutputPath, outputMapping.WeightedObservedData, outputResiduals); } return(residualResult); }
private DataTable createDataToExport(Simulation simulation) { //Id Time Output1 Output2 ... OutputN var dataTable = new DataTable(); if (!simulation.HasResults) { return(dataTable); } var simulationResults = simulation.Results; var allQuantities = _quantityRetriever.QuantitiesFrom(simulation); dataTable.AddColumn <int>(CoreConstants.SimulationResults.IndividualId); dataTable.AddColumn <string>(CoreConstants.NameWithUnitFor(CoreConstants.SimulationResults.Time, _timeDimension.BaseUnit)); var allQuantityPaths = simulationResults.AllQuantityPaths(); foreach (var quantityPath in allQuantityPaths) { var quantity = allQuantities[quantityPath]; if (quantity == null) { continue; } dataTable.AddColumn <string>(CoreConstants.NameWithUnitFor(quantityPath, quantity.Dimension.BaseUnit)); } dataTable.BeginLoadData(); int numberOfValues = simulationResults.Time.Length; foreach (var individualResults in simulationResults.OrderBy(x => x.IndividualId)) { var allQuantitiesCache = new Cache <string, QuantityValues>(x => x.QuantityPath); allQuantitiesCache.AddRange(individualResults); for (int i = 0; i < numberOfValues; i++) { var row = dataTable.NewRow(); row[CoreConstants.SimulationResults.IndividualId] = individualResults.IndividualId; row[CoreConstants.NameWithUnitFor(CoreConstants.SimulationResults.Time, _timeDimension.BaseUnit)] = simulationResults.Time[i].ConvertedTo <string>(); foreach (var quantityPath in allQuantityPaths) { var quantity = allQuantities[quantityPath]; if (quantity == null) { continue; } row[CoreConstants.NameWithUnitFor(quantityPath, quantity.Dimension.BaseUnit)] = allQuantitiesCache[quantityPath][i].ConvertedTo <string>(); } dataTable.Rows.Add(row); } } dataTable.EndLoadData(); return(dataTable); }
public static ICache <string, T> ToCache <T>(this IEnumerable <T> startValues) where T : class, IStartValue { var cache = new Cache <string, T>(x => x.Path.ToString(), x => null); cache.AddRange(startValues); return(cache); }
public void LoadFromSession(ISession session) { Clear(); var allCommandMetaData = session.CreateCriteria <CommandMetaData>().List <CommandMetaData>(); _allCommandMetaData.AddRange(allCommandMetaData); cacheParentChildrenRelationship(); }
private void cacheUsedBuildingBlockAndParametersFromSimulation(Simulation simulation) { simulation.UsedBuildingBlocks.Each(x => { _usedBuildingBlockCache.Add(x); _buildingBlockParameterCache.AddRange(x.BuildingBlock.GetAllChildren <IParameter>()); }); }
public void CreatePaneOrder() { //without ToList sortedPanes is empty after Clear var sortedPanes = _allPanes.OrderBy(x => x, this).ToList(); _allPanes.Clear(); _allPanes.AddRange(sortedPanes); }
public CreateIndividualResults CreateIndividual(IndividualCharacteristics individualCharacteristics) { var originData = originDataFrom(individualCharacteristics); var moleculeOntogenies = individualCharacteristics.MoleculeOntogenies; var individual = _individualFactory.CreateAndOptimizeFor(originData, individualCharacteristics.Seed); var individualProperties = _individualValuesMapper.MapFrom(individual); var allIndividualParameters = individualProperties.ParameterValues; var ontogenyParameters = _ontogenyFactorsRetriever.FactorsFor(originData, moleculeOntogenies).Select(x => new ParameterValueWithUnit(x)); var allDistributedParameterCache = _containerTask.CacheAllChildren <IDistributedParameter>(individual); var allIndividualParametersCache = _containerTask.CacheAllChildren <IParameter>(individual); var distributedParameters = new Cache <string, ParameterValueWithUnit>(x => x.ParameterPath); var derivedParameters = new List <ParameterValueWithUnit>(); //Add Age and Height parameter that is not distributed at the moment if (originData.Population.IsAgeDependent) { distributedParameters.Add(parameterValueFrom(individual.Organism.Parameter(CoreConstants.Parameters.AGE))); distributedParameters.Add(parameterValueFrom(individual.Organism.Parameter(Constants.Parameters.GESTATIONAL_AGE))); } if (originData.Population.IsHeightDependent) { distributedParameters.Add(parameterValueFrom(individual.Organism.Parameter(CoreConstants.Parameters.HEIGHT))); } distributedParameters.Add(parameterValueFrom(individual.Organism.Parameter(CoreConstants.Parameters.ONTOGENY_FACTOR_AGP))); distributedParameters.Add(parameterValueFrom(individual.Organism.Parameter(CoreConstants.Parameters.ONTOGENY_FACTOR_ALBUMIN))); foreach (var individualParameter in allIndividualParameters) { var parameter = allIndividualParametersCache[individualParameter.ParameterPath]; if (parameter == null) { continue; } var parameterValue = new ParameterValueWithUnit(individualParameter, parameter?.BaseUnitName()); if (allDistributedParameterCache.Contains(individualParameter.ParameterPath)) { distributedParameters.Add(parameterValue); } //Do not add parameters that were added specifically else if (!distributedParameters.Contains(individualParameter.ParameterPath)) { derivedParameters.Add(parameterValue); } } //add Ontogeny parameters distributedParameters.AddRange(ontogenyParameters); return(new CreateIndividualResults(distributedParameters.ToArray(), derivedParameters.ToArray(), individual.Seed)); }
private void finalizeTranports(IModel cloneModel, IEnumerable <ITransport> tmp, IEnumerable <ITransport> sourceTransports) { var cloneTransports = new Cache <string, ITransport>(x => x.Name); cloneTransports.AddRange(tmp); foreach (var transport in sourceTransports) { var cloneTransport = cloneTransports[transport.Name]; resolveAmounts(cloneModel, transport, cloneTransport); } }
public void VehicleFamilyCache_Populate() { Cache.AddRange(AdditionalFamilies); Cache.Populate(); var cacheObjects = Cache.GetCachedObjects().ToArray(); // Since Populate() clears the cache if it isn't empty, there should be only one item even though we // added the additional families. Then, Populate() gathers all families in the family storage location. // Since the Angara family is the only one saved there, it should be the only family in the cache. Assert.IsTrue(cacheObjects.Length == 1); Assert.IsTrue(cacheObjects.Contains(Family, Comparer)); }
public void LauncherCollectionCache_Populate() { Cache.AddRange(AdditionalCollections); Cache.Populate(); var cacheObjects = Cache.GetCachedObjects().ToArray(); // Since Populate() clears the cache if it isn't empty, there should be only one item even though we // added the additional collections. Then, Populate() gathers all collections in the storage location. // Since the A5 collection is the only one saved there, it should be the only collection in the cache. Assert.IsTrue(cacheObjects.Length == 1); Assert.IsTrue(cacheObjects.Contains(Collection, Comparer)); }
public void VehicleFamilyCache_Refresh() { Cache.AddRange(AdditionalFamilies); Cache.Refresh(); var cacheObjects = Cache.GetCachedObjects().ToArray(); var falcon = cacheObjects.SingleOrDefault(e => e.Name == "Falcon"); // We added the additional launchers and then refreshed the cache. Since the only family saved in // the storage location is the Angara family, then it should be the only one in the cached objects. Assert.IsTrue(cacheObjects.Contains(Family, Comparer)); Assert.IsTrue(!cacheObjects.Contains(falcon)); }
private void finalizeEventContainer(IContainer sourceEventGroup, IContainer cloneEventGroup, IModel cloneModel) { var sourceContainer = sourceEventGroup.GetChildren <IContainer>(); var cloneContainer = new Cache <string, IContainer>(x => x.Name); cloneContainer.AddRange(cloneEventGroup.GetChildren <IContainer>()); foreach (var source in sourceContainer) { var clone = cloneContainer[source.Name]; finalizeEventContainer(source, clone, cloneModel); } finalizeTransportsInMoleculeParentContainer(cloneModel, sourceEventGroup, cloneEventGroup); }
protected override void DoStart() { _allDiseaseSates.AddRange(_flatDiseaseStateRepository.All().MapAllUsing(_diseaseStateMapper)); foreach (var query in _flatPopulationDiseaseStateRepository.All().GroupBy(x => x.Population)) { var population = _populationRepository.FindByName(query.Key); var diseaseStates = new List<DiseaseState>(); diseaseStates.AddRange(query.Select(x => _allDiseaseSates[x.DiseaseState])); _allDiseaseStatePerPopulation[population] = diseaseStates; } _healthyState = _allDiseaseSates.FindByName(CoreConstants.DiseaseStates.HEALTHY); }
public void LauncherCollectionCache_Refresh() { Cache.AddRange(AdditionalCollections); Cache.Refresh(); var cacheObjects = Cache.GetCachedObjects().ToArray(); var falcon = cacheObjects.SingleOrDefault(e => e.Name == "Falcon"); // We added the additional collections and then refreshed the cache. Since the only collection saved in // the storage location is the A5 collection, then it should be the only one in the cached objects. Assert.IsTrue(cacheObjects.Contains(Collection, Comparer)); Assert.IsTrue(!cacheObjects.Contains(falcon)); }
private IEnumerable <DataColumn> selectedCurves(DataRepository dataRepository) { var selectedQuantities = new Cache <string, QuantitySelection>(x => x.Path); selectedQuantities.AddRange(_quantitySelectionPresenter.SelectedQuantities()); foreach (var dataColumn in dataRepository.Where(c => c.QuantityInfo != null)) { var path = dataColumn.QuantityInfo.PathAsString; if (selectedQuantities.Contains(path)) { yield return(dataColumn); } } }
private void addNodesForParametersUnder(ITreeNode node, IEnumerable <IParameter> allParameters) { var cache = new Cache <PathElements, IParameter>(_pathElementsMapper.MapFrom); cache.AddRange(allParameters); if (parameterHaveSameDisplayNamesAsOneParentGroup(cache.Keys, node)) { createNodeHierarchyWithoutParameterNameUnder(node, cache); } else { createNodeHierarchyWithParameterNameUnder(node, cache); } }
public void LauncherCache_AddRange() { Cache.Clear(); Cache.AddRange(AdditionalLaunchers); var cacheObjects = Cache.GetCachedObjects().ToArray(); var falcon9 = cacheObjects.SingleOrDefault(e => e.Name == "Falcon 9"); var deltaII = cacheObjects.SingleOrDefault(e => e.Name == "Delta II"); var atlasV = cacheObjects.SingleOrDefault(e => e.Name == "Atlas V"); // We cleared the cache and then added the additional launchers, so it should only contain those three launchers. Assert.IsTrue(cacheObjects.Contains(falcon9)); Assert.IsTrue(cacheObjects.Contains(deltaII)); Assert.IsTrue(cacheObjects.Contains(atlasV)); Assert.IsTrue(cacheObjects.Length == 3); }
public void LauncherCollectionCache_AddRange() { Cache.Clear(); Cache.AddRange(AdditionalCollections); var cacheObjects = Cache.GetCachedObjects().ToArray(); var falcon = cacheObjects.SingleOrDefault(e => e.Name == "Falcon"); var delta = cacheObjects.SingleOrDefault(e => e.Name == "Delta"); var atlas = cacheObjects.SingleOrDefault(e => e.Name == "Atlas"); // We cleared the cache and then added the additional collections, so it should only contain those three collections. Assert.IsTrue(cacheObjects.Contains(falcon)); Assert.IsTrue(cacheObjects.Contains(delta)); Assert.IsTrue(cacheObjects.Contains(atlas)); Assert.IsTrue(cacheObjects.Length == 3); }
public ICommand UpdateValuesByName(IEnumerable <IParameter> sourceParameters, IEnumerable <IParameter> targetParameters) { var updateCommands = new PKSimMacroCommand { CommandType = PKSimConstants.Command.CommandTypeEdit, ObjectType = PKSimConstants.ObjectTypes.Parameter }; var targetParameterCache = new Cache <string, IParameter>(p => p.Name, key => null); targetParameterCache.AddRange(targetParameters); foreach (var sourceParameter in sourceParameters) { var targetParameter = targetParameterCache[sourceParameter.Name]; if (targetParameter == null) { continue; } updateCommands.Add(UpdateValue(sourceParameter, targetParameter)); } return(updateCommands); }
public void Save(IHistoryManager historyManager, ISession session) { //only save history that were not saved yet var savedHistory = new Cache <string, HistoryItemMetaData>(x => x.Id, x => null); savedHistory.AddRange(allHistoryItemMetaData(session)); int sequence = 0; foreach (var historyItem in historyManager.History) { var savedHistoryItem = savedHistory[historyItem.Id]; if (savedHistoryItem == null) { saveNewHistoryItem(historyItem, sequence, session); } else if (commentHasChanged(savedHistoryItem, historyItem)) { updateComment(savedHistoryItem, historyItem, session); } sequence++; } }
public DataRepository CreateRepository(IModelCoreSimulation simulation, SimModelNET.ISimulation simModelSimulation, string repositoryName = null) { var repository = new DataRepository().WithName(repositoryName ?? _dataNamingService.GetNewRepositoryName()); var allPersitableQuantities = new Cache <string, IQuantity>(q => _objectPathFactory.CreateAbsoluteObjectPath(q).ToString(), x => null); allPersitableQuantities.AddRange(simulation.Model.Root.GetAllChildren <IQuantity>(x => x.Persistable)); var time = createTimeGrid(simModelSimulation.SimulationTimes); foreach (var quantityValue in simModelSimulation.AllValues) { var quantity = allPersitableQuantities[quantityValue.Path]; if (quantity == null) { continue; } repository.Add(createColumn(time, quantity, quantityValue, quantityValue.Path.ToPathArray(), simulation)); } return(repository); }
private DataTable createResultDataToExport(Simulation simulation) { //Id Time Output1 Output2 ... OutputN var dataTable = new DataTable(simulation.Name); if (!simulation.HasResults) { return(dataTable); } var simulationResults = simulation.Results; var allQuantities = _quantityRetriever.QuantitiesFrom(simulation); var timeColumnName = Constants.NameWithUnitFor(CoreConstants.SimulationResults.TIME, _timeDimension.BaseUnit); var quantityPathCache = new Cache <string, string>(); dataTable.AddColumn <int>(CoreConstants.SimulationResults.INDIVIDUAL_ID); dataTable.AddColumn <string>(timeColumnName); var allQuantityPaths = simulationResults.AllQuantityPaths(); foreach (var quantityPath in allQuantityPaths) { var quantity = allQuantities[quantityPath]; if (quantity == null) { continue; } //export results in base unit so that they can be computed automatically from matlab scripts quantityPathCache[quantityPath] = Constants.NameWithUnitFor(quantityPath, quantity.Dimension.BaseUnit); dataTable.AddColumn <string>(quantityPathCache[quantityPath]); } dataTable.BeginLoadData(); int numberOfValues = simulationResults.Time.Length; foreach (var individualResults in simulationResults.OrderBy(x => x.IndividualId)) { var allQuantitiesCache = new Cache <string, QuantityValues>(x => x.QuantityPath); allQuantitiesCache.AddRange(individualResults); for (int i = 0; i < numberOfValues; i++) { var row = dataTable.NewRow(); row[CoreConstants.SimulationResults.INDIVIDUAL_ID] = individualResults.IndividualId; row[timeColumnName] = simulationResults.Time[i].ConvertedTo <string>(); foreach (var quantityPath in allQuantityPaths) { var quantity = allQuantities[quantityPath]; if (quantity == null) { continue; } row[quantityPathCache[quantityPath]] = allQuantitiesCache[quantityPath][i].ConvertedTo <string>(); } dataTable.Rows.Add(row); } } dataTable.EndLoadData(); return(dataTable); }
protected override void Because() { var allMenuWithShortCuts = sut.All().Where(x => x.Shortcut != Keys.None); _allEntriesWithShortCuts.AddRange(allMenuWithShortCuts); }