<commit_before>#!/usr/bin/env python

# This file is part of VoltDB.
# Copyright (C) 2008-2014 VoltDB Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

import sys
import cgi
import os
import cPickle
import decimal
from distutils.util import strtobool
from optparse import OptionParser
from voltdbclient import VoltColumn, VoltTable, FastSerializer

__quiet = True

def highlight(s, flag):
    if not isinstance(s, basestring):
        s = str(s)
    return flag and "<span style=\"color: red\">%s</span>" % (s) or s

def generate_table_str(res, key):

    highlights = res.get("highlight")
    source = res[key].get("Result")
    if not source:
        return ""

    result = []
    result.append(highlight("column count: %d" % (len(source.columns)), "columns" == highlights))
    result.append(highlight("row count: %d" % (len(source.tuples)), "tuples" == highlights))
    result.append("cols: " + ", ".join(map(lambda x: str(x), source.columns)))
    result.append("rows -")
    if isinstance(highlights, list):
        for j in xrange(len(source.tuples)):
            result.append(highlight(source.tuples[j], j in highlights))
    else:
        result.extend(map(lambda x: str(x), source.tuples))
    tablestr = "<br />".join(result)
    return tablestr

def generate_detail(name, item, output_dir):
    if output_dir == None:
        return

    details = """
<html>
<head>
<title>Detail of "%s"</title>
<style>
td {width: 50%%}
</style>
</head>

<body>
<h2>%s</h2>
<table cellpadding=3 cellspacing=1 border=1>
<tr>
<th>VoltDB Response</th>
<th>HSQLDB Response</th>
</tr>
<tr>
<td>%s</td>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
<td>%s</td>
</tr>
</table>
</body>

</html>
""" % (cgi.escape(item["SQL"]),
       cgi.escape(item["SQL"]),
       highlight(item["jni"]["Status"], "Status" == item.get("highlight")),
       highlight(item["hsqldb"]["Status"], "Status" == item.get("highlight")),
       item["jni"].get("Info") or "",
       item["hsqldb"].get("Info") or "",
       generate_table_str(item, "jni"),
       generate_table_str(item, "hsqldb"))

    filename = "%s.html" % (item["id"])
    fd = open(os.path.join(output_dir, filename), "w")
    fd.write(details.encode("utf-8"))
    fd.close()

    return filename

def safe_print(s):
    if not __quiet:
        print s

def print_section(name, mismatches, output_dir):
    print "begin print section"
    #import pickle
    #with open('print_section_name', 'w') as f1, open('print_section_mismatches', 'w') as f2, open('print_section_output_dir', 'w') as f3:
#	pickle.dump(name, f1)
#	pickle.dump(mismatches, f2)
#	pickle.dump(name, f3)
    result = """
<h2>%s: %d</h2>
<table cellpadding=3 cellspacing=1 border=1>
<tr>
<th>ID</th>
<th>SQL Statement</th>
<th>VoltDB Status</th>
<th>HSQLDB Status</th>
</tr>
""" % (name, len(mismatches))

#attemp 1, use list and join
    temp = []

    for i in mismatches:
        safe_print(i["SQL"])
        #detail_page = ""
        detail_page = generate_detail(name, i, output_dir)
        jniStatus = i["jni"]["Status"]
        if jniStatus < 0:
            jniStatus = "Error: " + `jniStatus`
        hsqldbStatus = i["hsqldb"]["Status"]
        if hsqldbStatus < 0:
            hsqldbStatus = "Error: " + `hsqldbStatus`
	temp.append("""
<tr>
<td>%s</td>
<td><a href="%s">%s</a></td>
<td>%s</td>
<td>%s</td>
</tr>""" % (i["id"],
            detail_page,
            cgi.escape(i["SQL"]),
            jniStatus,
            hsqldbStatus))

    result += ''.join(temp)

    result += """
</table>
"""

    return result

