<commit_before>'use strict'

const TheadLayout=require('./thead-layout')
const data=require('./data')

$(function(){
	$('.crnx-ode-properties').each(function(){
		const $container=$(this)
		const dag={}, idag={}
		const selectedNodes={}
		for (let id in data) {
			if (data[id].importance<=1) {
				selectedNodes[id]=true
			}
			dag[id]=data[id].parents
			idag[id]={}
		}
		for (let id in data) {
			for (let pid in dag[id]) {
				idag[pid][id]=true
			}
		}
		let theadLayout=new TheadLayout(dag,selectedNodes)
		const breadthWalk=(graph,id)=>{
			const result=[]
			const visited={}
			const queue=[id]
			while (queue.length>0) {
				id=queue.shift()
				if (visited[id]) {
					continue
				}
				visited[id]=true
				if (!selectedNodes[id]) {
					result.push(id)
				}
				queue.push(...Object.keys(graph[id]).sort())
			}
			return result
		}
		const writeButton=(text,tip)=>{
			const $button=$(`<button type='button'><span>${text}</span></button>`)
			if (tip!==undefined) {
				$button.attr('title',tip)
			}
			return $button
		}
		const writeData=(name,id)=>{
			const output=[]
			const overrides={}
			const raiseOverride=iid=>{
				if (overrides[iid]===undefined) {
					overrides[iid]=0
				}
				overrides[iid]++
			}
			const lowerOverride=iid=>{
				overrides[iid]--
			}
			const rec=id=>{
				const forOverrides=fn=>{
					if (data[id][name]) {
						data[id][name].forEach(item=>{
							item.forEach(section=>{
								const type=section[0]
								if (section[0]=='override') {
									const iids=section[1]
									iids.forEach(iid=>{
										fn(iid)
									})
								}
							})
						})
					}
				}
				// raise overrides
				forOverrides(raiseOverride)
				// recursion on nodes that are not selected for display
				Object.keys(data[id].parents).sort().forEach(pid=>{
					if (!selectedNodes[pid]) {
						rec(pid)
					}
				})
				// output of things that are not overridden by children
				if (data[id][name]) {
					data[id][name].forEach(item=>{
						let skip=false
						item.forEach(section=>{
							const type=section[0]
							if (type=='id') {
								const iid=section[1]
								if (overrides[iid]) {
									skip=true
								}
							}
						})
						if (!skip) {
							output.push(item)
						}
					})
				}
				// lower overrides
				forOverrides(lowerOverride)
			}
			rec(id)
			if (output.length==0) return $()
			return $("<ul>").append(output.map(item=>{
				return $("<li>").append(item.map(section=>{
					const type=section[0]
					if (type=='id' || type=='override') {
						return
					}
					const contents=section[1]
					const $section=$(`<div class='${type}'>`).append(contents.map(line=>{
						if (type=='title') {
							return $(`<div><em>${line}</em>:</div>`)
						} else {
							return $(`<div>${line}</div>`)
						}
					}))
					if (type=='detail') {
						const $b1=writeButton("Open","Expand details")
						const $b2=writeButton("Open","Expand details")
						$section.prepend($b1).append($b2)
						const $bs=$b1.add($b2)
						$bs.click(function(){
							if (!$section.hasClass('open')) {
								$section.addClass('open')
								$bs.html("<span>Close</span>").attr('title',"Collapse details")
							} else {
								$section.removeClass('open')
								$bs.html("<span>Open</span>").attr('title',"Expand details")
							}<commit_msg>visit node only once while writing property/solution items<commit_after>'use strict'

const TheadLayout=require('./thead-layout')
const data=require('./data')

$(function(){
	$('.crnx-ode-properties').each(function(){
		const $container=$(this)
		const dag={}, idag={}
		const selectedNodes={}
		for (let id in data) {
			if (data[id].importance<=1) {
				selectedNodes[id]=true
			}
			dag[id]=data[id].parents
			idag[id]={}
		}
		for (let id in data) {
			for (let pid in dag[id]) {
				idag[pid][id]=true
			}
		}
		let theadLayout=new TheadLayout(dag,selectedNodes)
		const breadthWalk=(graph,id)=>{
			const result=[]
			const visited={}
			const queue=[id]
			while (queue.length>0) {
				id=queue.shift()
				if (visited[id]) {
					continue
				}
				visited[id]=true
				if (!selectedNodes[id]) {
					result.push(id)
				}
				queue.push(...Object.keys(graph[id]).sort())
			}
			return result
		}
		const writeButton=(text,tip)=>{
			const $button=$(`<button type='button'><span>${text}</span></button>`)
			if (tip!==undefined) {
				$button.attr('title',tip)
			}
			return $button
		}
		const writeData=(name,id)=>{
			const output=[]
			const visited={}
			const overrides={}
			const raiseOverride=iid=>{
				if (overrides[iid]===undefined) {
					overrides[iid]=0
				}
				overrides[iid]++
			}
			const lowerOverride=iid=>{
				overrides[iid]--
			}
			const rec=id=>{
				visited[id]=true
				const forOverrides=fn=>{
					if (data[id][name]) {
						data[id][name].forEach(item=>{
							item.forEach(section=>{
								const type=section[0]
								if (section[0]=='override') {
									const iids=section[1]
									iids.forEach(iid=>{
										fn(iid)
									})
								}
							})
						})
					}
				}
				forOverrides(raiseOverride)
				// recursion on nodes that are not selected for display
				Object.keys(data[id].parents).sort().forEach(pid=>{
					if (!selectedNodes[pid] && !visited[pid]) {
						rec(pid)
					}
				})
				// output of things that are not overridden by children
				if (data[id][name]) {
					data[id][name].forEach(item=>{
						let skip=false
						item.forEach(section=>{
							const type=section[0]
							if (type=='id') {
								const iid=section[1]
								if (overrides[iid]) {
									skip=true
								}
							}
						})
						if (!skip) {
							output.push(item)
						}
					})
				}
				forOverrides(lowerOverride)
			}
			rec(id)
			if (output.length==0) return $()
			return $("<ul>").append(output.map(item=>{
				return $("<li>").append(item.map(section=>{
					const type=section[0]
					if (type=='id' || type=='override') {
						return
					}
					const contents=section[1]
					const $section=$(`<div class='${type}'>`).append(contents.map(line=>{
						if (type=='title') {
							return $(`<div><em>${line}</em>:</div>`)
						} else {
							return $(`<div>${line}</div>`)
						}
					}))
					if (type=='detail') {
						const $b1=writeButton("Open","Expand details")
						const $b2=writeButton("Open","Expand details")
						$section.prepend($b1).append($b2)
						const $bs=$b1.add($b2)
						$bs.click(function(){
							if (!$section.hasClass('open')) {
								$section.addClass('open')
								$bs.html("<span>Close</span>").attr('title',"Collapse details")
							} else {
								$section.removeClass('open')
								$bs.html("<span>Open</span>").attr('title',"Expand details")
							}
{'fraction_non_alphanumeric': 0.1909727394607478, 'fraction_numerical': 0.005064799642484731, 'mean_word_length': 2.627228525121556, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 71, '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': '2581888', 'n_tokens_mistral': 3271, 'n_tokens_neox': 2305, 'n_words': 395}