scripts/stats.py
changeset 2592 040359ccd20b
parent 2345 f78caf12f32d
child 2642 1bb33f56a3f4
equal deleted inserted replaced
2591:6c57c482f913 2592:040359ccd20b
    82 
    82 
    83   def wrapped():
    83   def wrapped():
    84     gen = lambda: model.all()
    84     gen = lambda: model.all()
    85     it = interactive.deepFetch(gen)
    85     it = interactive.deepFetch(gen)
    86 
    86 
    87     entities = [(i.key().name(), i) for i in it]
    87     entities = [(i.key().id_or_name(), i) for i in it]
    88     return dict(entities)
    88     return dict(entities)
    89 
    89 
    90   return wrapped
    90   return wrapped
    91 
    91 
    92 
    92 
   354 
   354 
   355     print "deleted %d entities" % count
   355     print "deleted %d entities" % count
   356 
   356 
   357   print "Done"
   357   print "Done"
   358 
   358 
       
   359 
   359 def loadPickle(name):
   360 def loadPickle(name):
   360   """Loads a pickle.
   361   """Loads a pickle.
   361   """
   362   """
   362 
   363 
   363   f = open(name + '.dat')
   364   f = open(name + '.dat')
   370 
   371 
   371   f = open("%s.dat" % name, 'w')
   372   f = open("%s.dat" % name, 'w')
   372   cPickle.dump(target, f)
   373   cPickle.dump(target, f)
   373 
   374 
   374 
   375 
       
   376 def addOrganizationToSurveyRecords(survey_record_model):
       
   377   """Set Organization in SurveyRecords entities of a given model.
       
   378   """
       
   379   
       
   380   print "Fetching %s." % survey_record_model.__name__
       
   381   getSurveyRecord = getEntities(survey_record_model)
       
   382   survey_records = getSurveyRecord()
       
   383   survey_records_amount = len(survey_records)
       
   384   print "Fetched %d %s." % (survey_records_amount, survey_record_model.__name__)
       
   385   
       
   386   counter = 0
       
   387   
       
   388   for key in survey_records.keys():
       
   389     survey_records[key].org = survey_records[key].project.scope
       
   390     survey_records[key].put()
       
   391     
       
   392     counter += 1
       
   393     print str(counter) + '/' + str(survey_records_amount) + ' ' + str(key)
       
   394     
       
   395   print "Organization added to all %s." % survey_record_model.__name__
       
   396 
       
   397 
       
   398 def setOrganizationInSurveyRecords():
       
   399   """Sets Organization property in ProjectSurveyRecords 
       
   400   and GradingProjectSurveyRecords entities.
       
   401   """
       
   402   from soc.models.project_survey_record import ProjectSurveyRecord
       
   403   from soc.models.grading_project_survey_record \
       
   404       import GradingProjectSurveyRecord
       
   405   
       
   406   addOrganizationToSurveyRecords(ProjectSurveyRecord)
       
   407   addOrganizationToSurveyRecords(GradingProjectSurveyRecord)
       
   408 
       
   409 
   375 def acceptedStudentsCSVExport(csv_filename, program_key_name):
   410 def acceptedStudentsCSVExport(csv_filename, program_key_name):
   376   """Exports all accepted Students for particular program into CSV file.
   411   """Exports all accepted Students for particular program into CSV file.
   377   """
   412   """
   378   # TODO(Pawel.Solyga): Add additional Program parameter to this method 
   413   # TODO(Pawel.Solyga): Add additional Program parameter to this method 
   379   # so we export students from different programs
   414   # so we export students from different programs
   380   # TODO(Pawel.SOlyga): Make it universal so it works with both GHOP 
   415   # TODO(Pawel.Solyga): Make it universal so it works with both GHOP 
   381   # and GSoC programs
   416   # and GSoC programs
   382   
   417   
   383   from soc.models.student_project import StudentProject
   418   from soc.models.student_project import StudentProject
   384   from soc.models.student import Student
   419   from soc.models.student import Student
   385   from soc.models.organization import Organization
   420   from soc.models.organization import Organization
   489       'getMentors': getEntities(Mentor),
   524       'getMentors': getEntities(Mentor),
   490       'getOrgAdmins': getEntities(OrgAdmin),
   525       'getOrgAdmins': getEntities(OrgAdmin),
   491       'getStudentProjects': getEntities(StudentProject),
   526       'getStudentProjects': getEntities(StudentProject),
   492       'getProps': getProps,
   527       'getProps': getProps,
   493       'countStudentsWithProposals': countStudentsWithProposals,
   528       'countStudentsWithProposals': countStudentsWithProposals,
       
   529       'setOrganizationInSurveyRecords': setOrganizationInSurveyRecords,
   494       'convertProposals': convertProposals,
   530       'convertProposals': convertProposals,
   495       'addFollower': addFollower,
   531       'addFollower': addFollower,
   496       'Organization': Organization,
   532       'Organization': Organization,
   497       'Job': Job,
   533       'Job': Job,
   498       'User': User,
   534       'User': User,