def diff(self, report_a, report_b):
arguments = GLOBAL_ARGUMENTS + ['<STR_LIT>']<EOL>output = OrderedDict([<EOL>('<STR_LIT:a>', OrderedDict([(arg, report_a[arg]) for arg in arguments])),<EOL>('<STR_LIT:b>', OrderedDict([(arg, report_b[arg]) for arg in arguments])),<EOL>('<STR_LIT>', [])<EOL>])<EOL>output['<STR_LIT:a>']<EOL>for query_a in report_a['<STR_LIT>']:<EOL><INDENT>for query_b in report_b['<STR_LIT>']:<EOL><INDENT>if query_a['<STR_LIT>'] == query_b['<STR_LIT>']:<EOL><INDENT>diff = OrderedDict()<EOL>diff['<STR_LIT>'] = query_a['<STR_LIT>']<EOL>diff['<STR_LIT>'] = query_a['<STR_LIT>']<EOL>diff['<STR_LIT:data>'] = OrderedDict()<EOL>for metric, values in query_a['<STR_LIT:data>'].items():<EOL><INDENT>data_type = diff['<STR_LIT>'][metric]<EOL>diff['<STR_LIT:data>'][metric] = OrderedDict()<EOL>total_a = values['<STR_LIT>']<EOL>total_b = query_b['<STR_LIT:data>'][metric]['<STR_LIT>']<EOL>for label, value in values.items():<EOL><INDENT>a = value<EOL>try:<EOL><INDENT>b = query_b['<STR_LIT:data>'][metric][label]<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>change = b - a<EOL>percent_change = float(change) / a if a > <NUM_LIT:0> else None<EOL>percent_a = float(a) / total_a if total_a > <NUM_LIT:0> else None<EOL>percent_b = float(b) / total_b if total_b > <NUM_LIT:0> else None<EOL>if label == '<STR_LIT>' or data_type == '<STR_LIT>' or percent_a is None or percent_b is None:<EOL><INDENT>point_change = None<EOL><DEDENT>else:<EOL><INDENT>point_change = percent_b - percent_a<EOL><DEDENT>diff['<STR_LIT:data>'][metric][label] = OrderedDict([<EOL>('<STR_LIT>', change),<EOL>('<STR_LIT>', percent_change),<EOL>('<STR_LIT>', point_change),<EOL>])<EOL><DEDENT><DEDENT>output['<STR_LIT>'].append(diff)<EOL><DEDENT><DEDENT>query_b = report_b['<STR_LIT>']<EOL><DEDENT>return output<EOL>
Generate a diff for two data reports.