scripts/stats.py
changeset 2062 9c739b37c367
parent 2061 c7ba473b091e
child 2063 319d9f05955a
equal deleted inserted replaced
2061:c7ba473b091e 2062:9c739b37c367
    86     return dict(entities)
    86     return dict(entities)
    87 
    87 
    88   return wrapped
    88   return wrapped
    89 
    89 
    90 
    90 
    91 def getProps():
    91 def getProps(last=None):
    92   """Returns all proposals as a list of dictionaries.
    92   """Returns all proposals as a list of dictionaries.
    93   """
    93   """
    94 
    94 
    95   key_order = [
    95   key_order = [
    96       'link_id', 'scope_path', 'title', 'abstract', 'content',
    96       'link_id', 'scope_path', 'title', 'abstract', 'content',
    97       'additional_info', 'mentor', 'possible_mentors', 'score',
    97       'additional_info', '_mentor', 'possible_mentors', 'score',
    98       'status', 'org']
    98       'status', '_org', 'created_on', 'last_modified_on']
    99 
    99 
   100   from soc.models.student_proposal import StudentProposal
   100   from soc.models.student_proposal import StudentProposal
   101 
   101 
   102   gen = lambda: StudentProposal.all()
   102   gen = lambda: StudentProposal.all()
   103   it = interactive.deepFetch(gen)
   103 
   104 
   104   it = dateFetch(gen, last)
   105   proposals = [i.toDict(key_order) for i in it]
   105 
   106 
   106   proposals = [(i.key().name(), i.toDict(key_order)) for i in it]
   107   return proposals
   107 
       
   108   return dict(proposals)
   108 
   109 
   109 
   110 
   110 def orgStats(target):
   111 def orgStats(target):
   111   """Retrieves org stats.
   112   """Retrieves org stats.
   112   """
   113   """
   113 
   114 
   114   from soc.logic import dicts
   115   from soc.logic import dicts
   115 
   116 
   116   target = [addKey(i, 'org') for i in target]
   117   grouped = dicts.groupby(target.values(), '_org')
   117   grouped = dicts.groupby(target, 'org_key')
       
   118   popularity = [(k, len(v)) for k,v in grouped.iteritems()]
   118   popularity = [(k, len(v)) for k,v in grouped.iteritems()]
   119 
   119 
   120   return grouped, dict(popularity)
   120   return grouped, dict(popularity)
   121 
   121 
   122 
   122