Skip to content

Instantly share code, notes, and snippets.

View Aronyu127's full-sized avatar
🎯
Focusing

Aron yu Aronyu127

🎯
Focusing
View GitHub Profile
@Aronyu127
Aronyu127 / export_student_data.rb
Created June 20, 2017 07:58
學生資料的 CSV 匯出
def export_school_student(file_path, school_name)
CSV.open(file_path, "wb") do |csv|
csv << ['學校', '學號', '姓名', 'email', '提交回報次數', '提交回報案數', '提交回報法官數']
CourtObserver.where(school: "#{school_name}").each do |c|
observer_array = [c.school, c.student_number, c.name, c.email, c.schedule_scores.count, c.schedule_scores.map(&:story_id).uniq.count, c.schedule_scores.map(&:judge_id).uniq.count]
csv << observer_array
end
end
end
@Aronyu127
Aronyu127 / transfer_data.rb
Created June 5, 2017 08:29
轉換profile 資料
class Transfer
attr_reader :unknow_profile
def initialize
@educations_count = 0
@careers_count = 0
@licenses_count = 0
@awards_count = 0
@punishments_count = 0
@reviews_count = 0
@Aronyu127
Aronyu127 / get_story_scheedule_cont.rb
Created May 4, 2017 07:17
轉換 案件庭期數量
total = Story.all.size
Story.find_each(batch_size: 2000).with_index do |s ,i|
Story.reset_counters(s.id, :schedules)
puts "#{i} / #{total}" if i % 10000 == 0
end
@Aronyu127
Aronyu127 / get_story_type.rb
Last active March 29, 2017 13:07
轉換所有server 上面沒有案件類別的資料
story_ids = Story.where(story_type: nil).pluck(:id)
success_story_ids = []
fail_story_ids = []
def get_story_type(story)
url = story.verdict ? story.verdict.file.url : story.rules.last.file.url
uri = URI.parse('https:' + url)
str = uri.read
nokogiri_data = Nokogiri::HTML(str.force_encoding('UTF-8'))
@Aronyu127
Aronyu127 / convert_s3_file.rb
Last active March 29, 2017 07:12
轉換s3 上的 hash to json 檔
verdict_ids = []
def get_hash(url)
uri = URI.parse('https:' + url)
str = uri.read
eval(str.force_encoding(Encoding::UTF_8))
end
def generate_tempfile(data, file_name)
file = Tempfile.new([file_name, ".json"], "#{Rails.root}/tmp/")
@Aronyu127
Aronyu127 / Banner_add_pic_url.rb
Last active January 5, 2017 10:04
首頁橫幅自動抓取pic 圖片
Banner.all.map do |b|
image_url = 'http:' + b.pic_l.url
b.remote_pic_url = image_url
b.title = '臨時標題'
b.link = 'http//example.com'
b.save
end