Parsing the Log
Stardate 55132.6 ยท UES Magnanimous
Briefing
The contact is transmitting. It is a maintenance log, in a format we recognise, because it is ours: a stardate, a level, and a message, separated by pipe characters. Lt. Skree wants each line broken into its three parts so the analysis suite can read it.
Commander Raghunathan, reading over Skree's shoulder, has pointed at a line whose message reads "pressure|flow mismatch" and asked what happens to that pipe. Skree has gone quiet. It should stay in the message. Only the first two pipes separate fields; anything after them is message, pipes and all.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขA normal line splits into stardate, level and message
- โขThe stardate is a number, not text
- โขA message containing a pipe is kept whole
- โขLeading and trailing whitespace on the message is trimmed
- โขA different level and an empty message
Objective
Write parse_entry(line): line looks like
"55103.2|WARN|coolant low". Return a dict with keys "stardate"
(a float), "level" (a string) and "message" (a string, whitespace
trimmed at both ends). Only the first two pipes separate fields; the
message may contain more.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Keep the LogEntry struct as given. Write
parse_entry(line: &str) -> LogEntry: line looks like
"55103.2|WARN|coolant low". The stardate is an f64, the level
a String, the message a String trimmed at both ends. Only the
first two pipes separate fields; the message may contain more.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Split on the pipe, but only twice: Python's split('|', 2), Rust's splitn(3, '|'). Then convert the first part to a number and trim the last one.
Debrief
Every line parses, including the one with the pipe in it. The log is nineteen years old and belongs to a vessel with the same hull number as the Maggie. Skree has said "hm" again. Commander Raghunathan has stopped reading and gone to check something in Engineering.