Skip to content

Commit

Permalink
Implement admin cleanup of ground truth for Pablo
Browse files Browse the repository at this point in the history
  • Loading branch information
mizzao committed Aug 27, 2014
1 parent 80081a3 commit 5ea131b
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ mizzao:[email protected]
mizzao:[email protected]

# Temporary crap that needs to be moved due to shitty migration
mrt:bootstrap-3@3.2.0-2
mizzao:bootstrap-3
mizzao:jquery-ui
natestrauser:x-editable-bootstrap
natestrauser:x-editable-bootstrap@1.5.1

# Development packages
mizzao:user-status
Expand Down
2 changes: 1 addition & 1 deletion .meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
METEOR-CORE@0.9.0-rc12
[email protected]
8 changes: 4 additions & 4 deletions .meteor/versions
14 changes: 11 additions & 3 deletions client/views/events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,17 @@ acceptDrop = (draggable) ->
# drop check if the tweet is part of an event, below
return false unless tweet?

# Don't accept drops to the same event - check the event as it will be more
# up to date than the one-shot data context being used to render the helper,
# which may have changed.
###
Don't accept drops to the same event. There are two ways to do this:
- check the event as it will be more up to date than the one-shot data
context being used to render the helper, which may have changed.
- check the tweet to see if the event is attached.
TODO we need to implement something that will allow for admin cleanup of
multi-tagged events in the ground truth.
###
return false if $.inArray(tweet._id, event.sources) >= 0
return true

Expand Down
38 changes: 22 additions & 16 deletions lib/data.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ TurkServer.partitionCollection(Notifications, {
}
})

# Admin cannot edit unless it is a special ground truth instance
checkPermissions = ->
return unless TurkServer.isAdmin()
unless TurkServer.treatment().treatments[0] is "groundtruth"
throw new Meteor.Error(403, "Can't edit as admin")

