コード例 #1
0
ファイル: FactorsQuery.cs プロジェクト: MikeStower/REMS2020
        private void AddOperations(CompositeFactor factor, IEnumerable <Operation> items, string name)
        {
            if (!items.Any())
            {
                return;
            }

            factor.Specifications.Add($"[{name}]");
            var ops = new Operations {
                Name = name
            };

            ops.Operation = items.ToList();
            factor.Children.Add(ops);
        }
コード例 #2
0
ファイル: FactorsQuery.cs プロジェクト: MikeStower/REMS2020
        /// <inheritdoc/>
        protected override Factors Run()
        {
            var experiment = _context.Experiments.Find(ExperimentId);

            var model = new Factors {
                Name = "Factors"
            };

            foreach (var treatment in experiment.Treatments)
            {
                var factor = new CompositeFactor {
                    Name = treatment.Name
                };

                factor.Specifications = treatment.Designs.Select(d => d.Level)
                                        .SelectMany(l => GetSpecification(l))
                                        .ToList();

                var irrigs = treatment.Irrigations
                             .Select(i => new Operation {
                    Date = i.Date.ToString(), Action = $"[Irrigation].Apply({i.Amount})"
                });

                AddOperations(factor, irrigs, "Irrigations");

                var ferts = treatment.Fertilizations
                            .Select(f => new Operation {
                    Date = f.Date.ToString(), Action = FertAction(f)
                });

                AddOperations(factor, ferts, "Fertilisations");

                var unknowns = treatment.Fertilizations.Where(f => !Enum.IsDefined(typeof(Fertiliser.Types), f.Fertilizer.Name));
                foreach (var fert in unknowns.Select(f => f.Fertilizer.Name).Distinct())
                {
                    Report.AddLine($"Matching APSIM fertiliser type for {fert}" +
                                   $" not found in treatment {treatment.Name}. " +
                                   $"Using default type instead (NO3N).\n");
                }

                model.Children.Add(factor);
            }

            return(model);
        }