Ejemplo n.º 1
0
def get_top_var():
    """Find the top 100 variety keywords and return a list of strings"""
    in_file = open("ramen-ratings.csv", "r", encoding="utf-8")
    raw_vars = []
    for line in in_file:
        val = line.split(',')
        if len(val) < 3:
            continue

        varieties = val[2].split()

        for var in varieties:
            if len(raw_vars) == 0:
                temp_brand = count.Count(var)
                raw_vars.append(temp_brand)
            else:
                for item in raw_vars:
                    # If the var is already present, increase the count by 1
                    if var == item.name:
                        item.add_count()
                        break
                # If var hasn't been accounted for, add it
                temp_brand = count.Count(var)
                raw_vars.append(temp_brand)

    var_list = []
    for cnt in range(100):
        # Take the top 100 varieties and add them to the list
        temp_var = cnt_max(raw_vars)
        raw_vars.remove(temp_var)
        var_list.append(str(temp_var))

    in_file.close()
    return var_list
Ejemplo n.º 2
0
def get_major_brand():
    """Count each instance of a brand and return a list of major brands"""
    in_file = open("ramen-ratings.csv", "r", encoding="utf-8")
    brand_count = []
    for line in in_file:
        val = line.split(',')
        # Handle invalid lines
        if len(val) < 3:
            continue

        # Add the first value if the list is empty
        if len(brand_count) == 0:
            temp_brand = count.Count(val[1])
            brand_count.append(temp_brand)
        else:
            for item in brand_count:
                # If the brand is already present, increase the count by 1
                if val[1] == item.name:
                    item.add_count()
                    break

            # If brand hasn't been accounted for, add it
            temp_brand = count.Count(val[1])
            brand_count.append(temp_brand)

    # Create list of Brands with more than 1 occurrence
    major_brands = []
    for brand_object in brand_count:
        if brand_object.count > 1:
            major_brands.append(str(brand_object))

    in_file.close()
    return major_brands
Ejemplo n.º 3
0
def main():
    cnt = 1000
    play_model = model.model.PlayModel(filename="night_good.h5")
    led = drv.led.Led()
    camera = picamera.PiCamera()
    camera.resolution = (640, 480)
    stCnt = count.Count()
    for i in range(0, cnt):
        # led.setBlueOnTime(0.5)
        pic_fn = './pic/temp.jpg'
        camera.capture(pic_fn)
        start = datetime.datetime.now()
        predict = play_model.pred_pic(pic_fn)
        end = datetime.datetime.now()
        if predict > 0.5:
            stCnt.setState(True)
        else:
            stCnt.setState(False)
        if stCnt.getLastState() == True:
            led.setGreenOn()
        else:
            led.setRedOn()
        print("pridict is: 【%s】" % str(predict), end=", ")
        print("during is:%s" % str(end - start))
        print("Play second during sum is: %d(s)" % stCnt.getStateDuring(True))
        sleep(1)

    led.setAllOff()
Ejemplo n.º 4
0
    def __init__(self):
        c_pci_data_width = 128
        num_chnls = 3
        self.wordsize = 32
        self.ptrsize = 64
        combined_interface_tx = riffa.Interface(data_width=c_pci_data_width,
                                                num_chnls=num_chnls)
        combined_interface_rx = riffa.Interface(data_width=c_pci_data_width,
                                                num_chnls=num_chnls)

        # instantiate test "memory" module that responds to page fetch/writeback requests
        self.submodules.channelsplitter = riffa.ChannelSplitter(
            combined_interface_tx, combined_interface_rx)
        tx0, rx0 = self.channelsplitter.get_channel(0)
        tx1, rx1 = self.channelsplitter.get_channel(1)
        self.submodules.tbmem = TBMemory(tx0,
                                         rx0,
                                         tx1,
                                         rx1,
                                         c_pci_data_width=c_pci_data_width,
                                         init_fn=generate_data)

        # instantiate design under test
        self.submodules.dut = count.Count(
            combined_interface_rx=combined_interface_rx,
            combined_interface_tx=combined_interface_tx,
            c_pci_data_width=c_pci_data_width,
            wordsize=self.wordsize,
            ptrsize=self.ptrsize,
            drive_clocks=False)

        # channel to send args / receive results
        # remember rx/tx from FPGA side -> write to rx, read from tx
        self.tx, self.rx = self.channelsplitter.get_channel(2)
Ejemplo n.º 5
0
def cnt_max(in_list):
    """Returns a max from a list of count objects"""
    temp_max = count.Count("benchmark")
    for item in in_list:
        if item.count > temp_max.count:
            temp_max = item
    return temp_max
Ejemplo n.º 6
0
 def choosed(self):
     print(self.choicenum.get())
     if self.choicenum.get()==1:
         print('您选择了正向计时')
         self.root.destroy()
         self.count=count.Count()
     if self.choicenum.get()==2:
         print('您选择了倒计时')
         self.root.destroy()
         self.recount=reCount.Recount()
     if self.choicenum.get()==3:
         print('您选择了系统时间')
         self.root.destroy()
         self.show=show.Show()
Ejemplo n.º 7
0
import argparse

# Start a timer
start_time = time.time()

# Setup arguments of this code
parser = argparse.ArgumentParser(
    description=
    'Counting coloured areas in an image. The default shape is 256*256 and the default number of processes using is 2.'
)
parser.add_argument('file', type=str, help='Input a binary file')
parser.add_argument('--shape', type=str, help='Input height and width')
parser.add_argument('--process', type=int, help='Input number of processes')
parser.add_argument('--maxtask',
                    type=int,
                    help='Input maximum number of tasks for each process')
args = parser.parse_args()
c = count.Count()

# Print the amounts of coloured areas
if (args.shape):
    print(
        c.apply(args.file, int(args.shape.split(',')[0]),
                int(args.shape.split(',')[1]), args.process, args.maxtask))
else:
    print(c.apply(args.file, 256, 256, 1, 3))

# Stop and display the timer
elapsed_time = time.time() - start_time
print('Duration:', time.strftime("%H:%M:%S", time.gmtime(elapsed_time)))