gets a grade for a given set of data, spits out stuff
772926
def scoreit(pars, PmagSpecRec, accept, text, verbose):
    
    s = PmagSpecRec["er_specimen_name"]
    PmagSpecRec["measurement_step_min"] = '%8.3e' % (
        pars["measurement_step_min"])
    PmagSpecRec["measurement_step_max"] = '%8.3e' % (
        pars["measurement_step_max"])
    PmagSpecRec["measurement_step_unit"] = pars["measurement_step_unit"]
    PmagSpecRec["specimen_int_n"] = '%i' % (pars["specimen_int_n"])
    PmagSpecRec["specimen_lab_field_dc"] = '%8.3e' % (
        pars["specimen_lab_field_dc"])
    PmagSpecRec["specimen_int"] = '%8.3e ' % (pars["specimen_int"])
    PmagSpecRec["specimen_b"] = '%5.3f ' % (pars["specimen_b"])
    PmagSpecRec["specimen_q"] = '%5.1f ' % (pars["specimen_q"])
    PmagSpecRec["specimen_f"] = '%5.3f ' % (pars["specimen_f"])
    PmagSpecRec["specimen_fvds"] = '%5.3f' % (pars["specimen_fvds"])
    PmagSpecRec["specimen_b_beta"] = '%5.3f' % (pars["specimen_b_beta"])
    PmagSpecRec["specimen_int_mad"] = '%7.1f' % (pars["specimen_int_mad"])
    PmagSpecRec["specimen_dec"] = '%7.1f' % (pars["specimen_dec"])
    PmagSpecRec["specimen_inc"] = '%7.1f' % (pars["specimen_inc"])
    PmagSpecRec["specimen_int_dang"] = '%7.1f ' % (pars["specimen_int_dang"])
    PmagSpecRec["specimen_drats"] = '%7.1f ' % (pars["specimen_drats"])
    PmagSpecRec["specimen_int_ptrm_n"] = '%i ' % (pars["specimen_int_ptrm_n"])
    PmagSpecRec["specimen_rsc"] = '%6.4f ' % (pars["specimen_rsc"])
    PmagSpecRec["specimen_md"] = '%i ' % (int(pars["specimen_md"]))
    PmagSpecRec["specimen_b_sigma"] = '%5.3f ' % (pars["specimen_b_sigma"])
    if 'specimen_scat' in list(pars.keys()):
        PmagSpecRec['specimen_scat'] = pars['specimen_scat']
    if 'specimen_gmax' in list(pars.keys()):
        PmagSpecRec['specimen_gmax'] = '%5.3f' % (pars['specimen_gmax'])
    if 'specimen_frac' in list(pars.keys()):
        PmagSpecRec['specimen_frac'] = '%5.3f' % (pars['specimen_frac'])
    # PmagSpecRec["specimen_Z"]='%7.1f'%(pars["specimen_Z"])
  # check score
    #
    kill = grade(PmagSpecRec, accept, 'specimen_int')
    Grade = ""
    if len(kill) == 0:
        Grade = 'A'
    else:
        Grade = 'F'
    pars["specimen_grade"] = Grade
    if verbose == 0:
        return pars, kill
    diffcum = 0
    if pars['measurement_step_unit'] == 'K':
        outstr = "specimen     Tmin  Tmax  N  lab_field  B_anc  b  q  f(coe)  Fvds  beta  MAD  Dang  Drats  Nptrm  Grade  R  MD%  sigma  Gamma_max \n"
        pars_out = (s, (pars["measurement_step_min"] - 273), (pars["measurement_step_max"] - 273), (pars["specimen_int_n"]), 1e6 * (pars["specimen_lab_field_dc"]), 1e6 * (pars["specimen_int"]), pars["specimen_b"], pars["specimen_q"], pars["specimen_f"], pars["specimen_fvds"],
                    pars["specimen_b_beta"], pars["specimen_int_mad"], pars["specimen_int_dang"], pars["specimen_drats"], pars["specimen_int_ptrm_n"], pars["specimen_grade"], np.sqrt(pars["specimen_rsc"]), int(pars["specimen_md"]), pars["specimen_b_sigma"], pars['specimen_gamma'])
        outstring = '%s %4.0f %4.0f %i %4.1f %4.1f %5.3f %5.1f %5.3f %5.3f %5.3f  %7.1f %7.1f %7.1f %s %s %6.3f %i %5.3f %7.1f' % pars_out + '\n'
    elif pars['measurement_step_unit'] == 'J':
        outstr = "specimen     Wmin  Wmax  N  lab_field  B_anc  b  q  f(coe)  Fvds  beta  MAD  Dang  Drats  Nptrm  Grade  R  MD%  sigma  ThetaMax DeltaMax GammaMax\n"
        pars_out = (s, (pars["measurement_step_min"]), (pars["measurement_step_max"]), (pars["specimen_int_n"]), 1e6 * (pars["specimen_lab_field_dc"]), 1e6 * (pars["specimen_int"]), pars["specimen_b"], pars["specimen_q"], pars["specimen_f"], pars["specimen_fvds"], pars["specimen_b_beta"],
                    pars["specimen_int_mad"], pars["specimen_int_dang"], pars["specimen_drats"], pars["specimen_int_ptrm_n"], pars["specimen_grade"], np.sqrt(pars["specimen_rsc"]), int(pars["specimen_md"]), pars["specimen_b_sigma"], pars["specimen_theta"], pars["specimen_delta"], pars["specimen_gamma"])
        outstring = '%s %4.0f %4.0f %i %4.1f %4.1f %5.3f %5.1f %5.3f %5.3f %5.3f  %7.1f %7.1f %7.1f %s %s %6.3f %i %5.3f %7.1f %7.1f %7.1f' % pars_out + '\n'
    if pars["specimen_grade"] != "A":
        print('\n killed by:')
        for k in kill:
            print(k, ':, criterion set to: ',
                  accept[k], ', specimen value: ', pars[k])
        print('\n')
    print(outstr)
    print(outstring)
    return pars, kill
945782
def calculate(self):
      """"""
      self._calculated = True
      for name in self.transcripts:
         self.transcripts[name]['RPK'] = (float(self.transcripts[name]['count'])/float(self.transcripts[name]['length']))/float(1000)
      tot = 0.0
      for name in self.transcripts:
         tot += self.transcripts[name]['RPK']
      tot = tot/float(1000000)
      for name in self.transcripts:
         self.transcripts[name]['TPM'] = self.transcripts[name]['RPK']/tot
      """do the FPKM calculation"""
      tot = 0
      for name in self.transcripts: tot += self.transcripts[name]['count']
      tot = float(tot)/float(1000000)
      for name in self.transcripts:
         if tot > 0:
            rpm = float(self.transcripts[name]['count'])/float(tot)
            self.transcripts[name]['FPKM'] = 1000*rpm/self.transcripts[name]['length']
433744
def data(cls, cube, weighted, prune):
        """"""
        return cls()._data(cube, weighted, prune)
1319167
def get_specs(data):
    
    # sort the specimen names
    speclist = []
    for rec in data:
        try:
            spec = rec["er_specimen_name"]
        except KeyError as e:
            spec = rec["specimen"]
        if spec not in speclist:
            speclist.append(spec)
    speclist.sort()
    return speclist
152059
def _get_validate_plotdata_yaml(grading_file, data):
    
    with open(grading_file) as in_handle:
        grade_stats = yaml.safe_load(in_handle)
    for sample_stats in grade_stats:
        sample = sample_stats["sample"]
        for vtype, cat, val in _flatten_grading(sample_stats):
            yield [sample, variant.get("variantcaller", ""),
                   vtype, cat, val]
272323
def _parse_achievements(self, rows):
        
        for row in rows:
            cols = row.find_all('td')
            if len(cols) != 2:
                continue
            field, value = cols
            grade = str(field).count("achievement-grade-symbol")
            name = value.text.strip()
            self.achievements.append(Achievement(name, grade))
443201
def build_input_data(sentences, labels, vocabulary):
    """"""
    x = np.array([[vocabulary[word] for word in sentence] for sentence in sentences])
    y = np.array(labels)
    return [x, y]
408862
public static function fetch_users_grades($grade_item, $userids, $include_missing=true) {
        global $DB;

        // hmm, there might be a problem with length of sql query
        // if there are too many users requested - we might run out of memory anyway
        $limit = 2000;
        $count = count($userids);
        if ($count > $limit) {
            $half = (int)($count/2);
            $first  = array_slice($userids, 0, $half);
            $second = array_slice($userids, $half);
            return grade_grade::fetch_users_grades($grade_item, $first, $include_missing) + grade_grade::fetch_users_grades($grade_item, $second, $include_missing);
        }

        list($user_ids_cvs, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'uid0');
        $params['giid'] = $grade_item->id;
        $result = array();
        if ($grade_records = $DB->get_records_select('grade_grades', "itemid=:giid AND userid $user_ids_cvs", $params)) {
            foreach ($grade_records as $record) {
                $result[$record->userid] = new grade_grade($record, false);
            }
        }
        if ($include_missing) {
            foreach ($userids as $userid) {
                if (!array_key_exists($userid, $result)) {
                    $grade_grade = new grade_grade();
                    $grade_grade->userid = $userid;
                    $grade_grade->itemid = $grade_item->id;
                    $result[$userid] = $grade_grade;
                }
            }
        }

        return $result;
    }
673781
function score(data, candidate) {
    var result = 0;
    /*
        Scoring calculations here
    */

    //Last Name
    if (!data.name.last || !candidate.name.last) {
        result = result + 0;
    } else if (data.name.last.toUpperCase() === candidate.name.last.toUpperCase()) {
        result = result + 9.58;
    } else if (data.name.last.toUpperCase().substring(0, 3) === candidate.name.last.toUpperCase().substring(0, 3)) {
        result = result + 5.18;
    } else if (data.name.last.toUpperCase().substring(0, 3) !== candidate.name.last.toUpperCase().substring(0, 3)) {
        result = result - 3.62;
    }

    //First Name
    if (!data.name.first || !candidate.name.first) {
        result = result + 0;
    } else if (data.name.first.toUpperCase() === candidate.name.first.toUpperCase()) {
        result = result + 6.69;
    } else if (data.name.first.toUpperCase().substring(0, 3) === candidate.name.first.toUpperCase().substring(0, 3)) {
        result = result + 3.37;
    } else if (data.name.first.toUpperCase().substring(0, 3) !== candidate.name.first.toUpperCase().substring(0, 3)) {
        result = result - 3.27;
    }

    //Middle Initial
    if (!data.name.middle || !candidate.name.middle) {
        result = result + 0;
    } else if (data.name.middle.toUpperCase().substring(0, 1) === candidate.name.middle.toUpperCase().substring(0, 1)) {
        result = result + 3.65;
    }

    //DOB
    if (!data.dob || !candidate.dob) {
        result = result + 0;
    } else if (data.dob.substring(0, 10) === candidate.dob.substring(0, 10)) {
        result = result + 6.22;
    }

    //Initials
    result = result + 0;

    return result;
}
1179001
def get_grade_systems(self):
        
        if self.retrieved:
            raise errors.IllegalState('List has already been retrieved.')
        self.retrieved = True
        return objects.GradeSystemList(self._results, runtime=self._runtime)
