<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def format_energy_results(energy):
 """Take the result of an energy measurement and return a flat dictionary that contains all values."""

    if not energy:
        return {}
    result = {}
    cpuenergy = Decimal(0)
    for pkg, domains in energy.items():
        for domain, value in domains.items():
            if domain == DOMAIN_PACKAGE:
                cpuenergy += value
                result['cpuenergy-pkg{}'.format(pkg)] = value
            else:
                result['cpuenergy-pkg{}-{}'.format(pkg, domain)] = value
    result['cpuenergy'] = cpuenergy
    result = collections.OrderedDict(sorted(result.items()))
    return result