scripts/stats.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 30 Jul 2009 10:49:19 +0200
changeset 2691 f8e0a007d99b
parent 2642 1bb33f56a3f4
child 2769 279d26439495
permissions -rwxr-xr-x
Pre-storing the information for setStudentProjectSurveyInfo. This is a rename from getStudentProjectSurveyInfo because it now sets the info directly in the list content. This is done because Django queries the wrapper method every time the info is called in the template.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Starts an interactive shell with statistic helpers.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
]
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
import cPickle
2079
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
    26
import datetime
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
import operator
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
import sys
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
    29
import time
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
import interactive
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
2058
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    34
def dateFetch(queryGen, last=None, batchSize=100):
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    35
  """Iterator that yields an entity in batches.
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    36
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    37
  Args:
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    38
    queryGen: should return a Query object
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    39
    last: used to .filter() for last_modified_on
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    40
    batchSize: how many entities to retrieve in one datastore call
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    41
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    42
  Retrieved from http://tinyurl.com/d887ll (AppEngine cookbook).
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    43
  """
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    44
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    45
  from google.appengine.ext import db
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    46
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    47
   # AppEngine will not fetch more than 1000 results
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    48
  batchSize = min(batchSize,1000)
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    49
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    50
  query = None
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    51
  done = False
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    52
  count = 0
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    53
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    54
  while not done:
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    55
    print count
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    56
    query = queryGen()
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    57
    query.order('last_modified_on')
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    58
    if last:
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    59
      query.filter("last_modified_on > ", last)
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    60
    results = query.fetch(batchSize)
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    61
    for result in results:
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    62
      count += 1
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    63
      yield result
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    64
    if batchSize > len(results):
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    65
      done = True
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    66
    else:
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    67
      last = results[-1].last_modified_on
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    68
773b13d86309 Add dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2052
diff changeset
    69
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
def addKey(target, fieldname):
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    71
  """Adds the key of the specified field.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    72
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    74
  result = target.copy()
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    75
  result['%s_key' % fieldname] = target[fieldname].key().name()
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    76
  return result
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    79
def getEntities(model):
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    80
  """Returns all users as dictionary.
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
    81
  """
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
    82
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    83
  def wrapped():
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    84
    gen = lambda: model.all()
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    85
    it = interactive.deepFetch(gen)
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
    86
2592
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
    87
    entities = [(i.key().id_or_name(), i) for i in it]
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    88
    return dict(entities)
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
    89
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
    90
  return wrapped
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
    91
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
    92
2062
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
    93
def getProps(last=None):
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
  """Returns all proposals as a list of dictionaries.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
  key_order = [
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
      'link_id', 'scope_path', 'title', 'abstract', 'content',
2062
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
    99
      'additional_info', '_mentor', 'possible_mentors', 'score',
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
   100
      'status', '_org', 'created_on', 'last_modified_on']
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
  from soc.models.student_proposal import StudentProposal
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
  gen = lambda: StudentProposal.all()
2062
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
   105
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
   106
  it = dateFetch(gen, last)
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
2062
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
   108
  proposals = [(i.key().name(), i.toDict(key_order)) for i in it]
