Skip to content

Commit 48fee79

Browse files
ELI-674 - tweaks to validator
1 parent f83f492 commit 48fee79

1 file changed

Lines changed: 35 additions & 32 deletions

File tree

  • src/rules_validation_api

src/rules_validation_api/app.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,54 +76,57 @@ def main() -> None: # pragma: no cover
7676

7777

7878
def display_current_iteration(result: RulesValidation) -> None:
79-
no_of_iterations = 0
79+
config = result.campaign_config
80+
iterations = config.iterations
81+
is_campaign_live = config.campaign_live
82+
today = datetime.now(tz=UTC).date()
8083

81-
# Current Iteration
82-
try:
83-
no_of_iterations = len(result.campaign_config.iterations)
84-
current = result.campaign_config.current_iteration
85-
except StopIteration:
86-
current = None
87-
is_campaign_live = result.campaign_config.campaign_live
84+
no_of_iterations = len(iterations)
85+
is_campaign_expired = config.end_date < today
86+
87+
# ---- Current Iteration ----
8888
if is_campaign_live:
8989
sys.stdout.write(f"{YELLOW}Campaign is {RESET}{GREEN}LIVE{RESET}\n")
90-
if current is None:
91-
sys.stdout.write(f"{YELLOW}No active iteration could be determined{RESET}\n")
92-
else:
90+
current = config.current_iteration
91+
if current:
9392
sys.stdout.write(
9493
f"{YELLOW}Current active Iteration Number: {RESET}{GREEN}{current.iteration_number}{RESET}\n"
9594
)
9695
sys.stdout.write(
9796
f"{YELLOW}Current active Iteration's date&time: {RESET}{GREEN}{current.iteration_datetime}{RESET}\n"
9897
)
98+
else:
99+
sys.stdout.write(f"{YELLOW}No active iteration could be determined{RESET}\n")
99100

100101
else:
101-
sys.stdout.write(f"{YELLOW}Campaign is {RESET}{GREEN}NOT LIVE{RESET}\n")
102+
sys.stdout.write(f"{YELLOW}Campaign is {RESET}{GREEN}NOT LIVE{RESET}")
102103

103-
# Next Iteration
104-
try:
105-
sorted_iterations = sorted(result.campaign_config.iterations, key=attrgetter("iteration_date"))
106-
today = datetime.now(tz=UTC).date()
107-
next_iteration = (
108-
next(i for i in sorted_iterations if i.iteration_date > today) if sorted_iterations else None
109-
)
110-
except StopIteration:
111-
next_iteration = None
104+
if is_campaign_expired:
105+
sys.stdout.write(f"{YELLOW}[EXPIRED on {config.end_date}]{RESET}\n")
106+
else:
107+
sys.stdout.write(f"{YELLOW}[To be STARTED on {RESET}{GREEN}{config.start_date}{RESET}{YELLOW}]{RESET}\n")
112108

113-
if next_iteration:
114-
sys.stdout.write(
115-
f"{YELLOW}Next active Iteration Number: {RESET}{GREEN}{next_iteration.iteration_number}{RESET}\n"
109+
# ---- Next Iteration ----
110+
if not is_campaign_expired:
111+
sorted_iterations = sorted(iterations, key=attrgetter("iteration_date"))
112+
next_iteration = next(
113+
(i for i in sorted_iterations if i.iteration_date > today), None
116114
)
117-
sys.stdout.write(
118-
f"{YELLOW}Next active Iteration's date&time: {RESET}{GREEN}{next_iteration.iteration_datetime}{RESET}\n"
119-
)
120-
else:
121-
sys.stdout.write(f"{YELLOW}No next active iteration could be determined{RESET}\n")
122115

116+
if next_iteration:
117+
sys.stdout.write(
118+
f"{YELLOW}Next active Iteration Number: {RESET}{GREEN}{next_iteration.iteration_number}{RESET}\n"
119+
)
120+
sys.stdout.write(
121+
f"{YELLOW}Next active Iteration's date&time: {RESET}{GREEN}{next_iteration.iteration_datetime}{RESET}\n"
122+
)
123+
else:
124+
sys.stdout.write(f"{YELLOW}No next active iteration could be determined{RESET}\n")
123125

124-
# Total no of iterations
125-
sys.stdout.write(f"{YELLOW}Total iterations configured: {RESET}{GREEN}{no_of_iterations}{RESET}\n")
126-
126+
# ---- Total Iterations ----
127+
sys.stdout.write(
128+
f"{YELLOW}Total iterations configured: {RESET}{GREEN}{no_of_iterations}{RESET}\n"
129+
)
127130

128131
if __name__ == "__main__": # pragma: no cover
129132
main()

0 commit comments

Comments
 (0)