Preview a service configuration
Build a deployment settings preview: normalize its identity fields, then interpret its configuration values.
Inputs are validated. Complete the marked sections in exercise.py; signatures, result dictionaries, and display branches are supplied. No loops, branches, or validation code are required.
Replace each raise NotImplementedError with indented assignments. Keep the supplied return blocks, which send values to the caller. Functions are covered in detail later.
If you have an older saved draft with minutes_to_seconds or greeting, download it if you want to keep it, then use Reset starter code to load this practice's new interface.
Prototype: the identity section
Complete preview_identity(service_name, deployment_id, labels_text) by assigning these names above the supplied return:
name: service name with surrounding whitespace removed; preserve case, punctuation, and internal spaces.identifier: the deployment ID exactly as supplied, as a string.labels: a new list of whitespace-separated labels; preserve order, case, and duplicates.labels_display: labels joined by", "; empty labels produce"".label_count: the number of labels, as an integer.heading:"NAME [ID]"using the normalized name and exact ID.
The supplied return uses service_name and deployment_id as the first two output field names; the other names match the list above. The service name is nonempty after stripping. The ID is a nonempty string of ASCII digits without surrounding whitespace; leading zeros and large IDs are valid. Labels may be empty, including whitespace-only text.
For (" payments-worker ", "9007199254740993", " payments nightly "), the identity section is:
identity = {
"service_name": "payments-worker",
"deployment_id": "9007199254740993",
"labels": ["payments", "nightly"],
"labels_display": "payments, nightly",
"label_count": 2,
"heading": "payments-worker [9007199254740993]",
}
print(identity["heading"]) # payments-worker [9007199254740993]The result dictionary is supplied in the starter.
Final: the complete preview
Complete preview_configuration(...). It already calls your identity function and assembles the final result. Assign these values in its marked section:
workers: integer parsed fromworkers_text.capacity:workersmultiplied by the suppliedper_worker_capacity.timeout_seconds: milliseconds fromtimeout_ms_textconverted to seconds, as a float.timeout_display:"Ns Mms", using whole seconds and the remaining 0–999 milliseconds; for example"125s 500ms".sample_rate: float parsed fromsample_rate_text; preserve the underlying value.enabled: a genuine boolean parsed fromenabled_text, ignoring surrounding whitespace and case.
workers_text and timeout_ms_text represent nonnegative base-ten integers. The validator limits the timeout to 86,400,000 milliseconds (one day), keeping this conversion within ordinary float range. Surrounding whitespace and a leading + are valid. sample_rate_text is valid finite float text between 0 and 1 inclusive; scientific notation is allowed. enabled_text is always true or false after stripping and case normalization. per_worker_capacity is a supplied nonnegative integer, defaulting to 20. Deployment IDs stay text and do not share the timeout's numeric bound.
fallback is either None or a string that is nonempty after stripping. None means inherit environment routing; an explicit string names the fallback. The supplied branches preserve None in the result, strip an explicit name, and render inherited only for absence. Keep them intact. Zero workers, zero sampling, and an explicitly false flag are valid values, not missing data.
For the prototype's identity fields plus workers_text=" 3 ", timeout_ms_text="125500", sample_rate_text="0.125", enabled_text=" false ", and the default fallback/capacity, the result contains that identity and:
workers: 3
capacity: 60
timeout_seconds: 125.5
timeout_display: "125s 500ms"
sample_rate: 0.125
enabled: False
fallback: NoneThe supplied display field renders those values as:
payments-worker [9007199254740993]
3 workers / 60 slots
timeout 125s 500ms / sample 12.5%
disabled / fallback inherited
labels: payments, nightlyThere is no trailing newline. The display formats the sampling rate to one decimal percentage point; the stored float keeps its parsed value. Each call returns a fresh preview and label list. Editing one preview must not change another.
Useful checks before submitting: an ID of "000042"; " FaLsE "; zero workers and sampling; a timeout of "999"; no labels; repeated labels; and an explicit fallback. All final checks include the prototype behavior.
In the browser, Submit runs the final checks.
Complete the starter code, then run the checks.
Results and errors will appear here.