<commit_before># Server admin code

# Only admin gets server facts
Facts.setUserIdFilter (userId) -> Meteor.users.findOne(userId)?.admin

Meteor.publish "tsAdmin", ->
  return unless @userId and Meteor.users.findOne(@userId).admin

  # Publish all admin data
  return [
    Batches.find(),
    Treatments.find(),
    Experiments.find(),
    # Grouping.find(),
    Assignments.find(),
    Workers.find(),
    LobbyStatus.find()
  ]

userFindOptions =
  # {"status.online": true},
  fields:
    status: 1
    turkserver: 1
    username: 1
    workerId: 1

# Admin users - needs to update if group updates
Meteor.publish "tsAdminUsers", (groupId) ->
  return unless @userId and Meteor.users.findOne(@userId).admin

  return Meteor.users.find {}, userFindOptions

# Helper publish function to get users for experiments that have ended.
# Necessary to watch completed experiments.
Meteor.publish "tsGroupUsers", (groupId) ->
  sub = this
  exp = Experiments.findOne(groupId)
  return unless exp

  # This won't update if users changes, but it shouldn't after an experiment is completed
  # TODO Just return everything here; we don't know what the app subscription was using
  subHandle = Meteor.users.find({ _id: $in: exp.users}, userFindOptions).observeChanges
    added: (id, fields) ->
      sub.added "users", id, fields
    changed: (id, fields) ->
      sub.changed "users", id, fields
    removed: (id) ->
      sub.removed "users", id

  sub.ready()
  sub.onStop -> subHandle.stop()<commit_msg>don't publish status for users in completed experiments<commit_after># Server admin code

# Only admin gets server facts
Facts.setUserIdFilter (userId) -> Meteor.users.findOne(userId)?.admin

Meteor.publish "tsAdmin", ->
  return unless @userId and Meteor.users.findOne(@userId).admin

  # Publish all admin data
  return [
    Batches.find(),
    Treatments.find(),
    Experiments.find(),
    # Grouping.find(),
    Assignments.find(),
    Workers.find(),
    LobbyStatus.find()
  ]

userFindOptions =
  fields:
    status: 1
    turkserver: 1
    username: 1
    workerId: 1

# Admin users - needs to update if group updates
Meteor.publish "tsAdminUsers", (groupId) ->
  return unless @userId and Meteor.users.findOne(@userId).admin

  return Meteor.users.find {}, userFindOptions

# Don't return status here as the user is not connected to this experiment
offlineFindOptions =
  fields:
    turkserver: 1
    username: 1
    workerId: 1

# Helper publish function to get users for experiments that have ended.
# Necessary to watch completed experiments.
Meteor.publish "tsGroupUsers", (groupId) ->
  sub = this
  exp = Experiments.findOne(groupId)
  return unless exp

  # This won't update if users changes, but it shouldn't after an experiment is completed
  # TODO Just return everything here; we don't know what the app subscription was using
  subHandle = Meteor.users.find({ _id: $in: exp.users}, offlineFindOptions).observeChanges
    added: (id, fields) ->
      sub.added "users", id, fields
    changed: (id, fields) ->
      sub.changed "users", id, fields
    removed: (id) ->
      sub.removed "users", id

  sub.ready()
  sub.onStop -> subHandle.stop()
{'fraction_non_alphanumeric': 0.10925165772023998, 'fraction_numerical': 0.0034733185980423114, 'mean_word_length': 3.5517241379310347, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959083', 'n_tokens_mistral': 986, 'n_tokens_neox': 949, 'n_words': 313}