[EventSubscribe("FinalInitialise")] // "Commencing" private void OnCommencing(object sender, EventArgs e) { if (ResourceGroupsToReport is null || !ResourceGroupsToReport.Any()) { return; } timers = FindAllChildren <IActivityTimer>(); List <string> variableNames = new List <string>(); if (ResourceGroupsToReport.Where(a => a.Contains("[Clock].Today")).Any() is false) { variableNames.Add("[Clock].Today as Date"); } if (ResourceGroupsToReport != null) { for (int i = 0; i < this.ResourceGroupsToReport.Length; i++) { // each variable name is now a ResourceGroup bool isDuplicate = StringUtilities.IndexOfCaseInsensitive(variableNames, this.ResourceGroupsToReport[i].Trim()) != -1; if (!isDuplicate && this.ResourceGroupsToReport[i] != string.Empty) { if (this.ResourceGroupsToReport[i].StartsWith("[")) { variableNames.Add(this.ResourceGroupsToReport[i]); } else { // check it is a ResourceGroup CLEMModel model = resources.FindResource <ResourceBaseWithTransactions>(this.ResourceGroupsToReport[i]); if (model == null) { summary.WriteMessage(this, $"Invalid resource group [r={this.ResourceGroupsToReport[i]}] in ReportResourceBalances [{this.Name}]{Environment.NewLine}Entry has been ignored", MessageType.Warning); } else { if (model is Labour) { string amountStr = "Amount"; if (ReportLabourIndividuals) { amountStr = "Individuals"; } for (int j = 0; j < (model as Labour).Items.Count; j++) { if (ReportAmount) { variableNames.Add("[Resources]." + this.ResourceGroupsToReport[i] + ".Items[" + (j + 1).ToString() + $"].{amountStr} as " + (model as Labour).Items[j].Name); } //TODO: what economic metric is needed for labour //TODO: add ability to report labour value if required } } else { foreach (CLEMModel item in model.FindAllChildren <CLEMModel>()) { string amountStr = "Amount"; switch (item) { case FinanceType ftype: amountStr = "Balance"; break; case LandType ltype: if (ReportLandEntire) { amountStr = "LandArea"; } break; default: break; } if (item is RuminantType) { // add each variable needed foreach (var category in (model as RuminantHerd).GetReportingGroups(item as RuminantType)) { if (ReportAmount) { variableNames.Add($"[Resources].{this.ResourceGroupsToReport[i]}.GetRuminantReportGroup(\"{(item as IModel).Name}\",\"{category}\").Count as {item.Name.Replace(" ", "_")}{(((model as RuminantHerd).TransactionStyle != RuminantTransactionsGroupingStyle.Combined) ? $".{category.Replace(" ", "_")}" : "")}.Count"); } if (ReportAnimalEquivalents) { variableNames.Add($"[Resources].{this.ResourceGroupsToReport[i]}.GetRuminantReportGroup(\"{(item as IModel).Name}\",\"{category}\").TotalAdultEquivalent as {item.Name.Replace(" ", "_")}{(((model as RuminantHerd).TransactionStyle != RuminantTransactionsGroupingStyle.Combined) ? $".{category.Replace(" ", "_")}" : "")}.TotalAdultEquivalent"); } if (ReportAnimalWeight) { variableNames.Add($"[Resources].{this.ResourceGroupsToReport[i]}.GetRuminantReportGroup(\"{(item as IModel).Name}\",\"{category}\").TotalWeight as {item.Name.Replace(" ", "_")}{(((model as RuminantHerd).TransactionStyle != RuminantTransactionsGroupingStyle.Combined) ? $".{category.Replace(" ", "_")}" : "")}.TotalWeight"); } if (ReportValue) { variableNames.Add($"[Resources].{this.ResourceGroupsToReport[i]}.GetRuminantReportGroup(\"{(item as IModel).Name}\",\"{category}\").TotalPrice as {item.Name.Replace(" ", "_")}{(((model as RuminantHerd).TransactionStyle != RuminantTransactionsGroupingStyle.Combined) ? $".{category.Replace(" ", "_")}" : "")}.TotalPrice"); } } } else { if (ReportAmount) { variableNames.Add($"[Resources].{this.ResourceGroupsToReport[i]}.{ item.Name}.{ amountStr } as { item.Name.Replace(" ", "_") }_Amount"); } if (ReportValue & item.GetType() != typeof(FinanceType)) { variableNames.Add($"[Resources].{this.ResourceGroupsToReport[i]}.{item.Name}.Value as { item.Name.Replace(" ", "_") }_DollarValue"); } } } } } } } } } VariableNames = variableNames.ToArray(); // Subscribe to events. if (EventNames == null || !EventNames.Where(a => a.Trim() != "").Any()) { EventNames = new string[] { "[Clock].CLEMFinalizeTimeStep" } } ; SubscribeToEvents(); }