Skip to content

Instantly share code, notes, and snippets.

@kikorb
Last active May 22, 2023 16:21
Show Gist options
  • Save kikorb/6635ea3d44939a60d6c3669229f8f614 to your computer and use it in GitHub Desktop.
Save kikorb/6635ea3d44939a60d6c3669229f8f614 to your computer and use it in GitHub Desktop.
require 'csv'
file = "#{Rails.root}/public/skills_#{Date.today.strftime('%Y_%m_%d')}.csv"
headers = ["Value", "Created at", "Updated at", "Admin approved at", "Curated at", "Global", "Profile Connections", "Demand Connections", "Position Connections", "Certificates Connnections"]
account = Account.find(3)
skills_type = CustomType.find_by(name: 'skills', account_id: account.id)
CSV.open(file, "w", write_headers: true, headers: headers) do |writer|
CustomValue.where(custom_type_id: skills_type.id).find_each do |skill|
writer << [skill.value,
skill.created_at,
skill.updated_at,
skill.admin_approved_at,
skill.curated_at,
skill.global_id.present?,
skill.dictionary_connections.where(customizable_type: 'Profile').where.not(experience: 0).count,
skill.dictionary_connections.where(customizable_type: 'Task').count,
skill.dictionary_connections.where(customizable_type: 'Position').count,
skill.dictionary_connections.where(customizable_type: 'Certificates').count
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment