<commit_before>import sys
from scoring import Scoring
from output import output_dance_stats

status_frequency = 1000

class Candidate(object):
  def __init__(self, dance, scores):
    self.dance = dance
    self.scores = scores

class Strategy(object):
  def __init__(self, name, random_dance_generator, scoring):
    self.name = name
    self._random_dance_generator = random_dance_generator
    self._scoring = scoring
    self._best_candidate = None

  def iterate(self):
    """Override this to do work"""
    pass

  def run(self, cards_output_file=sys.stdout, stats_output_file=sys.stderr):
    self.print_settings(file=stats_output_file)
    count = 0
    last_output = None
    while True:
      self.iterate()
      if count % status_frequency == 0:
        self.output_stats(count, file=stats_output_file)
        stats_output_file.flush()
        if self._best_candidate != last_output:
          last_output = self._best_candidate
          output_dance_stats(last_output, cards_output_file)
      count = count + 1

  def print_settings(self, file):
    print("Algorithm=%s" % self.name, file=file)

  def output_stats(self, count, file):
    print(count, self._best_candidate.scores.total_score, file=file)

  def generate_dance(self):<commit_msg>Flushes card output file after outputting new best dancecard.<commit_after>import sys
from scoring import Scoring
from output import output_dance_stats

status_frequency = 1000

class Candidate(object):
  def __init__(self, dance, scores):
    self.dance = dance
    self.scores = scores

class Strategy(object):
  def __init__(self, name, random_dance_generator, scoring):
    self.name = name
    self._random_dance_generator = random_dance_generator
    self._scoring = scoring
    self._best_candidate = None

  def iterate(self):
    """Override this to do work"""
    pass

  def run(self, cards_output_file=sys.stdout, stats_output_file=sys.stderr):
    self.print_settings(file=stats_output_file)
    count = 0
    last_output = None
    while True:
      self.iterate()
      if count % status_frequency == 0:
        self.output_stats(count, file=stats_output_file)
        stats_output_file.flush()
        if self._best_candidate != last_output:
          last_output = self._best_candidate
          output_dance_stats(last_output, cards_output_file)
          cards_output_file.flush()
      count = count + 1

  def print_settings(self, file):
    print("Algorithm=%s" % self.name, file=file)

  def output_stats(self, count, file):
    print(count, self._best_candidate.scores.total_score, file=file)

  def generate_dance(self):
{'fraction_non_alphanumeric': 0.08902532617037605, 'fraction_numerical': 0.005372217958557176, 'mean_word_length': 3.7747252747252746, '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': '4347512', 'n_tokens_mistral': 826, 'n_tokens_neox': 793, 'n_words': 186}