Skip to content

Commit dc85fcb

Browse files
committed
CV2-6723: export workspace tasks data
1 parent 9f85951 commit dc85fcb

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

lib/tasks/data/check_sunset.rake

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ namespace :check do
150150
unless team.nil?
151151
data_csv = []
152152
team.team_users.where(status: 'member').find_each do |tu|
153+
print '.'
153154
user = tu.user
154155
data_csv << [
155156
user.name,
@@ -186,6 +187,31 @@ namespace :check do
186187
slug = args[:slug].to_s
187188
team = Team.find_by_slug slug
188189
unless team.nil?
190+
team_tasks = team.team_tasks
191+
headers_id = team_tasks.map(&:id)
192+
data_csv = []
193+
team.project_medias.find_each do |pm|
194+
print '.'
195+
a_ttid = {}
196+
pm.get_annotations(['task']).find_each do |a|
197+
a_ttid[a.data["team_task_id"]] = a.id
198+
end
199+
a_answer = {}
200+
DynamicAnnotation::Field.select("a.annotated_id AS tid, dynamic_annotation_fields.value AS answer")
201+
.joins("INNER JOIN annotations a ON a.id = dynamic_annotation_fields.annotation_id INNER JOIN annotations a2 ON a2.id = a.annotated_id")
202+
.where("field_name LIKE 'response_%'")
203+
.where('a.annotated_type' => 'Task', 'a2.annotated_type' => 'ProjectMedia', 'a2.annotated_id' => pm.id).each do |f|
204+
a_answer[f.tid] = begin JSON.parse(f.answer) rescue f.answer end
205+
end
206+
pm_raw = []
207+
headers_id.each do |ttid|
208+
pm_raw << a_answer[a_ttid[ttid]] || '-'
209+
end
210+
data_csv << pm_raw
211+
end
212+
file = "#{Rails.root}/public/#{team.slug}/workspace_tasks_data.csv"
213+
headers = team_tasks.map(&:label)
214+
write_to_csv(file, headers, data_csv)
189215
end
190216
end
191217
task :export_workspace_tipline_requets_data,[:slug] => [:environment, :export_workspace_tasks_data] do |_t, args|
@@ -195,6 +221,7 @@ namespace :check do
195221
unless team.nil?
196222
data_csv = []
197223
TiplineRequest.where(team_id: team.id).find_each do |tr|
224+
print '.'
198225
data_csv << [
199226
tr.id,
200227
tr.language,
@@ -222,6 +249,7 @@ namespace :check do
222249
unless team.nil?
223250
data_csv = []
224251
team.project_medias.includes(:source, :media).find_each do |pm|
252+
print '.'
225253
media = pm.media
226254
media_data = media.quote || media.url || media.file&.url
227255
data_csv << [
@@ -254,6 +282,7 @@ namespace :check do
254282

255283
# Upload workspace data to S3
256284
task :export_and_upload_workspace_data,[:slug] => [:environment, :export_workspace_item_data] do |_t, args|
285+
started = Time.now.to_i
257286
print_task_title 'Uploading workspace data'
258287
slug = args[:slug].to_s
259288
team = Team.find_by_slug slug
@@ -267,11 +296,13 @@ namespace :check do
267296
download_url = CheckS3.write_presigned("export/workspaces_data/#{team.slug}/#{Time.now.to_i}/#{team.slug}.zip", 'application/zip', zip_path, CheckConfig.get('export_csv_expire', 7.days.to_i, :integer))
268297
puts "Download link (valid 7 days): #{download_url}"
269298
# Send download link to workspace admins
270-
team.team_users.where(status: 'member').find_each do |tu|
271-
puts "Sending email to #{tu.user.email}\n"
272-
SunsetMailer.delay.notify(tu.user, tu.team.name)
273-
end
299+
# team.team_users.where(status: 'member').find_each do |tu|
300+
# puts "Sending email to #{tu.user.email}\n"
301+
# SunsetMailer.delay.notify(tu.user, tu.team.name)
302+
# end
274303
end
304+
minutes = ((Time.now.to_i - started) / 60).to_i
305+
puts "[#{Time.now}] Done in #{minutes} minutes."
275306
end
276307
end
277308
end

0 commit comments

Comments
 (0)