2079
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   109
  if proposals:
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   110
    last = i.last_modified_on # last modified entity
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   111
  else:
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   112
    last = datetime.datetime.now()
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
2079
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   114
  return dict(proposals), last
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
2079
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   117
def orgStats(target, orgs):
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
  """Retrieves org stats.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
  from soc.logic import dicts
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
2079
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   123
  orgs = [(v.key(), v) for k, v in orgs.iteritems()]
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   124
  orgs = dict(orgs)
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   125
2062
9c739b37c367 Refactor getProps to use dateFetch
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2061
diff changeset
   126
  grouped = dicts.groupby(target.values(), '_org')
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
2079
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   128
  grouped = [(orgs[k], v) for k, v in grouped.iteritems()]
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   129
  popularity = [(k.link_id, len(v)) for k, v in grouped]
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   130
086c60aad3d8 Minor tweaks to orgStats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2063
diff changeset
   131
  return dict(grouped), dict(popularity)
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   134
def countStudentsWithProposals():
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   135
  """Retrieves number of Students who have submitted at least one Student Proposal.
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   136
  """
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   137
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   138
  proposals = getStudentProposals()
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   139
  students = {}
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   140
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   141
  for proposal_key in proposals.keys():
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   142
    students[proposals[proposal_key].scope_path] = True
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   143
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   144
  return len(students)
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   145
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   146
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   147
def printPopularity(popularity):
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   148
  """Prints the popularity for the specified proposals.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   151
  g = operator.itemgetter(1)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   152
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   153
  for item in sorted(popularity.iteritems(), key=g, reverse=True):
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   154
    print "%s: %d" % item
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   155
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   156
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   157
def saveValues(values, saver):
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
  """Saves the specified popularities.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   161
  import logging
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   162
  from google.appengine.ext import db
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   163
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   164
  from soc.models.organization import Organization
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   165
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   166
  def txn(key, value):
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   167
    org = Organization.get_by_key_name(key)
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   168
    saver(org, value)
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   169
    org.put()
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   170
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   171
  for key, value in sorted(values.iteritems()):
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   172
    print key
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   173
    db.run_in_transaction_custom_retries(10, txn, key, value)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   174
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   175
  print "done"
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
2090
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   178
def addFollower(follower, proposals, add_public=True, add_private=True):
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   179
  """Adds a user as follower to the specified proposals.
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   180
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   181
  Args:
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   182
    follower: the User to add as follower
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   183
    proposals: a list with the StudnetProposals that should be subscribed to
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   184
    add_public: whether the user is subscribed to public updates
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   185
    add_private: whether the user should be subscribed to private updates
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   186
  """
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   187
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   188
  from soc.models.review_follower import ReviewFollower
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   189
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   190
  result = []
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   191
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   192
  for i in proposals:
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   193
     properties = {
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   194
       'user': follower,
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   195
       'link_id': follower.link_id,
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   196
       'scope': i,
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   197
       'scope_path': i.key().name(),
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   198
       'key_name': '%s/%s' % (i.key().name(), follower.link_id),
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   199
       'subscribed_public': add_public,
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   200
       'subscribed_private': add_private,
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   201
     }
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   202
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   203
     entity = ReviewFollower(**properties)
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   204
     result.append(entity)
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   205
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   206
  return result
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   207
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   208
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   209
def convertProposals(org):
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   210
  """Convert all proposals for the specified organization.
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   211
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   212
  Args:
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   213
    org: the organization for which all proposals will be converted
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   214
  """
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   215
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   216
  from soc.logic.models.student_proposal import logic as proposal_logic
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   217
  from soc.logic.models.student_project import logic as project_logic
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   219
  proposals = proposal_logic.getProposalsToBeAcceptedForOrg(org)
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   220
2262
5b0576dcc107 Set batch size to 10
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2245
diff changeset
   221
  print "accepting %d proposals, with %d slots" % (len(proposals), org.slots)
5b0576dcc107 Set batch size to 10
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2245
diff changeset
   222
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   223
  for proposal in proposals:
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   224
    fields = {
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   225
        'link_id': 't%i' % (int(time.time()*100)),
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   226
        'scope_path': proposal.org.key().id_or_name(),
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   227
        'scope': proposal.org,
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   228
        'program': proposal.program,
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   229
        'student': proposal.scope,
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   230
        'title': proposal.title,
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   231
        'abstract': proposal.abstract,
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   232
        'mentor': proposal.mentor,
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   233
        }
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   234
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   235
    project = project_logic.updateOrCreateFromFields(fields, silent=True)
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   236
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   237
    fields = {
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   238
        'status':'accepted',
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   239
        }
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   240
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   241
    proposal_logic.updateEntityProperties(proposal, fields, silent=True)
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   242
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   243
  fields = {
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   244
      'status': ['new', 'pending'],
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   245
      'org': org,
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   246
      }
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   247
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   248
  querygen = lambda: proposal_logic.getQueryForFields(fields)
2262
5b0576dcc107 Set batch size to 10
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2245
diff changeset
   249
  proposals = [i for i in interactive.deepFetch(querygen, batchSize=10)]
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   250
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   251
  print "rejecting %d proposals" % len(proposals)
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   252
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   253
  fields = {
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   254
      'status': 'rejected',
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   255
      }
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   256
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   257
  for proposal in proposals:
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   258
    proposal_logic.updateEntityProperties(proposal, fields, silent=True)
2218
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   259
84b0ce492cf5 Add a script to convert proposals.
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2151
diff changeset
   260
2234
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   261
def startSpam():
2270
543f11d7b0e4 Fix missing dot in stats.py docstring.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2265
diff changeset
   262
  """Creates the job that is responsible for sending mails.
