예제 #1
0
def main():

    import config

    from model import load_model
    model = load_model()
    while not model:
        config.model_path = input('valid model: ')
        model = load_model()

    from data import load_data, split_data
    d = load_data(with_meta=True)
    d, _ = split_data(d)

    # from random import shuffle
    # shuffle(d)
    d = d[:config.hm_output_file]

    for i, (seq, meta) in enumerate(d):

        from model import respond_to
        _, seq = respond_to(model, [seq[:config.hm_extra_steps]],
                            training_run=False,
                            extra_steps=config.hm_extra_steps)
        seq = seq.detach()
        if config.use_gpu:
            seq = seq.cpu()
        seq = seq.numpy()

        from data import data_to_audio, write
        seq = data_to_audio(seq, meta)
        write(f'{config.output_file}{i}.wav', config.sample_rate, seq)
예제 #2
0
    def dump(self, directory, features, detail=None):
        if not os.path.exists(directory):
            os.mkdir(directory)

        # Noise
        if self.label is None:
            path = os.path.join(directory, "noise.jsonl")

        # Not noise
        else:
            path = os.path.join(directory, "cluster.json")
            with open(path, "w") as fp:
                json.dump(self.analyze(features), fp, indent=4)

            path = os.path.join(directory, "items.jsonl")

        def item(point):
            return {
                "log": features[point][extractor.FEATURE_LOG],
                "url": features[point][extractor.FEATURE_URL] or None,
                "merged": features[point][extractor.FEATURE_MERGED],
                "test": features[point][extractor.FEATURE_NAME],
                "tracker": features[point][extractor.FEATURE_TRACKER] or None,
            }

        # Write out all the items
        data.write(path, map(item, self.points))
예제 #3
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument('--input', default='tweets.tsv', help='tweets file')
    ap.add_argument('--liwc', action='store_true', default=False, help='use LIWC features [unimpl]')
    ap.add_argument('--log', action='store_true', default=False, help='compute log of feature values')
    ap.add_argument('--min-df', metavar='MIN_DF', type=int, default=20, help='min number of different county a word must appear in')
    ap.add_argument('--norm', default='none', help='how to normalize counts [user, word, none]')
    ap.add_argument('--output', default='counties.pkl', help='output file')
    ap.add_argument('--perma', action='store_true', default=False, help='use PERMA features [unimpl]')
    ap.add_argument('--unigrams', action='store_true', default=False, help='retain unigrams')
    args = ap.parse_args()
    logger.info(args)

    if os.path.exists(args.output):
        logger.info('already done!')
        sys.exit()
    features, users_by_county, alpha = read_tweets(tweet.from_tsv(args.input), args.norm == 'user', args.unigrams, args.liwc, args.perma)
    features, alpha = filter_by_count(features, alpha, args.min_df)
    normalize(features, users_by_county, alpha, args.norm)
    features = densify(features, alpha)  # default_dict_to_dict(features)
    if args.log:
        logify(features)
    logger.info('10 words from alpha: %s' % alpha.keys()[:10])
    logger.info('first 10 features from first county: %s' % features.values()[0][:10])
    data.write(args.output, data.Data(args, features, alpha))
예제 #4
0
    def dump(self, directory):
        if not os.path.exists(directory):
            os.mkdir(directory)

        for key, group in self.data.items():
            group.finalize()

        path = os.path.join(directory, "{0}.jsonl".format(self.name))
        data.write(path, self.data.values())
예제 #5
0
def write_db():

    if request.method == 'POST':

        topic = request.form["topic"]
        dur = request.form["Addcontent"]
        color = request.form["Tags"]
        hair = request.form["Levels"]
        print(topic, dur, color, hair)
        data.write(topic=topic, content=dur, tags=color, levels=hair)

    return render_template('movies.html', p="ok", name=topic)
예제 #6
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument('--input', default='tweets.tsv', help='tweets file')
    ap.add_argument('--liwc',
                    action='store_true',
                    default=False,
                    help='use LIWC features [unimpl]')
    ap.add_argument('--log',
                    action='store_true',
                    default=False,
                    help='compute log of feature values')
    ap.add_argument(
        '--min-df',
        metavar='MIN_DF',
        type=int,
        default=20,
        help='min number of different county a word must appear in')
    ap.add_argument('--norm',
                    default='none',
                    help='how to normalize counts [user, word, none]')
    ap.add_argument('--output', default='counties.pkl', help='output file')
    ap.add_argument('--perma',
                    action='store_true',
                    default=False,
                    help='use PERMA features [unimpl]')
    ap.add_argument('--unigrams',
                    action='store_true',
                    default=False,
                    help='retain unigrams')
    args = ap.parse_args()
    logger.info(args)

    if os.path.exists(args.output):
        logger.info('already done!')
        sys.exit()
    features, users_by_county, alpha = read_tweets(tweet.from_tsv(args.input),
                                                   args.norm == 'user',
                                                   args.unigrams, args.liwc,
                                                   args.perma)
    features, alpha = filter_by_count(features, alpha, args.min_df)
    normalize(features, users_by_county, alpha, args.norm)
    features = densify(features, alpha)  # default_dict_to_dict(features)
    if args.log:
        logify(features)
    logger.info('10 words from alpha: %s' % alpha.keys()[:10])
    logger.info('first 10 features from first county: %s' %
                features.values()[0][:10])
    data.write(args.output, data.Data(args, features, alpha))
예제 #7
0
def task():

    taskApp = data.read()
    task = taskapp_pb2.Task()
    newTask = toBuffer(request.data, task, gettingJson(request))

    matchingTasks = filterById(taskApp.tasks, newTask.id)
    if len(matchingTasks) > 0:
        data.update(matchingTasks[0], newTask)
        data.write(taskApp)
    else:
        newTask.time_created.GetCurrentTime()
        newTask.last_updated.GetCurrentTime()
        newTask.id = str(uuid.uuid4())
        taskApp.tasks.extend([newTask])
        data.write(taskApp)

    return fromBuffer(newTask, gettingJson(request))
예제 #8
0
def hybrid_system():
    # load data and functions
    slot_presentation, presentation_presentation, presentation_supervisor, supervisor_preference = dt.load()

    # initialize matrices
    slot_no = slot_presentation.shape[0]
    presentation_no = slot_presentation.shape[1]
    population_size = 10
    population = np.empty([population_size, slot_no, presentation_no], dtype=np.int8)
    penalty_points = np.empty(population_size, dtype=int)

    # create initial population
    for i in range(population_size):
        chromosome = ga.generate_chromosome(slot_presentation)
        population[i] = chromosome
        penalty_point = \
            penalty(chromosome, presentation_presentation, presentation_supervisor, supervisor_preference)[0]
        penalty_points[i] = penalty_point

    # sort initial population based on penalty points
    population = population[penalty_points.argsort()]
    penalty_points = penalty_points[penalty_points.argsort()]

    # run genetic algorithm for 100 generations
    ga_max_generations = 100
    population, penalty_points, ga_plot_data = \
        ga.reproduction(ga_max_generations, population, penalty_points, presentation_presentation,
                        presentation_supervisor, supervisor_preference)

    # run simulated annealing after running genetic algorithm
    temperature = penalty_points[population_size - 1] - penalty_points[0]
    candidate = population[0]
    penalty_point = penalty_points[0]
    best_candidate, best_penalty_point, sa_plot_data = \
        sa.anneal(temperature, candidate, penalty_point, presentation_presentation,
                  presentation_supervisor, supervisor_preference)

    # write result data
    constraint_counts = \
        penalty(best_candidate, presentation_presentation, presentation_supervisor, supervisor_preference)
    plot_data = np.concatenate([ga_plot_data, sa_plot_data])
    dt.write(best_candidate, supervisor_preference, constraint_counts, plot_data)
예제 #9
0
def write_db():

    if request.method == 'POST':

        movie = request.form["moviescount"]
        actor = request.form["name"]
        dur = request.form["screenduration"]
        insta = request.form["instagramfollowers"]
        dress = request.form["dressmatchmeter"]
        criticscore = request.form["criticscore"]
        consistency = request.form["consistency"]

        data.write(movie=movie,
                   actor=actor,
                   duration=dur,
                   insta=insta,
                   dress=dress,
                   consistency=consistency,
                   criticscore=criticscore)

    return render_template('movies.html', p="ok", name=actor)
예제 #10
0
def execute():
    global ret_pc
    global jmp_pc
    global call_pc
    global pred_pc
    global w_icode
    global w_valE
    global w_valM
    global w_dstE
    global w_dstM
    global m_icode
    global m_valE
    global m_valM
    global m_dstE
    global m_dstM
    global e_icode
    global e_bch
    global e_valE
    global e_valM
    global e_dstE
    global e_dstM
    global d_icode
    global d_ifunc
    global d_valC
    global d_valA
    global d_valB
    global d_dstE
    global d_dstM
    global d_srcA
    global d_srcB
    global f_icode
    global f_ifunc
    global f_ra
    global f_rb
    global f_valC
    global f_valP
    while data.isend() == False:
        data.show()
        global clocknum
        clocknum += 1
        print("CLOCK_NO:%d" % (clocknum))
        PipeClock.PipeClock()
        ret_pc = ""
        jmp_pc = ""
        call_pc = ""
        pred_pc = ""

        # print("CLOCK-------------------------------")
        # WriteBack---------------------------------
        # print("writeback:")
        w_icode = data.read("W_icode")
        w_valE = data.read("W_valE")
        w_valM = data.read("W_valM")
        w_dstE = data.read("W_dstE")
        w_dstM = data.read("W_dstM")

        if w_icode == "0":  # nop
            nothing()
        elif w_icode == "1":  # halt
            data.write("M_index", "X")
            data.write("M_icode", "0")
            data.write("E_index", "X")
            data.write("E_icode", "0")
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
            data.setend()
        elif w_icode == "2":  # rrmovl
            data.RegWrite(w_dstE, w_valE)
        elif w_icode == "3":  # irmovl
            data.RegWrite(w_dstE, w_valE)
        elif w_icode == "4":  # rmmovl
            nothing()
        elif w_icode == "5":  # mrmovl
            data.RegWrite(w_dstE, w_valM)
        elif w_icode == "6":  # op
            data.RegWrite(w_dstE, w_valE)
        elif w_icode == "7":  # jmp
            nothing()
        elif w_icode == "8":  # call
            data.RegWrite("4", w_valE)
        elif w_icode == "9":  # ret
            data.RegWrite("4", w_valE)
        elif w_icode == "a":  # push
            data.RegWrite("4", w_valE)
        elif w_icode == "b":  # popl
            data.RegWrite("4", w_valE)
            data.RegWrite(w_dstE, w_valM)
        # Memory--------------------------------------
        # print("Memory:")

        m_icode = ""
        m_valE = ""
        m_valM = ""
        m_dstE = ""
        m_dstM = ""

        m_icode = data.read("M_icode")
        m_valE = data.read("M_valE")
        m_valM = data.read("M_valM")
        m_dstE = data.read("M_dstE")
        m_dstM = data.read("M_dstM")

        if m_icode == "0":  # nop
            nothing()
            m_valE = ""
            m_valM = ""
            m_dstE = ""
            m_dstM = ""
        elif m_icode == "1":  # halt
            data.write("E_index", "X")
            data.write("E_icode", "0")
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
        elif m_icode == "2":  # rrmovl
            nothing()
        elif m_icode == "3":  # irmovl
            nothing()
        elif m_icode == "4":  # rmmovl
            data.MemoryWrite(m_dstM, m_valM)
        elif m_icode == "5":  # mrmovl
            m_valM = data.MemoryRead(m_dstM)
        elif m_icode == "6":  # op
            nothing()
        elif m_icode == "7":  # jmp
            nothing()
        elif m_icode == "8":  # call
            data.MemoryWrite(m_valE, m_valM)
        elif m_icode == "9":  # ret
            m_valM = data.MemoryRead(m_dstM)
            ret_pc = arc(m_valM)
            data.write("E_index", "X")
            data.write("E_icode", "0")
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
        elif m_icode == "a":  # push
            data.MemoryWrite(m_valE, m_valM)
        elif m_icode == "b":  # pop
            m_valM = data.MemoryRead(m_dstM)

        data.write("W_index", data.read("M_index"))

        data.write("W_icode", m_icode)
        data.write("W_valE", m_valE)
        data.write("W_valM", m_valM)
        data.write("W_dstE", m_dstE)
        data.write("W_dstM", m_dstM)
        # Execute----------------------------------------------
        # print("Execute:")

        e_icode = ""
        e_bch = ""
        e_valE = ""
        e_valM = ""
        e_dstE = ""
        e_dstM = ""

        e_icode = data.read("E_icode")
        e_ifunc = data.read("E_ifunc")
        e_valC = data.read("E_valC")
        e_valA = data.read("E_valA")
        e_valB = data.read("E_valB")
        e_dstE = data.read("E_dstE")
        e_dstM = data.read("E_dstM")
        srcA = data.read("srcA")
        srcB = data.read("srcB")

        if e_icode == "0":  # nop
            nothing()
            e_bch = ""
            e_valE = ""
            e_valM = ""
            e_dstE = ""
            e_dstM = ""
        elif e_icode == "1":  # halt
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
        elif e_icode == "2":  # rrmovl
            e_valE = e_valA
        elif e_icode == "3":  # irmovl
            e_valE = e_valC
        elif e_icode == "4":  # rmmovl
            aluA = e_valB
            aluB = e_valC
            e_dstM = data.alu("0", aluA, aluB)
            e_valM = e_valA
        elif e_icode == "5":  # mrmovl
            aluA = e_valB
            aluB = e_valC
            e_dstM = data.alu("0", aluA, aluB)
            e_dstE = srcA
        elif e_icode == "6":  # op
            aluA = e_valA
            aluB = e_valB
            e_valE = data.alu(e_ifunc, aluA, aluB)
            e_dstE = srcB
        elif e_icode == "7":  # jmp
            if data.check(e_ifunc):
                data.write("D_index", "X")
                data.write("D_icode", "0")
                data.write("pc", "X")
                data.write("F_icode", "0")
                jmp_pc = arc(e_valC)
                e_bch = jmp_pc
        elif e_icode == "8":  # call
            e_valM = e_valB
            aluA = e_valA
            aluB = "04000000"
            e_valE = data.alu("1", aluB, aluA)
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
            call_pc = arc(e_valC)
            e_bch = call_pc
        elif e_icode == "9":  # ret
            aluA = e_valA
            aluB = "04000000"
            e_valE = data.alu("0", aluA, aluB)
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
            e_dstM = e_valA
        elif e_icode == "a":  # push
            aluA = e_valB
            aluB = "04000000"
            e_valE = data.alu("1", aluB, aluA)
            e_valM = e_valA
        elif e_icode == "b":  # popl
            aluA = e_valB
            aluB = "04000000"
            e_valE = data.alu("0", aluA, aluB)
            e_dstM = e_valB
            e_dstE = srcA

        data.write("M_index", data.read("E_index"))

        data.write("M_icode", e_icode)
        data.write("bch", e_bch)
        data.write("M_valE", e_valE)
        data.write("M_valM", e_valM)
        data.write("M_dstE", e_dstE)
        data.write("M_dstM", e_dstM)
        # Decode----------------------------------
        # print("Decode:")

        d_icode = ""
        d_ifunc = ""
        d_valC = ""
        d_valA = ""
        d_valB = ""
        d_dstE = ""
        d_dstM = ""
        d_srcA = ""
        d_srcB = ""

        d_icode = data.read("D_icode")
        d_ifunc = data.read("D_ifunc")
        ra = data.read("rA")
        rb = data.read("rB")
        d_valC = data.read("D_valC")
        d_valP = data.read("D_valP")

        if d_icode == "0":  # nop
            nothing()
            d_ifunc = ""
            d_valC = ""
            d_valA = ""
            d_valB = ""
            d_dstE = ""
            d_dstM = ""
            d_srcA = ""
            d_srcB = ""
        elif d_icode == "1":  # halt
            nothing()
        elif d_icode == "2":  # rrmovl
            Temp = forwarding(ra)
            if Temp == "X":
                data.setstall()
            else:
                d_valA = Temp
            d_dstE = rb
            d_srcA = ra
            d_srcB = rb
        elif d_icode == "3":  # irmovl
            d_valA = d_valC
            d_dstE = rb
        elif d_icode == "4":  # rmmovl-------------------------------------------------------------
            Temp = forwarding(ra)
            if Temp == "X":
                data.setstall()
            else:
                d_valA = Temp
            Temp = forwarding(rb)
            if Temp == "X":
                data.setstall()
            else:
                d_valB = Temp
            d_srcA = ra
            d_srcB = rb
        elif d_icode == "5":  # mrmovl-------------------------------------------------------
            Temp = forwarding(rb)
            if Temp == "X":
                data.setstall()
            else:
                d_valB = Temp
            d_dstE = ra
            d_srcA = ra
            d_srcB = rb
        elif d_icode == "6":  # op------------------------------------------------------------------------
            Temp = forwarding(ra)
            if Temp == "X":
                data.setstall()
            else:
                d_valA = Temp
            Temp = forwarding(rb)
            if Temp == "X":
                data.setstall()
            else:
                d_valB = Temp
            d_srcA = ra
            d_srcB = rb
            d_dstE = rb
        elif d_icode == "7":  # jmp----------------------
            nothing()
        elif d_icode == "8":  # call---------------------
            Temp = forwarding("4")
            if Temp == "X":
                data.setstall()
            else:
                d_valA = Temp
            d_valB = d_valP
            d_srcA = "4"
            d_dstE = "4"
        elif d_icode == "9":  # ret--------------------------------------
            Temp = forwarding("4")
            if Temp == "X":
                data.setstall()
            else:
                d_valA = Temp
            d_dstE = "4"
            d_srcA = "4"
        elif d_icode == "a":  # push-------------------------------------
            Temp = forwarding(ra)
            if Temp == "X":
                data.setstall()
            else:
                d_valA = Temp
            Temp = forwarding("4")
            if Temp == "X":
                data.setstall()
            else:
                d_valB = Temp
            d_srcA = ra
            d_srcB = "4"
            d_dstE = "4"
        elif d_icode == "b":  # popl---------------------------------------------------------------
            Temp = forwarding("4")
            if Temp == "4":
                data.setstall()
            else:
                d_valB = Temp
            d_dstE = ra
            d_srcA = ra
            d_srcB = "4"

        if data.isstall():
            data.write("E_icode", "0")
            data.write("E_index", "X")
        else:
            data.write("E_index", data.read("D_index"))

            data.write("E_icode", d_icode)
            data.write("E_ifunc", d_ifunc)
            data.write("E_valC", d_valC)
            data.write("E_valA", d_valA)
            data.write("E_valB", d_valB)
            data.write("E_dstE", d_dstE)
            data.write("E_dstM", d_dstM)
            data.write("srcA", d_srcA)
            data.write("srcB", d_srcB)
        # Fetch---------------------------------------------
        # print("Fetch:")

        f_icode = ""
        f_ifunc = ""
        f_ra = ""
        f_rb = ""
        f_valC = ""
        f_valP = ""

        f_icode = data.read("F_icode")
        pc = data.read("pc")

        if pc == "X":
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("F_icode", "1")
            f_ifunc = ""
            f_ra = ""
            f_rb = ""
            f_valC = ""
            f_valP = ""
            data.write("D_ifunc", f_ifunc)
            data.write("rA", f_ra)
            data.write("rB", f_rb)
            data.write("D_valC", f_valC)
            data.write("D_valP", f_valP)
        elif f_icode == "0":
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("F_icode", "1")
            f_ifunc = ""
            f_ra = ""
            f_rb = ""
            f_valC = ""
            f_valP = ""
            data.write("D_ifunc", f_ifunc)
            data.write("rA", f_ra)
            data.write("rB", f_rb)
            data.write("D_valC", f_valC)
            data.write("D_valP", f_valP)
        elif data.isstall():
            nothing()
        else:
            pred_pc = data.next(pc)
            s = data.MemoryGet(pc)

            if s[0] == "0":  # nop
                nothing()
            if s[0] == "1":  # halt
                nothing()
            if s[0] == "2":  # rrmovl
                f_ra = s[2]
                f_rb = s[3]
            if s[0] == "3":  # irmovl
                f_rb = s[3]
                f_valC = s[4:12]
            if s[0] == "4":  # rmmovl
                f_ra = s[2]
                f_rb = s[3]
                f_valC = s[4:12]
            if s[0] == "5":  # mrmovl
                f_ra = s[2]
                f_rb = s[3]
                f_valC = s[4:12]
            if s[0] == "6":  # op
                f_ra = s[2]
                f_rb = s[3]
            if s[0] == "7":  # jmp
                f_valC = s[2:10]
            if s[0] == "8":  # call
                f_valC = s[2:10]
                f_ra = "4"
            if s[0] == "9":  # ret
                f_ra = "4"
                nothing()
            if s[0] == "a":  # push
                f_ra = s[2]
                f_rb = "4"
            if s[0] == "b":  # pop
                f_ra = s[2]
                f_rb = "4"

            f_icode = s[0]
            f_ifunc = s[1]

            if data.isstall():
                nothing()
            else:
                data.write("D_index", pc)
                data.write("D_icode", f_icode)
                data.write("D_ifunc", f_ifunc)
                data.write("rA", f_ra)
                data.write("rB", f_rb)
                data.write("D_valC", f_valC)
                if pred_pc[0] != "X":
                    data.write("D_valP", arc(pred_pc))
                else:
                    data.write("D_valP", "X")
        # PC------------------------------------
        # print("PC:")
        if data.isstall():
            data.start()
            return 0

        if ret_pc != "":
            data.write("pc", ret_pc)
        elif call_pc != "":
            data.write("pc", call_pc)
        elif jmp_pc != "":
            data.write("pc", jmp_pc)
        elif pred_pc != "":
            data.write("pc", pred_pc)
        return 0
