Classic Note Entries

AWK program to Report Video Use

# video.awk
# 2009-08-27
# Takes dumped item data from III and formats it for the web
# Part of a pipeline that starts with the data sorted by using sort command
BEGIN { FS = " \t "
     OFS = " \t " ;
    indexes = "count,circs,uses"
     split(indexes , cd ,  ",")
     split(indexes , dvd ,  ",")
     split(indexes , video ,  ",")
     print  startDtml() > "c_cds.html"
     print  startTable() > "c_cds.html"
     print  startDtml() > "c_dvds.html"
     print  startTable() > "c_dvds.html"
     print  startDtml() > "c_videos.html"
     print  startTable() > "c_videos.html"
}
function  startHtml(title) {
    s = "<html> \n <head> \n <title>" title "</title> \n "
    s = s   "<link rel= \" stylesheet \"  type= \" text/css \"  href= \" /bk.css \"  /> \n <link rel= \" stylesheet \"  type= \" text/css \"  href= \" style_sheet \"  />" 
    s = s "</head> \n <body> \n <img src= \" /images/2rf.gif \"  align= \" middle \"  hspace= \" 10 \"  ><h1>" title "</h1> \n "
     return  s
}
function  endHtml() {
    s = "</body> \n </html>"
     return  s
}
function  startDtml(title) {
    s = "<dtml-var standard_html_header> \n <img src= \" /images/2rf.gif \"  align= \" middle \"  hspace= \" 10 \"  ><h1>"title "</h1>"
     return  s
}
function  endDtml() {
    s = "<dtml-var standard_html_footer>"
     return  s
}
function  startTable() {
    s = "<table> \n "
     return  s
}
function  endTable() {
    s = "</table> \n "
     return  s
}
function  printRow(count , title) {
    s = "<tr><td>"count "</td><td>"title "</td></tr>"
     return  s
}
function  commas(n) {
     gsub( /,/ , "" ,n)
    point = index(n , ".") - 1
     if  (point < 0) point = length(n)
     while  (point > 3) {
        point -= 3
        n = substr(n , 1 ,point) "," substr(n ,point + 1)
    }
     return  n
}
function  outputResults(type , counter) {
    totalcnt = counter[ "count"]
    tc = commas(totalcnt)
    circs = counter[ "circs"]
    noncirccount = counter[ "count"] - counter[ "uses"]
    noncircpercent = (noncirccount / totalcnt) * 100
    s = "<h1>Report for " type "</h1> \n "
    s = s "<h3>Total Item Count: " commas(totalcnt) " </h3> \n "
    s = s "<h3>Count of Non Circulating Items: " commas(noncirccount) "</h3> \n "
    s = s "<h3>Percent Non Circulating Items: " noncircpercent "</h3> \n "
    s = s "<h3>Total Circs: " commas(circs) "</h3> \n "
     return  s
}
$3 ~ /whcd/ {
    cd[ "count"]++
    cd[ "circs"]+= $2
     if  ( $2 > 0)  
        cd[ "uses"]++
     print  printRow( $2 , $1) > "c_cds.html"
}
$3 ~ /whdvd/ {
    dvd[ "count"]++
    dvd[ "circs"]+= $2
     if  ( $2 > 0)  
        dvd[ "uses"]++
     print  printRow( $2 , $1) > "c_dvds.html"
}
$3 ~ /whv/ {
    video[ "count"]++
    video[ "circs"]+= $2
     if  ( $2 > 0)  
        video[ "uses"]++
     print  printRow( $2 , $1) > "c_videos.html"
}
END {
     print  startDtml() > "c_summary.html"
     print  outputResults( "CDs" , cd) > "c_summary.html"
     print   "<a href= \" c_cds.html \" >View CD Data</a>  (in decending order) \n\n " > "c_summary.html"
     print   outputResults( "DVDs" , dvd) > "c_summary.html"
     print   "<a href= \" c_dvds.html \" >View DVD Data</a>  (in decending order) \n\n " > "c_summary.html"
     print   outputResults( "Videos" , video) > "c_summary.html"
     print   "<a href= \" c_videos.html \" >View Video Tape Data</a>  (in decending order) \n\n " > "c_summary.html"
     print  endDtml()  > "c_summary.html"
     print  endTable() > "c_cds.html"
     print  endDtml() > "c_cds.html"
     print  endTable() > "c_dvds.html"
     print  endDtml() > "c_dvds.html"
     print  endTable() > "c_videos.html"
     print  endDtml() > "c_videos.html"
}