1118567
def scoreatpercentile(data,per,axis=0):
    ''
    a = np.sort(data,axis=axis)
    idx = per/100. * (data.shape[axis]-1)

    if (idx % 1 == 0):
        return a[[slice(None) if ii != axis else idx for ii in range(a.ndim)]]
    else:
        lowerweight = 1-(idx % 1)
        upperweight = (idx % 1)
        idx = int(np.floor(idx))
        return lowerweight * a[[slice(None) if ii != axis else idx for ii in range(a.ndim)]] \
                + upperweight * a[[slice(None) if ii != axis else idx+1 for ii in range(a.ndim)]]
944297
def grade(PmagRec, ACCEPT, type, data_model=2.5):
    
    GREATERTHAN = ['specimen_q', 'site_k', 'site_n', 'site_n_lines', 'site_int_n', 'measurement_step_min', 'specimen_int_ptrm_n', 'specimen_fvds', 'specimen_frac', 'specimen_f', 'specimen_n', 'specimen_int_n', 'sample_int_n', 'average_age_min', 'average_k', 'average_r', 'specimen_magn_moment',
                   'specimen_magn_volume', 'specimen_rsc', 'sample_n', 'sample_n_lines', 'sample_n_planes', 'sample_k', 'sample_r', 'site_magn_moment', 'site_magn_volume', 'site_magn_mass', 'site_r']  # these statistics must be exceede to pass, all others must be less than (except specimen_scat, which must be true)
    ISTRUE = ['specimen_scat']
    kill = []  # criteria that kill the record
    sigma_types = ['sample_int_sigma', 'sample_int_sigma_perc', 'site_int_sigma',
                   'site_int_sigma_perc', 'average_int_sigma', 'average_int_sigma_perc']
    sigmas = []
    accept = {}
    if type == 'specimen_int':
        USEKEYS = ['specimen_q', 'measurement_step_min', 'measurement_step_max', 'specimen_int_ptrm_n', 'specimen_fvds', 'specimen_frac', 'specimen_f', 'specimen_int_n', 'specimen_magn_moment',
                   'specimen_magn_volume', 'specimen_rsc', 'specimen_scat', 'specimen_drats', 'specimen_int_mad', 'specimen_int_dang', 'specimen_md', 'specimen_b_beta', 'specimen_w', 'specimen_gmax']
        if data_model == 3.0:
            USEKEYS = [map_magic.spec_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'specimen_dir':
        USEKEYS = ['measurement_step_min', 'measurement_step_max', 'specimen_mad',
                   'specimen_n', 'specimen_magn_moment', 'specimen_magn_volume']
        if data_model == 3.0:
            USEKEYS = [map_magic.spec_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'sample_int':
        USEKEYS = ['sample_int_n', 'sample_int_sigma', 'sample_int_sigma_perc']
        if data_model == 3.0:
            USEKEYS = [map_magic.samp_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'sample_dir':
        USEKEYS = ['sample_alpha95', 'sample_n', 'sample_n_lines',
                   'sample_n_planes', 'sample_k', 'sample_r']
        if data_model == 3.0:
            USEKEYS = [map_magic.samp_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'site_int':
        USEKEYS = ['site_int_sigma', 'site_int_sigma_perc', 'site_int_n']
        if data_model == 3.0:
            USEKEYS = [map_magic.site_magic2_2_magic3_map[k] for k in USEKEYS]
    elif type == 'site_dir':
        USEKEYS = ['site_alpha95', 'site_k', 'site_n',
                   'site_n_lines', 'site_n_planes', 'site_r']
        if data_model == 3.0:
            USEKEYS = [map_magic.site_magic2_2_magic3_map[k] for k in USEKEYS]

    for key in list(ACCEPT.keys()):
        if ACCEPT[key] != "" and key in USEKEYS:
            if key in ISTRUE and ACCEPT[key] == 'TRUE' or ACCEPT[key] == 'True':
                # this is because Excel always capitalizes True to TRUE and
                # python doesn't recognize that as a boolean.  never mind
                ACCEPT[key] = '1'
            elif ACCEPT[key] == 'FALSE' or ACCEPT[key] == 'False':
                ACCEPT[key] = '0'
            elif eval(ACCEPT[key]) == 0:
                ACCEPT[key] = ""
            accept[key] = ACCEPT[key]
    for key in sigma_types:
        if key in USEKEYS and key in list(accept.keys()) and key in list(PmagRec.keys()):
            sigmas.append(key)
    if len(sigmas) > 1:
        if PmagRec[sigmas[0]] == "" or PmagRec[sigmas[1]] == "":
            kill.append(sigmas[0])
            kill.append(sigmas[1])
        elif eval(PmagRec[sigmas[0]]) > eval(accept[sigmas[0]]) and eval(PmagRec[sigmas[1]]) > eval(accept[sigmas[1]]):
            kill.append(sigmas[0])
            kill.append(sigmas[1])
    elif len(sigmas) == 1 and sigmas[0] in list(accept.keys()):
        if PmagRec[sigmas[0]] > accept[sigmas[0]]:
            kill.append(sigmas[0])
    for key in list(accept.keys()):
        if accept[key] != "":
            if key not in list(PmagRec.keys()) or PmagRec[key] == '':
                kill.append(key)
            elif key not in sigma_types:
                if key in ISTRUE:  # boolean must be true
                    if PmagRec[key] != '1':
                        kill.append(key)
                if key in GREATERTHAN:
                    if eval(str(PmagRec[key])) < eval(str(accept[key])):
                        kill.append(key)
                else:
                    if eval(str(PmagRec[key])) > eval(str(accept[key])):
                        kill.append(key)
    return kill
29681
function daleChallGradeLevel(score) {
  score = Math.floor(score)

  if (score < 5) {
    score = 4
  } else if (score > 9) {
    score = 10
  }

  return gradeMap[score].concat()
}
1316670
def load_data(limit=0, split=0.8):
    """"""
    # Partition off part of the train data for evaluation
    train_data, _ = thinc.extra.datasets.imdb()
    random.shuffle(train_data)
    train_data = train_data[-limit:]
    texts, labels = zip(*train_data)
    cats = [{"POSITIVE": bool(y), "NEGATIVE": not bool(y)} for y in labels]
    split = int(len(train_data) * split)
    return (texts[:split], cats[:split]), (texts[split:], cats[split:])
960952
def score(self, i):
        """"""
        if self.minimize:
            return self.data[i][0]
        else:
            return self.data[(-1 * i) - 1][0]
684548
def compare_report_print(sorted_list, scores, best_name):
    
    title_items = ["Rank", "Name", "Class-Score", "Overall-Score"]
    class_scores_len = map(lambda x: len(
        str(x["class"])), list(scores.values()))
    shifts = ["%-" +
              str(len(sorted_list) +
                  4) +
              "s", "%-" +
              str(max(map(lambda x: len(str(x)), sorted_list)) +
                  4) +
              "s", "%-" +
              str(max(class_scores_len) + 11) + "s"]
    result = ""
    result += "Best : " + str(best_name) + "\n\n"
    result += ("".join(shifts)
               ) % tuple(title_items[:-1]) + title_items[-1] + "\n"
    prev_rank = 0
    for index, cm in enumerate(sorted_list):
        rank = index
        if scores[sorted_list[rank]] == scores[sorted_list[prev_rank]]:
            rank = prev_rank
        result += ("".join(shifts)) % (str(rank + 1), str(cm),
                                       str(scores[cm]["class"])) + str(scores[cm]["overall"]) + "\n"
        prev_rank = rank
    if best_name is None:
        result += "\nWarning: " + COMPARE_RESULT_WARNING
    return result
545751
def scores(self, text: str) -> Dict[str, float]:
        
        values = extract(text)
        input_fn = _to_func(([values], []))
        prediction = self._classifier.predict_proba(input_fn=input_fn)
        probabilities = next(prediction).tolist()
        sorted_languages = sorted(self.languages)
        return dict(zip(sorted_languages, probabilities))