Last active
October 11, 2017 05:42
-
-
Save umar-siddiqui/e48f2c1e29cc0c8153515d44a7c4b25e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = [ | |
{ | |
:src => :letters, | |
'Sample' => { 'BoY' => :boy_letter_score_for_sample, 'EoY' => :eoy_letter_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_letter_scores, 'BoY' => :boy_letter_score } | |
}, | |
{ | |
:src => :sound_score, | |
'Sample' => { 'BoY' => :boy_sound_score_for_sample, 'EoY' => :eoy_sound_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sound_score_for_control, 'BoY' => :boy_sound_score_for_control } | |
}, | |
{ | |
:src => :wcpm, | |
'Sample' => { 'BoY' => :boy_wcpm_score_for_sample, 'EoY' => :eoy_wcpm_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_wcpm_score_for_control, 'BoY' => :boy_wcpm_score_for_control } | |
}, | |
{ | |
:src => :digraph_words_score, | |
'Sample' => { 'BoY' => :boy_digraphs_score_for_sample, 'EoY' => :eoy_digraph_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_diagraphs_score_for_control, 'BoY' => :boy_diagraphs_score_for_control } | |
}, | |
{ | |
:src => :cvc_words_score, | |
'Sample' => { 'BoY' => :boy_cvc_score_for_sample, 'EoY' => :eoy_cvc_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_cvc_score_for_control, 'BoY' => :boy_cvc_score_for_control } | |
}, | |
{ | |
:src => :magic_e_score, | |
'Sample' => { 'BoY' => :boy_magic_e_score_for_sample, 'EoY' => :eoy_magic_e_score_for_sample11 }, | |
'Control' => { 'EoY' => :eoy_magic_e_score_for_control, 'BoY' => :boy_magic_e_score_for_control } | |
}, | |
{ | |
:src => :comprehension_score, | |
'Sample' => { 'BoY' => :boy_comprehension_score_for_sample, 'EoY' => :eoy_comprehension_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_comprehension_score_for_control, 'BoY' => :boy_comprehension_score_for_control } | |
}, | |
{ | |
:src => :dictation_score, | |
'Sample' => { 'BoY' => :boy_dictation_score_for_sample, 'EoY' => :eoy_comprehension_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_dictation_score_for_control, 'BoY' => :boy_dictation_score_for_control } | |
}, | |
{ | |
:src => :accuracy, | |
'Sample' => { 'BoY' => :boy_accuracy__for_sample, 'EoY' => :eoy_accuracy__for_sample }, | |
'Control' => { 'EoY' => :eoy_accuracy___for_control44, 'BoY' => :boy_accuracy__for_control } | |
} | |
] | |
Mongoid.override_database 'sterlite_resustain_io' | |
puts indxs = IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').count | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').each_with_index do |ir, i| | |
puts i.to_s + '/' + indxs.to_s | |
h = {} | |
m.each do |n| | |
# puts ir[:type_of_set].to_s + ' ' + ir[:assesment_conducted_on].to_s | |
target = n[ir[:type_of_set]][ir[:assesment_conducted_on]] | |
# sleep 10 if target.nil? | |
h[target] = ir[n[:src]] if target.present? | |
end | |
puts h.inspect | |
IndicatorRecord.where(_id: ir._id).update_all(h) if h.present? | |
end | |
Mongoid.override_database 'sterlite_resustain_io' | |
puts indxs = IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').count | |
def sys_fields(ir, r) | |
return if r.start_date.nil? | |
fin_start_month = Settings.analytics.fin_start_month | |
if r.start_date.month >= fin_start_month | |
## add 1 to fin year if start month is not Jan | |
ir[:sys_fin_year] = 'FY' + (r.start_date.year + 1).to_s unless fin_start_month == 0 | |
months_between = r.start_date.month - fin_start_month | |
else | |
ir[:sys_fin_year] = 'FY' + r.start_date.year.to_s | |
months_between = r.start_date.month - fin_start_month + 12 | |
end | |
ir[:sys_fin_quarter] = "Q#{( months_between / 3 ).floor + 1}" | |
ir[:sys_fin_half] = "H#{( months_between / 6 ).floor + 1}" | |
end | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').each_with_index do |ir, i| | |
puts i.to_s + '/' + indxs.to_s | |
h = {} | |
sys_fields(h, ir) | |
puts h.inspect | |
IndicatorRecord.where(_id: ir._id).update_all(h) if h.present? | |
end | |
Mongoid.override_database 'sterlite_resustain_io' | |
Mongoid::Multitenancy.current_tenant = Client.first | |
callbacks = IndicatorRecord._save_callbacks.select { |cb| cb.kind == :before }.map { |cb| cb.as_json["key"] }.map(&:to_sym) | |
indi = Indicator.find('5910150062cee9ae1a000002') | |
indicator_attri = indi.indicator_attributes.where(attribute_type: 'formula') | |
IndicatorRecord.skip_callback(:save, :before, *callbacks) | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002', grade: '6th', :start_date.gte => 'June 1,2015', type_of_set: 'Sample', :start_date.lte => 'March 1,2016').each_with_index do |ir,i| | |
puts i | |
indicator_attri.each {|ia| ir.recalc_formula(ia) } | |
ir.save! | |
end | |
IndicatorRecord.set_callback(:save, :before, *callbacks) | |
m = [ | |
{ | |
:src => :time, | |
'Sample' => { 'BoY' => :boy_time_score_for_sample, 'EoY' => :eoy_time_taken_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_time_score_for_control, 'BoY' => :boy_time_taken_score_for_control } | |
}, | |
{ | |
:src => :match_picture_score, | |
'Sample' => { 'BoY' => :boy_match_picture_score_for_sample, 'EoY' => :eoy_match_picture_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_match_picture_score_for_control, 'BoY' => :boy_match_picture_score_for_control } | |
}, | |
{ | |
:src => :blends_score, | |
'Sample' => { 'BoY' => :boy_blends_score_for_sample12, 'EoY' => :eoy_blend_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_blend_score_for_control, 'BoY' => :boy_blends_score_for_control } | |
}, | |
{ | |
:src => :suffixes_score, | |
'Sample' => { 'BoY' => :boy_blends_score_for_sample, 'EoY' => :eoy_suffixes_score_for_sample11 }, | |
'Control' => { 'EoY' => :eoy_suffixes_score_for_control22, 'BoY' => :boy_suffixes_score_for_control } | |
}, | |
{ | |
:src => :sight_words_81150_score, | |
'Sample' => { 'BoY' => :boy_sight_words_81150__score_for_sample, 'EoY' => :eoy_sight_words_81150__score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sight_words_81150_score_for_control, 'BoY' => :boy_sight_words_81150__score_for_control } | |
}, | |
{ | |
:src => :sight_words_151200_score, | |
'Sample' => { 'BoY' => :boy_sight_words_151100_score_for_sample, 'EoY' => :eoy_sight_words_151100_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sight_words_151100_score_for_control, 'BoY' => :boy_sight_words_151200_score_control } | |
}, | |
{ | |
:src => :total, | |
'Sample' => { 'BoY' => :boy_total_score_for_sample, 'EoY' => :boy_total_score_for_sample33 }, | |
'Control' => { 'EoY' => :eoy_total_score_for_control66, 'BoY' => :boy_total_score_for_control } | |
}, | |
{ | |
:src => :sentence_accuracy_, | |
'Sample' => { 'BoY' => :boy_sentence_accuracy_for_sample, 'EoY' => :eoy_sentence_accuracy_for_sample }, | |
'Control' => { 'EoY' => :eoy_sentence_accuracy_for_control, 'BoY' => :boy_sentence_accuracy_score_for_control } | |
} | |
] | |
Mongoid.override_database 'sterlite_resustain_io' | |
puts indxs = IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').count | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').each_with_index do |ir, i| | |
puts i.to_s + '/' + indxs.to_s | |
h = {} | |
m.each do |n| | |
# puts ir[:type_of_set].present?.to_s + ' ' + ir[:assesment_conducted_on].present?.to_s | |
next if ir[:type_of_set].nil? || ir[:assesment_conducted_on].nil? | |
target = n[ir[:type_of_set]][ir[:assesment_conducted_on]] | |
# sleep 10 if target.nil? | |
h[target] = ir[n[:src]] if target.present? | |
end | |
puts h.keys.count | |
IndicatorRecord.where(_id: ir._id).update_all(h) if h.present? | |
end | |
m = [ | |
{ | |
:src => :sight_words_81150_score, | |
'Sample' => { 'BoY' => :boy_sight_words_81150__score_for_sample, 'EoY' => :eoy_sight_words_81150__score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sight_words_81150_score_for_control, 'BoY' => :boy_sight_words_81150__score_for_control } | |
} | |
] | |
Mongoid.override_database 'sterlite_resustain_io' | |
puts indxs = IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').count | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').each_with_index do |ir, i| | |
puts i.to_s + '/' + indxs.to_s | |
h = {} | |
m.each do |n| | |
# puts ir[:type_of_set].present?.to_s + ' ' + ir[:assesment_conducted_on].present?.to_s | |
next if ir[:type_of_set].nil? || ir[:assesment_conducted_on].nil? | |
target = n[ir[:type_of_set]][ir[:assesment_conducted_on]] | |
# sleep 10 if target.nil? | |
h[target] = ir[n[:src]] if target.present? | |
end | |
puts h.keys.count | |
IndicatorRecord.where(_id: ir._id).update_all(h) if h.present? | |
end | |
IndicatorAttribute.where(attribute_type: 'formula').to_a.select {|ia| ia.formula_segments.where(indicator_attribute_id: '592bf4bf62cee90764000ebb').first }.map {|ia| [ia.name,ia.label]} | |
Mongoid.override_database 'sterlite_resustain_io' | |
['save', 'update', 'create', 'destroy'].each do |cb| | |
bcallbacks = IndicatorRecord.send("_#{cb}_callbacks").select { |cb| cb.kind == :before }.map { |cb| cb.as_json["key"] }.map(&:to_s).map(&:to_sym) | |
acallbacks = IndicatorRecord.send("_#{cb}_callbacks").select { |cb| cb.kind == :after }.map { |cb| cb.as_json["key"] }.map(&:to_s).map(&:to_sym) | |
IndicatorRecord.skip_callback(cb.to_s.to_sym, :before, *bcallbacks) | |
IndicatorRecord.skip_callback(cb.to_s.to_sym, :after, *acallbacks) | |
end | |
ias = IndicatorAttribute.where(attribute_type: 'formula').in(label: ['WC Score','WCPM', 'Total', 'Accuracy(%)']).to_a | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002', :start_date.gte => "01 Jun 2016", :start_date.lte => "01 March 2017").each_with_index do |record, i| | |
puts i | |
ias.each { |ia| record.recalc_formula(ia) } | |
record.save! | |
end | |
m = [ | |
{ | |
:src => :letters, | |
'Sample' => { 'BoY' => :boy_letter_score_for_sample, 'EoY' => :eoy_letter_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_letter_scores, 'BoY' => :boy_letter_score } | |
}, | |
{ | |
:src => :sound_score, | |
'Sample' => { 'BoY' => :boy_sound_score_for_sample, 'EoY' => :eoy_sound_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sound_score_for_control, 'BoY' => :boy_sound_score_for_control } | |
}, | |
{ | |
:src => :wcpm, | |
'Sample' => { 'BoY' => :boy_wcpm_score_for_sample, 'EoY' => :eoy_wcpm_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_wcpm_score_for_control, 'BoY' => :boy_wcpm_score_for_control } | |
}, | |
{ | |
:src => :digraph_words_score, | |
'Sample' => { 'BoY' => :boy_digraphs_score_for_sample, 'EoY' => :eoy_digraph_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_diagraphs_score_for_control, 'BoY' => :boy_diagraphs_score_for_control } | |
}, | |
{ | |
:src => :cvc_words_score, | |
'Sample' => { 'BoY' => :boy_cvc_score_for_sample, 'EoY' => :eoy_cvc_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_cvc_score_for_control, 'BoY' => :boy_cvc_score_for_control } | |
}, | |
{ | |
:src => :magic_e_score, | |
'Sample' => { 'BoY' => :boy_magic_e_score_for_sample, 'EoY' => :eoy_magic_e_score_for_sample11 }, | |
'Control' => { 'EoY' => :eoy_magic_e_score_for_control, 'BoY' => :boy_magic_e_score_for_control } | |
}, | |
{ | |
:src => :comprehension_score, | |
'Sample' => { 'BoY' => :boy_comprehension_score_for_sample, 'EoY' => :eoy_comprehension_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_comprehension_score_for_control, 'BoY' => :boy_comprehension_score_for_control } | |
}, | |
{ | |
:src => :dictation_score, | |
'Sample' => { 'BoY' => :boy_dictation_score_for_sample, 'EoY' => :eoy_comprehension_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_dictation_score_for_control, 'BoY' => :boy_dictation_score_for_control } | |
}, | |
{ | |
:src => :accuracy, | |
'Sample' => { 'BoY' => :boy_accuracy__for_sample, 'EoY' => :eoy_accuracy__for_sample }, | |
'Control' => { 'EoY' => :eoy_accuracy___for_control44, 'BoY' => :boy_accuracy__for_control } | |
}, | |
{ | |
:src => :time, | |
'Sample' => { 'BoY' => :boy_time_score_for_sample, 'EoY' => :eoy_time_taken_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_time_score_for_control, 'BoY' => :boy_time_taken_score_for_control } | |
}, | |
{ | |
:src => :match_picture_score, | |
'Sample' => { 'BoY' => :boy_match_picture_score_for_sample, 'EoY' => :eoy_match_picture_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_match_picture_score_for_control, 'BoY' => :boy_match_picture_score_for_control } | |
}, | |
{ | |
:src => :blends_score, | |
'Sample' => { 'BoY' => :boy_blends_score_for_sample12, 'EoY' => :eoy_blend_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_blend_score_for_control, 'BoY' => :boy_blends_score_for_control } | |
}, | |
{ | |
:src => :suffixes_score, | |
'Sample' => { 'BoY' => :boy_blends_score_for_sample, 'EoY' => :eoy_suffixes_score_for_sample11 }, | |
'Control' => { 'EoY' => :eoy_suffixes_score_for_control22, 'BoY' => :boy_suffixes_score_for_control } | |
}, | |
{ | |
:src => :sight_words_81150_score, | |
'Sample' => { 'BoY' => :boy_sight_words_81150__score_for_sample, 'EoY' => :eoy_sight_words_81150__score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sight_words_81150_score_for_control, 'BoY' => :boy_sight_words_81150__score_for_control } | |
}, | |
{ | |
:src => :sight_words_151200_score, | |
'Sample' => { 'BoY' => :boy_sight_words_151100_score_for_sample, 'EoY' => :eoy_sight_words_151100_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sight_words_151100_score_for_control, 'BoY' => :boy_sight_words_151200_score_control } | |
}, | |
{ | |
:src => :total, | |
'Sample' => { 'BoY' => :boy_total_score_for_sample, 'EoY' => :boy_total_score_for_sample33 }, | |
'Control' => { 'EoY' => :eoy_total_score_for_control66, 'BoY' => :boy_total_score_for_control } | |
}, | |
{ | |
:src => :sentence_accuracy_, | |
'Sample' => { 'BoY' => :boy_sentence_accuracy_for_sample, 'EoY' => :eoy_sentence_accuracy_for_sample }, | |
'Control' => { 'EoY' => :eoy_sentence_accuracy_for_control, 'BoY' => :boy_sentence_accuracy_score_for_control } | |
} | |
] | |
Mongoid.override_database 'sterlite_resustain_io' | |
puts indxs = IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').count | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').each_with_index do |ir, i| | |
puts i.to_s + '/' + indxs.to_s | |
h = {} | |
m.each do |n| | |
# puts ir[:type_of_set].present?.to_s + ' ' + ir[:assesment_conducted_on].present?.to_s | |
next if ir[:type_of_set].nil? || ir[:assesment_conducted_on].nil? | |
target = n[ir[:type_of_set]][ir[:assesment_conducted_on]] | |
# sleep 10 if target.nil? | |
h[target] = ir[n[:src]] if target.present? | |
end | |
puts h.keys.count | |
IndicatorRecord.where(_id: ir._id).update_all(h) if h.present? | |
end | |
m = [ | |
{ | |
:src => :letters, | |
'Sample' => { 'BoY' => :boy_letter_score_for_sample, 'EoY' => :eoy_letter_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_letter_scores, 'BoY' => :boy_letter_score } | |
}, | |
{ | |
:src => :sound_score, | |
'Sample' => { 'BoY' => :boy_sound_score_for_sample, 'EoY' => :eoy_sound_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_sound_score_for_control, 'BoY' => :boy_sound_score_for_control } | |
}, | |
{ | |
:src => :wcpm, | |
'Sample' => { 'BoY' => :boy_wcpm_score_for_sample, 'EoY' => :eoy_wcpm_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_wcpm_score_for_control, 'BoY' => :boy_wcpm_score_for_control } | |
}, | |
{ | |
:src => :digraph_words_score, | |
'Sample' => { 'BoY' => :boy_digraphs_score_for_sample, 'EoY' => :eoy_digraph_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_diagraphs_score_for_control, 'BoY' => :boy_diagraphs_score_for_control } | |
}, | |
{ | |
:src => :cvc_words_score, | |
'Sample' => { 'BoY' => :boy_cvc_score_for_sample, 'EoY' => :eoy_cvc_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_cvc_score_for_control, 'BoY' => :boy_cvc_score_for_control } | |
}, | |
{ | |
:src => :magic_e_score, | |
'Sample' => { 'BoY' => :boy_magic_e_score_for_sample, 'EoY' => :eoy_magic_e_score_for_sample11 }, | |
'Control' => { 'EoY' => :eoy_magic_e_score_for_control, 'BoY' => :boy_magic_e_score_for_control } | |
}, | |
{ | |
:src => :comprehension_score, | |
'Sample' => { 'BoY' => :boy_comprehension_score_for_sample, 'EoY' => :eoy_comprehension_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_comprehension_score_for_control, 'BoY' => :boy_comprehension_score_for_control } | |
}, | |
{ | |
:src => :dictation_score, | |
'Sample' => { 'BoY' => :boy_dictation_score_for_sample, 'EoY' => :eoy_comprehension_score_for_sample }, | |
'Control' => { 'EoY' => :eoy_dictation_score_for_control, 'BoY' => :boy_dictation_score_for_control } | |
}, | |
{ | |
:src => :accuracy, | |
'Sample' => { 'BoY' => :boy_accuracy__for_sample, 'EoY' => :eoy_accuracy__for_sample }, | |
'Control' => { 'EoY' => :eoy_accuracy___for_control44, 'BoY' => :boy_accuracy__for_control } | |
} | |
] | |
Mongoid.override_database 'sterlite_resustain_io' | |
puts indxs = IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').count | |
def sys_fields(ir, r) | |
return if r.start_date.nil? | |
fin_start_month = Settings.analytics.fin_start_month | |
if r.start_date.month >= fin_start_month | |
## add 1 to fin year if start month is not Jan | |
ir[:sys_fin_year] = 'FY' + (r.start_date.year + 1).to_s unless fin_start_month == 0 | |
months_between = r.start_date.month - fin_start_month | |
else | |
ir[:sys_fin_year] = 'FY' + r.start_date.year.to_s | |
months_between = r.start_date.month - fin_start_month + 12 | |
end | |
ir[:sys_fin_quarter] = "Q#{( months_between / 3 ).floor + 1}" | |
ir[:sys_fin_half] = "H#{( months_between / 6 ).floor + 1}" | |
end | |
IndicatorRecord.where(indicator_id: '5910150062cee9ae1a000002').each_with_index do |ir, i| | |
puts i.to_s + '/' + indxs.to_s | |
h = {} | |
sys_fields(h, ir) | |
puts h.inspect | |
IndicatorRecord.where(_id: ir._id).update_all(h) if h.present? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment