Example #1
0
        /// <summary>
        /// Search the grown crops for all valid crop types, and track
        /// them in the GrainIDs list
        /// </summary>
        private void SetGrains()
        {
            GrainIDs = new List <int>();

            // Row of crop IDs
            var crops = CropsGrown.GetRowData <int>(0);

            // Row of area allocated to crop
            var areas = CropsGrown.GetRowData <double>(2);

            // Select all non-zero IDs
            var ids =
                from id in crops
                where id != 0
                select id;

            foreach (int id in ids)
            {
                int index = crops.IndexOf(id);

                // Check the crop has growing area
                if (areas.ElementAt(index) <= 0)
                {
                    continue;
                }

                // Add the crop to the list of grown grains
                if (!GrainIDs.Exists(i => i == id))
                {
                    GrainIDs.Add(id);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Builds the list of animal fodder pools used in the simulation,
        /// and stores the ID of the crops grown
        /// </summary>
        private void GetGrownFodderPools()
        {
            WorksheetPart crop = (WorksheetPart)Book.GetPartById(SearchSheets("crop_inputs").Id);
            var           rows = crop.Worksheet.Descendants <Row>().Skip(1);

            // Attempt to find the fodder pool for each crop
            foreach (int id in GrainIDs)
            {
                // Check if the crop has residue
                if (CropsGrown.GetData <double>(4, id) <= 0)
                {
                    continue;
                }

                // Find the cropname
                string cropname = CropSpecs.RowNames.ElementAt(id + 1);

                // Check data was found
                int pool = 0;
                if (rows.Any(r => TestRow(id, r)))
                {
                    // Select the first row of the valid inputs
                    Cell input = rows.First(r => TestRow(id, r)).Descendants <Cell>().ElementAt(10);

                    // Find what pool the residue uses
                    int.TryParse(ParseCell(input), out pool);
                }
                else
                {
                    Shared.WriteError(new ErrorData()
                    {
                        FileName = Name,
                        FileType = "IAT",
                        Message  = $"Crop type {cropname} wasn't found in the inputs sheet",
                        Severity = "Low",
                        Table    = "-",
                        Sheet    = "crop_inputs"
                    });
                }

                // If the pool does not exist, create a new pool with the residue in it
                if (!Pools.ContainsKey(pool))
                {
                    Pools.Add(pool, $"{cropname}_Residue");
                }
                // If the pool exists already, add the residue to it.
                else
                {
                    Pools[pool] = Pools[pool] + $", {cropname}_Residue";
                }
            }
        }
Example #3
0
        /// <summary>
        /// Model products sold
        /// </summary>
        public IEnumerable <ProductStoreType> GetProductStoreTypes(ProductStore store)
        {
            List <ProductStoreType> products = new List <ProductStoreType>();

            var row = CropsGrown.GetRowData <int>(0);

            foreach (var id in GrainIDs)
            {
                int col  = row.IndexOf(id);
                var sold = CropsGrown.GetData <double>(5, col);

                if (sold > 0)
                {
                    products.Add(new ProductStoreType(store)
                    {
                        Name = CropSpecs.RowNames[id + 1]
                    });
                }
            }

            return(products);
        }
Example #4
0
        /// <summary>
        /// Finds all crops in the source IAT which require management
        /// </summary>
        public IEnumerable <CropActivityManageCrop> GetManageCrops(ActivityFolder manage)
        {
            List <CropActivityManageCrop> crops = new List <CropActivityManageCrop>();

            int[] ids = CropsGrown.GetRowData <int>(0).ToArray();

            // Find the name of the crop in the file
            Sheet         sheet  = SearchSheets("crop_inputs");
            WorksheetPart inputs = (WorksheetPart)Book.GetPartById(sheet.Id);

            // Find the name of the crop
            int rows = sheet.Elements <Row>().Count();

            foreach (int id in GrainIDs)
            {
                string name = "Unknown";
                int    row  = 1;

                while (row < rows)
                {
                    if (GetCellValue(inputs, row, 3) == id.ToString())
                    {
                        name = GetCellValue(inputs, row, 4);
                        break;
                    }
                    row++;
                }

                // Find which column holds the data for a given crop ID
                int col = Array.IndexOf(ids, id);

                // Find names
                int    land     = CropsGrown.GetData <int>(1, col);
                string cropname = CropSpecs.RowNames[id + 1];

                // Model the crop management
                CropActivityManageCrop crop = new CropActivityManageCrop(manage)
                {
                    Name = "Manage " + cropname,
                    LandItemNameToUse = LandSpecs.RowNames[land - 1],
                    AreaRequested     = CropsGrown.GetData <double>(2, col)
                };

                // Find the storage pool which the crop uses
                string pool = Pools.Values.ToList().Find(s => s.Contains(cropname));

                // Add the product management model
                crop.Add(new CropActivityManageProduct(crop)
                {
                    Name = "Manage grain",
                    ModelNameFileCrop = "FileCrop",
                    CropName          = name,
                    ProportionKept    = 1.0 - CropsGrown.GetData <double>(5, col) / 100.0,
                    StoreItemName     = "HumanFoodStore." + pool
                });

                // Add the residue management
                crop.Add(new CropActivityManageProduct(crop)
                {
                    Name = "Manage residue",
                    ModelNameFileCrop = "FileCropResidue",
                    CropName          = name,
                    ProportionKept    = CropsGrown.GetData <double>(4, col) / 100.0,
                    StoreItemName     = "AnimalFoodStore." + pool
                });

                crops.Add(crop);
            }
            return(crops);
        }