-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountgenre.tcl
71 lines (58 loc) · 1.25 KB
/
countgenre.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
proc load_genre_database {} {
#global genre_db
global sortedgenrelist
global midi
global exec_out
if {[array exist genre_db]} return
set genrefile genre.tsv
set i 0
set genrelist {}
set inhandle [open $genrefile]
while {![eof $inhandle]} {
gets $inhandle line
set data [split $line \t]
set f [lindex $data 0]
set g [lindex $data 1]
if {![info exist count($g)]} {
set count($g) 1} else {
set count($g) [expr $count($g) + 1]
}
incr i
}
close $inhandle
puts "last record number = $i"
set countlist [array get count]
set gcounts {}
foreach {item0 item1} $countlist {
#puts "$item0 $item1"
set elem [list $item0 $item1]
lappend gcounts $elem
}
set gcounts [lsort -index 1 -integer -decreasing $gcounts]
return $gcounts
}
proc output_gcounts {gcounts} {
foreach elem $gcounts {
puts "[lindex $elem 0]\t[lindex $elem 1]"
}
}
proc output_html_table {gcounts} {
set i 0
puts "<table>"
foreach elem $gcounts {
set out "[lindex $elem 0] ([lindex $elem 1])"
if {[lindex $elem 0] == ""} continue
if {[expr $i % 4] == 0} {
puts " <tr>"
}
puts " <td> $out </td>"
if {[expr $i % 4] == 3} {
puts " </tr>"}
incr i
}
puts " </tr>"
puts "</table>"
}
set gcounts [load_genre_database]
#output_gcounts $gcounts
output_html_table $gcounts