Last active
February 8, 2017 23:10
-
-
Save s4parke/dcc84f687d57088823ea69eee3540c72 to your computer and use it in GitHub Desktop.
Reset "time traveling" mySmartSKin participants and clean up participation data
This file contains hidden or 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
## Find all time travel test participants | |
Participant.find( :all, :participant_type => 'Patient', :deleted => false, | |
:conditions => ['IFNULL(time_delta_days,0) != 0'] ) | |
## Reset time offset and timezone | |
@participant.time_delta_days = 0 | |
@participant.timezone = 'US/Eastern' | |
## Delete all of their moles and Diaries | |
@participant.moles.destroy_all | |
@participant.diaries.destroy_all | |
## Clean up study participation events | |
event_types = %w[ SendEmail UserLogin DailySleep% MonthlySkinSelfCheck% ] | |
@emails = Event.find_all_by_participant_id( @pid, | |
:conditions = ['event_type in ?', event_types.join(',')] ) | |
@emails.each{|e| | |
EventData.find_all_by_event_id( e.id ).destroy_all | |
e.destroy | |
} | |
## Create events | |
@event_data = { 'UserLogin' => 'Last login time reset', | |
'ParticipantReinstated' => 'Cleanup participant data and events', | |
'ParticipantReady' => 'MSSC moles / selfchecks removed', | |
'PendingActionDeleted' => 'Cleanup pending time offset actions' | |
} | |
@event_data.each{|key,value| | |
Event.create_event(:event_type => "#{key}", | |
:marker_type => 'completed', | |
:skip_trigger_checks => true, | |
:participant_id => @pid, | |
:category => 'SYS', | |
:level => 2, | |
:description => "#{value} by BHT System User" ) | |
} | |
## Delete pending actions | |
@actions = Action.find(:all, conditions => { :participant_id => @pid, :was_executed => 0 }) | |
@actions.each{|a| | |
ActionData.find_all_by_action_id( a.id ).destroy_all | |
a.destroy | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create events
events = {
'ParticipantReinstated' => 'Cleanup participant data and events',
'ParticipantReady' => 'MSSC moles / selfchecks removed',
'PendingActionDeleted' => 'Cleanup pending time offset actions'
}
def traveller_fix participant, events
Reset time offset and timezone
participant.time_delta_days = 0
participant.timezone = 'US/Eastern'
participant.skip_trigger_checks = true
participant.save
Delete all of their moles and Diaries
participant.moles.destroy_all
participant.diaries.destroy_all
Clean up study participation events
events_to_cleanup.each{|e|
EventData.find(:all, :conditions=>{:event_id => e.id} ).each{|ed| EventData.destroy(ed.id)}
Event.destroy(e.id)
}
events.each do |event_type, note|
Event.create_event(:event_type => "#{event_type}",
:marker_type => 'completed',
:skip_trigger_checks => true,
:participant_id => participant.id,
:category => 'SYS',
:level => 2,
:description => "#{note} by BHT System User" )
end
Event.record_login(participant.id, 'SYSTEM')
end
Find all time travel test participants
travellers=Participant.all.select{|p| p.time_delta_days && p.time_delta_days > 0
travellers.each{|traveller| traveller_fix traveller, events}