def is_different(x, cntonly):
    """Notes the attributes that are different. Since the whole table will be
    printed out as a single string.
    the first line is column count,<commit_msg>clean SQLCoverageReport.py, remove debug comment<commit_after>#!/usr/bin/env python

# This file is part of VoltDB.
# Copyright (C) 2008-2014 VoltDB Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

import sys
import cgi
import os
import cPickle
import decimal
from distutils.util import strtobool
from optparse import OptionParser
from voltdbclient import VoltColumn, VoltTable, FastSerializer

__quiet = True

def highlight(s, flag):
    if not isinstance(s, basestring):
        s = str(s)
    return flag and "<span style=\"color: red\">%s</span>" % (s) or s

def generate_table_str(res, key):

    highlights = res.get("highlight")
    source = res[key].get("Result")
    if not source:
        return ""

    result = []
    result.append(highlight("column count: %d" % (len(source.columns)), "columns" == highlights))
    result.append(highlight("row count: %d" % (len(source.tuples)), "tuples" == highlights))
    result.append("cols: " + ", ".join(map(lambda x: str(x), source.columns)))
    result.append("rows -")
    if isinstance(highlights, list):
        for j in xrange(len(source.tuples)):
            result.append(highlight(source.tuples[j], j in highlights))
    else:
        result.extend(map(lambda x: str(x), source.tuples))
    tablestr = "<br />".join(result)
    return tablestr

def generate_detail(name, item, output_dir):
    if output_dir == None:
        return

    details = """
<html>
<head>
<title>Detail of "%s"</title>
<style>
td {width: 50%%}
</style>
</head>

<body>
<h2>%s</h2>
<table cellpadding=3 cellspacing=1 border=1>
<tr>
<th>VoltDB Response</th>
<th>HSQLDB Response</th>
</tr>
<tr>
<td>%s</td>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
<td>%s</td>
</tr>
</table>
</body>

</html>
""" % (cgi.escape(item["SQL"]),
       cgi.escape(item["SQL"]),
       highlight(item["jni"]["Status"], "Status" == item.get("highlight")),
       highlight(item["hsqldb"]["Status"], "Status" == item.get("highlight")),
       item["jni"].get("Info") or "",
       item["hsqldb"].get("Info") or "",
       generate_table_str(item, "jni"),
       generate_table_str(item, "hsqldb"))

    filename = "%s.html" % (item["id"])
    fd = open(os.path.join(output_dir, filename), "w")
    fd.write(details.encode("utf-8"))
    fd.close()

    return filename

def safe_print(s):
    if not __quiet:
        print s

def print_section(name, mismatches, output_dir):
    result = """
<h2>%s: %d</h2>
<table cellpadding=3 cellspacing=1 border=1>
<tr>
<th>ID</th>
<th>SQL Statement</th>
<th>VoltDB Status</th>
<th>HSQLDB Status</th>
</tr>
""" % (name, len(mismatches))

    temp = []
    for i in mismatches:
        safe_print(i["SQL"])
        detail_page = generate_detail(name, i, output_dir)
        jniStatus = i["jni"]["Status"]
        if jniStatus < 0:
            jniStatus = "Error: " + `jniStatus`
        hsqldbStatus = i["hsqldb"]["Status"]
        if hsqldbStatus < 0:
            hsqldbStatus = "Error: " + `hsqldbStatus`
	temp.append("""
<tr>
<td>%s</td>
<td><a href="%s">%s</a></td>
<td>%s</td>
<td>%s</td>
</tr>""" % (i["id"],
            detail_page,
            cgi.escape(i["SQL"]),
            jniStatus,
            hsqldbStatus))

    result += ''.join(temp)

    result += """
</table>
"""

    return result

def is_different(x, cntonly):
    """Notes the attributes that are different. Since the whole table will be
    printed out as a single string.
    the first line is column count,
{'fraction_non_alphanumeric': 0.15584556824361065, 'fraction_numerical': 0.0057640021750951604, 'mean_word_length': 3.5865336658354114, 'pattern_counts': {'":': 0, '<': 141, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992596', 'n_tokens_mistral': 3144, 'n_tokens_neox': 3081, 'n_words': 919}