Skip to content

Commit aa685db

Browse files
aliex-13chadell
andauthored
Add multi-windows for LLM (#314)
* Add multi-windows for LLM * Use get() for dictionary check Co-authored-by: Christian Adell <[email protected]> * Fix linting * Fix linting issues after merged commit --------- Co-authored-by: Christian Adell <[email protected]>
1 parent 44c7ef4 commit aa685db

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

circuit_maintenance_parser/parser.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,18 @@ class LLM(Parser):
341341
"type": "string",
342342
}
343343
}
344+
"backup_windows": {
345+
type: "array",
346+
"items": {
347+
"type": "datetime",
348+
}
349+
}
344350
}
345351
More context:
346352
* Circuit IDs are also known as service or order
347353
* Status could be confirmed, ongoing, cancelled, completed or rescheduled
354+
* If you see any other backup windows, create a new list entry for each pair of start/end seen there.
355+
* If no backup windows are found. leave the backup_windows list empty.
348356
"""
349357

350358
def parser_hook(self, raw: bytes, content_type: str):
@@ -487,7 +495,10 @@ def parse_content(self, content):
487495

488496
impact = self._get_impact(generated_json)
489497

490-
data = {
498+
# Main maintenance entry
499+
data_list = []
500+
501+
main_data = {
491502
"circuits": self._get_circuit_ids(generated_json, impact),
492503
"start": int(self._get_start(generated_json)),
493504
"end": int(self._get_end(generated_json)),
@@ -496,16 +507,46 @@ def parse_content(self, content):
496507
"account": str(self._get_account(generated_json)),
497508
}
498509

499-
data["maintenance_id"] = str(
510+
# Generate maintenance ID for main window
511+
main_data["maintenance_id"] = str(
500512
self._get_maintenance_id(
501513
generated_json,
502-
data["start"],
503-
data["end"],
504-
data["circuits"],
514+
main_data["start"],
515+
main_data["end"],
516+
main_data["circuits"],
505517
)
506518
)
507519

508-
return [data]
520+
data_list.append(main_data)
521+
522+
# Process backup windows
523+
for window in generated_json.get("backup_windows", []):
524+
if "start" in window and "end" in window:
525+
backup_start = self._convert_str_datetime_to_epoch(window["start"])
526+
backup_end = self._convert_str_datetime_to_epoch(window["end"])
527+
528+
backup_data = {
529+
"circuits": main_data["circuits"], # Same circuits
530+
"start": backup_start,
531+
"end": backup_end,
532+
"summary": main_data["summary"],
533+
"status": main_data["status"],
534+
"account": main_data["account"],
535+
}
536+
537+
# Generate a new maintenance ID for the backup window
538+
backup_data["maintenance_id"] = str(
539+
self._get_maintenance_id(
540+
generated_json,
541+
backup_start,
542+
backup_end,
543+
backup_data["circuits"],
544+
)
545+
)
546+
547+
data_list.append(backup_data)
548+
549+
return data_list # Returning a list with main and backup windows
509550

510551

511552
class Xlsx(Parser):

0 commit comments

Comments
 (0)