<commit_before>import itertools

class Layout:
	def writeRowHeaders(self,rowHeaders):
		raise NotImplementedError
	def writeColHeaders(self,colHeaders):
		raise NotImplementedError
	def writeAmount(self,r,c,amount):
		raise NotImplementedError
	def writeRowSum(self,r,c,amount,c1,c2,cs,isLowestLevel):
		raise NotImplementedError
	def writeColSum(self,r,c,amount,r1,r2,rs,isLowestLevel):
		raise NotImplementedError

class Spreadsheet:
	def __init__(self,filename):
		self.filename=filename
	def makeLayout(self,nCaptionLines,rowEntries,colEntries,staticColStyles,amountColStyles):
		# mainly, number of entries is needed
		# but names can be used, for example, in html col classes for styling
		# should return Layout object
		raise NotImplementedError
	def save(self):
		raise NotImplementedError

class XlsxSpreadsheet(Spreadsheet):
	def __init__(self,filename):
		super().__init__(filename)
		import xlsxwriter
		self.wb=xlsxwriter.Workbook(self.filename)
		self.ws=self.wb.add_worksheet('expenditures')
	def makeLayout(self,nCaptionLines,rowEntries,colEntries,staticColStyles,amountColStyles):
		ws=self.ws
		amountStyle=self.wb.add_format({'num_format':'#,##0.0;-#,##0.0;""'})
		class XlsxLayout(Layout):
			def __init__(self):
				r0=nCaptionLines+len(colEntries)
				ws.freeze_panes(r0,0)
			def write(self,r,c,value):
				ws.write(r,c,value)<commit_msg>set col widths - but col folds disappeared!<commit_after>import itertools

class Layout:
	def writeRowHeaders(self,rowHeaders):
		raise NotImplementedError
	def writeColHeaders(self,colHeaders):
		raise NotImplementedError
	def writeAmount(self,r,c,amount):
		raise NotImplementedError
	def writeRowSum(self,r,c,amount,c1,c2,cs,isLowestLevel):
		raise NotImplementedError
	def writeColSum(self,r,c,amount,r1,r2,rs,isLowestLevel):
		raise NotImplementedError

class Spreadsheet:
	def __init__(self,filename):
		self.filename=filename
	def makeLayout(self,nCaptionLines,rowEntries,colEntries,staticColStyles,amountColStyles):
		# mainly, number of entries is needed
		# but names can be used, for example, in html col classes for styling
		# should return Layout object
		raise NotImplementedError
	def save(self):
		raise NotImplementedError

class XlsxSpreadsheet(Spreadsheet):
	def __init__(self,filename):
		super().__init__(filename)
		import xlsxwriter
		self.wb=xlsxwriter.Workbook(self.filename)
		self.ws=self.wb.add_worksheet('expenditures')
	def makeLayout(self,nCaptionLines,rowEntries,colEntries,staticColStyles,amountColStyles):
		ws=self.ws
		amountStyle=self.wb.add_format({'num_format':'#,##0.0;-#,##0.0;""'})
		class XlsxLayout(Layout):
			def __init__(self):
				r0=nCaptionLines+len(colEntries)
				c0=0
				ws.freeze_panes(r0,0)
				def width(style):
					if 'name' in style:
						return 100
					elif 'department' in style:
						return 4
					elif 'section' in style:
						return 5
					elif 'category' in style:
						return 8
					elif 'type' in style:
						return 4
					elif 'amount' in style:
						return 15
				for c,style in enumerate(itertools.chain(staticColStyles,amountColStyles)):
					w=width(style)
					if w:
						self.setColWidth(c,w)
			def setColWidth(self,c,width):
				ws.set_column(c,c,width)
			def write(self,r,c,value):
				ws.write(r,c,value)
{'fraction_non_alphanumeric': 0.10752688172043011, 'fraction_numerical': 0.010138248847926268, 'mean_word_length': 5.551307847082495, 'pattern_counts': {'":': 0, '<': 3, '<?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': '484627', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1124, 'n_words': 219}