예제 #11
0
async def on_message(message):
    msg = word(message.content)
    val = URLValidator()

    if message.author.id in admins:
        if msg.startswith(prefix + 'add '):
            msg.clearfront(len(prefix) + 4)
            subject, link, version = None, None, None
            try:
                subject, link, version = msg.word.split(', ', 3)
                subject = subject.lower()
            except ValueError:
                await message.channel.send(
                    f'```Error! Invalid Syntax! Correct syntax: {prefix}add <subject>, <link>, <version>```'
                )
                return
            else:
                try:
                    val(link)
                except ValidationError:
                    await message.channel.send(
                        f'```Error! Invalid Link! Make sure your link includes https/http```'
                    )
                    return
                else:
                    if subject in alias.keys():
                        subject = alias[subject]
                    elif subject not in alias.values():
                        await message.channel.send(
                            f'```Invalid subject \"{subject}\"!```')
                        return

            now = datetime.now(tz=pytz.timezone('Asia/Singapore'))
            month = '%02d' % now.month
            day = '%02d' % now.day
            hour = '%02d' % now.hour
            minute = '%02d' % now.minute
            second = '%02d' % now.second

            if subject in links.keys():
                links[subject][version] = [
                    link, f'{now.year}/{month}/{day} {hour}:{minute}:{second}'
                ]
            else:
                links[subject] = {
                    version: [
                        link,
                        f'{now.year}/{month}/{day} {hour}:{minute}:{second}'
                    ]
                }

            await message.channel.send(embed=createEmbed(
                title='Success',
                text=f'You have uploaded {version} of {subject} ( {link} )',
                colour=0x00ff7f))
            await client.get_user(611513933710229504).send(
                f'<@!611513933710229504>, <@!{message.author.id}> has uploaded {version} of {subject} at {link}.'
            )

        elif msg.startswith(prefix + 'del '):
            msg.clearfront(len(prefix) + 4)
            subject, version = None, None

            try:
                subject, version = msg.word.split(', ', 2)
                subject = subject.lower()
            except ValueError:
                await message.channel.send(
                    f'```Error! Invalid Syntax! Correct syntax: {prefix}del <subject>, <version>```'
                )
            else:
                if subject in alias.keys():
                    subject = alias[subject]
                elif subject not in alias.values():
                    await message.channel.send(
                        f'```Invalid subject \"{subject}\"!```')
                    return

            if version in links[subject].keys():
                await message.channel.send(embed=createEmbed(
                    title='Success',
                    text=
                    f'You deleted {version} of {subject} (Link: {links[subject][version][0]}, Uploaded: {links[subject][version][1]})!',
                    colour=0x00ff7f))
                await client.get_user(611513933710229504).send(
                    f'<@!611513933710229504>, <@!{message.author.id}> has deleted {version} of {subject} at {links[subject][version][0]} [{links[subject][version][1]}].'
                )
                links[subject].pop(version)
            else:
                await message.channel.send(
                    f'```Error! Invalid Syntax! Correct syntax: {prefix}del <subject>, <version>```'
                )

    if msg.startswith(prefix + 'list '):
        msg.clearfront(len(prefix) + 5)
        subject = msg.word.lower()

        if subject in alias.keys():
            subject = alias[subject]
        elif subject not in alias.values():
            await message.channel.send(f'Invalid subject \"{subject}\"!')
            return

        txt = ''

        if subject not in links.keys():
            await message.channel.send(
                f'```No data found for subject \"{subject}\"!```')
            return

        x = len(links[subject])
        for version, link in links[subject].items():
            if x == 1:
                txt += f'\n\n**Latest Version**:\n{version} - {link[0]} [{link[1]}]'
            else:
                txt += f'{version} - {link[0]} [{link[1]}]\n'
            x -= 1

        if txt != '':
            await message.channel.send(embed=createEmbed(
                title=f'Versions of {subject} notes',
                text=txt,
                colour=discord.Color.blue(),
                footer=
                'Press Ctrl + P to see the document(and then you can access the bookmarks)'
            ))
        else:
            await message.channel.send(
                f'```No data found for subject \"{subject}\"!```')

    with open('data.py', 'w') as data:
        data.write('data = ' + str(links))
예제 #12
0
파일: actor_m.py 프로젝트: mtiarn/teatr
 def rep(self):
     self.date=input("Введите дату (ДД.ММ.ГГГГ): ")
     d.training.append(self.date)
     d.write()
     print('Желаемые даты репетиций: ', sorted(d.training, key=lambda x: datetime.datetime.strptime(x, '%d.%m.%Y')))
예제 #13
0
                    #grabs the player's discord id
                    player_name = player_data[target_member.id][0]

                    #sends the id to the champion function, which will return the champion name
                    champ_name = Get_Champion(player_name)

                    #sets the nickname
                    await target_member.edit(nick=champ_name)

                    player_data[target_member.id][2] = int(time.time())
                    print('timer passed')

                    run_timer_thread(target_member)

                #'handles' the error
                except KeyError:
                    pass
                    print('timer exceded')

    #now that the rest of the code is out of the way, it's time to start the bot
    client.run(token)

#handles anything that might interrupt the code
#it will back up player_data to its storage file before closing
except:

    data = open('data.py', 'w')
    data.truncate()
    data.write("player_data={}".format(player_data))
    data.close()
예제 #14
0
def actions():
    global action
    global act
    if access == 0:
        while act == True:
            print(
                'Выберете действите: посмотреть даты спектаклей - 1, Оставить пожелания на даты репетиций - 2, Оставить заявку на костюмы - 3, Посмотреть список костюмов - 4, Зарезервировать билеты - 5, Сменить пользователя - 6'
            )
            action = input()
            if action == '1':
                ac.date()
                n.write()
            if action == '2':
                ac.rep()
                n.write()
            if action == '3':
                ac.suit()
                n.write()
            if action == '4':
                ac.w_suit()
                n.write()
            if action == '5':
                ac.res_tik()
                n.write()
            if action == '6':
                enter()
            new = input('Хотите выполнить другое действие? (Да/Нет) ')
            if new == 'Да' or new == 'да':
                pass
            if new == 'Нет' or new == 'нет':
                act = False

    if access == 1:
        while act == True:
            print(
                'Выберете действите: Назначить дату спектакля - 1, Управление репетициями - 2, Управление заявками на костюмы и их списками - 3, Одобрить зарезервированные билеты - 4, Сменить пользователя - 5'
            )
            action = input()
            if action == '1':
                ad.a_date()
                n.write()
            if action == '2':
                ad.a_rep()
                n.write()
            if action == '3':
                ad.a_suit()
                n.write()
            if action == '4':
                ad.true_res_tik()
                n.write()
            if action == '5':
                enter()
            new = input('Хотите выполнить другое действие? (Да/Нет) ')
            if new == 'Да' or new == 'да':
                pass
            if new == 'Нет' or new == 'нет':
                act = False
예제 #15
0
 def write(self):
     body = "".join([data.write() for data in self.data_fields])
     header = Formats.Data_Header
     footer = Formats.Data_Footer
     return "".join([header, body, footer])
예제 #16
0
            prediction = model(in_data)
            torch.cuda.synchronize()
            end = time.time()
            times.append(end - start)
            # store video frame(s)
            x = in_data[:, data.N_FRAMES, 0:3, :, :] if 'reproj' in args.type else in_data[:, 0:3, :, :]
            p = prediction[:, 0:3, :, :]
            y = target[:, 0:3, :, :]
            # postprocess
            frame = (torch.sqrt(torch.clamp(torch.cat((x, p, y), dim=-1), 0, 1)) * 255).to(torch.uint8)
            frame = frame.transpose_(-3, -1).transpose_(-3, -2)
            video[args.batch_size*idx:args.batch_size*idx+p.size(0)] = frame.cpu().numpy()
            # write images to disk?
            if args.images:
                img = torch.cat((x, p, y), dim=-1) if args.cmp else p
                data.write([f'{name}/{name}_{args.batch_size*idx+j:06}.{args.format}' for j in range(frame.size(0))], img.cpu().numpy())
            tq.update(args.batch_size)
        tq.close()

    print(f'avg inference time (in s):', np.array(times).mean(), 'std:', np.array(times).std())

    # write video
    ffmpeg = imageio_ffmpeg.write_frames(f'{name}/{name}.mp4', (3*sample.shape[-1], sample.shape[-2]), fps=args.fps, quality=5)
    ffmpeg.send(None) # seed
    ffmpeg.send(video)
    ffmpeg.close()
    print(f'{name}/{name}.mp4 written.')
    # make sure images were written
    data.pool.close()
    data.pool.join()
예제 #17
0
def execute():#执行一个clock周期中每一阶段的语句
    global ret_pc
    global jmp_pc
    global call_pc
    global pred_pc
    global w_icode
    global w_valE
    global w_valM
    global w_dstE
    global w_dstM
    global m_icode
    global m_valE
    global m_valM
    global m_dstE
    global m_dstM
    global e_icode
    global e_bch
    global e_valE
    global e_valM
    global e_dstE
    global e_dstM
    global d_icode
    global d_ifunc
    global d_valC
    global d_valA
    global d_valB
    global d_dstE
    global d_dstM
    global d_srcA
    global d_srcB
    global f_icode
    global f_ifunc
    global f_ra
    global f_rb
    global f_valC
    global f_valP
    global total_cycle
    global valid_cycle
    while(data.isend()==False):#如果程序的结束状态为假,继续执行
        #data.show()
        #global clocknum
        #clocknum+=1
        #print("CLOCK_NO:%d" %(clocknum))
        #PipeClock.PipeClock();
        ret_pc=""
        jmp_pc=""
        call_pc=""
        pred_pc=""
    
        valid_cycle=data.intread("valid_cycle")
        total_cycle=data.intread("total_cycle")
        total_cycle+=1
        #print("CLOCK-------------------------------")
#WriteBack---------------------------------
        #print("writeback:")
        w_icode=data.read("W_icode")#从外部寄存器读入信号
        w_valE=data.read("W_valE")
        w_valM=data.read("W_valM")
        w_dstE=data.read("W_dstE")
        w_dstM=data.read("W_dstM")
    
        if(w_icode=="0"):#nop
            nothing()
        elif(w_icode=="1"):#halt  如果halt阶段执行完writeback阶段,程序就结束了,并且强行清空之前的4个阶段
            data.write("M_index","X")
            data.write("M_icode","0")
            data.write("E_index","X")
            data.write("E_icode","0")
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("pc","X")
            data.write("F_icode","0")
            data.setend()
        elif(w_icode=="2"):#rrmovl
            data.RegWrite(w_dstE,w_valE)
        elif(w_icode=="3"):#irmovl
            data.RegWrite(w_dstE,w_valE)
        elif(w_icode=="4"):#rmmovl
            nothing()
        elif(w_icode=="5"):#mrmovl
            data.RegWrite(w_dstE,w_valM)
        elif(w_icode=="6"):#op
            data.RegWrite(w_dstE,w_valE)
        elif(w_icode=="7"):#jmp
            nothing()
        elif(w_icode=="8"):#call
            data.RegWrite("4",w_valE)
        elif(w_icode=="9"):#ret
            data.RegWrite("4",w_valE)
        elif(w_icode=="a"):#push
            data.RegWrite("4",w_valE)
        elif(w_icode=="b"):#popl
            data.RegWrite("4",w_valE)
            data.RegWrite(w_dstE,w_valM)
        elif(w_icode=="c"):#iaddl
            data.RegWrite(w_dstE,w_valE)
        elif(w_icode=="d"):#leave
            data.RegWrite("4",w_valE)
            data.RegWrite("5",w_valM)

        if(w_icode=="0"):
            nothing()
        else:
            valid_cycle+=1
