source: tools/perf/sample.py @ e4d7c1c

ADTast-experimental
Last change on this file since e4d7c1c was 0a79fd9, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Simple python tool to down sample data

  • Property mode set to 100755
File size: 670 bytes
Line 
1#!/usr/bin/python3
2
3import argparse, json, random, sys
4
5parser = argparse.ArgumentParser()
6parser.add_argument('--infile', type=argparse.FileType('r'), default=sys.stdin)
7parser.add_argument('--outfile', type=argparse.FileType('w'), default=sys.stdout)
8
9args = parser.parse_args()
10
11data = json.load(args.infile)
12
13
14
15print(len(data['values']))
16print(int(len(data['values']) / 1000))
17
18sample = random.sample(data['values'], int(len(data['values']) / 1000))
19print(len(sample))
20
21# Sort by timestamp (the second element)
22# take second element for sort
23def takeSecond(elem):
24    return elem[1]
25
26sample.sort(key=takeSecond)
27
28data['values'] = sample
29json.dump(data, args.outfile)
Note: See TracBrowser for help on using the repository browser.