<commit_before>    Module = require '../../module'
    q      = require 'q'

    class PngRenderer extends Module
      deps: [ 'fs', 'canvas', 'path', 'config' ]
      pub:  [ 'render', 'flush' ]

      @draw_to: undefined
      @ctx:     undefined

      initialize: (params) =>
        deferred = q.defer()

        super()
          .then =>
            @initialize_drawing_context()

            deferred.resolve @

        deferred.promise

      initialize_drawing_context: =>
        width  = @config.width  * @config.grid[0].length
        height = @config.height * @config.grid.length

        PngRenderer.draw_to = new @canvas width, height
        PngRenderer.ctx     = PngRenderer.draw_to.getContext '2d'

      render: (path, level_name) =>
        location = @path.join __dirname, '..', '..', '..', 'output', "#{level_name}.json"
        @fs.readFile location, 'utf8', (err, data) =>
          @done @do_render PngRenderer.ctx, JSON.parse data

      flush: (level) =>
        stream = @fs.createWriteStream @path.join __dirname, '..', '..', '..', 'output', "#{level}.png"

        for row, r in @config.grid
          for cell, c in @config.grid[r]
            @config.grid[r][c] = false

        stream.on 'finish', => @done 'Persisted', location: level

        PngRenderer.draw_to.createPNGStream().pipe stream

    module.exports = PngRenderer<commit_msg>A few changes to PngRenderer.flush<commit_after>    Module = require '../../module'
    q      = require 'q'

    class PngRenderer extends Module
      deps: [ 'fs', 'canvas', 'path', 'config' ]
      pub:  [ 'render', 'flush' ]

      @draw_to: undefined
      @ctx:     undefined

      initialize: (params) =>
        deferred = q.defer()

        super()
          .then =>
            @initialize_drawing_context()

            deferred.resolve @

        deferred.promise

      initialize_drawing_context: =>
        width  = @config.width  * @config.grid[0].length
        height = @config.height * @config.grid.length

        PngRenderer.draw_to = new @canvas width, height
        PngRenderer.ctx     = PngRenderer.draw_to.getContext '2d'

      render: (path, level_name) =>
        location = @path.join __dirname, '..', '..', '..', 'output', "#{level_name}.json"
        @fs.readFile location, 'utf8', (err, data) =>
          @done @do_render PngRenderer.ctx, JSON.parse data

      flush: (level_name) =>
        stream = @fs.createWriteStream @path.join __dirname, '..', '..', '..', 'output', "#{level_name}.png"

        stream.on 'finish', =>
          @initialize_drawing_context()
          @done 'Persisted', location: level_name

        PngRenderer.draw_to.createPNGStream().pipe stream

    module.exports = PngRenderer
{'fraction_non_alphanumeric': 0.1488970588235294, 'fraction_numerical': 0.0022058823529411764, 'mean_word_length': 2.193661971830986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4931619', 'n_tokens_mistral': 848, 'n_tokens_neox': 824, 'n_words': 182}