#Memory--------------------------------------
        #print("Memory:")
    
        m_icode=""
        m_valE=""
        m_valM=""
        m_dstE=""
        m_dstM=""

        m_icode=data.read("M_icode")#从外部读入信号
        m_valE=data.read("M_valE")
        m_valM=data.read("M_valM")
        m_dstE=data.read("M_dstE")
        m_dstM=data.read("M_dstM")
    
        if(m_icode=="0"):#nop
            m_valE=""
            m_valM=""
            m_dstE=""
            m_dstM=""
        elif(m_icode=="1"):#halt 一旦halt出现就要强行结束之前的3个阶段
            data.write("E_index","X")
            data.write("E_icode","0")
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("pc","X")
            data.write("F_icode","0")
        elif(m_icode=="2"):#rrmovl
            nothing()
        elif(m_icode=="3"):#irmovl
            nothing()
        elif(m_icode=="4"):#rmmovl
            data.MemoryWrite(m_dstM,m_valM)
        elif(m_icode=="5"):#mrmovl
            m_valM=data.MemoryRead(m_dstM)
        elif(m_icode=="6"):#op
            nothing()
        elif(m_icode=="7"):#jmp
            nothing()
        elif(m_icode=="8"):#call
            data.MemoryWrite(m_valE,m_valM)
        elif(m_icode=="9"):#ret ret阶段也要清空之前的所有阶段,直到下一步的指令明确
            m_valM=data.MemoryRead(m_dstM)
            ret_pc=arc(m_valM)# 从内存中读取出来的pc,用于更新pred_pc
            data.write("E_index","X")
            data.write("E_icode","0")
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("pc","X")
            data.write("F_icode","0")
        elif(m_icode=="a"):#push
            data.MemoryWrite(m_valE,m_valM)
        elif(m_icode=="b"):#pop
            m_valM=data.MemoryRead(m_dstM)
        elif(m_icode=="c"):#iaddl
            nothing()
        elif(m_icode=="d"):#leave
            m_valM=data.MemoryRead(m_dstM)
    
        data.write("W_index",data.read("M_index"))
    
        data.write("W_icode",m_icode)#将信号写入下一阶段
        data.write("W_valE",m_valE)
        data.write("W_valM",m_valM)
        data.write("W_dstE",m_dstE)
        data.write("W_dstM",m_dstM)
#Execute----------------------------------------------
        #print("Execute:")

        e_icode=""
        e_bch=""
        e_valE=""
        e_valM=""
        e_dstE=""
        e_dstM=""

        e_icode=data.read("E_icode")#从外部读入信号
        e_ifunc=data.read("E_ifunc")
        e_valC=data.read("E_valC")
        e_valA=data.read("E_valA")
        e_valB=data.read("E_valB")
        e_dstE=data.read("E_dstE")
        e_dstM=data.read("E_dstM")
        srcA=data.read("srcA")
        srcB=data.read("srcB")

        if(e_icode=="0"):#nop
            nothing()
            e_bch=""
            e_valE=""
            e_valM=""
            e_dstE=""
            e_dstM=""
        elif(e_icode=="1"):#halt 清空之前所有阶段
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("pc","X")
            data.write("F_icode","0")
        elif(e_icode=="2"):#rrmovl
            e_valE=e_valA
        elif(e_icode=="3"):#irmovl
            e_valE=e_valC
        elif(e_icode=="4"):#rmmovl
            aluA=e_valB
            aluB=e_valC
            e_dstM=data.alu("0",aluA,aluB)
            e_valM=e_valA
        elif(e_icode=="5"):#mrmovl
            aluA=e_valB
            aluB=e_valC
            e_dstM=data.alu("0",aluA,aluB)
            e_dstE=srcA
        elif(e_icode=="6"):#op
            aluA=e_valA
            aluB=e_valB
            e_valE=data.alu(e_ifunc,aluA,aluB)
            e_dstE=srcB
        elif(e_icode=="7"):#jmp
            if(data.check(e_ifunc)):#根据CF,SF,OF,ZF判断是否跳转
                data.write("D_index","X")
                data.write("D_icode","0")
                data.write("pc","X")
                data.write("F_icode","0")
                jmp_pc=arc(e_valC)#如果要改变当前流程的话,记录对应的pc值
                e_bch=jmp_pc
        elif(e_icode=="8"):#call
            e_valM=e_valB#将返回地址存入栈中
            aluA=e_valA
            aluB="04000000"
            e_valE=data.alu("1",aluB,aluA)
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("pc","X")
            data.write("F_icode","0")
            call_pc=arc(e_valC)        
            e_bch=call_pc    
        elif(e_icode=="9"):#ret
            aluA=e_valA
            aluB="04000000"
            e_valE=data.alu("0",aluA,aluB)
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("pc","X")
            data.write("F_icode","0")
            e_dstM=e_valA
        elif(e_icode=="a"):#push
            aluA=e_valB
            aluB="04000000"
            e_valE=data.alu("1",aluB,aluA)
            e_valM=e_valA
        elif(e_icode=="b"):#popl
            aluA=e_valB
            aluB="04000000"
            e_valE=data.alu("0",aluA,aluB)
            e_dstM=e_valB
            e_dstE=srcA
        elif(e_icode=="c"):#iaddl
            aluA=e_valA
            aluB=e_valC
            e_valE=data.alu("0",aluA,aluB)
            e_dstE=srcA
        elif(e_icode=="d"):#leave
            aluA=e_valA
            aluB="04000000"
            e_valE=data.alu("0",aluB,aluA)
            e_dstM=e_valA
            e_dstE="4"
        data.write("M_index",data.read("E_index"))

        data.write("M_icode",e_icode)#把信号写入到下一阶段
        data.write("bch",e_bch)
        data.write("M_valE",e_valE)
        data.write("M_valM",e_valM)
        data.write("M_dstE",e_dstE)
        data.write("M_dstM",e_dstM)
#Decode----------------------------------
        #print("Decode:")

        d_icode=""
        d_ifunc=""
        d_valC=""
        d_valA=""
        d_valB=""
        d_dstE=""
        d_dstM=""
        d_srcA=""
        d_srcB=""
    
        d_icode=data.read("D_icode")#从外部读入信号
        d_ifunc=data.read("D_ifunc")
        ra=data.read("rA")
        rb=data.read("rB")
        d_valC=data.read("D_valC")
        d_valP=data.read("D_valP")

        if(d_icode=="0"):#nop
            nothing()
            d_ifunc=""
            d_valC=""
            d_valA=""
            d_valB=""
            d_dstE=""
            d_dstM=""
            d_srcA=""
            d_srcB=""
        elif(d_icode=="1"):#halt
            nothing()
        elif(d_icode=="2"):#rrmovl
            Temp=forwarding(ra)#判断是否存在加载使用冒险
            if(Temp=="X"):
                data.setstall()#存在就暂停
            else:
                d_valA=Temp#否则取得forwarding的值
            d_dstE=rb
            d_srcA=ra
            d_srcB=rb
        elif(d_icode=="3"):#irmovl
            d_valA=d_valC
            d_dstE=rb
        elif(d_icode=="4"):#rmmovl-------------------------------------------------------------
            Temp=forwarding(ra)#判断要读取的寄存器a是否存在冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            Temp=forwarding(rb)#判断要读取的寄存器b是否存在冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valB=Temp
            d_srcA=ra
            d_srcB=rb
        elif(d_icode=="5"):#mrmovl-------------------------------------------------------
            Temp=forwarding(rb)#判断寄存器b是否存在冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valB=Temp
            d_dstE=ra
            d_srcA=ra
            d_srcB=rb
        elif(d_icode=="6"):#op------------------------------------------------------------------------
            Temp=forwarding(ra)#判断寄存器a是否存在冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            Temp=forwarding(rb)#判断寄存器b是否存在冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valB=Temp
            d_srcA=ra
            d_srcB=rb
            d_dstE=rb
        elif(d_icode=="7"):#jmp----------------------
            nothing()
        elif(d_icode=="8"):#call---------------------
            Temp=forwarding("4")#特别要注意的是call隐式调用了esp,需要判断是否冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            d_valB=d_valP
            d_srcA="4"
            d_dstE="4"
        elif(d_icode=="9"):#ret--------------------------------------
            Temp=forwarding("4")#ret 调用了esp,需要判断冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            d_dstE="4"
            d_srcA="4"
        elif(d_icode=="a"):#push-------------------------------------
            Temp=forwarding(ra)#push 同时调用了esp ebp需要同时判断冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            Temp=forwarding("4")
            if(Temp=="X"):
                data.setstall()
            else:
                d_valB=Temp
            d_srcA=ra
            d_srcB="4"
            d_dstE="4"
        elif(d_icode=="b"):#popl---------------------------------------------------------------
            Temp=forwarding("4")#pop 调用了esp,需要判断冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valB=Temp
            d_dstE=ra
            d_srcA=ra
            d_srcB="4"
        elif(d_icode=="c"):#iaddl-------------------------------------------------------------
            Temp=forwarding(ra)#判断iaddl的寄存器冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            d_valB=d_valC
            d_dstE=ra
            d_srcA=ra
        elif(d_icode=="d"):#leave------------------------------------------------------------
            Temp=forwarding("5")#leave要读取ebp,需要判断冒险
            if(Temp=="X"):
                data.setstall()
            else:
                d_valA=Temp
            d_dstE="4"
            d_dstM="5"
            d_srcA="5"

        if(data.isstall()):#如果说cycle中的decode和fetch处于暂停状态的话,在下一个Execute阶段需要插入一个bubble
            data.write("E_icode","0")
            data.write("E_index","X")
        else:#其他情况下,正常复制信号到外部寄存器
            data.write("E_index",data.read("D_index"))
    
            data.write("E_icode",d_icode)
            data.write("E_ifunc",d_ifunc)
            data.write("E_valC",d_valC)
            data.write("E_valA",d_valA)
            data.write("E_valB",d_valB)
            data.write("E_dstE",d_dstE)
            data.write("E_dstM",d_dstM)
            data.write("srcA",d_srcA)
            data.write("srcB",d_srcB)
