From a6b580610dde598148dd758f1ad3fb948fc18fe8 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 10 Aug 2024 13:02:51 -0400 Subject: [PATCH] Program: Add option to set the output schedule length --- README.md | 7 ++++--- Rotationator/Program.cs | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 85d60e1..626c8d5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ Arguments: The output VSSetting BYAML file. Options: - --phaseLength The length of each phase, in hours. [default: 4] - --version Show version information - -?, -h, --help Show help and usage information + --phaseLength The length of each phase in hours. [default: 4] + --scheduleLength How long the schedule should be in days. [default: 30] + --version Show version information + -?, -h, --help Show help and usage information ``` diff --git a/Rotationator/Program.cs b/Rotationator/Program.cs index dd09435..3dac013 100644 --- a/Rotationator/Program.cs +++ b/Rotationator/Program.cs @@ -10,8 +10,8 @@ using Rotationator; // Constants // -const int maximumPhases = 192; // TODO correct? const int defaultPhaseLength = 4; +const int defaultScheduleLength = 30; Dictionary> bannedStages = new Dictionary>() { @@ -67,11 +67,15 @@ Argument outputByamlArg = new Argument("outputByaml", "The outpu Option phaseLengthOption = new Option("--phaseLength", () => defaultPhaseLength, "The length of each phase in hours."); +Option scheduleLengthOption = new Option("--scheduleLength", () => defaultScheduleLength, + "How long the schedule should be in days."); + Command command = new RootCommand("Generates a new VSSetting BYAMl file.") { lastByamlArg, outputByamlArg, - phaseLengthOption + phaseLengthOption, + scheduleLengthOption }; command.SetHandler(context => Run(context)); @@ -89,6 +93,7 @@ void Run(InvocationContext context) string lastByamlPath = context.ParseResult.GetValueForArgument(lastByamlArg); string outputByamlPath = context.ParseResult.GetValueForArgument(outputByamlArg); int phaseLength = context.ParseResult.GetValueForOption(phaseLengthOption); + int scheduleLength = context.ParseResult.GetValueForOption(scheduleLengthOption); dynamic lastByaml = ByamlFile.Load(lastByamlPath); @@ -131,10 +136,35 @@ void Run(InvocationContext context) { throw new NotImplementedException("not supported yet"); } - + // The last phase is set to 10 years, so correct this to the correct phase length. currentPhases.Last().Length = phaseLength; + // + // Find the maximum number of phases to add. + // + + DateTime endTime = baseTime.AddDays(scheduleLength); + + loopTime = baseTime; + + for (int i = 0; i < currentPhases.Count; i++) + { + loopTime = loopTime.AddHours(currentPhases[i].Length); + } + + int maximumPhases = currentPhases.Count; + + // This definitely isn't the most efficient way to do this, but it works. + while (endTime > loopTime) + { + maximumPhases++; + + loopTime = loopTime.AddHours(phaseLength); + } + + Console.WriteLine($"Generating {maximumPhases} phases to reach {endTime:O} (already have {currentPhases.Count})"); + // // Generate new phases to fill out the schedule //