Exemple #1
0
def medication_edit_view(request, **kwargs):
    medication = get_object_or_404(Medication, pk=kwargs['pk'])
    return render(request, 'patients_app/medications/med_form.html', {
        'medication': medication,
        'date_prescribed': date_to_str(medication.date_prescribed),
        'date_started_taking': date_to_str(medication.date_started_taking),
        'date_stopped_taking,': date_to_str(medication.date_stopped_taking),
        'dispense_quantity': num_to_str(medication.dispense_quantity),
        'dosage_quantity': num_to_str(medication.dosage_quantity),
        'number_refills': num_to_str(medication.number_refills),
        'method': 'PATCH',
    })
Exemple #2
0
def op_code_match(opcode, a0, a1, b0, b1, changeset=None, sm=None, text=None):
    optr = ''
    chrb = ''
    print "    !@#$", opcode, "A:'" + repr(sm.a[a0:a1]) + "'", "B:'" + repr(
        sm.b[b0:b1]) + "'"
    if opcode == 'equal':
        print "    EQUAL"
        # if substr contains a newlines
        if '\n' in sm.a[a0:a1]:
            print "    CONTAINS NL"
            # "|L=N" : Keep N characters from the source text,
            #          containing L newlines. The last character kept
            #          MUST be a newline, and the final newline of
            #          the document is allowed.
            nls = [a0 + m.start() + 1 for m in re.finditer('\n', sm.b[a0:a1])]
            print "    nls", nls
            if sm.a[a0:a1][-1] == '\n':
                print "    ENDS WITH NL: |=", len(nls), a1 - a0
                optr += '|' + num_to_str(len(nls), 36)
                optr += '=' + num_to_str(a1 - a0, 36)
            # if substr does not end with a newline
            else:
                print "    DOES NOT END WITH NL"
                nls = [a0] + nls + [a1]
                print nls
                changeset['ops'] += optr
                for c0, c1 in zip(nls, nls[1:]):
                    #print "PYF", repr(sm.a[c0:c1])
                    op_code_match('equal', c0, c1, c0, c1, changeset, sm, text)
        else:
            print "    CONTAINS NO NL: =", a1 - a0
            optr += '=' + num_to_str(a1 - a0, 36)
    elif opcode == 'insert':
        print "    INSERT *+", b1 - b0
        # "|L+N" : Insert N characters from the source text,
        #          containing L newlines. The last character
        #          inserted MUST be a newline, but not the
        #          (new) document's final newline.
        if text._authors.get_user_id():
            optr += '*' + text._authors.get_user_id()
        optr += '+' + num_to_str(b1 - b0, 36)
        chrb += sm.b[b0:b1]
    elif opcode == 'delete':
        print "    DELETE -", a1 - a0
        # "|L-N" : Delete N characters from the source text,
        #          containing L newlines. The last character
        #          inserted MUST be a newline, but not the (old)
        #          document's final newline.
        optr += '-' + num_to_str(a1 - a0, 36)
    elif opcode == 'replace':
        print "    REPLACE"
    changeset['ops'] += optr
    changeset['char_bank'] += chrb