#Fetch---------------------------------------------
        #print("Fetch:")
    
        f_icode=""
        f_ifunc=""
        f_ra=""
        f_rb=""
        f_valC=""
        f_valP=""
    
        f_icode=data.read("F_icode")#从外部寄存器读入信号
        pc=data.read("pc")    
    
        if(pc=="X"):#如果Fetch阶段因为stall不能取指,那么Fetch阶段本次不执行,但是需要将stall的一回合锁定取消,以保证下次能取指
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("F_icode","1")
            f_ifunc=""
            f_ra=""
            f_rb=""
            f_valC=""
            f_valP=""
            data.write("D_ifunc",f_ifunc)
            data.write("rA",f_ra)
            data.write("rB",f_rb)
            data.write("D_valC",f_valC)
            data.write("D_valP",f_valP)
        elif(f_icode=="0"):#如果Fetch阶段是因为ret和jXX被清零,那么同样恢复合法状态,保证下次能取指
            data.write("D_index","X")
            data.write("D_icode","0")
            data.write("F_icode","1")
            f_ifunc=""
            f_ra=""
            f_rb=""
            f_valC=""
            f_valP=""
            data.write("D_ifunc",f_ifunc)
            data.write("rA",f_ra)
            data.write("rB",f_rb)
            data.write("D_valC",f_valC)
            data.write("D_valP",f_valP)
        else:#如果就是合法,那么就根据内容正常取指
            pred_pc=data.next(pc)
            s=data.MemoryGet(pc)
                    
            if(s[0]=="0"):#nop
                nothing()
            if(s[0]=="1"):#halt
                nothing()
            if(s[0]=="2"):#rrmovl
                f_ra=s[2]
                f_rb=s[3]
            if(s[0]=="3"):#irmovl
                f_rb=s[3]
                f_valC=s[4:12]
            if(s[0]=="4"):#rmmovl
                f_ra=s[2]
                f_rb=s[3]
                f_valC=s[4:12]
            if(s[0]=="5"):#mrmovl
                f_ra=s[2]
                f_rb=s[3]
                f_valC=s[4:12]
            if(s[0]=="6"):#op
                f_ra=s[2]
                f_rb=s[3]
            if(s[0]=="7"):#jmp
                f_valC=s[2:10]
            if(s[0]=="8"):#call
                f_valC=s[2:10]
                f_ra="4"
            if(s[0]=="9"):#ret
                f_ra="4"
                nothing()
            if(s[0]=="a"):#push
                f_ra=s[2] 
                f_rb="4"
            if(s[0]=="b"):#pop
                f_ra=s[2]
                f_rb="4"
            if(s[0]=="c"):#iaddl
                f_ra=s[3]
                f_valC=s[4:12]
            if(s[0]=="d"):#leave
                f_ra="5"

        
            f_icode=s[0]
            f_ifunc=s[1]
            
            if(data.isstall()):
                nothing()
            else:#不暂停的合法状态下,将信号写入下一个Decode阶段
                data.write("D_index",pc)
                data.write("D_icode",f_icode)
                data.write("D_ifunc",f_ifunc)
                data.write("rA",f_ra)
                data.write("rB",f_rb)
                data.write("D_valC",f_valC)
                if(pred_pc[0]!="X"):
                    data.write("D_valP",arc(pred_pc))
                else:
                    data.write("D_valP","X")
#PC------------------------------------
        data.intwrite("total_cycle",total_cycle)#将总周期数写入外部
        data.intwrite("valid_cycle",valid_cycle)#将实际执行的周期数写入外部
        #print("PC:")
        if(data.isstall()):
            data.start()
            return 0

        if(ret_pc!=""):#判断下一个pc应该取什么值
            data.write("pc",ret_pc)#有ret先取ret_pc
        elif(call_pc!=""):
            data.write("pc",call_pc)#有call,取call_pc
        elif(jmp_pc!=""):
            data.write("pc",jmp_pc)#有jXX,取jmp_pc
        elif(pred_pc!=""):
            data.write("pc",pred_pc)#都没有的情况下取得下一个pc
        return 0
예제 #18
0
def execute():
    global ret_pc
    global jmp_pc
    global call_pc
    global pred_pc
    global w_icode
    global w_valE
    global w_valM
    global w_dstE
    global w_dstM
    global m_icode
    global m_valE
    global m_valM
    global m_dstE
    global m_dstM
    global e_icode
    global e_bch
    global e_valE
    global e_valM
    global e_dstE
    global e_dstM
    global d_icode
    global d_ifunc
    global d_valC
    global d_valA
    global d_valB
    global d_dstE
    global d_dstM
    global d_srcA
    global d_srcB
    global f_icode
    global f_ifunc
    global f_ra
    global f_rb
    global f_valC
    global f_valP
    while (data.isend() == False):
        data.show()
        global clocknum
        clocknum += 1
        print("CLOCK_NO:%d" % (clocknum))
        PipeClock.PipeClock()
        ret_pc = ""
        jmp_pc = ""
        call_pc = ""
        pred_pc = ""

        #print("CLOCK-------------------------------")
        #WriteBack---------------------------------
        #print("writeback:")
        w_icode = data.read("W_icode")
        w_valE = data.read("W_valE")
        w_valM = data.read("W_valM")
        w_dstE = data.read("W_dstE")
        w_dstM = data.read("W_dstM")

        if (w_icode == "0"):  #nop
            nothing()
        elif (w_icode == "1"):  #halt
            data.write("M_index", "X")
            data.write("M_icode", "0")
            data.write("E_index", "X")
            data.write("E_icode", "0")
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
            data.setend()
        elif (w_icode == "2"):  #rrmovl
            data.RegWrite(w_dstE, w_valE)
        elif (w_icode == "3"):  #irmovl
            data.RegWrite(w_dstE, w_valE)
        elif (w_icode == "4"):  #rmmovl
            nothing()
        elif (w_icode == "5"):  #mrmovl
            data.RegWrite(w_dstE, w_valM)
        elif (w_icode == "6"):  #op
            data.RegWrite(w_dstE, w_valE)
        elif (w_icode == "7"):  #jmp
            nothing()
        elif (w_icode == "8"):  #call
            data.RegWrite("4", w_valE)
        elif (w_icode == "9"):  #ret
            data.RegWrite("4", w_valE)
        elif (w_icode == "a"):  #push
            data.RegWrite("4", w_valE)
        elif (w_icode == "b"):  #popl
            data.RegWrite("4", w_valE)
            data.RegWrite(w_dstE, w_valM)
