myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [1876] branches/event_logging: News generation.


From: noreply
Subject: [myexperiment-hackers] [1876] branches/event_logging: News generation.
Date: Mon, 20 Oct 2008 12:47:18 -0400 (EDT)

Revision
1876
Author
alekses6
Date
2008-10-20 12:47:18 -0400 (Mon, 20 Oct 2008)

Log Message

News generation. Started work on a script, which will populate the ActivityLogs table to make the transition to the new news generation system seamless.

Added Paths

Diff

Added: branches/event_logging/lib/maintenance/populate_activity_log.rb (0 => 1876)


--- branches/event_logging/lib/maintenance/populate_activity_log.rb	                        (rev 0)
+++ branches/event_logging/lib/maintenance/populate_activity_log.rb	2008-10-20 16:47:18 UTC (rev 1876)
@@ -0,0 +1,190 @@
+# myExperiment: lib/populate_activity_log.rb
+#
+# Copyright (c) 2008 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+module Maintenance
+  
+  # modify this setting to get the appropriate coverage of events from
+  # the point in the setting up to "now"
+  FETCH_EVENTS_AFTER = Time.now - 1.week
+  
+  
+  def populate_activity_log_with_events()
+    # output initial data about the script
+    start_time = Time.now
+    puts "\nThis script will populate 'activity_log' table with events from"
+    puts "various tables - this will make a list of friendships, memberships,"
+    puts "updated files, packs, workflows, etc. All of this is required to"
+    puts "make the seamless transition to the new news generation system from"
+    puts "activity logs."
+    puts "\n\nStarted at: " + start_time.to_s
+    puts "This may take a while..."
+    
+    
+    puts "\n\n============= USERS ============="
+    users = User.find(:all, :order => "created_at ASC", :conditions => ["created_at > ?", FETCH_EVENTS_AFTER])
+    users.each do |u|
+      # CREATE
+      ActivityLog.create(:action ="" "create", :activity_loggable => u, :created_at => u.created_at, :updated_at => u.created_at)
+      puts "\nUser (#{u.id}) -> create"
+      
+      # ACTIVATE
+      if u.activated?
+        ActivityLog.create(:action ="" "activate", :activity_loggable => u, :created_at => u.activated_at, :updated_at => u.activated_at)
+        puts "User (#{u.id}) -> activate"
+      end
+    end
+    
+    
+    puts "\n\n============= SITE ANNOUNCEMENTS ============="
+    site_announcements = Announcement.find(:all, :order => "created_at ASC", :conditions => ["created_at > ?", FETCH_EVENTS_AFTER])
+    site_announcements.each do |ann|
+      # CREATE
+      ActivityLog.create(:action ="" "create", :activity_loggable => ann, :culprit => ann.user, :created_at => ann.created_at, :updated_at => ann.created_at)
+      puts "\nSite announcement (#{ann.id}) -> create"
+    end
+    
+    puts "\n\n============= PICTURE SELECTIONS ============="
+    picture_selections = PictureSelection.find(:all, :order => "created_at ASC", :conditions => ["created_at > ?", FETCH_EVENTS_AFTER])
+    picture_selections.each do |sel|
+      # CREATE
+      ActivityLog.create(:action ="" "create", :activity_loggable => sel, :culprit => sel.user, :referenced => sel.picture, :created_at => sel.created_at, :updated_at => sel.created_at)
+      puts "\nPicture selection (#{sel.id}) -> create"
+    end
+    
+    
+    puts "\n\n============= FRIENDSHIPS ============="
+    # can make record of "requests" and "accepts"
+    accepted_friendships = 0
+    friendships = Friendship.find(:all, :order => "created_at ASC", :conditions => ["created_at > ?", FETCH_EVENTS_AFTER])
+    friendships.each do |f|
+      # REQUEST
+      ActivityLog.create(:action ="" "create", :activity_loggable => f, :culprit => f.user, :referenced => f.friend, :created_at => f.created_at, :updated_at => f.created_at)
+      puts "\nFriendship (#{f.id}) -> create"
+      
+      # ACCEPT
+      if f.accepted?
+        ActivityLog.create(:action ="" "accept", :activity_loggable => f, :culprit => f.friend, :referenced => f.user, :created_at => f.accepted_at, :updated_at => f.accepted_at)
+        puts "Friendship (#{f.id}) -> accept"
+        accepted_friendships += 1
+      end
+    end
+    
+    puts "\n\n============= MESSAGES ============="
+    # can make record of "create" / "read"
+    #
+    # NB! This could also record all cases of use of messages for status --
+    # i.e. when someone gets automated "X has rejected your friendships request" --
+    # but we don't want these automated messages to be treated as user activity,
+    # so any messages with "deleted_by_sender" flag won't be logged
+    messages = Message.find(:all, :order => "created_at ASC", :conditions => ["deleted_by_sender = ? AND created_at > ?", false, FETCH_EVENTS_AFTER])
+    messages.each do |m|
+      # CREATE
+      ActivityLog.create(:action ="" "create", :activity_loggable => m, :culprit => m.u_from, :referenced => m.u_to, :created_at => m.created_at, :updated_at => m.created_at)
+      puts "\nMessage (#{m.id}) -> create"
+      
+      # READ
+      if m.read?
+        ActivityLog.create(:action ="" "read", :activity_loggable => m, :culprit => m.u_to, :referenced => m.u_from, :created_at => m.read_at, :updated_at => m.read_at)
+        puts "Message (#{m.id}) -> read"
+      end
+      
+      # SOFT_DELETE (by recipient only)
+      if m.deleted_by_recipient
+        timestamp = (m.read? ? m.read_at : m.created_at) + 1.second
+        ActivityLog.create(:action ="" "soft_delete", :activity_loggable => m, :culprit => m.u_to, :referenced => m.u_from, :created_at => timestamp, :updated_at => timestamp)
+        puts "Message (#{m.id}) -> soft_delete (by recipient)"
+      end
+    end
+    
+    puts "\n\n============= GROUPS ============="
+    
+    
+    
+    puts "\n\n============= GROUP ANNOUNCEMENTS ============="
+    
+    
+    puts "\n\n============= MEMBERSHIPS ============="
+    # can make record of "invites / requests" and "accepts"
+    membership_invites = 0
+    membership_requests = 0
+    accepted_memberships = 0
+    memberships = Membership.find(:all, :order => "created_at ASC", :conditions => ["created_at > ?", FETCH_EVENTS_AFTER])
+    memberships.each do |m|
+      # INVITE / REQUEST
+      if m.is_invite?
+        ActivityLog.create(:action ="" "invite", :activity_loggable => m, :culprit => m.network, :referenced => m.user, :created_at => m.created_at, :updated_at => m.created_at)
+        puts "Membership (#{m.id}) -> invite"
+        membership_invites += 1
+      else
+        ActivityLog.create(:action ="" "request", :activity_loggable => m, :culprit => m.user, :referenced => m.network, :created_at => m.created_at, :updated_at => m.created_at)
+        puts "Membership (#{m.id}) -> request"
+        memberships_requests += 1
+      end
+      
+      # ACCEPT
+      if m.accepted?
+        if m.is_invite?
+          culprit = m.user
+          referenced = m.network
+        else
+          culprit = m.network
+          referenced = m.user
+        end
+        ActivityLog.create(:action ="" "accept", :activity_loggable => m, :culprit => culprit, :referenced => referenced, :created_at => m.accepted_at, :updated_at => m.accepted_at)
+        puts "Membership (#{m.id}) -> accept\n"
+        accepted_memberships += 1
+      end
+    end
+    
+    puts "\n\n============= FILES ============="
+    
+    puts "\n\n============= WORKFLOWS ============="
+    
+    puts "\n\n============= PACKS ============="
+    
+    
+    puts "\n\n============= RATINGS ============="
+    
+    puts "\n\n============= BOOKMARKS ============="
+    
+    puts "\n\n============= REVIEWS ============="
+    
+    puts "\n\n============= COMMENTS ============="
+    
+    puts "\n\n============= TAGGINGS ============="
+    
+    
+    
+ 
+    # unknown who has done the action, can't populate any data from these tables:
+    # PERMISSIONS, CREDITATIONS, ATTRIBUTIONS
+    #
+    # puts "\n\n============= PROFILES ============="
+    # unknown what changes are done to profiles, so no need to log? 
+    
+    
+    # checking-fixing all policies done, output stats
+    end_time = Time.now
+    puts "\n\nFinished at:  " + end_time.to_s
+    puts "Processing took:  " + (end_time - start_time).to_s + "\n"
+    puts "text\n\n\n"
+    
+    # STATS FOR OUTPUT
+    
+    # users.length
+    # site_announcements.length
+    # messages.length
+
+    # friendships.length
+    # accepted_friendships
+    
+    # memberships.length
+    # membership_invites
+    # membership_requests
+    # accepted_memberships
+    
+  end
+  
+end
\ No newline at end of file

Added: branches/event_logging/populate_activity_log.rb (0 => 1876)


--- branches/event_logging/populate_activity_log.rb	                        (rev 0)
+++ branches/event_logging/populate_activity_log.rb	2008-10-20 16:47:18 UTC (rev 1876)
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + '/config/environment'
+# test methods are in /lib/policy_consistency_fixer.rb
+require File.dirname(__FILE__) + '/lib/maintenance/populate_activity_log'
+
+# This script is required to populate "activity_logs" table (which is assumed to be created
+# by the migration file earlier) with events inferred from other tables - this is to minimize
+# the transition effect between the old news generation system and the new (log-based) one.
+
+include Maintenance
+
+# execute the action & output the results
+populate_activity_log_with_events()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]