#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../config/environment.rb'

# 2% si nb photos < 5000 / 1% si nb photos > 5000 et < 20000 / 0.5% si nb photos > 20000

Provider.all.each do |p|
  nb = Image.where(provider_id: p.id).count
  if nb < 5001
    pourcent = (nb*2)/100
  elsif nb < 20001
    pourcent = nb/100
  else
    pourcent = (nb*0.5)/100
  end
  RefreshProvider.create(provider_id: p.id, total_update: percent.to_i)
  puts "#{p.name} nb = #{nb} total = #{pourcent}"
end