Exemple #3
0
def op_code_match(opcode, a0, a1, b0, b1, changeset=None, sm=None, text=None):
    optr = ''
    chrb = ''
    print "    !@#$", opcode, "A:'"+repr(sm.a[a0:a1])+"'", "B:'"+repr(sm.b[b0:b1])+"'"
    if opcode == 'equal':
        print "    EQUAL"
        # if substr contains a newlines
        if '\n' in sm.a[a0:a1]:
            print "    CONTAINS NL"
            # "|L=N" : Keep N characters from the source text,
            #          containing L newlines. The last character kept
            #          MUST be a newline, and the final newline of
            #          the document is allowed.
            nls = [a0+m.start()+1 for m in re.finditer('\n', sm.b[a0:a1])]
            print "    nls", nls
            if sm.a[a0:a1][-1] == '\n':
                print "    ENDS WITH NL: |=", len(nls), a1-a0
                optr += '|' + num_to_str(len(nls), 36)
                optr += '=' + num_to_str(a1-a0, 36)
            # if substr does not end with a newline
            else:
                print "    DOES NOT END WITH NL"
                nls = [a0] + nls + [a1]
                print nls
                changeset['ops'] += optr
                for c0, c1 in zip(nls, nls[1:]):
                    #print "PYF", repr(sm.a[c0:c1])
                    op_code_match('equal', c0, c1, c0, c1, changeset, sm, text)
        else:
            print "    CONTAINS NO NL: =", a1-a0
            optr += '=' + num_to_str(a1-a0, 36)
    elif opcode == 'insert':
        print "    INSERT *+", b1-b0
        # "|L+N" : Insert N characters from the source text,
        #          containing L newlines. The last character
        #          inserted MUST be a newline, but not the
        #          (new) document's final newline.
        if text._authors.get_user_id():
            optr += '*' + text._authors.get_user_id()
        optr += '+' + num_to_str(b1-b0, 36)
        chrb += sm.b[b0:b1]
    elif opcode == 'delete':
        print "    DELETE -", a1-a0
        # "|L-N" : Delete N characters from the source text,
        #          containing L newlines. The last character
        #          inserted MUST be a newline, but not the (old)
        #          document's final newline.
        optr += '-' + num_to_str(a1-a0, 36)
    elif opcode == 'replace':
        print "    REPLACE"
    changeset['ops'] += optr
    changeset['char_bank'] += chrb
Exemple #4
0
def pack(csd):
    """
    Packs a Changeset dict into a string encoded Changeset
    @param cs {dict} a Changeset dict
    @returns {string} String encoded Changeset
    """
    log.debug("pack: %s" % (csd,))
    if not csd:
        return None
    len_diff = csd["new_len"] - csd["old_len"]
    len_diff_str = ">" + num_to_str(len_diff) if len_diff >= 0 else "<" + num_to_str(-len_diff)
    cs = [ 'Z:', num_to_str(csd["old_len"]), len_diff_str, csd["ops"], "$", csd["char_bank"] ]
    cs = ''.join(cs)
    log.debug("pack: returns %s" % (cs,))
    return cs
Exemple #5
0
def pack(csd):
    """
    Packs a Changeset dict into a string encoded Changeset
    @param cs {dict} a Changeset dict
    @returns {string} String encoded Changeset
    """
    log.debug("pack: %s" % (csd, ))
    if not csd:
        return None
    len_diff = csd["new_len"] - csd["old_len"]
    len_diff_str = ">" + num_to_str(
        len_diff) if len_diff >= 0 else "<" + num_to_str(-len_diff)
    cs = [
        'Z:',
        num_to_str(csd["old_len"]), len_diff_str, csd["ops"], "$",
        csd["char_bank"]
    ]
    cs = ''.join(cs)
    log.debug("pack: returns %s" % (cs, ))
    return cs
Exemple #6
0
                               tokenizer=tripgen.tknzr,
                               batch_size=args.batch_size,
                               window=args.window,
                               max_len=MAX_LEN)
    utils.oov_pct(tripgen.data, tripgen.tknzr.word_index[datagen.OOV])

    if 'bpe' in args.corpus or 'BPE' in args.corpus:
        preprocess = '-bpe'
    else:
        preprocess = ''
    if args.filters:
        preprocess += '-filters'
    else:
        preprocess += '-nofilters'

    suffix = '-c' + utils.num_to_str(len(tripgen.data)) \
                            + '-' + args.cell + str(args.size) \
                            + '-w' + str(args.window) \
                            + '-e' + str(args.embedding_dim) \
                            + '-v' + utils.num_to_str(args.vocab_size) \
                            + preprocess
    modelname = 'models/' + args.model \
                            + suffix \
                            + '.best.h5'
    tokenname = 'models/' + args.tokenizer \
                            + suffix \
                            +'.pkl'
    datagen.save_tokenizer(tripgen.tknzr, tokenname)
    print('Vocab size:', args.vocab_size)
    print('Num samples:', len(tripgen.data))