Skip to content

Commit

Permalink
Merge pull request #56 from mcrossley/master
Browse files Browse the repository at this point in the history
b3069
  • Loading branch information
mcrossley authored Mar 12, 2020
2 parents 7cb4fb6 + 650588e commit f74030a
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 41 deletions.
6 changes: 6 additions & 0 deletions CumulusMX/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 11 additions & 9 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
142 changes: 142 additions & 0 deletions CumulusMX/DataEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DayFileEditor>(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<string>(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<DatalogEditor>(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<string>(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";
Expand Down
67 changes: 40 additions & 27 deletions CumulusMX/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http_portnum> - Sets the HTTP port Cumulus will use (default 8998)");
Console.WriteLine(" -lang <culture_name> - 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();
}
}

Expand Down Expand Up @@ -129,6 +131,17 @@ private static void Main(string[] args)
}
}

private static void usage()
{
Console.WriteLine();
Console.WriteLine("Valid arugments are:");
Console.WriteLine(" -port <http_portnum> - Sets the HTTP port Cumulus will use (default 8998)");
Console.WriteLine(" -lang <culture_name> - 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
Expand Down
6 changes: 3 additions & 3 deletions CumulusMX/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
8 changes: 6 additions & 2 deletions CumulusMX/WeatherStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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] + "\"";
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions Updates.txt
Original file line number Diff line number Diff line change
@@ -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\<too much to list>



3.4.4 - b3068
=============
- Fix for incorrect NOAA yearly report, annual averages for tempertaure and wind were calculated incorrectly
Expand Down

0 comments on commit f74030a

Please sign in to comment.