#Memory--------------------------------------
#print("Memory:")

        m_icode = ""
        m_valE = ""
        m_valM = ""
        m_dstE = ""
        m_dstM = ""

        m_icode = data.read("M_icode")
        m_valE = data.read("M_valE")
        m_valM = data.read("M_valM")
        m_dstE = data.read("M_dstE")
        m_dstM = data.read("M_dstM")

        if (m_icode == "0"):  #nop
            nothing()
            m_valE = ""
            m_valM = ""
            m_dstE = ""
            m_dstM = ""
        elif (m_icode == "1"):  #halt
            data.write("E_index", "X")
            data.write("E_icode", "0")
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
        elif (m_icode == "2"):  #rrmovl
            nothing()
        elif (m_icode == "3"):  #irmovl
            nothing()
        elif (m_icode == "4"):  #rmmovl
            data.MemoryWrite(m_dstM, m_valM)
        elif (m_icode == "5"):  #mrmovl
            m_valM = data.MemoryRead(m_dstM)
        elif (m_icode == "6"):  #op
            nothing()
        elif (m_icode == "7"):  #jmp
            nothing()
        elif (m_icode == "8"):  #call
            data.MemoryWrite(m_valE, m_valM)
        elif (m_icode == "9"):  #ret
            m_valM = data.MemoryRead(m_dstM)
            ret_pc = arc(m_valM)
            data.write("E_index", "X")
            data.write("E_icode", "0")
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
        elif (m_icode == "a"):  #push
            data.MemoryWrite(m_valE, m_valM)
        elif (m_icode == "b"):  #pop
            m_valM = data.MemoryRead(m_dstM)

        data.write("W_index", data.read("M_index"))

        data.write("W_icode", m_icode)
        data.write("W_valE", m_valE)
        data.write("W_valM", m_valM)
        data.write("W_dstE", m_dstE)
        data.write("W_dstM", m_dstM)
        #Execute----------------------------------------------
        #print("Execute:")

        e_icode = ""
        e_bch = ""
        e_valE = ""
        e_valM = ""
        e_dstE = ""
        e_dstM = ""

        e_icode = data.read("E_icode")
        e_ifunc = data.read("E_ifunc")
        e_valC = data.read("E_valC")
        e_valA = data.read("E_valA")
        e_valB = data.read("E_valB")
        e_dstE = data.read("E_dstE")
        e_dstM = data.read("E_dstM")
        srcA = data.read("srcA")
        srcB = data.read("srcB")

        if (e_icode == "0"):  #nop
            nothing()
            e_bch = ""
            e_valE = ""
            e_valM = ""
            e_dstE = ""
            e_dstM = ""
        elif (e_icode == "1"):  #halt
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
        elif (e_icode == "2"):  #rrmovl
            e_valE = e_valA
        elif (e_icode == "3"):  #irmovl
            e_valE = e_valC
        elif (e_icode == "4"):  #rmmovl
            aluA = e_valB
            aluB = e_valC
            e_dstM = data.alu("0", aluA, aluB)
            e_valM = e_valA
        elif (e_icode == "5"):  #mrmovl
            aluA = e_valB
            aluB = e_valC
            e_dstM = data.alu("0", aluA, aluB)
            e_dstE = srcA
        elif (e_icode == "6"):  #op
            aluA = e_valA
            aluB = e_valB
            e_valE = data.alu(e_ifunc, aluA, aluB)
            e_dstE = srcB
        elif (e_icode == "7"):  #jmp
            if (data.check(e_ifunc)):
                data.write("D_index", "X")
                data.write("D_icode", "0")
                data.write("pc", "X")
                data.write("F_icode", "0")
                jmp_pc = arc(e_valC)
                e_bch = jmp_pc
        elif (e_icode == "8"):  #call
            e_valM = e_valB
            aluA = e_valA
            aluB = "04000000"
            e_valE = data.alu("1", aluB, aluA)
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
            call_pc = arc(e_valC)
            e_bch = call_pc
        elif (e_icode == "9"):  #ret
            aluA = e_valA
            aluB = "04000000"
            e_valE = data.alu("0", aluA, aluB)
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("pc", "X")
            data.write("F_icode", "0")
            e_dstM = e_valA
        elif (e_icode == "a"):  #push
            aluA = e_valB
            aluB = "04000000"
            e_valE = data.alu("1", aluB, aluA)
            e_valM = e_valA
        elif (e_icode == "b"):  #popl
            aluA = e_valB
            aluB = "04000000"
            e_valE = data.alu("0", aluA, aluB)
            e_dstM = e_valB
            e_dstE = srcA

        data.write("M_index", data.read("E_index"))

        data.write("M_icode", e_icode)
        data.write("bch", e_bch)
        data.write("M_valE", e_valE)
        data.write("M_valM", e_valM)
        data.write("M_dstE", e_dstE)
        data.write("M_dstM", e_dstM)
        #Decode----------------------------------
        #print("Decode:")

        d_icode = ""
        d_ifunc = ""
        d_valC = ""
        d_valA = ""
        d_valB = ""
        d_dstE = ""
        d_dstM = ""
        d_srcA = ""
        d_srcB = ""

        d_icode = data.read("D_icode")
        d_ifunc = data.read("D_ifunc")
        ra = data.read("rA")
        rb = data.read("rB")
        d_valC = data.read("D_valC")
        d_valP = data.read("D_valP")

        if (d_icode == "0"):  #nop
            nothing()
            d_ifunc = ""
            d_valC = ""
            d_valA = ""
            d_valB = ""
            d_dstE = ""
            d_dstM = ""
            d_srcA = ""
            d_srcB = ""
        elif (d_icode == "1"):  #halt
            nothing()
        elif (d_icode == "2"):  #rrmovl
            Temp = forwarding(ra)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valA = Temp
            d_dstE = rb
            d_srcA = ra
            d_srcB = rb
        elif (d_icode == "3"):  #irmovl
            d_valA = d_valC
            d_dstE = rb
        elif (
                d_icode == "4"
        ):  #rmmovl-------------------------------------------------------------
            Temp = forwarding(ra)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valA = Temp
            Temp = forwarding(rb)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valB = Temp
            d_srcA = ra
            d_srcB = rb
        elif (
                d_icode == "5"
        ):  #mrmovl-------------------------------------------------------
            Temp = forwarding(rb)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valB = Temp
            d_dstE = ra
            d_srcA = ra
            d_srcB = rb
        elif (
                d_icode == "6"
        ):  #op------------------------------------------------------------------------
            Temp = forwarding(ra)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valA = Temp
            Temp = forwarding(rb)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valB = Temp
            d_srcA = ra
            d_srcB = rb
            d_dstE = rb
        elif (d_icode == "7"):  #jmp----------------------
            nothing()
        elif (d_icode == "8"):  #call---------------------
            Temp = forwarding("4")
            if (Temp == "X"):
                data.setstall()
            else:
                d_valA = Temp
            d_valB = d_valP
            d_srcA = "4"
            d_dstE = "4"
        elif (d_icode == "9"):  #ret--------------------------------------
            Temp = forwarding("4")
            if (Temp == "X"):
                data.setstall()
            else:
                d_valA = Temp
            d_dstE = "4"
            d_srcA = "4"
        elif (d_icode == "a"):  #push-------------------------------------
            Temp = forwarding(ra)
            if (Temp == "X"):
                data.setstall()
            else:
                d_valA = Temp
            Temp = forwarding("4")
            if (Temp == "X"):
                data.setstall()
            else:
                d_valB = Temp
            d_srcA = ra
            d_srcB = "4"
            d_dstE = "4"
        elif (
                d_icode == "b"
        ):  #popl---------------------------------------------------------------
            Temp = forwarding("4")
            if (Temp == "4"):
                data.setstall()
            else:
                d_valB = Temp
            d_dstE = ra
            d_srcA = ra
            d_srcB = "4"

        if (data.isstall()):
            data.write("E_icode", "0")
            data.write("E_index", "X")
        else:
            data.write("E_index", data.read("D_index"))

            data.write("E_icode", d_icode)
            data.write("E_ifunc", d_ifunc)
            data.write("E_valC", d_valC)
            data.write("E_valA", d_valA)
            data.write("E_valB", d_valB)
            data.write("E_dstE", d_dstE)
            data.write("E_dstM", d_dstM)
            data.write("srcA", d_srcA)
            data.write("srcB", d_srcB)
#Fetch---------------------------------------------
#print("Fetch:")

        f_icode = ""
        f_ifunc = ""
        f_ra = ""
        f_rb = ""
        f_valC = ""
        f_valP = ""

        f_icode = data.read("F_icode")
        pc = data.read("pc")

        if (pc == "X"):
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("F_icode", "1")
            f_ifunc = ""
            f_ra = ""
            f_rb = ""
            f_valC = ""
            f_valP = ""
            data.write("D_ifunc", f_ifunc)
            data.write("rA", f_ra)
            data.write("rB", f_rb)
            data.write("D_valC", f_valC)
            data.write("D_valP", f_valP)
        elif (f_icode == "0"):
            data.write("D_index", "X")
            data.write("D_icode", "0")
            data.write("F_icode", "1")
            f_ifunc = ""
            f_ra = ""
            f_rb = ""
            f_valC = ""
            f_valP = ""
            data.write("D_ifunc", f_ifunc)
            data.write("rA", f_ra)
            data.write("rB", f_rb)
            data.write("D_valC", f_valC)
            data.write("D_valP", f_valP)
        elif (data.isstall()):
            nothing()
        else:
            pred_pc = data.next(pc)
            s = data.MemoryGet(pc)

            if (s[0] == "0"):  #nop
                nothing()
            if (s[0] == "1"):  #halt
                nothing()
            if (s[0] == "2"):  #rrmovl
                f_ra = s[2]
                f_rb = s[3]
            if (s[0] == "3"):  #irmovl
                f_rb = s[3]
                f_valC = s[4:12]
            if (s[0] == "4"):  #rmmovl
                f_ra = s[2]
                f_rb = s[3]
                f_valC = s[4:12]
            if (s[0] == "5"):  #mrmovl
                f_ra = s[2]
                f_rb = s[3]
                f_valC = s[4:12]
            if (s[0] == "6"):  #op
                f_ra = s[2]
                f_rb = s[3]
            if (s[0] == "7"):  #jmp
                f_valC = s[2:10]
            if (s[0] == "8"):  #call
                f_valC = s[2:10]
                f_ra = "4"
            if (s[0] == "9"):  #ret
                f_ra = "4"
                nothing()
            if (s[0] == "a"):  #push
                f_ra = s[2]
                f_rb = "4"
            if (s[0] == "b"):  #pop
                f_ra = s[2]
                f_rb = "4"

            f_icode = s[0]
            f_ifunc = s[1]

            if (data.isstall()):
                nothing()
            else:
                data.write("D_index", pc)
                data.write("D_icode", f_icode)
                data.write("D_ifunc", f_ifunc)
                data.write("rA", f_ra)
                data.write("rB", f_rb)
                data.write("D_valC", f_valC)
                if (pred_pc[0] != "X"):
                    data.write("D_valP", arc(pred_pc))
                else:
                    data.write("D_valP", "X")


