<commit_before>require 'json'

module Libsyn
  class PanicJson
    attr_reader :input

    def initialize(input)
      @input = input
    end

    def totals
      episodes, downloads, months = parse(input)

      datapoints = []

      months.reverse.each do |month|
        datapoints << {
          "title" => month, "value" => downloads[month].inject(&:+)
        }
      end

      {
        "graph" => {
          "title" => "Downloads",
          "refreshEveryNSeconds" => 120,
          "datasequences" => [{
            "title" => "Total",
            "datapoints" => datapoints
          }]
        }
      }.to_json
    end

    def most_recent
      episodes, downloads, months = parse(input)

      datapoint = { "title" => months.first, "value" => downloads[months.first].first }

      {
        "graph" => {
          "title" => episodes.first,
          "refreshEveryNSeconds" => 120,
          "datasequences" => [{
            "title" => "Downloads",
            "datapoints" => [ datapoint ]
          }]
        }
      }.to_json
    end

    def to_s
      [most_recent, totals].join "\n"
    end

    private

    def parse(input)
      @parse ||= begin
        downloads = Hash.new { |h, k| h[k] = [] }
        episodes  = []
<commit_msg>Add another line separator in json<commit_after>require 'json'

module Libsyn
  class PanicJson
    attr_reader :input

    def initialize(input)
      @input = input
    end

    def totals
      episodes, downloads, months = parse(input)

      datapoints = []

      months.reverse.each do |month|
        datapoints << {
          "title" => month, "value" => downloads[month].inject(&:+)
        }
      end

      {
        "graph" => {
          "title" => "Downloads",
          "refreshEveryNSeconds" => 120,
          "datasequences" => [{
            "title" => "Total",
            "datapoints" => datapoints
          }]
        }
      }.to_json
    end

    def most_recent
      episodes, downloads, months = parse(input)

      datapoint = { "title" => months.first, "value" => downloads[months.first].first }

      {
        "graph" => {
          "title" => episodes.first,
          "refreshEveryNSeconds" => 120,
          "datasequences" => [{
            "title" => "Downloads",
            "datapoints" => [ datapoint ]
          }]
        }
      }.to_json
    end

    def to_s
      [most_recent, totals].join "\n\n"
    end

    private

    def parse(input)
      @parse ||= begin
        downloads = Hash.new { |h, k| h[k] = [] }
        episodes  = []

{'fraction_non_alphanumeric': 0.1370239497447978, 'fraction_numerical': 0.004711425206124852, 'mean_word_length': 1.6404145077720207, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5361790', 'n_tokens_mistral': 841, 'n_tokens_neox': 793, 'n_words': 167}