Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91518174
compute_frequency_duplicate_nodes.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 11, 20:44
Size
1 KB
Mime Type
text/x-python
Expires
Wed, Nov 13, 20:44 (2 d)
Engine
blob
Format
Raw Data
Handle
22277155
Attached To
rCADDMESH CADD_mesher
compute_frequency_duplicate_nodes.py
View Options
#!/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
Log In to Comment