#PC------------------------------------
#print("PC:")
        if (data.isstall()):
            data.start()
            return 0

        if (ret_pc != ""):
            data.write("pc", ret_pc)
        elif (call_pc != ""):
            data.write("pc", call_pc)
        elif (jmp_pc != ""):
            data.write("pc", jmp_pc)
        elif (pred_pc != ""):
            data.write("pc", pred_pc)
        return 0
예제 #19
0
            return float(s) if '.' in s else int(s)
        except ValueError:
            return s

    p_kwargs = {}
    if args.parser_kwarg:
        for item in args.parser_kwarg:
            kw, val = item.split('=')
            p_kwargs[kw] = cast_if_number(val)
    log.debug(p_kwargs)

    w_kwargs = {}
    if args.writer_kwarg:
        for item in args.writer_kwarg:
            kw, val = item.split('=')
            w_kwargs[kw] = cast_if_number(val)
    log.debug(w_kwargs)

    ds = data.parse(args.input,
                    load_data=True,
                    ignore_json=args.ignore_json,
                    filetype=args.parser,
                    **p_kwargs)

    if not ds:
        raise DataError('%s could not be parsed' % args.input)
    if ds.data is None:
        raise DataError('%s has no data' % args.input)

    data.write(ds, ds.data, outbase, filetype=args.writer, **w_kwargs)
예제 #20
0
#!/usr/bin/env python3.6

from data import write

if __name__ == '__main__':
    write()

예제 #21
0
파일: data.py 프로젝트: garikoitz/data
    outbase = args.outbase or os.path.basename(os.path.splitext(args.input.rstrip('/'))[0])

    def cast_if_number(s):
        try:
            return float(s) if '.' in s else int(s)
        except ValueError:
            return s

    p_kwargs = {}
    if args.parser_kwarg:
        for item in args.parser_kwarg:
            kw, val = item.split('=')
            p_kwargs[kw] = cast_if_number(val)
    log.debug(p_kwargs)

    w_kwargs = {}
    if args.writer_kwarg:
        for item in args.writer_kwarg:
            kw, val = item.split('=')
            w_kwargs[kw] = cast_if_number(val)
    log.debug(w_kwargs)

    ds = data.parse(args.input, load_data=True, ignore_json=args.ignore_json, filetype=args.parser, **p_kwargs)

    if not ds:
        raise DataError('%s could not be parsed' % args.input)
    if ds.data is None:
        raise DataError('%s has no data' % args.input)

    data.write(ds, ds.data, outbase, filetype=args.writer, **w_kwargs)
예제 #22
0
def setY86(register, memory):
    data.write("CF", register["CF"])
    data.write("OF", register["OF"])
    data.write("ZF", register["ZF"])
    data.write("SF", register["SF"])

    data.write("stall", register["stall"])
    data.write("end", register["end"])

    data.write("pc", register["pc"])
    data.write("F_icode", register["F_icode"])

    data.write("D_index", register["D_index"])
    data.write("D_icode", register["D_icode"])
    data.write("D_ifunc", register["D_ifunc"])
    data.write("rA", register["rA"])
    data.write("rB", register["rB"])
    data.write("D_valC", register["D_valC"])
    data.write("D_valP", register["D_valP"])

    data.write("E_index", register["E_index"])
    data.write("E_icode", register["E_icode"])
    data.write("E_ifunc", register["E_ifunc"])
    data.write("E_valC", register["E_valC"])
    data.write("E_valA", register["E_valA"])
    data.write("E_valB", register["E_valB"])
    data.write("E_dstE", register["E_dstE"])
    data.write("E_dstM", register["E_dstM"])
    data.write("srcA", register["srcA"])
    data.write("srcB", register["srcB"])

    data.write("M_index", register["M_index"])
    data.write("M_icode", register["M_icode"])
    data.write("bch", register["bch"])
    data.write("M_valE", register["M_valE"])
    data.write("M_valM", register["M_valM"])
    data.write("M_dstE", register["M_dstE"])
    data.write("M_dstM", register["M_dstM"])

    data.write("W_index", register["W_index"])
    data.write("W_icode", register["W_icode"])
    data.write("W_valE", register["W_valE"])
    data.write("W_valM", register["W_valM"])
    data.write("W_dstE", register["W_dstE"])
    data.write("W_dstM", register["W_dstM"])

    data.RegWrite("0", register["eax"])
    data.RegWrite("1", register["ecx"])
    data.RegWrite("2", register["edx"])
    data.RegWrite("3", register["ebx"])
    data.RegWrite("4", register["esp"])
    data.RegWrite("5", register["ebp"])
    data.RegWrite("6", register["esi"])
    data.RegWrite("7", register["edi"])

    data.intwrite("total_cycle", register["total_cycle"])
    data.intwrite("valid_cycle", register["valid_cycle"])

    data.Memory = memory
예제 #23
0
def setY86(register,memory):
    data.write("CF",register["CF"])
    data.write("OF",register["OF"])
    data.write("ZF",register["ZF"])
    data.write("SF",register["SF"])

    data.write("stall",register["stall"])
    data.write("end",register["end"])

    data.write("pc",register["pc"])
    data.write("F_icode",register["F_icode"])

    data.write("D_index",register["D_index"])
    data.write("D_icode",register["D_icode"])
    data.write("D_ifunc",register["D_ifunc"])
    data.write("rA",register["rA"])
    data.write("rB",register["rB"])
    data.write("D_valC",register["D_valC"])
    data.write("D_valP",register["D_valP"])

    data.write("E_index",register["E_index"])
    data.write("E_icode",register["E_icode"])
    data.write("E_ifunc",register["E_ifunc"])
    data.write("E_valC",register["E_valC"])
    data.write("E_valA",register["E_valA"])
    data.write("E_valB",register["E_valB"])
    data.write("E_dstE",register["E_dstE"])
    data.write("E_dstM",register["E_dstM"])
    data.write("srcA",register["srcA"])
    data.write("srcB",register["srcB"])

    data.write("M_index",register["M_index"])
    data.write("M_icode",register["M_icode"])
    data.write("bch",register["bch"])
    data.write("M_valE",register["M_valE"])
    data.write("M_valM",register["M_valM"])
    data.write("M_dstE",register["M_dstE"])
    data.write("M_dstM",register["M_dstM"])

    data.write("W_index",register["W_index"])
    data.write("W_icode",register["W_icode"])
    data.write("W_valE",register["W_valE"])
    data.write("W_valM",register["W_valM"])
    data.write("W_dstE",register["W_dstE"])
    data.write("W_dstM",register["W_dstM"])
    
    data.RegWrite("0",register["eax"])
    data.RegWrite("1",register["ecx"])
    data.RegWrite("2",register["edx"])
    data.RegWrite("3",register["ebx"])
    data.RegWrite("4",register["esp"])
    data.RegWrite("5",register["ebp"])
    data.RegWrite("6",register["esi"])
    data.RegWrite("7",register["edi"])

    data.intwrite("total_cycle",register["total_cycle"])
    data.intwrite("valid_cycle",register["valid_cycle"])    

    data.Memory=memory
예제 #24
0
import data as csv

__version__ = "0.2"
callsign_endpoint = "http://hamcall.net/call?callsign="

print(f"AirLog Version: {__version__}")

questions = ["Callsign", "Name", "Location", "Comm type", "Notes", "signal ( x/10 )"]

data = {}

while 0 < len(questions):
	for question in questions:
		print(question + "?")
		answer = input(">")
		if len(answer) != 0:
			data[question] = answer
			questions.remove(question)

headings = csv.toHeadings(data)
csv.write(headings, data)