Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop econ data being wiped in every simulation #8868

Merged
merged 1 commit into from Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 24 additions & 14 deletions Models/Management/FarmEconomics.cs
Expand Up @@ -11,7 +11,6 @@
// TODO
// machinery
// annual overheads & capital repayments
// table of annual paddock activity
namespace Models.Management
{
/// <summary>
Expand Down Expand Up @@ -53,7 +52,8 @@ public class PaddockExpenditureArgs : EventArgs
public double Rate { get; set; }
/// <summary> </summary>
public double Area { get; set; }
}
}

/// <summary> Farm level income</summary>
// income {amount 64000.0} {comment "description here"}
public class FarmIncomeArgs : EventArgs
Expand All @@ -66,8 +66,8 @@ public class FarmIncomeArgs : EventArgs
public double Amount { get; set; } // whole $/farm
}
/// <summary> Paddock level income</summary>
// income {category cropprice} {name wheat} {yield 4000} {protein 12.3} {comment "description here"}
// income {category cropprice} {name sorghum} {yield 6000} {comment "description here"}
// income {category cropprice} {name wheat} {yield 4000} {protein 12.3} {comment "description here"}
// income {category cropprice} {name sorghum} {yield 6000} {comment "description here"}
public class PaddockIncomeArgs : EventArgs
{
/// <summary> </summary>
Expand Down Expand Up @@ -136,26 +136,32 @@ public void DoManagement(object sender, EventArgs e)
public void DoPaddockIncome(object sender, PaddockIncomeArgs e)
{
var f = this.FindChild<CostPriceInfo>(e.Name);
double price = f?.Price ?? 0.0;
double amount = price * e.Yield * e.Area;
if (f == null)
Summary.WriteMessage(this, $"DoPaddockIncome: {e.Name} ({e.Description}) has no cost/price information", MessageType.Warning);
else
{
double amount = f.Price * e.Yield * e.Area;

Summary.WriteMessage(this, $"{e.Description} Income = ${amount}", MessageType.Information);
Balance += amount;
logIt(Clock.Today, e.Paddock, amount, 0, e.Category, e.Description);
Summary.WriteMessage(this, $"{e.Description} Income = ${amount}", MessageType.Information);
Balance += amount;
logIt(Clock.Today, e.Paddock, amount, 0, e.Category, e.Description);
}
}
/// <summary> Whole farm </summary>

/// <summary> Whole farm ($) </summary>
[EventSubscribe("DoFarmIncome")]
public void DoFarmIncome(object sender, FarmIncomeArgs e)
{
Summary.WriteMessage(this, $"{e.Description} Income = ${e.Amount}", MessageType.Information);
Balance += e.Amount;
logIt(Clock.Today, "", e.Amount, 0, e.Category, e.Description);
}
/// <summary> </summary>

/// <summary> Paddock (area based rate, eg kg/ha)</summary>
[EventSubscribe("DoPaddockExpenditure")]
public void DoPaddockExpenditure(object sender, PaddockExpenditureArgs e)
{
double cost = 1;
double cost = 0;
var f = this.FindChild<CostPriceInfo>(e.Name);
if (f != null)
cost = f.VariableCost;
Expand All @@ -164,16 +170,20 @@ public void DoPaddockExpenditure(object sender, PaddockExpenditureArgs e)
var f2 = this.FindChild<CostInfo>(e.Name);
if (f2 != null)
cost = f2.Cost;
else
Summary.WriteMessage(this, $"DoPaddockExpenditure: {e.Name} ({e.Description}) has no cost/price information", MessageType.Warning);
}
double amount = cost * e.Rate * e.Area;

Summary.WriteMessage(this, $"{e.Description} Expenditure = ${amount}", MessageType.Information);
Balance -= amount;
logIt(Clock.Today, e.Paddock, 0, amount, e.Category, e.Description);
}
/// <summary> </summary>
/// <summary> Whole farm ($) </summary>
[EventSubscribe("DoFarmExpenditure")]
public void DoFarmExpenditure(object sender, FarmExpenditureArgs e)
{
Summary.WriteMessage(this, $"{e.Description} Expenditure = ${e.Cost}", MessageType.Information);
Balance -= e.Cost;
logIt(Clock.Today, "", 0, e.Cost, e.Category, e.Description);
}
Expand Down Expand Up @@ -212,7 +222,7 @@ private void writeLogs()
{
table.Rows.Add(item);
}
storage.Writer.WriteTable(table, deleteAllData: true);
storage.Writer.WriteTable(table, deleteAllData: false);
}
}
}