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

import svgwrite

import os.path
import sys

class Colors:
	black = '#000000'
	gray = '#C0C0C0'

class Sequence:
	def __init__(self, filename):
		self.filename = filename
		self.actors = []
		self.actors_map = {}
		self.actions = []
		# read actions into file
		with open(filename) as f:
			for i, line in enumerate(f):
				tokens = line.split(',')
				assert len(tokens) >= 3, 'line %i has less than 3 tokens' % (i)
				if len(tokens) < 3:
					continue
				actor0 = tokens[0].strip()
				actor1 = tokens[1].strip()
				action = tokens[2].strip()
				if actor0 not in self.actors_map:
					key = len(self.actors)
					self.actors_map[actor0] = key
					self.actors.append(actor0)
				if actor1 not in self.actors_map:
					key = len(self.actors)
					self.actors_map[actor1] = key
					self.actors.append(actor1)
				key0 = self.actors_map[actor0]
				key1 = self.actors_map[actor1]
				color = Colors.black
				if len(tokens) > 3:
					color = tokens[3].strip()
				self.actions.append((key0, key1, action, color))
		# create drawing
		self.top_left = (50, 50)
		self.step_size = (100, 25)
		self.text_fudge = (0, 5)
		self.width = self.top_left[0] + (len(self.actors) + 1)*self.step_size[0]
		self.height = self.top_left[1] + (len(self.actions) + 1)*self.step_size[1]
		self.drawing = svgwrite.Drawing('out.svg', size=(self.width, self.height))

	def build(self):
		self.create_header()
		self.create_actors()
		self.create_actions()
		pass

	def to_string(self):
		return self.drawing.tostring()

	def create_header(self):
			text = 'filename: %s' % self.filename
			self.drawing.add(self.drawing.text(text, insert=(self.top_left[0], 0.5*self.top_left[1]), stroke='none', fill=Colors.black, font_family="Helevetica", font_size="8pt", text_anchor="start"))

	def create_actors(self):
		x = self.top_left[0]
		y = self.top_left[1]
		for name in self.actors:
			self.drawing.add(self.drawing.text(name, insert=(x, y - self.text_fudge[1]), stroke='none', fill=Colors.black, font_family="Helevetica", font_size="8pt", text_anchor="middle"))
			line = self.drawing.add(self.drawing.line((x, y), (x, self.height), stroke=Colors.gray, stroke_width=1))
			line.dasharray([5, 5])
			x += self.step_size[0]

	def create_actions(self):
		# add actions
		y = self.top_left[1] + self.step_size[1]
		for (a0, a1, act, color) in self.actions:
			x0 = self.top_left[0] + a0*self.step_size[0]
			x1 = self.top_left[0] + a1*self.step_size[0]
			if a0 == a1:
				self.drawing.add(self.drawing.circle((x0, y), r=2, fill=color))<commit_msg>Make filename gray instead of black<commit_after>#!/usr/local/bin/python

import svgwrite

import os.path
import sys

class Colors:
	black = '#000000'
	gray = '#C0C0C0'

class Sequence:
	def __init__(self, filename):
		self.filename = filename
		self.actors = []
		self.actors_map = {}
		self.actions = []
		# read actions into file
		with open(filename) as f:
			for i, line in enumerate(f):
				tokens = line.split(',')
				assert len(tokens) >= 3, 'line %i has less than 3 tokens' % (i)
				if len(tokens) < 3:
					continue
				actor0 = tokens[0].strip()
				actor1 = tokens[1].strip()
				action = tokens[2].strip()
				if actor0 not in self.actors_map:
					key = len(self.actors)
					self.actors_map[actor0] = key
					self.actors.append(actor0)
				if actor1 not in self.actors_map:
					key = len(self.actors)
					self.actors_map[actor1] = key
					self.actors.append(actor1)
				key0 = self.actors_map[actor0]
				key1 = self.actors_map[actor1]
				color = Colors.black
				if len(tokens) > 3:
					color = tokens[3].strip()
				self.actions.append((key0, key1, action, color))
		# create drawing
		self.top_left = (50, 50)
		self.step_size = (100, 25)
		self.text_fudge = (0, 5)
		self.width = self.top_left[0] + (len(self.actors) + 1)*self.step_size[0]
		self.height = self.top_left[1] + (len(self.actions) + 1)*self.step_size[1]
		self.drawing = svgwrite.Drawing('out.svg', size=(self.width, self.height))

	def build(self):
		self.create_header()
		self.create_actors()
		self.create_actions()
		pass

	def to_string(self):
		return self.drawing.tostring()

	def create_header(self):
			text = 'filename: %s' % self.filename
			self.drawing.add(self.drawing.text(text, insert=(self.top_left[0], 0.5*self.top_left[1]), stroke='none', fill=Colors.gray, font_family="Helevetica", font_size="8pt", text_anchor="start"))

	def create_actors(self):
		x = self.top_left[0]
		y = self.top_left[1]
		for name in self.actors:
			self.drawing.add(self.drawing.text(name, insert=(x, y - self.text_fudge[1]), stroke='none', fill=Colors.black, font_family="Helevetica", font_size="8pt", text_anchor="middle"))
			line = self.drawing.add(self.drawing.line((x, y), (x, self.height), stroke=Colors.gray, stroke_width=1))
			line.dasharray([5, 5])
			x += self.step_size[0]

	def create_actions(self):
		# add actions
		y = self.top_left[1] + self.step_size[1]
		for (a0, a1, act, color) in self.actions:
			x0 = self.top_left[0] + a0*self.step_size[0]
			x1 = self.top_left[0] + a1*self.step_size[0]
			if a0 == a1:
				self.drawing.add(self.drawing.circle((x0, y), r=2, fill=color))
{'fraction_non_alphanumeric': 0.1602177717285631, 'fraction_numerical': 0.029943612677425627, 'mean_word_length': 3.8436911487758945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4578117', 'n_tokens_mistral': 2288, 'n_tokens_neox': 1963, 'n_words': 400}