1*77c1e3ccSAndroid Build Coastguard Worker#!/usr/bin/env python3 2*77c1e3ccSAndroid Build Coastguard Worker## Copyright (c) 2017, Alliance for Open Media. All rights reserved. 3*77c1e3ccSAndroid Build Coastguard Worker## 4*77c1e3ccSAndroid Build Coastguard Worker## This source code is subject to the terms of the BSD 2 Clause License and 5*77c1e3ccSAndroid Build Coastguard Worker## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6*77c1e3ccSAndroid Build Coastguard Worker## was not distributed with this source code in the LICENSE file, you can 7*77c1e3ccSAndroid Build Coastguard Worker## obtain it at www.aomedia.org/license/software. If the Alliance for Open 8*77c1e3ccSAndroid Build Coastguard Worker## Media Patent License 1.0 was not distributed with this source code in the 9*77c1e3ccSAndroid Build Coastguard Worker## PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10*77c1e3ccSAndroid Build Coastguard Worker## 11*77c1e3ccSAndroid Build Coastguard Worker"""Aggregate multiple entropy stats output which is written in 32-bit int. 12*77c1e3ccSAndroid Build Coastguard Worker 13*77c1e3ccSAndroid Build Coastguard Workerpython ./aggregate_entropy_stats.py [dir of stats files] [keyword of filenames] 14*77c1e3ccSAndroid Build Coastguard Worker [filename of final stats] 15*77c1e3ccSAndroid Build Coastguard Worker""" 16*77c1e3ccSAndroid Build Coastguard Worker 17*77c1e3ccSAndroid Build Coastguard Worker__author__ = "[email protected]" 18*77c1e3ccSAndroid Build Coastguard Worker 19*77c1e3ccSAndroid Build Coastguard Workerimport os 20*77c1e3ccSAndroid Build Coastguard Workerimport sys 21*77c1e3ccSAndroid Build Coastguard Workerimport numpy as np 22*77c1e3ccSAndroid Build Coastguard Worker 23*77c1e3ccSAndroid Build Coastguard Workerdef main(): 24*77c1e3ccSAndroid Build Coastguard Worker dir = sys.argv[1] 25*77c1e3ccSAndroid Build Coastguard Worker sum = [] 26*77c1e3ccSAndroid Build Coastguard Worker for fn in os.listdir(dir): 27*77c1e3ccSAndroid Build Coastguard Worker if sys.argv[2] in fn: 28*77c1e3ccSAndroid Build Coastguard Worker stats = np.fromfile(dir + fn, dtype=np.int32) 29*77c1e3ccSAndroid Build Coastguard Worker if len(sum) == 0: 30*77c1e3ccSAndroid Build Coastguard Worker sum = stats 31*77c1e3ccSAndroid Build Coastguard Worker else: 32*77c1e3ccSAndroid Build Coastguard Worker sum = np.add(sum, stats) 33*77c1e3ccSAndroid Build Coastguard Worker if len(sum) == 0: 34*77c1e3ccSAndroid Build Coastguard Worker print("No stats file is found. Double-check directory and keyword?") 35*77c1e3ccSAndroid Build Coastguard Worker else: 36*77c1e3ccSAndroid Build Coastguard Worker sum.tofile(dir+sys.argv[3]) 37*77c1e3ccSAndroid Build Coastguard Worker 38*77c1e3ccSAndroid Build Coastguard Workerif __name__ == '__main__': 39*77c1e3ccSAndroid Build Coastguard Worker main() 40