Page MenuHomec4science

compute_frequency_duplicate_nodes.py
No OneTemporary

File Metadata

Created
Mon, Nov 11, 20:44

compute_frequency_duplicate_nodes.py

#!/usr/bin/env python
from __future__ import print_function
from collections import defaultdict
import re
import sys
def parse_file(filename):
counter = defaultdict(int)
pattern = re.compile('^<Piece NumberOfPoints= "(\d+)', re.MULTILINE)
with open(filename, 'r') as fh:
match = None
while not match:
line = fh.next()
match = re.match(pattern,line)
if match:
nb_points = int(match.groups()[0])
fh.next()
for i in range(nb_points):
curr_pt = tuple((float(num) for num in fh.next().strip().split()))
counter[curr_pt] +=1
return counter
def main():
filename = sys.argv[1]
counter = parse_file(filename)
histo = defaultdict(list)
for point, nb_occurences in counter.items():
histo[nb_occurences].append(point)
print("nb_duplicates: nb_occurences")
for key, value in histo.items():
print("{0:>13}: {1:>4}".format(key, len(value)))
for point in histo[4]:
print(point)
if __name__ == "__main__":
main()

Event Timeline