Exemple #1
0
 def handle(self, *args, **options):
   for c in Candidate.objects.all().prefetch_related('offer'):
     s = ranked_offers(c)
     if s == '':
       continue # no offers
     offers = s.split()
     for offer in offers:
       if offer[0] == '(':
         continue # promoted
       elif offer[0] == 'P':
         # physphil offer
         course_type = Candidate.COURSE_PHYSPHIL_ONLY
       elif offer[0] == '3':
         # physics offer
         course_type = Candidate.COURSE_THREEYEAR
       elif offer[0] == '4':
         course_type = Candidate.COURSE_FOURYEAR
       else:
         self.stderr.write("Unrecognized offer string {0}".format(offer))
         break
       try:
         col = College.objects.get(adss_code=offer[2:5])
       except ObjectDoesNotExist:
         self.stderr.write("College code {0} unrecognized".format(offer[2:5]))
         continue
       try:
         offobj = Offer.objects.get(college=col, candidate=c, course_type=course_type)
       except ObjectDoesNotExist:
         self.stderr.write("Offer not found:  {0}[{1}] {2}".format(course_type, col.adss_code, c.ucas_id))
         continue
       except:
         self.stderr.write("Error locating offer:  {0}[{1}] {2}".format(course_type, col.adss_code, c.ucas_id))
         continue
       offobj.final = True
       offobj.save()
       self.stdout.write("   offer string:  {0}".format(offers))
       self.stdout.write("Offer finalized:  {0}[{1}] {2}".format(course_type, col.adss_code, c.info.surname))
       break # only process the first valid offer found
Exemple #2
0
  def make_json(self, candidate, overallstate, statephase):
    student = candidate.info
    name = student.surname + ", " + student.forenames
    if len(student.preferred_name) > 0:
      name = name + " (" + student.preferred_name + ")"

    pm = candidate.pat_maths
    pp = candidate.pat_physics

    if overallstate == OverallState.SHORTLIST and statephase == 0:
      int1 = 0
      int2 = 0
      int3 = 0
      int4 = 0
      int5 = 0
    else:
      int1 = candidate.interview1
      int2 = candidate.interview2
      int3 = candidate.interview3
      int4 = candidate.interview4
      int5 = candidate.interview5
    js = pm + pp + 3*(int1 + int2) + 4*int3

    j = { \
      "pk": candidate.pk, \
      "status": "", \
      "pm": "{}".format(pm), \
      "pp": "{}".format(pp), \
      "pt": "{}".format(pm+pp), \
      "i1": "{}".format(int1) if int1 > 0 else '', \
      "i2": "{}".format(int2) if int2 > 0 else '', \
      "i3": "{}".format(int3) if int3 > 0 else '', \
      "i4": "{}".format(int4) if int4 > 0 else '', \
      "i5": "{}".format(int5) if int5 > 0 else '', \
      "js": "{}".format(js) if js > 0 else '', \
      "rank": "{}".format(candidate.stored_rank), \
      "name": name, \
      "g": student.gender, \
      "y": student.matriculation_year(), \
      "scht": "U", \
      "course": candidate.course_type, \
      "sdm": "0", \
      "pred": "None", \
      "obt": "None", \
      "cgcse": student.cgcse_score, \
      "care": render_boolean(student.declared_in_care), \
      "gcse": render_boolean(student.gcse), \
      "alev": render_boolean(student.a_level), \
      "offa": render_boolean(student.offa), \
      "offa1": render_boolean(student.offa1), \
      "acorn": render_boolean(student.acorn), \
      "polar": render_boolean(student.polar), \
      "access": render_boolean(student.access), \
      "ovf": render_boolean(student.overall), \
      "c1" : candidate.college1.adss_code if candidate.college1 else '', \
      "c2" : candidate.college2.adss_code if candidate.college2 else '', \
      "c3" : candidate.college3.adss_code if candidate.college3 else '', \
      "c4" : candidate.college4.adss_code if candidate.college4 else '', \
      "c5" : candidate.college5.adss_code if candidate.college5 else '', \
      "c6" : candidate.college6.adss_code if candidate.college6 else '' \
      }

    # add details
    status = ranked_offers(candidate)
    if status == '':
      status = candidate.state
      if status == Candidate.STATE_APPLIED:
        status = ''
      elif status == Candidate.STATE_SUMMONED:
        status = '+' if overallstate == OverallState.LONGLIST else ''
      elif status == Candidate.STATE_DESUMMONED:
        status = 'Desum'
      if candidate.rescued:
        status = status + 'R'
      if candidate.reserved:
        status = status + 'K' # S (for keep)
    j['status'] = status
    apd = {
      'id': candidate.ucas_id,
      'email': student.email,
      'bd': student.birth_date.strftime('%d/%m/%y'),
      # '{0}y{1}m'.format(ap.age.years, ap.age.months),
      'ovs': "Overseas" if student.overseas else "EU" if student.eu else "Home",
      'spec': render_boolean(student.has_special_needs),
      'dcode': student.disability_code,
      'dis': student.disability_notes,
      'tel': student.telephone,
      'mob': student.mobile
    }
    j["det"] = apd

    # school details
    usepre = False
    usepost = False
    schd = []
    for sch in student.schools.all():
      sdet = {
        's': sch.start_date,
        'b': render_monthyear(sch.start_date),
        'e': render_monthyear(sch.end_date),
        'id': sch.ucas_school_id,
        'det': sch.school_details
        }
      if sch.ucas_school_id == student.gcse_school_id:
        sdet['pre'] = student.school_pre16_performance
        sdet['gold'] = student.school_pre16_gold_performance
        usepre = True
      if sch.ucas_school_id == student.a_level_school_id:
        sdet['post'] = student.school_post16_performance
        j['scht'] = sch.school_type.physics_type
        usepost = True
      schd.append(sdet)
    #self.stdout.write("School list for {}:  {}".format(name, schd))

    # sort first by start date, and then school id (school details not reliably well formed)
    # (this depends on python sort order being stable, which is true after python 2.2)
    schd.sort(key=lambda a: a['id'])
    schd.sort(key=lambda a: a['s'], reverse=True)
    for sch in schd:
      del sch['s']

    if not usepre:
      self.stdout.write('Pre16 school id {0} not found for student {1}'.format(
          student.gcse_school_id,name))
      schd.append({'b':'','e':'','id':student.gcse_school_id,'det':'',
                   'pre':student.school_pre16_performance,
                   'gold':student.school_pre16_gold_performance})
    if not usepost:
      self.stdout.write('Post16 school id {0} not found for student {1}'.format(
          student.a_level_school_id,name))
      schd.append({'b':'','e':'','id':student.a_level_school_id,'det':'',
                   'post':student.school_post16_performance})
    j["detsch"] = schd

    # student qualifications
    oqs = []
    pqs = []
    for q in student.qualifications.all():
      qtype = q.qualification_type.short_name if q.qualification_type.short_name else q.qualification_type.name
      qtype = qtype.replace('International Baccalaureate', 'IB')
      units = q.unit_grades.strip().replace('&#10;', '<br>')

      sq = {
        's': q.qualification_date,
        'd': render_monthyear(q.qualification_date),
        'b': q.award_body,
        't': qtype,
        'r': q.result,
        'ti': q.title,
        'g': q.grade,
        'u': units
        }
      if q.predicted_grade or q.result == 'Incomplete':
        sq['r'] = sq['g']
        if sq['r'] == 'Incomplete':
          sq['r'] = '?'
        pqs.append(sq)
      else:
        oqs.append(sq)

    sd = 0.0
    # sort by start date first, then title
    oqs.sort(key=lambda a: a['ti'])
    oqs.sort(key=lambda a: a['s'])
    oqual = {}
    for q in oqs:
      self.add_qual_summary(oqual, q)
      sd = max(sd, self.calc_sd(q, False))
      del q['s']
    oqs.reverse() # to list most recent first

    pqs.sort(key=lambda a: a['ti'])
    pqs.sort(key=lambda a: a['s'])
    pqual = {}
    for q in pqs:
      self.add_qual_summary(pqual, q)
      sd = max(sd, self.calc_sd(q, True))
      del q['s']
    pqs.reverse()

    j["detobt"] = oqs
    j["detpred"] = pqs
    j["sdm"] = "{}".format(sd)

    if len(pqual) > 0:
      j["pred"] = self.order_qual_summary(pqual)
    else:
      j["pred"] = '({})'.format(len(pqs))

    if len(oqual) > 0:
      j["obt"] = self.order_qual_summary(oqual)
    else:
      j["obt"] = '({})'.format(len(oqs))

    j["astar"] = student.qualifications.gcse_a_stars()

    # comments
    if candidate.comments.count() > 0:
      cmts = []
      for c in candidate.comments.all():
        cd = {}
        cd['who'] = c.commenter.get_full_name()
        cd['when'] = "{}".format(c.time)
        cd['t'] = c.text
        cmts.append(cd)
      j["comments"] = cmts

    return j