public IEnumerable <Node> GetFiles(ZoneCLEM clem) { List <Node> files = new List <Node>(); files.Add(new FileSQLiteGRASP(clem) { Name = "FileGrasp", FileName = Source.Name.LocalName + ".db" }); XElement forages = FindByNameTag(Source, "Forages File"); string file = FindFirst(forages, "string").Value; if (file != "") { CSVtoPRN(Shared.InDir + "/" + file); files.Add(new FileCrop(clem) { Name = "FileForage", FileName = Path.ChangeExtension(file, "prn") }); } return(files); }
/// <summary> /// IAT does not use GRASP files, so an empty element is returned /// </summary> public IEnumerable <Node> GetFiles(ZoneCLEM clem) { List <Node> files = new List <Node>(); // Add the crop files.Add(new FileCrop(clem) { FileName = clem.Source.Name + "\\FileCrop.prn", Name = "FileCrop" }); // Add the crop residue files.Add(new FileCrop(clem) { FileName = clem.Source.Name + "\\FileCropResidue.prn", Name = "FileCropResidue" }); // Add the forage crop files.Add(new FileCrop(clem) { FileName = clem.Source.Name + "\\FileForage.prn", Name = "FileForage" }); return(files.AsEnumerable()); }
/// <inheritdoc/> public override string ModelSummary() { using (StringWriter htmlWriter = new StringWriter()) { if (this.Parent.GetType() != typeof(LabourActivityFeed)) { htmlWriter.Write("<div class=\"warningbanner\">This Labour Feed Group must be placed beneath a Labour Activity Feed component</div>"); return(htmlWriter.ToString()); } LabourFeedActivityTypes ft = (this.Parent as LabourActivityFeed).FeedStyle; htmlWriter.Write("\r\n<div class=\"activityentry\">"); switch (ft) { case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE: case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual: htmlWriter.Write("<span class=\"" + ((Value <= 0) ? "errorlink" : "setvalue") + "\">" + Value.ToString() + "</span>"); break; default: break; } ZoneCLEM zoneCLEM = FindAncestor <ZoneCLEM>(); ResourcesHolder resHolder = zoneCLEM.FindChild <ResourcesHolder>(); HumanFoodStoreType food = resHolder.FindResourceType <HumanFoodStore, HumanFoodStoreType>(this, (this.Parent as LabourActivityFeed).FeedTypeName, OnMissingResourceActionTypes.Ignore, OnMissingResourceActionTypes.Ignore); if (food != null) { htmlWriter.Write(" " + food.Units + " "); } htmlWriter.Write("<span class=\"setvalue\">"); switch (ft) { case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual: htmlWriter.Write(" per individual per day"); break; case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE: htmlWriter.Write(" per AE per day"); break; default: break; } htmlWriter.Write("</span> "); switch (ft) { case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE: case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual: htmlWriter.Write("is fed to each individual"); break; } htmlWriter.Write(" that matches the following conditions:"); htmlWriter.Write("</div>"); return(htmlWriter.ToString()); } }
public ResourcesHolder(ZoneCLEM parent) : base(parent) { Name = "Resources"; Add(new Land(this)); Add(new Labour(this)); Add(new RuminantHerd(this)); Add(new Finance(this)); Add(new AnimalFoodStore(this)); Add(new GrazeFoodStore(this)); Add(new ProductStore(this)); Add(new HumanFoodStore(this)); }
/// <inheritdoc/> public override string ModelSummary() { using (StringWriter htmlWriter = new StringWriter()) { ZoneCLEM clemParent = FindAncestor <ZoneCLEM>(); ResourcesHolder resHolder; Finance finance = null; if (clemParent != null) { resHolder = clemParent.FindAllChildren <ResourcesHolder>().FirstOrDefault() as ResourcesHolder; finance = resHolder.FindResourceGroup <Finance>(); if (finance != null && !finance.Enabled) { finance = null; } } if (finance == null) { htmlWriter.Write("\r\n<div class=\"activityentry\">This activity is not required as no <span class=\"resourcelink\">Finance</span> resource is available.</div>"); } else { htmlWriter.Write("\r\n<div class=\"activityentry\">Interest rates are set in the <span class=\"resourcelink\">FinanceType</span> component</div>"); foreach (FinanceType accnt in finance.FindAllChildren <FinanceType>().Where(a => a.Enabled)) { if (accnt.InterestRateCharged == 0 & accnt.InterestRatePaid == 0) { htmlWriter.Write("\r\n<div class=\"activityentry\">This activity is not needed for <span class=\"resourcelink\">" + accnt.Name + "</span> as no interest rates are set.</div>"); } else if (accnt.InterestRateCharged > 0) { htmlWriter.Write("\r\n<div class=\"activityentry\">This activity will calculate interest charged for <span class=\"resourcelink\">" + accnt.Name + "</span> at a rate of <span class=\"setvalue\">" + accnt.InterestRateCharged.ToString("#.00") + "</span>%</div>"); } else { htmlWriter.Write("\r\n<div class=\"activityentry\">This activity will calculate interest paid for <span class=\"resourcelink\">" + accnt.Name + "</span> at a rate of <span class=\"setvalue\">" + accnt.InterestRatePaid.ToString("#.00") + "</span>%</div>"); } } } return(htmlWriter.ToString()); } }
/// <summary> /// Gets the names of all the items for each ResourceGroup whose items you want to put into a dropdown list. /// eg. "AnimalFoodStore,HumanFoodStore,ProductStore" /// Will create a dropdown list with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// /// To help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. /// </summary> /// <returns>Will create a string array with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// to help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. </returns> private string[] GetCLEMResourceNames(Type[] resourceNameResourceGroups) { List <string> result = new List <string>(); ZoneCLEM zoneCLEM = Apsim.Parent(this.model, typeof(ZoneCLEM)) as ZoneCLEM; ResourcesHolder resHolder = Apsim.Child(zoneCLEM, typeof(ResourcesHolder)) as ResourcesHolder; foreach (Type resGroupType in resourceNameResourceGroups) { IModel resGroup = Apsim.Child(resHolder, resGroupType); if (resGroup != null) //see if this group type is included in this particular simulation. { foreach (IModel item in resGroup.Children) { result.Add(resGroup.Name + "." + item.Name); } } } return(result.ToArray()); }
/// <summary> /// Provides the description of the model settings for summary (GetFullSummary) /// </summary> /// <param name="formatForParentControl">Use full verbose description</param> /// <returns></returns> public override string ModelSummary(bool formatForParentControl) { string html = ""; ZoneCLEM clemParent = FindAncestor <ZoneCLEM>(); ResourcesHolder resHolder; Finance finance = null; if (clemParent != null) { resHolder = clemParent.FindAllChildren <ResourcesHolder>().FirstOrDefault() as ResourcesHolder; finance = resHolder.FinanceResource(); } if (finance == null) { html += "\n<div class=\"activityentry\">This activity is not required as no <span class=\"resourcelink\">Finance</span> resource is available.</div>"; } else { html += "\n<div class=\"activityentry\">Interest rates are set in the <span class=\"resourcelink\">FinanceType</span> component</div>"; foreach (FinanceType accnt in finance.FindAllChildren <FinanceType>()) { if (accnt.InterestRateCharged == 0 & accnt.InterestRatePaid == 0) { html += "\n<div class=\"activityentry\">This activity is not needed for <span class=\"resourcelink\">" + accnt.Name + "</span> as no interest rates are set.</div>"; } else { if (accnt.InterestRateCharged > 0) { html += "\n<div class=\"activityentry\">This activity will calculate interest charged for <span class=\"resourcelink\">" + accnt.Name + "</span> at a rate of <span class=\"setvalue\">" + accnt.InterestRateCharged.ToString("#.00") + "</span>%</div>"; } else { html += "\n<div class=\"activityentry\">This activity will calculate interest paid for <span class=\"resourcelink\">" + accnt.Name + "</span> at a rate of <span class=\"setvalue\">" + accnt.InterestRatePaid.ToString("#.00") + "</span>%</div>"; } } } } return(html); }
/// <summary> /// Gets the names of all the items for each ResourceGroup whose items you want to put into a dropdown list. /// eg. "AnimalFoodStore,HumanFoodStore,ProductStore" /// Will create a dropdown list with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// /// To help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. /// </summary> /// <returns>Will create a string array with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// to help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. </returns> private string[] GetCLEMResourceNames(Type[] resourceNameResourceGroups) { List <string> result = new List <string>(); ZoneCLEM zoneCLEM = Apsim.Parent(this.model, typeof(ZoneCLEM)) as ZoneCLEM; ResourcesHolder resHolder = Apsim.Child(zoneCLEM, typeof(ResourcesHolder)) as ResourcesHolder; if (resourceNameResourceGroups != null) { // resource groups specified (use them) foreach (Type resGroupType in resourceNameResourceGroups) { IModel resGroup = Apsim.Child(resHolder, resGroupType); if (resGroup != null) //see if this group type is included in this particular simulation. { foreach (IModel item in resGroup.Children) { if (item.GetType() != typeof(Memo)) { result.Add(resGroup.Name + "." + item.Name); } } } } } else { // no resource groups specified so use all avaliable resources foreach (IModel resGroup in Apsim.Children(resHolder, typeof(IModel))) { foreach (IModel item in resGroup.Children) { if (item.GetType() != typeof(Memo)) { result.Add(resGroup.Name + "." + item.Name); } } } } return(result.ToArray()); }
public ActivitiesHolder(ZoneCLEM parent) : base(parent) { Name = "Activities"; // Model the finance activities GetCashFlow(); // Model the crop growth activities ActivityFolder crops = new ActivityFolder(this) { Name = "Manage crops" }; crops.Add(Source.GetManageCrops(crops)); Add(crops); // Model the forage growth activities ActivityFolder forages = new ActivityFolder(this) { Name = "Manage forages" }; forages.Add(Source.GetManageForages(forages)); if (forages.Children.Count > 0) { forages.Add(Source.GetNativePasture(forages)); } Add(forages); // Model the ruminant activities GetHerd(); // Model the pasture management Add(Source.GetManagePasture(this)); // Attach summary/report Add(new SummariseRuminantHerd(this)); Add(new ReportRuminantHerd(this)); }
/// <summary> /// Gets the names of all the items for each ResourceGroup whose items you want to put into a dropdown list. /// eg. "AnimalFoodStore,HumanFoodStore,ProductStore" /// Will create a dropdown list with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// A blank list of ResourceNameResourceGroups will result in all available resources types being created in the list /// /// To help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. /// </summary> /// <returns>Will create a string array with all the items from the AnimalFoodStore, HumanFoodStore and ProductStore. /// to help uniquely identify items in the dropdown list will need to add the ResourceGroup name to the item name. /// eg. The names in the drop down list will become AnimalFoodStore.Wheat, HumanFoodStore.Wheat, ProductStore.Wheat, etc. </returns> private string[] GetCLEMResourceNames(Type[] resourceNameResourceGroups) { List <string> result = new List <string>(); ZoneCLEM zoneCLEM = model as ZoneCLEM; if (zoneCLEM == null) { zoneCLEM = model.FindAncestor <ZoneCLEM>(); } ResourcesHolder resHolder = zoneCLEM.FindChild <ResourcesHolder>(); foreach (Type resGroupType in resourceNameResourceGroups) { IModel resGroup = resHolder.Children.Find(c => resGroupType.IsAssignableFrom(c.GetType())); if (resGroup != null) //see if this group type is included in this particular simulation. { foreach (IModel item in resGroup.Children) { result.Add(resGroup.Name + "." + item.Name); } } } return(result.ToArray()); }
private void OnCLEMInitialiseResource(object sender, EventArgs e) { // activity is performed in CLEMUpdatePasture not CLEMGetResources and has no labour this.AllocationStyle = ResourceAllocationStyle.Manual; // locate Land Type resource for this forage. LinkedLandItem = Resources.GetResourceItem(this, LandTypeNameToUse, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as LandType; LandConditionIndex = FindAllDescendants <RelationshipRunningValue>().Where(a => (new string[] { "lc", "landcondition", "landcon", "landconditionindex" }).Contains(a.Name.ToLower())).FirstOrDefault() as RelationshipRunningValue; GrassBasalArea = FindAllDescendants <RelationshipRunningValue>().Where(a => (new string[] { "gba", "basalarea", "grassbasalarea" }).Contains(a.Name.ToLower())).FirstOrDefault() as RelationshipRunningValue; FilePasture = ZoneCLEM.Parent.FindAllDescendants().Where(a => a.Name == PastureDataReader).FirstOrDefault() as IFilePasture; if (FilePasture != null) { // check that database has region id and land id ZoneCLEM clem = FindAncestor <ZoneCLEM>(); int recs = FilePasture.RecordsFound((FilePasture as FileSQLitePasture).RegionColumnName, clem.ClimateRegion); if (recs == 0) { throw new ApsimXException(this, $"No pasture production records were located by [x={(FilePasture as Model).Name}] for [a={this.Name}] given [Region id] = [{clem.ClimateRegion}] as specified in [{clem.Name}]"); } LandType land = Resources.GetResourceItem(this, LandTypeNameToUse, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as LandType; if (land != null) { recs = FilePasture.RecordsFound((FilePasture as FileSQLitePasture).LandIdColumnName, land.SoilType); if (recs == 0) { throw new ApsimXException(this, $"No pasture production records were located by [x={(FilePasture as Model).Name}] for [a={this.Name}] given [Land id] = [{land.SoilType}] as specified in [{land.Name}] used to manage the pasture"); } } } if (UseAreaAvailable) { LinkedLandItem.TransactionOccurred += LinkedLandItem_TransactionOccurred; } ResourceRequestList = new List <ResourceRequest> { new ResourceRequest() { AllowTransmutation = false, Required = UseAreaAvailable ? LinkedLandItem.AreaAvailable : AreaRequested, ResourceType = typeof(Land), ResourceTypeName = LandTypeNameToUse.Split('.').Last(), ActivityModel = this, Category = UseAreaAvailable ?"Assign unallocated":"Assign", FilterDetails = null } }; CheckResources(ResourceRequestList, Guid.NewGuid()); gotLandRequested = TakeResources(ResourceRequestList, false); //Now the Land has been allocated we have an Area if (gotLandRequested) { //get the units of area for this run from the Land resource parent. unitsOfArea2Ha = Resources.Land().UnitsOfAreaToHaConversion; // locate Pasture Type resource LinkedNativeFoodType = Resources.GetResourceItem(this, FeedTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType; //Assign the area actually got after taking it. It might be less than AreaRequested (if partial) Area = ResourceRequestList.FirstOrDefault().Provided; // ensure no other activity has set the area of this GrazeFoodStore LinkedNativeFoodType.Manager = this as IPastureManager; soilIndex = ((LandType)ResourceRequestList.FirstOrDefault().Resource).SoilType; if (!(LandConditionIndex is null)) { LinkedNativeFoodType.CurrentEcologicalIndicators.LandConditionIndex = LandConditionIndex.StartingValue; } if (!(GrassBasalArea is null)) { LinkedNativeFoodType.CurrentEcologicalIndicators.GrassBasalArea = GrassBasalArea.StartingValue; } LinkedNativeFoodType.CurrentEcologicalIndicators.StockingRate = StartingStockingRate; StockingRateSummed = StartingStockingRate; //Now we have a stocking rate and we have starting values for Land Condition and Grass Basal Area //get the starting pasture data list from Pasture reader if (FilePasture != null) { GetPastureDataList_TodayToNextEcolCalculation(); SetupStartingPasturePools(StartingAmount); } } }
/// <summary> /// Provides the description of the model settings for summary (GetFullSummary) /// </summary> /// <param name="formatForParentControl">Use full verbose description</param> /// <returns></returns> public override string ModelSummary(bool formatForParentControl) { string html = ""; if (this.Parent.GetType() != typeof(LabourActivityFeed)) { html += "<div class=\"warningbanner\">This Labour Feed Group must be placed beneath a Labour Activity Feed component</div>"; return(html); } LabourFeedActivityTypes ft = (this.Parent as LabourActivityFeed).FeedStyle; html += "\n<div class=\"activityentry\">"; switch (ft) { case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE: case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual: html += "<span class=\"" + ((Value <= 0) ? "errorlink" : "setvalue") + "\">" + Value.ToString() + "</span>"; break; default: break; } ZoneCLEM zoneCLEM = Apsim.Parent(this, typeof(ZoneCLEM)) as ZoneCLEM; ResourcesHolder resHolder = Apsim.Child(zoneCLEM, typeof(ResourcesHolder)) as ResourcesHolder; HumanFoodStoreType food = resHolder.GetResourceItem(this, (this.Parent as LabourActivityFeed).FeedTypeName, OnMissingResourceActionTypes.Ignore, OnMissingResourceActionTypes.Ignore) as HumanFoodStoreType; if (food != null) { html += " " + food.Units + " "; } html += "<span class=\"setvalue\">"; switch (ft) { case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual: html += " per individual per day"; break; case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE: html += " per AE per day"; break; default: break; } html += "</span> "; switch (ft) { case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE: case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual: html += "is fed to each individual"; break; } html += " that matches the following conditions:"; html += "</div>"; return(html); }