<commit_before>package blocks

import (
	"container/heap"
	"github.com/nytlabs/gojee" // jee
	"log"
	"time"
)

// build the histogram JSON for output
func buildHistogram(histogram map[string]*PriorityQueue) map[string]interface{} {

	buckets := make([]map[string]interface{}, len(histogram))

	i := 0
	for k, pq := range histogram {
		bucket := map[string]interface{}{
			"Count": len(*pq),
			"Label": k,
		}
		buckets[i] = bucket
		i++
	}
	data := map[string]interface{}{
		"Histogram": buckets,
	}
	return data
}

// creates a histogram of a specified key
func Histogram(b *Block) {

	type histogramRule struct {
		Window string
		Path   string
	}

	var rule *histogramRule
	var tree *jee.TokenTree
	var err error

	waitTimer := time.NewTimer(100 * time.Millisecond)
	window := time.Duration(0)

	histogram := map[string]*PriorityQueue{}
	emptyByte := make([]byte, 0)

	for {
		select {
		case query := <-b.Routes["histogram"]:
			data := buildHistogram(histogram)
			marshal(query, data)<commit_msg>make it so histogram can be manipulated by gojee<commit_after>package blocks

import (
	"container/heap"
	"github.com/nytlabs/gojee" // jee
	"log"
	"time"
)

// build the histogram JSON for output
func buildHistogram(histogram map[string]*PriorityQueue) interface{} {
	var data interface{}
	var buckets []interface{}
	buckets = make([]interface{}, len(histogram))

	i := 0
	for k, pq := range histogram {
		var bucket interface{}
		bucket = map[string]interface{}{
			"Count": len(*pq),
			"Label": k,
		}
		buckets[i] = bucket
		i++
	}

	data = map[string]interface{}{
		"Histogram": buckets,
	}
	return data
}

// creates a histogram of a specified key
func Histogram(b *Block) {

	type histogramRule struct {
		Window string
		Path   string
	}

	var rule *histogramRule
	var tree *jee.TokenTree
	var err error

	waitTimer := time.NewTimer(100 * time.Millisecond)
	window := time.Duration(0)

	histogram := map[string]*PriorityQueue{}
	emptyByte := make([]byte, 0)

	for {
		select {
		case query := <-b.Routes["histogram"]:
			data := buildHistogram(histogram)
			marshal(query, data)
{'fraction_non_alphanumeric': 0.1382775119617225, 'fraction_numerical': 0.005741626794258373, 'mean_word_length': 4.075242718446602, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, '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': '6230874', 'n_tokens_mistral': 786, 'n_tokens_neox': 701, 'n_words': 192}