diff --git a/CumulusMX/Api.cs b/CumulusMX/Api.cs index 72d2f7fc..a3030881 100644 --- a/CumulusMX/Api.cs +++ b/CumulusMX/Api.cs @@ -223,6 +223,12 @@ public bool EditData() case "thisyear": return this.JsonResponse(dataEditor.EditThisYearRecs(this)); + + case "dayfile": + return this.JsonResponse(dataEditor.EditDayFile(this)); + + case "datalogs": + return this.JsonResponse(dataEditor.EditDatalog(this)); } throw new KeyNotFoundException("Key Not Found: " + lastSegment); diff --git a/CumulusMX/Cumulus.cs b/CumulusMX/Cumulus.cs index 4db612f5..ac11340b 100644 --- a/CumulusMX/Cumulus.cs +++ b/CumulusMX/Cumulus.cs @@ -30,8 +30,8 @@ namespace CumulusMX public class Cumulus { ///////////////////////////////// - public string Version = "3.4.4"; - public string Build = "3068"; + public string Version = "3.4.5"; + public string Build = "3069"; ///////////////////////////////// private const string appGuid = "57190d2e-7e45-4efb-8c09-06a176cef3f3"; @@ -2425,24 +2425,26 @@ internal void DoMoonPhase() DateTime utcNow = DateTime.UtcNow; double moonAngle = MoonriseMoonset.MoonPhase(utcNow.Year, utcNow.Month, utcNow.Day, utcNow.Hour); MoonPercent = (100.0 * (1.0 + Math.Cos(moonAngle * Math.PI / 180)) / 2.0); + var phasePercent = Math.Round(MoonPercent); // If between full moon and new moon, angle is between 180 and 360, make percent negative to indicate waning if (moonAngle > 180) { MoonPercent = -MoonPercent; + phasePercent = -phasePercent; } - if ((MoonPercent > 1) && (MoonPercent < 49)) + if ((phasePercent > 2) && (phasePercent < 48)) MoonPhaseString = WaxingCrescent; - else if ((MoonPercent >= 49) && (MoonPercent <= 51)) + else if ((phasePercent >= 48) && (phasePercent <= 52)) MoonPhaseString = FirstQuarter; - else if ((MoonPercent > 51) && (MoonPercent < 99)) + else if ((phasePercent > 52) && (phasePercent < 98)) MoonPhaseString = WaxingGibbous; - else if ((MoonPercent >= 99) || (MoonPercent <= -99)) + else if ((phasePercent >= 98) || (phasePercent <= -98)) MoonPhaseString = Fullmoon; - else if ((MoonPercent < -51) && (MoonPercent > -99)) + else if ((phasePercent < -52) && (phasePercent > -98)) MoonPhaseString = WaningGibbous; - else if ((MoonPercent <= -49) && (MoonPercent >= -51)) + else if ((phasePercent <= -48) && (phasePercent >= -52)) MoonPhaseString = LastQuarter; - else if ((MoonPercent > -49) && (MoonPercent < -1)) + else if ((phasePercent > -48) && (phasePercent < -2)) MoonPhaseString = WaningCrescent; else MoonPhaseString = Newmoon; diff --git a/CumulusMX/DataEditor.cs b/CumulusMX/DataEditor.cs index c7311dc1..7f5987c0 100644 --- a/CumulusMX/DataEditor.cs +++ b/CumulusMX/DataEditor.cs @@ -2916,6 +2916,148 @@ internal string EditCurrentCond(IHttpContext context) return "{\"result\":\"" + (result ? "Success" : "Failed") + "\"}"; } + internal string EditDayFile(IHttpContext context) + { + var request = context.Request; + string text; + using (var reader = new StreamReader(request.InputStream, request.ContentEncoding)) + { + text = reader.ReadToEnd(); + } + + var newData = JsonConvert.DeserializeObject(text); + + // read dayfile into a List + var lines = File.ReadAllLines(cumulus.DayFile).ToList(); + + var lineNum = newData.LineNum - 1; // our List is zero relative + + if (newData.Action == "Edit") + { + // replace the edited line + var newLine = String.Join(cumulus.ListSeparator, newData.Data); + + lines[lineNum] = newLine; + } + else if (newData.Action == "Delete") + { + // Just double check we are deleting the correct line - see if the dates match + var lineData = lines[lineNum].Split(cumulus.ListSeparator.ToCharArray()[0]); + if (lineData[0] == newData.Data[0]) + { + lines.RemoveAt(lineNum); + } + else + { + //throw("Failed, line to delete does not match the file contents"); + return "{\"result\":\"Failed, line to delete does not match the file contents\"}"; + } + } + else + { + //throw("Failed, unrecognised action"); + return "{\"result\":\"Failed, unrecognised action\"}"; + } + // write dayfile back again + File.WriteAllLines(cumulus.DayFile, lines); + + // return the updated record + var rec = new List(newData.Data); + rec.Insert(0, newData.LineNum.ToString()); + return JsonConvert.SerializeObject(rec); + } + + private class DayFileEditor + { + public readonly string Action; + public readonly int LineNum; + public readonly string[] Data; + + public DayFileEditor(string action, int line, string[] data) + { + Action = action; + LineNum = line; + Data = data; + } + } + + internal string EditDatalog(IHttpContext context) + { + var request = context.Request; + string text; + using (var reader = new StreamReader(request.InputStream, request.ContentEncoding)) + { + text = reader.ReadToEnd(); + } + + var newData = JsonConvert.DeserializeObject(text); + + // date will (hopefully) be in format "m-yyyy" or "mm-yyyy" + int month = Convert.ToInt32(newData.Month.Split('-')[0]); + int year = Convert.ToInt32(newData.Month.Split('-')[1]); + + // Get a timestamp, use 15th day to avoid wrap issues + var ts = new DateTime(year, month, 15); + + var logfile = (newData.Extra ? cumulus.GetExtraLogFileName(ts) : cumulus.GetLogFileName(ts)); + var numFields = (newData.Extra ? Cumulus.NumExtraLogFileFields : Cumulus.NumLogFileFields); + + // read the log file into a List + var lines = File.ReadAllLines(logfile).ToList(); + + var lineNum = newData.LineNum - 1; // our List is zero relative + + if (newData.Action == "Edit") + { + // replace the edited line + var newLine = String.Join(cumulus.ListSeparator, newData.Data); + + lines[lineNum] = newLine; + } + else if (newData.Action == "Delete") + { + // Just double check we are deleting the correct line - see if the dates match + var lineData = lines[lineNum].Split(cumulus.ListSeparator.ToCharArray()[0]); + if (lineData[0] == newData.Data[0]) + { + lines.RemoveAt(lineNum); + } + else + { + //throw("Failed, line to delete does not match the file contents"); + return "{\"result\":\"Failed, line to delete does not match the file contents\"}"; + } + } + + + // write logfile back again + File.WriteAllLines(logfile, lines); + + // return the updated record + var rec = new List(newData.Data); + rec.Insert(0, newData.LineNum.ToString()); + return JsonConvert.SerializeObject(rec); + } + + private class DatalogEditor + { + public readonly string Action; + public readonly int LineNum; + public readonly string Month; + public readonly bool Extra; + public readonly string[] Data; + + public DatalogEditor(string action, int line, string month, bool extra, string[] data) + { + Action = action; + LineNum = line; + Month = month; + Extra = extra; + Data = data; + } + } + + private bool SetCurrCondText(string currCondText) { var fileName = cumulus.AppDir + "currentconditions.txt"; diff --git a/CumulusMX/Program.cs b/CumulusMX/Program.cs index 8722cf27..c6ae6b9e 100644 --- a/CumulusMX/Program.cs +++ b/CumulusMX/Program.cs @@ -68,36 +68,38 @@ private static void Main(string[] args) for (int i = 0; i < args.Length; i++) { - if (args[i] == "-lang" && args.Length >= i) + try { - var lang = args[++i]; - - CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(lang); - CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(lang); - } - else if (args[i] == "-port" && args.Length >= i) - { - httpport = Convert.ToInt32(args[++i]); - } - else if (args[i] == "-debug") - { - // Switch on debug and and data logging from the start - debug = true; + if (args[i] == "-lang" && args.Length >= i) + { + var lang = args[++i]; + + CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(lang); + CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(lang); + } + else if (args[i] == "-port" && args.Length >= i) + { + httpport = Convert.ToInt32(args[++i]); + } + else if (args[i] == "-debug") + { + // Switch on debug and and data logging from the start + debug = true; + } + else if (args[i] == "-wsport") + { + i++; + Console.WriteLine("The use of the -wsport command line parameter is deprecated"); + } + else + { + Console.WriteLine($"Invalid command line argument \"{args[i]}\""); + usage(); + } } - else if (args[i] == "-wsport") + catch { - i++; - Console.WriteLine("The use of the -wsport command line parameter is deprecated"); - } - else - { - Console.WriteLine($"Invalid command line argument \"{args[i]}\""); - Console.WriteLine("Valid arugments are:"); - Console.WriteLine(" -port - Sets the HTTP port Cumulus will use (default 8998)"); - Console.WriteLine(" -lang - Sets the Language Cumulus will use (defaults to current user language)"); - Console.WriteLine(" -debug - Switches on debug and data logging from Cumulus start"); - Console.WriteLine("\nCumulus terminating"); - Environment.Exit(1); + usage(); } } @@ -129,6 +131,17 @@ private static void Main(string[] args) } } + private static void usage() + { + Console.WriteLine(); + Console.WriteLine("Valid arugments are:"); + Console.WriteLine(" -port - Sets the HTTP port Cumulus will use (default 8998)"); + Console.WriteLine(" -lang - Sets the Language Cumulus will use (defaults to current user language)"); + Console.WriteLine(" -debug - Switches on debug and data logging from Cumulus start"); + Console.WriteLine("\nCumulus terminating"); + Environment.Exit(1); + } + private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e) { try diff --git a/CumulusMX/Properties/AssemblyInfo.cs b/CumulusMX/Properties/AssemblyInfo.cs index 7ddd8990..ac50b69f 100644 --- a/CumulusMX/Properties/AssemblyInfo.cs +++ b/CumulusMX/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("CumulusMX")] -[assembly: AssemblyDescription("Build 3068")] +[assembly: AssemblyDescription("Build 3069")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("CumulusMX")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.4.4.3068")] -[assembly: AssemblyFileVersion("3.4.4.3068")] +[assembly: AssemblyVersion("3.4.5.3069")] +[assembly: AssemblyFileVersion("3.4.5.3069")] diff --git a/CumulusMX/WeatherStation.cs b/CumulusMX/WeatherStation.cs index 64bd4577..36f69fdb 100644 --- a/CumulusMX/WeatherStation.cs +++ b/CumulusMX/WeatherStation.cs @@ -8863,11 +8863,13 @@ public string GetDayfile(string draw, int start, int length) var lines = File.ReadLines(cumulus.DayFile).Skip(start).Take(length); + var lineNum = start + 1; // Start is zero relative + foreach (var line in lines) { var fields = line.Split(Convert.ToChar(cumulus.ListSeparator)); var numFields = fields.Length; - json += "["; + json += $"[{lineNum++},"; for (var i = 0; i < numFields; i++) { json = json + "\"" + fields[i] + "\""; @@ -8980,10 +8982,12 @@ public string GetLogfile(string date, string draw, int start, int length, bool e var lines = File.ReadLines(logfile).Skip(start).Take(length); + var lineNum = start + 1; // Start is zero relative + foreach (var line in lines) { var fields = line.Split(Convert.ToChar(cumulus.ListSeparator)); - json += "["; + json += $"[{lineNum++},"; for (var i = 0; i < numFields; i++) { if (i < fields.Length) diff --git a/Updates.txt b/Updates.txt index aee477ad..5fe38620 100644 --- a/Updates.txt +++ b/Updates.txt @@ -1,3 +1,17 @@ +3.5.0 - b3069 +============= +- Adds Editors for: Dayfile, Monthly Logs, Extra Logs +- Adds line numbers to the log file viewer/editors +- Widens the time windows for the Moons phase names +- Fix for <#MoonPercent> and <#MoonPercentAbs> always showing integer values even with the dp=n option + + +- Updated files + \CumulusMX.exe + \interface\ + + + 3.4.4 - b3068 ============= - Fix for incorrect NOAA yearly report, annual averages for tempertaure and wind were calculated incorrectly