<commit_before>- series = []
- interventions = Intervention.real.of_civil_year(@campaign.harvest_year)
- if @campaign && interventions.any?
  :ruby
    started_at = interventions.reorder(:started_at).first.started_at.to_date
    stopped_at = interventions.reorder(:started_at).last.stopped_at.to_date

    unit = Nomen::Unit[:hour]

    cost_unit = Nomen::Currency[Preference[:currency]]

    categories = {}

    date = started_at
    stopped_at = started_at + 1 if started_at >= stopped_at
    while date < stopped_at
      categories[date.year.to_s + date.month.to_s.rjust(3, '0')] = date.l(format: "%b %Y")
      date = date >> 1
    end

    # data for bar chart times by activities and by month
    Activity.actives.find_each do |activity|
      activity_target_id = activity.productions.pluck(:support_id)
      targets = Product.find(activity_target_id)
      interventions = Intervention.real.with_targets(targets).of_civil_year(@campaign.harvest_year).reorder(:started_at)
      if interventions.any?
        sums = interventions.sums_of_periods.sort.inject({}) do |hash, period|
          hash[period.expr.to_i.to_s] = period.sum.to_i.in_second.in(unit).round(2).to_f
          hash
        end
        series << { name: activity.name, data: normalize_serie(sums, categories.keys), tooltip: {value_suffix: unit.symbol }, color: activity.color, stack: 'time'}
        #cost_sums = interventions.inject({}) do |hash, i|
        #  hash[i.started_at.year.to_s + '0' + i.started_at.month.to_s] = i.total_cost.to_s.to_f
        #  hash
        #end
        #series << { name: activity.name, data: normalize_serie(cost_sums, categories.keys), tooltip: {value_suffix: cost_unit.symbol }, color: activity.color, stack: 'cost'}
      end
    end<commit_msg>Fix red page on production time by activity graph (#512)<commit_after>- series = []
- interventions = Intervention.real.of_civil_year(@campaign.harvest_year)
- if @campaign && interventions.any?
  :ruby
    started_at = interventions.reorder(:started_at).first.started_at.to_date
    stopped_at = interventions.reorder(:started_at).last.stopped_at.to_date

    unit = Nomen::Unit[:hour]

    cost_unit = Nomen::Currency[Preference[:currency]]

    categories = {}

    date = started_at
    stopped_at = started_at + 1 if started_at >= stopped_at
    while date < stopped_at
      categories[date.year.to_s + date.month.to_s.rjust(3, '0')] = date.l(format: "%b %Y")
      date = date >> 1
    end

    # data for bar chart times by activities and by month
    Activity.actives.find_each do |activity|
      targets = activity.productions.map(&:support).compact
      interventions = Intervention.real.with_targets(targets).of_civil_year(@campaign.harvest_year).reorder(:started_at)
      if interventions.any?
        sums = interventions.sums_of_periods.sort.inject({}) do |hash, period|
          hash[period.expr.to_i.to_s] = period.sum.to_i.in_second.in(unit).round(2).to_f
          hash
        end
        series << { name: activity.name, data: normalize_serie(sums, categories.keys), tooltip: {value_suffix: unit.symbol }, color: activity.color, stack: 'time'}
        #cost_sums = interventions.inject({}) do |hash, i|
        #  hash[i.started_at.year.to_s + '0' + i.started_at.month.to_s] = i.total_cost.to_s.to_f
        #  hash
        #end
        #series << { name: activity.name, data: normalize_serie(cost_sums, categories.keys), tooltip: {value_suffix: cost_unit.symbol }, color: activity.color, stack: 'cost'}
      end
    end
{'fraction_non_alphanumeric': 0.12810271041369473, 'fraction_numerical': 0.0042796005706134095, 'mean_word_length': 3.4891165172855314, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2657908', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1141, 'n_words': 220}