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

# Render PredicateTrace output.
#
# Author: <NAME> <<EMAIL>>

require 'open3'
require 'cgi'
$:.unshift(File.dirname(File.expand_path(__FILE__)))
require 'render'

DOT = 'dot'
RESOURCES = split_data()

if ARGV.length > 1
  puts "Usage: #{$0} [<trace>]"
  exit 1
end

input = STDERR
if ! ARGV.empty?
  input = File.open(ARGV[0])
end

# Write header.
puts RESOURCES['Header']

id = 0
extract_dot(input.read) do |type, data|
  if type == :line
    if data =~ /^PredicateTrace (\w+) context=([^ ]+) consider=(\d+) inject=(\d+)/
      phase, context, consider, inject = $1, $2, $3, $4
      id += 1
      puts "<div class=ptrace_header onclick=\"expand_collapse('ptrace_body-#{id}')\">#{data}</div>"
      puts "<div id=ptrace_body-#{id} style='display:inline'>"<commit_msg>predicate/render_ptrace.rb: Fix bug when no argument given.<commit_after>#!/usr/bin/env ruby

# Render PredicateTrace output.
#
# Author: <NAME> <<EMAIL>>

require 'open3'
require 'cgi'
$:.unshift(File.dirname(File.expand_path(__FILE__)))
require 'render'

DOT = 'dot'
RESOURCES = split_data()

if ARGV.length > 1
  puts "Usage: #{$0} [<trace>]"
  exit 1
end

input = STDIN
if ! ARGV.empty?
  input = File.open(ARGV[0])
end

# Write header.
puts RESOURCES['Header']

id = 0
extract_dot(input.read) do |type, data|
  if type == :line
    if data =~ /^PredicateTrace (\w+) context=([^ ]+) consider=(\d+) inject=(\d+)/
      phase, context, consider, inject = $1, $2, $3, $4
      id += 1
      puts "<div class=ptrace_header onclick=\"expand_collapse('ptrace_body-#{id}')\">#{data}</div>"
      puts "<div id=ptrace_body-#{id} style='display:inline'>"
{'fraction_non_alphanumeric': 0.19237749546279492, 'fraction_numerical': 0.013309134906231096, 'mean_word_length': 4.20125786163522, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '3278071', 'n_tokens_mistral': 656, 'n_tokens_neox': 625, 'n_words': 153}