in mozetl/hardware_report/summarize_json.py [0:0]
def validate_finalized_data(data):
"""Validate the aggregated and finalized data.
This checks that the aggregated hardware data object contains all the expected keys
and that they sum up roughly 1.0.
When a problem is found a message is printed to make debugging easier.
Args:
data: Data in aggregated form.
Returns:
True if the data validates correctly, false otherwise.
"""
keys_accumulator = {
"browserArch": 0.0,
"cpuCores": 0.0,
"cpuCoresSpeed": 0.0,
"cpuVendor": 0.0,
"cpuSpeed": 0.0,
"gpuVendor": 0.0,
"gpuModel": 0.0,
"resolution": 0.0,
"ram": 0.0,
"osName": 0.0,
"osArch": 0.0,
"hasFlash": 0.0,
}
# We expect to have at least a key in |data| whose name begins with one
# of the keys in |keys_accumulator|. Iterate through the keys in |data|
# and accumulate their values in the accumulator.
for key, value in data.items():
if key in ["inactive", "broken", "date"]:
continue
# Get the name of the property to look it up in the accumulator.
property_name = key.split("_")[0]
if property_name not in keys_accumulator:
logger.warning("Cannot find {} in |keys_accumulator|".format(property_name))
return False
keys_accumulator[property_name] += value
# Make sure all the properties add up to 1.0 (or close enough).
for key, value in keys_accumulator.items():
if abs(1.0 - value) > 0.05:
logger.warning(
"{} values do not add up to 1.0. Their sum is {}.".format(key, value)
)
return False
return True