Skip to content

Commit

Permalink
New web tag <#AnnualRainfall>
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Crossley committed Jul 21, 2024
1 parent da4ea07 commit 957e123
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 31 additions & 1 deletion CumulusMX/webtags.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -3598,7 +3599,7 @@ private string TagMonthTempAvg(Dictionary<string, string> tagParams)

if (start.Date == DateTime.Now.AddHours(cumulus.GetHourInc()).Date)
{
// first day of the currebt month, there are no dayfile entries
// first day of the current month, there are no dayfile entries
// so return the average temp so far today
return Tagavgtemp(tagParams);
}
Expand Down Expand Up @@ -3638,6 +3639,34 @@ private string TagYearTempAvg(Dictionary<string, string> tagParams)
return CheckRcDp(CheckTempUnit(avg, tagParams), tagParams, cumulus.TempDPlaces);
}

private string TagAnnualRainfall(Dictionary<string, string> tagParams)
{
var year = tagParams.Get("y");
DateTime start;
DateTime end;
double total;

if (year != null)
{
if (int.Parse(year) == DateTime.Now.Year)
{
total = station.RainYear;
}
else
{
start = new DateTime(int.Parse(year), 1, 1, 0, 0, 0, DateTimeKind.Local);
end = start.AddYears(1);
total = station.DayFile.Where(x => x.Date >= start && x.Date < end).Sum(x => x.TotalRain);
}
}
else
{
total = station.RainYear;
}

return CheckRcDp(CheckRainUnit(total, tagParams), tagParams, cumulus.RainDPlaces);
}

private string TagThwIndex(Dictionary<string, string> tagParams)
{
return CheckRcDp(CheckTempUnit(station.THWIndex, tagParams), tagParams, 1);
Expand Down Expand Up @@ -6752,6 +6781,7 @@ public void InitialiseWebtags()
// Specifc Month/Year values
{ "MonthTempAvg", TagMonthTempAvg },
{ "YearTempAvg", TagYearTempAvg },
{ "AnnualRainfall", TagAnnualRainfall },
// Options
{ "Option_useApparent", TagOption_useApparent },
{ "Option_showSolar", TagOption_showSolar },
Expand Down
3 changes: 3 additions & 0 deletions Updates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ New
- For Standard format specifiers see: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings
- The default output is generated using the format string "{0:%d} days {0:%h} hours"
- You can customise this like this example: <#SystemUpTime format="{0:%d}d {0:%h}h {0:%m}m"> --> "12d 9h 46m"
- New web tag <#AnnualRainfall>
- Defaults to the current year if no year is specified, so = <#ryear>
- Accepts a tag parameter of y=nnnn, which will return the total rainfall for the specified year. Eg. <#AnnualRainfall y=2021>

Changed
- Daily backup now runs asynchronously to prevent it stopping MX continue to run
Expand Down

0 comments on commit 957e123

Please sign in to comment.