diff options
author | Heiko Bernloehr <freeit@nflexpvipecs.rus.uni-stuttgart.de> | 2016-02-12 05:29:04 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2016-02-12 06:20:01 +0100 |
commit | 9501a137529e0ac22873750484ddc781ae7e4f2a (patch) | |
tree | cd62ae01d16cc7af65a9cad5510a077ead316a55 | |
parent | 2042748f2c65b346f5fe5408e4cd990081a7380e (diff) | |
download | ecs2-9501a137529e0ac22873750484ddc781ae7e4f2a.tar.gz ecs2-9501a137529e0ac22873750484ddc781ae7e4f2a.zip |
New rake vip:count_ttl_exercises task.
-rw-r--r-- | lib/tasks/vip_count_exercises_with_ttl.rake | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/tasks/vip_count_exercises_with_ttl.rake b/lib/tasks/vip_count_exercises_with_ttl.rake new file mode 100644 index 0000000..2642fbc --- /dev/null +++ b/lib/tasks/vip_count_exercises_with_ttl.rake @@ -0,0 +1,25 @@ +namespace :vip do + desc "Count exercises with TTL attribute." + task :count_ttl_exercises => :environment do + ttl=[] + noexercise=0 + Message.for_resource("numlab", "exercises").sort{|x,y| x.created_at <=> y.created_at}.each do |msg| + begin + if JSON.parse(msg.body)['Exercise'].nil? + noexercise+= 1 + elsif !JSON.parse(msg.body)['Exercise']['TTL'].nil? + puts "Exercise (#{msg.id}) with TTL = " + JSON.parse(msg.body)['Exercise']['TTL'].to_s + ttl << msg + end + rescue JSON::ParserError, Exception + txt= "Filter Exception: "+$!.class.to_s+": #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}" + RAILS_DEFAULT_LOGGER.error txt + puts txt + end + end + puts "ID's of exercises with ttl: " + ttl.map{|m| m.id}.join(', ') + puts "noexercise: "+noexercise.to_s + puts "Number of exercises: #{Message.for_resource("numlab", "exercises").length-noexercise}" + puts "Number of exercises with ttl: " + ttl.length.to_s + end +end |