2265
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   263
  """
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   264
2234
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   265
  from soc.logic.models.job import logic as job_logic
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   266
  from soc.logic.models.priority_group import logic as priority_logic
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   267
  from soc.logic.models.program import logic as program_logic
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   268
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   269
  program_entity = program_logic.getFromKeyName('google/gsoc2009')
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   270
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   271
  priority_group = priority_logic.getGroup(priority_logic.EMAIL)
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   272
  job_fields = {
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   273
      'priority_group': priority_group,
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   274
      'task_name': 'setupStudentProposalMailing',
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   275
      'key_data': [program_entity.key()]}
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   276
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   277
  job_logic.updateOrCreateFromFields(job_fields)
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   278
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   279
2345
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   280
def startUniqueUserIdConversion():
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   281
  """Creates the job that is responsible for adding unique user ids.
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   282
  """
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   283
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   284
  from soc.logic.models.job import logic as job_logic
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   285
  from soc.logic.models.priority_group import logic as priority_logic
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   286
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   287
  priority_group = priority_logic.getGroup(priority_logic.CONVERT)
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   288
  job_fields = {
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   289
      'priority_group': priority_group,
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   290
      'task_name': 'setupUniqueUserIdAdder'}
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   291
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   292
  job_logic.updateOrCreateFromFields(job_fields)
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   293
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   294
2265
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   295
def reviveJobs(amount):
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   296
  """Sets jobs that are stuck in 'aborted' to waiting.
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   297
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   298
  Args:
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   299
    amount: the amount of jobs to revive
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   300
  """
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   301
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   302
  from soc.models.job import Job
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   303
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   304
  query = Job.all().filter('status', 'aborted')
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   305
  jobs = query.fetch(amount)
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   306
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   307
  if not jobs:
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   308
    print "no dead jobs"
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   309
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   310
  for job in jobs:
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   311
     job.status = 'waiting'
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   312
     job.put()
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   313
     print "restarted %d" % job.key().id()
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   314
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   315
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   316
def deidleJobs(amount):
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   317
  """Sets jobs that are stuck in 'started' to waiting.
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   318
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   319
  Args:
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   320
    amount: the amount of jobs to deidle
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   321
  """
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   322
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   323
  from soc.models.job import Job
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   324
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   325
  query = Job.all().filter('status', 'started')
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   326
  jobs = query.fetch(amount)
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   327
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   328
  if not jobs:
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   329
    print "no idle jobs"
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   330
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   331
  for job in jobs:
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   332
     job.status = 'waiting'
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   333
     job.put()
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   334
     print "restarted %d" % job.key().id()
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   335
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   336
2245
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   337
def deleteEntities(model, step_size=25):
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   338
  """Deletes all entities of the specified type
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   339
  """
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   340
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   341
  print "Deleting..."
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   342
  count = 0
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   343
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   344
  while True:
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   345
    entities = model.all().fetch(step_size)
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   346
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   347
    if not entities:
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   348
      break
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   349
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   350
    for entity in entities:
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   351
      entity.delete()
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   352
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   353
    count += step_size
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   354
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   355
    print "deleted %d entities" % count
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   356
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   357
  print "Done"
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   358
2592
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   359
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   360
def loadPickle(name):
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   361
  """Loads a pickle.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   362
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   363
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   364
  f = open(name + '.dat')
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   365
  return cPickle.load(f)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   366
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   367
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   368
def dumpPickle(target, name):
2061
c7ba473b091e Style fixes
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2060
diff changeset
   369
  """Dumps a pickle.
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   370
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   371
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   372
  f = open("%s.dat" % name, 'w')
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   373
  cPickle.dump(target, f)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   374
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   375
2592
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   376
def addOrganizationToSurveyRecords(survey_record_model):
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   377
  """Set Organization in SurveyRecords entities of a given model.
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   378
  """
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   379
  
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   380
  print "Fetching %s." % survey_record_model.__name__
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   381
  getSurveyRecord = getEntities(survey_record_model)
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   382
  survey_records = getSurveyRecord()
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   383
  survey_records_amount = len(survey_records)
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   384
  print "Fetched %d %s." % (survey_records_amount, survey_record_model.__name__)
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   385
  
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   386
  counter = 0
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   387
  
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   388
  for key in survey_records.keys():
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   389
    survey_records[key].org = survey_records[key].project.scope
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   390
    survey_records[key].put()
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   391
    
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   392
    counter += 1
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   393
    print str(counter) + '/' + str(survey_records_amount) + ' ' + str(key)
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   394
    
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   395
  print "Organization added to all %s." % survey_record_model.__name__
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   396
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   397
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   398
def setOrganizationInSurveyRecords():
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   399
  """Sets Organization property in ProjectSurveyRecords 
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   400
  and GradingProjectSurveyRecords entities.
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   401
  """
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   402
  from soc.models.project_survey_record import ProjectSurveyRecord
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   403
  from soc.models.grading_project_survey_record \
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   404
      import GradingProjectSurveyRecord
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   405
  
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   406
  addOrganizationToSurveyRecords(ProjectSurveyRecord)
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   407
  addOrganizationToSurveyRecords(GradingProjectSurveyRecord)
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   408
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   409
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   410
def acceptedStudentsCSVExport(csv_filename, program_key_name):
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   411
  """Exports all accepted Students for particular program into CSV file.
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   412
  """
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   413
  # TODO(Pawel.Solyga): Add additional Program parameter to this method 
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   414
  # so we export students from different programs
2592
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   415
  # TODO(Pawel.Solyga): Make it universal so it works with both GHOP 
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   416
  # and GSoC programs
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   417
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   418
  from soc.models.student_project import StudentProject
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   419
  from soc.models.student import Student
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   420
  from soc.models.organization import Organization
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   421
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   422
  getStudentProjects = getEntities(StudentProject)
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   423
  student_projects = getStudentProjects()
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   424
  student_projects_amount = len(student_projects)
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   425
  print "Fetched %d Student Projects." % student_projects_amount
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   426
  print "Fetching Student entities from Student Projects."
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   427
  accepted_students = {}
2642
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   428
  student_extra_data = {}
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   429
  counter = 0
2642
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   430
  
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   431
  for sp_key in student_projects.keys():
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   432
    key = student_projects[sp_key].student.key().name()
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   433
    accepted_students[key] = student_projects[sp_key].student
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   434
    org_name = student_projects[sp_key].scope.name
2642
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   435
    student_extra_data[key] = {}
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   436
    student_extra_data[key]['organization'] = org_name
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   437
    student_extra_data[key]['project_status'] = student_projects[sp_key].status
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   438
    counter += 1
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   439
    print str(counter) + '/' + str(student_projects_amount) + ' ' + key + ' (' + org_name + ')'
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   440
  print "All Student entities fetched."
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   441
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   442
  students_key_order = ['link_id', 'given_name', 'surname', 
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   443
      'name_on_documents', 'email', 'res_street', 'res_city', 'res_state',
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   444
      'res_country', 'res_postalcode', 'phone', 'ship_street', 'ship_city',
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   445
      'ship_state', 'ship_country', 'ship_postalcode', 'birth_date', 
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   446
      'tshirt_size', 'tshirt_style', 'name', 'school_name', 'school_country',
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   447
      'major', 'degree']
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   448
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   449
  print "Preparing Students data for export."
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   450
  students_data = [accepted_students[i].toDict(students_key_order) for i in accepted_students.keys()]
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   451
  
2642
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   452
  print "Adding organization name and project status to Students data."
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   453
  for student in students_data:
2642
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   454
    extra_data = student_extra_data[program_key_name + '/' + student['link_id']]
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   455
    student['organization'] = extra_data['organization']
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   456
    student['project_status'] = extra_data['project_status']
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   457
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   458
  students_key_order.append('organization')
2642
1bb33f56a3f4 Add new project status column to accepted students csv export.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2592
diff changeset
   459
  students_key_order.append('project_status')
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   460
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   461
  saveDataToCSV(csv_filename, students_data, students_key_order)
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   462
  print "Accepted Students exported to %s file." % csv_filename
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   463
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   464
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   465
def saveDataToCSV(csv_filename, data, key_order):
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   466
  """Saves data in order into CSV file.
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   467
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   468
  This is a helper function used with acceptedStudentsCSVExport().
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   469
  """
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   470
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   471
  import csv
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   472
  import StringIO
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   473
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   474
  from soc.logic import dicts
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   475
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   476
  file_handler = StringIO.StringIO()
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   477
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   478
  writer = csv.DictWriter(file_handler, key_order, dialect='excel')
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   479
  writer.writerow(dicts.identity(key_order))
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   480
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   481
  # encode the data to UTF-8 to ensure compatibiliy
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   482
  for row_dict in data:
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   483
    for key in row_dict.keys():
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   484
      value = row_dict[key]
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   485
      if isinstance(value, basestring):
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   486
        row_dict[key] = value.encode("utf-8")
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   487
      else:
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   488
        row_dict[key] = str(value)
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   489
    writer.writerow(row_dict)
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   490
  
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   491
  csv_data = file_handler.getvalue()
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   492
  csv_file = open(csv_filename, 'w')
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   493
  csv_file.write(csv_data)
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   494
  csv_file.close()
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   495
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   496
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   497
def main(args):
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   498
  """Main routine.
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   499
  """
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   500
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   501
  interactive.setup()
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   502
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   503
  from soc.models.organization import Organization
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   504
  from soc.models.user import User
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   505
  from soc.models.student import Student
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   506
  from soc.models.mentor import Mentor
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   507
  from soc.models.org_admin import OrgAdmin
2245
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   508
  from soc.models.job import Job
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   509
  from soc.models.student_proposal import StudentProposal
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   510
  from soc.models.student_project import StudentProject
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   511
2151
f58515b0b2e1 Style fix in function names in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2148
diff changeset
   512
  def slotSaver(org, value):
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   513
    org.slots = value
2151
f58515b0b2e1 Style fix in function names in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2148
diff changeset
   514
  def popSaver(org, value):
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   515
    org.nr_applications = value
2151
f58515b0b2e1 Style fix in function names in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2148
diff changeset
   516
  def rawSaver(org, value):
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   517
    org.slots_calculated = value
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   518
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   519
  context = {
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   520
      'load': loadPickle,
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   521
      'dump': dumpPickle,
2052
a723a2509e21 Add some additional functions for stats to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2047
diff changeset
   522
      'orgStats': orgStats,
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   523
      'printPopularity': printPopularity,
2148
0345046ed7a5 Make it possible to save any value with saveValues
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2090
diff changeset
   524
      'saveValues': saveValues,
2245
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   525
      'getEntities': getEntities,
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   526
      'deleteEntities': deleteEntities,
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   527
      'getOrgs': getEntities(Organization),
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   528
      'getUsers': getEntities(User),
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   529
      'getStudents': getEntities(Student),
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   530
      'getMentors': getEntities(Mentor),
2063
319d9f05955a Fixed a typo in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2062
diff changeset
   531
      'getOrgAdmins': getEntities(OrgAdmin),
2274
1885cda38bb7 Add getStudentsProjects to context in stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2270
diff changeset
   532
      'getStudentProjects': getEntities(StudentProject),
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   533
      'getProps': getProps,
2060
45029d87be4a Add and use a getEntities method
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2058
diff changeset
   534
      'countStudentsWithProposals': countStudentsWithProposals,
2592
040359ccd20b Add setOrganizationInSurveyRecords function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2345
diff changeset
   535
      'setOrganizationInSurveyRecords': setOrganizationInSurveyRecords,
2222
a91d55e9c9cd Various improvements to convertProposals
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2218
diff changeset
   536
      'convertProposals': convertProposals,
2090
a07ff1e1bd1f Add a script to subscribe someone to all updates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2089
diff changeset
   537
      'addFollower': addFollower,
2089
b8a9691da6e7 Add the entities to the context too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2079
diff changeset
   538
      'Organization': Organization,
2245
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   539
      'Job': Job,
2089
b8a9691da6e7 Add the entities to the context too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2079
diff changeset
   540
      'User': User,
b8a9691da6e7 Add the entities to the context too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2079
diff changeset
   541
      'Student': Student,
b8a9691da6e7 Add the entities to the context too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2079
diff changeset
   542
      'Mentor': Mentor,
b8a9691da6e7 Add the entities to the context too
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2079
diff changeset
   543
      'OrgAdmin': OrgAdmin,
2245
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   544
      'StudentProject': StudentProject,
46e490606f3d Added deleteEntities methods to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2234
diff changeset
   545
      'StudentProposal': StudentProposal,
2151
f58515b0b2e1 Style fix in function names in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2148
diff changeset
   546
      'slotSaver': slotSaver,
f58515b0b2e1 Style fix in function names in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2148
diff changeset
   547
      'popSaver': popSaver,
f58515b0b2e1 Style fix in function names in stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2148
diff changeset
   548
      'rawSaver': rawSaver,
2234
69539a5ca63a Add a startSpam method to stats
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2222
diff changeset
   549
      'startSpam': startSpam,
2265
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   550
      'reviveJobs': reviveJobs,
bfaadb6ab559 Added reviveJobs and deidleJobs to stats.py
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2262
diff changeset
   551
      'deidleJobs': deidleJobs,
2322
98fe07a5542f Add acceptedStudentsCSVExport function to stats.py script.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2274
diff changeset
   552
      'acceptedStudentsCSVExport': acceptedStudentsCSVExport,
2345
f78caf12f32d Add helper functions, model update and jobs for unique user ids.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2322
diff changeset
   553
      'startUniqueUserIdConversion': startUniqueUserIdConversion,
2047
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   554
  }
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   555
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   556
  interactive.remote(args, context)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   557
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   558
if __name__ == '__main__':
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   559
  if len(sys.argv) < 2:
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   560
    print "Usage: %s app_id [host]" % (sys.argv[0],)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   561
    sys.exit(1)
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   562
7e9656691c8e Added a stats module to scripts
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   563
  main(sys.argv[1:])