Blob Blame History Raw
#!/bin/sh
# Compares the output of two repo-font-audit runs and print test score changes

DATADIR="$(dirname $0)/../private"

usage() {
cat >&2 << EOF_USAGE
Usage: $0 <resultset1> <resultset2>
<resultsetx>: “Extracted data” archive produced by repo-font-audit

Example:
$0 repo-font-audit-fedora-12-20091121T110127Z.tar.xz repo-font-audit-rawhide-20091121T110127Z.tar.xz
EOF_USAGE
exit 1
}


find_package_changes() {
awk -F '|' '
  FNR==1 {
    filenames = filenames FILENAME "|"
  }
  (FNR>1) && ($15!="") {
    rpm[$3] = rpm[$3] FILENAME "|" $1 "|" $2 "|" $7 "|" $10 "|" $11 "|" $12 "|" $15 "#"
  }
  END {
    sub("\\|$","",filenames)
    split(filenames,filenamest,"|")

    print "B. Font package changes:"
    nr = asorti(rpm,rpms)
    for ( r = 1 ; r <= nr ; r++ ) {
      sub("#$","",rpm[rpms[r]])
      na = split(rpm[rpms[r]],rpma,"#")
      delete rpmv
      for ( a = 1 ; a <= na ; a++ ) {
        if (rpmv[rpma[a]]) {
          delete rpma[a]
        }
        else {
          rpmv[rpma[a]] = 1
        }
      }
      for (i in minus) {
        delete minus[i]
      }
      for (i in plus) {
        delete plus[i]
      }
      for (i in changed) {
        delete changed[i]
      }
      infom = ""
      infop = ""
      na = asort(rpma)
      for ( a = 1 ; a <= na ; a++ ) {
        ni = split(rpma[a],rpmi,"|")
        if ( rpmi[1] == filenamest[1] ) {
          infom = rpmi[2] "|" rpmi[3] "|" rpmi[4]
          minus[rpmi[5]] = rpmi[6] "|" rpmi[7] "|" rpmi[8]
        }
        if ( rpmi[1] == filenamest[2] ) {
          infop = rpmi[2] "|" rpmi[3] "|" rpmi[4]
          plus[rpmi[5]] = rpmi[6] "|" rpmi[7] "|" rpmi[8]
        }
      }
      for ( file in minus ) {
        if ( plus[file] == minus[file] ) {
            delete plus[file]
            delete minus[file]
        }
        else {
          changed[file] = 1
          if ( plus[file] == "" ) {
            delete plus[file]
          }
        }
      }
      for ( file in plus ) {
        changed[file] = 1
      }
      change = 0
      if ( length(minus) > 0 ) {
        change = 1
      }
      if ( length(plus) > 0 ) {
        change = change + 2
      }
     if ( change > 0 ) {
        split(infom, infomt, "|")
        split(infop, infopt, "|")
        if ( infomt[3] == "M" ) {
          infomt[3] = ", M"
        }
        if ( infopt[3] == "M" ) {
          infopt[3] = ", M"
        }
        if ( change == 1 ) {
          print "— " rpms[r] ".rpm (" infomt[2] ".src.rpm , " infomt[1] infomt[3] ")"
          rpmcount = rpmcount - 1
        }
        if ( change == 2 ) {
          print "+ " rpms[r] ".rpm (" infopt[2] ".src.rpm, " infopt[1] infopt[3] ")"
          rpmcount = rpmcount + 1
        }
        if ( change == 3 ) {
          print "= " rpms[r] ".rpm (" infomt[2] ".src.rpm, " infomt[1] infomt[3] ")"
          print "    ⇒ " infopt[2] ".src.rpm, " infopt[1] infopt[3]
        }
        nc = asorti(changed)
        for (i in out) {
          delete out[i]
        }
        for ( c = 1 ; c <= nc ; c++ ) {
          if ( minus[changed[c]] ) {
            split(minus[changed[c]], infoc, "|")
            sig = infoc[1] ", " infoc[2]
            out[sig] = out [sig] infoc[3] "|−|" changed[c] "#" 
            formatcount[infoc[3]] = formatcount[infoc[3]] - 1
            maintcount[infomt[1]] = maintcount[infomt[1]] - 1
          }
          if ( plus[changed[c]] ) {
            split(plus[changed[c]], infoc, "|")
            sig = infoc[1] ", " infoc[2]
            out[sig] = out [sig] infoc[3] "|+|" changed[c] "#"
            formatcount[infoc[3]] = formatcount[infoc[3]] + 1
            maintcount[infopt[1]] = maintcount[infopt[1]] + 1
          }
        }
        no = asorti(out, outs)
        for ( o = 1 ; o <= no ; o++ ) {
          font = outs[o]
          sub("#$", "", out[font])
          nf = split(out[font],fs, "#")
          asort(fs)
          for ( f = 1 ; f <= nf ; f++ ) {
            split(fs[f], oi, "|")
            print "    " oi[2] " " font ", " oi[1] "\t" oi[3]
          }
        }
      }
    }
    nf = asorti (formatcount, fcs)
    for ( f = 1 ; f <= nf ; f++ ) {
      if ( formatcount[fcs[f]] > 0 ) {
        total = total "+" formatcount[fcs[f]] " " fcs[f] ", "
      }
      if ( formatcount[fcs[f]] < 0 ) {
        total = total formatcount[fcs[f]] " " fcs[f] ", "
      }
    }
    sub(", $", ".", total)
    if ( total == "" ) {
      total = "—"
    }
    print ""
    print "C. Font count changes: " total
    print ""
    print "D. Packager activity: "
    for ( m in maintcount ) {
      score = maintcount[m]
      if ( score < 0 ) { score = - score }
      score = score / 10000
      rmaintcount[score] = rmaintcount[score] m "|"
    }
    nc = asorti(rmaintcount, rmcs)
    for ( c = nc ; c >= 1 ; c-- ) {
      sub("\\|$", "", rmaintcount[rmcs[c]])
      split(rmaintcount[rmcs[c]], maint, "|")
      nm = asort(maint)
      for ( m = 1 ; m <= nm ; m++ ) {
        print maint[m]
      }
    }
  }' "$1" "$2"
}

compare_tests() {

awk -F '|' '
  BEGIN {
    lh = 7
  }
  FNR==1 {
    filenames = filenames FILENAME "|"
    for (i = lh ; i <= NF ; i++) {
      testid[ FILENAME "|" i ] = $i
    }
  }
  FNR>1 {
    for (i = lh ; i <= NF ; i++) {
      score[ FILENAME "|" $1 "|" $2 "|" $3 "|" i ] += $i
    }
  }
  END {
    sub("\\|$","",filenames)
    split(filenames,filenamest,"|")
    for ( sig in score ) {
      split(sig,sigt,"|")
      nsig = sigt[2] "|" sigt[3] "|" sigt[4] "|" testid[ sigt[1] "|" sigt[5] ]
      if ( sigt[1] == filenamest[1] ) {
        total_score[nsig] = total_score[nsig] - score[sig]
      }
      if ( sigt[1] == filenamest[2] ) {
        total_score[nsig] = total_score[nsig] + score[sig]
      }
    }
    for ( sig in total_score ) {
      split(sig,sigt,"|")
      if ( total_score[sig] != 0 ) {
        test_diff[ sigt[4] ] = 1
        pk_diff[ sigt[1] "|" sigt[2] "|" sigt[3] ] = 1
        total_score_diff[sig] = total_score[sig]
      }
    }
    line = "Maintainer|SRPM|RPM|"
    nt = asorti(test_diff)
    for ( t = 1 ; t <= nt ; t++ ) {
      line = line test_diff[t] "|"
    }
    sub("\\|$","",line)
    print line
    np = asorti(pk_diff)
    for ( p = 1 ; p <= np ; p++ ) {
      line = pk_diff[p] "|"
      for ( t = 1 ; t <= nt ; t++ ) {
        line = line total_score_diff[ pk_diff[p] "|" test_diff[t] ] "|"
      }
      sub("\\|$","",line)
      print line
    }
  }' "$1" "$2"
}


pretty_print() {
awk -F '|' '
  BEGIN {
    lh = 4
  }
  NR==1 {
    max = NF
    headline = "P#"
    for ( i = lh ; i < max ; i++ ) {
      headline = headline "|t" i+1-lh
    }
    print headline
  }
  NR>1 {
    line = NR - 1
    for ( i = lh ; i < max ; i++ ) {
      if ( $i ) { line = line "|" $i }
      else      { line = line "|‧"   }
      total[i] = total[i] + $i
    }
    print line
  }
 END {
  totalline = "Balance"
  for ( i = lh ; i < max ; i++ ) {
      totalline = totalline "|" total[i]
    }
  print totalline
  }' "$1" | column -t -s '|'

  echo ""

awk -F '|' '
  BEGIN {
    lh = 4
  }
  NR==1 {
    print "P#|Maintainer|RPM|SRPM"
  }
  NR>1 {
    line = NR - 1
    for ( i = 1 ; i < lh ; i++ ) {
      if ( $i ) { line = line "|" $i }
      else      { line = line "| "   }
    }
    print line
  }' "$1" | column -t -s '|'

  echo ""

  awk -F '|' '
    BEGIN { lh = 4 }
    NR==1 {
      for ( i = lh ; i < NF ; i++ ) {
        print "t" i+1-lh "|" $i
      }
    }' "$1" \
  | while read line ; do
      testnumber=$(echo $line | cut -d "|" -f 1)
      testid=$(echo $line | cut -d "|" -f 2)
      echo -n "$testnumber. "
      "$DATADIR/test-info" $testid title
    done
}

[ "$#" -lt "2" ] && usage

TIMESTAMP=$(date -u +%Y%m%dT%H%M%SZ)

FL="consolidated-data.csv"
TSUM="test-summary.csv"

TMPDIR=$(mktemp -d --tmpdir=/tmp "$(basename $0)-$TIMESTAMP-XXXXXXXXXX")

tar xf "$1" "*/$TSUM" -O > "$TMPDIR/1-$TSUM"
tar xf "$1" "*/$FL" -O > "$TMPDIR/1-$FL"
tar xf "$2" "*/$TSUM" -O > "$TMPDIR/2-$TSUM"
tar xf "$2" "*/$FL" -O > "$TMPDIR/2-$FL"

echo "A. Test result changes:"
echo ""

compare_tests "$TMPDIR/1-$TSUM" "$TMPDIR/2-$TSUM" > "$TMPDIR/D-$TSUM"
[ $(cat "$TMPDIR/D-$TSUM" | wc -l) -gt 1 ] && pretty_print "$TMPDIR/D-$TSUM"

echo ""
find_package_changes "$TMPDIR/1-$FL" "$TMPDIR/2-$FL"

rm -fr "$TMPDIR"