1#!/usr/bin/python3 -B 2 3# Copyright 2021 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Command line tool to report the statistics of EXPECTED_UPSTREAM file.""" 18 19import collections 20 21from common_util import ExpectedUpstreamFile 22from common_util import OJLUNI_JAVA_BASE_PATH 23 24 25def get_major_version(git_ref: str) -> str: 26 index = git_ref.find('/') 27 if index == -1: 28 return git_ref 29 return git_ref[:index] 30 31 32def main() -> None: 33 expected_upstream_file = ExpectedUpstreamFile() 34 expected_entries = expected_upstream_file.read_all_entries() 35 36 non_test_filter = lambda e: e.dst_path.startswith(OJLUNI_JAVA_BASE_PATH) 37 non_test_entries = list(filter(non_test_filter, expected_entries)) 38 non_test_refs = list(map(lambda e: e.git_ref, non_test_entries)) 39 total = len(non_test_refs) 40 41 minor_groups = dict(collections.Counter(non_test_refs)) 42 43 top_tree = {} 44 for git_ref, count in minor_groups.items(): 45 major_version = get_major_version(git_ref) 46 if major_version not in top_tree: 47 top_tree[major_version] = {} 48 top_tree[major_version][git_ref] = count 49 50 top_tree = {k: top_tree[k] for k in sorted(top_tree)} 51 52 print('=== Ojluni Version Report ===') 53 for major_version, counts in top_tree.items(): 54 subtotal = sum(counts[key] for key in counts) 55 percentages = '{:.2%}'.format(subtotal / total) 56 print(f'{major_version}:\t{subtotal}\t{percentages}') 57 for minor_version, count in counts.items(): 58 sub_percentages = '{:.2%}'.format(count / subtotal) 59 print(f' {minor_version}:\t{count}\t{sub_percentages}') 60 61 62if __name__ == '__main__': 63 main() 64