Meteor.methods
###
Data Methods
###
dataHide: (tweetId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(tweetId, String)

# Can't hide tagged events
Expand All @@ -62,7 +68,7 @@ Meteor.methods
return

dataLink: (tweetId, eventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(tweetId, String)
check(eventId, String)

Expand All @@ -86,7 +92,7 @@ Meteor.methods
return

dataUnlink: (tweetId, eventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(tweetId, String)
check(eventId, String)

Expand All @@ -109,7 +115,7 @@ Meteor.methods

# Dragging a tweet frome one event to another
dataMove: (tweetId, fromEventId, toEventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(tweetId, String)
check(fromEventId, String)
check(toEventId, String)
Expand Down Expand Up @@ -142,7 +148,7 @@ Meteor.methods
Event Methods
###
createEvent: (eventId, fields) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(eventId, String)

obj = {
Expand Down Expand Up @@ -170,7 +176,7 @@ Meteor.methods
return

editEvent: (eventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(eventId, String)

userId = Meteor.userId()
Expand Down Expand Up @@ -198,7 +204,7 @@ Meteor.methods
return

updateEvent: (eventId, fields) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(eventId, String)

Events.update eventId,
Expand All @@ -218,7 +224,7 @@ Meteor.methods
return

unmapEvent: (eventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(eventId, String)

Events.update eventId,
Expand Down Expand Up @@ -249,7 +255,7 @@ Meteor.methods
return

voteEvent: (eventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(eventId, String)

userId = Meteor.userId()
Expand Down Expand Up @@ -291,7 +297,7 @@ Meteor.methods
return

deleteEvent: (eventId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(eventId, String)

# Pull all tweet links
Expand All @@ -318,7 +324,7 @@ Meteor.methods
Doc Methods
###
createDocument: (docName) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(docName, String)

docId = Documents.insert
Expand All @@ -336,7 +342,7 @@ Meteor.methods
return docId

renameDocument: (docId, newTitle) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(docId, String)
check(newTitle, String)

Expand All @@ -353,7 +359,7 @@ Meteor.methods
return

deleteDocument: (docId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(docId, String)

Documents.update docId,
Expand All @@ -371,7 +377,7 @@ Meteor.methods
Chat Methods
###
createChat: (roomName) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(roomName, String)

roomId = ChatRooms.insert
Expand All @@ -390,7 +396,7 @@ Meteor.methods
return roomId

renameChat: (roomId, newName) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(roomId, String)
check(newName, String)

Expand All @@ -415,7 +421,7 @@ Meteor.methods
###

deleteChat: (roomId) ->
TurkServer.checkNotAdmin()
checkPermissions()
check(roomId, String)

if @isSimulation
Expand Down
1 change: 1 addition & 0 deletions packages/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/mrt:bootstrap-3
/mrt:moment
/natestrauser:x-editable-bootstrap
/mizzao:bootstrap-3
2 changes: 1 addition & 1 deletion packages/csv/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
]
],
"pluginDependencies": [],
"toolVersion": "[email protected].16",
"toolVersion": "[email protected].25",
"format": "1.0"
}
119 changes: 119 additions & 0 deletions server/analysis.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# For debugging query errors: https://groups.google.com/forum/#!msg/meteor-talk/dnnEseBCCiE/l_LHsw-XAWsJ

#Meteor.startup ->
# wrappedFind = Meteor.Collection.prototype.find
#
# console.log('[startup] wrapping Collection.find')
#
# Meteor.Collection.prototype.find = ->
# console.log(this._name + '.find', JSON.stringify(arguments))
# return wrappedFind.apply(this, arguments)

# Special groundtruth tag for these instances
TurkServer.ensureTreatmentExists
name: "groundtruth"

Meteor.methods
# Create and populate a world that represents the Pablo data from groups of
# 16 and 32
"cm-aggregate-pablo-gt": (force) ->
TurkServer.checkAdmin()

instanceName = "groundtruth-pablo"

if Experiments.findOne(instanceName)?
throw new Meteor.Error(403, "aggregated instance already exists") unless force?
# Reuse same tweets that are loaded
console.log ("removing old event aggregation data")
Events.direct.remove({_groupId: instanceName})
instance = TurkServer.Instance.getInstance(instanceName)

else
Experiments.upsert(instanceName, $set: {})

# First run, load new tweets
instance = TurkServer.Instance.getInstance(instanceName)
instance.bindOperation ->
Mapper.loadCSVTweets("PabloPh_UN_cm.csv", 2000)
console.log("Loaded new tweets")

# Sleep a moment until all tweets are loaded, before proceeding
sleep = Meteor._wrapAsync((time, cb) -> Meteor.setTimeout (-> cb undefined), time)
sleep(2000)

# Fake identifier for this instance to allow admin editing
Experiments.upsert(instanceName, $set: { treatments: [ "groundtruth" ]})

batch = Batches.findOne({name: "group sizes redux"})

exps = Experiments.find({
batchId: batch._id
treatments: $in: [ "group_16", "group_32" ]
users: $exists: true
}).fetch()

console.log "Found #{exps.length} experiments"

instance.bindOperation ->
# Start with all tweets hidden. un-hide them if any group has them
# hidden or attached
Datastream.update({}, {
$set: {hidden: true, events: []}
}, {multi: true})

remapSources = (sources) ->
for source in sources
num = Datastream.direct.findOne(source).num
Datastream.direct.findOne({_groupId: instanceName, num})._id

###
Process existing groups as follows:
- Create all (non-deleted) events referencing the tweet with the same number
- Re-map sources and events to the new ids
- Unhide any tweets that are attached or not hidden
###

currentNum = 0

for exp in exps
console.log "Processing #{exp._id} (#{exp.users.length})"

Events.direct.find({
_groupId: exp._id
deleted: $exists: false
}, {
fields: {num: 0, editor: 0}
}).forEach (event) ->

# omit the _id field, and transform the sources array
delete event._id
event.sources = remapSources(event.sources)
event.num = ++currentNum

instance.bindOperation ->
# Insert the transformed event
newEventId = Events.insert(event)
# Push this event on to remapped tweets
Datastream.update({
_id: { $in: event.sources }
}, {
$addToSet: { events: newEventId }
}, {multi: true})

console.log "Done copying events"

# unhide any tweets that were not hidden or attached
remainingTweets = Datastream.direct.find({
_groupId: exp._id,
hidden: { $exists: false }
}).map (tweet) -> tweet._id

Datastream.direct.update({
_id: $in: remapSources(remainingTweets)
}, {
$unset: {hidden: null}
}, {
multi: true
})

console.log "done"
28 changes: 2 additions & 26 deletions server/experiment_init.coffee
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
loadCSVTweets = (file, limit) ->
# csv is exported by the csv package

Assets.getText file, (err, res) ->
throw err if err

csv()
.from.string(res, {
columns: true
trim: true
})
.to.array Meteor.bindEnvironment ( arr, count ) ->

i = 0
while i < limit and i < arr.length
Datastream.insert
num: i+1 # Indexed from 1
text: arr[i].text
i++
# console.log(i + " tweets inserted")

, (e) ->
Meteor._debug "Exception while reading CSV:", e

TurkServer.initialize ->
return if Datastream.find().count() > 0

if @instance.treatment().tutorialEnabled
loadCSVTweets("tutorial.csv", 10)
Mapper.loadCSVTweets("tutorial.csv", 10)
else
# Load initial tweets on first start
# Meta-cleaned version has 1567 tweets
loadCSVTweets("PabloPh_UN_cm.csv", 2000)
Mapper.loadCSVTweets("PabloPh_UN_cm.csv", 2000)
# Create a seed instructions document for the app
docId = Documents.insert
title: "Instructions"
Expand Down
Loading

0 comments on commit 5ea131b

Please sign in to comment.