Beispiel #1
0
 def Searching(self, food):
     if isinstance(food, list) == False:
         raise ParamError("Threads need a list.")
         return None
     con = threading.Condition()
     warp = []
     storage = []
     storage.append([])
     storage.append([])
     t1 = Thread(target=TianMaoReader.Reading,
                 args=(food[0], con, warp, storage[0]))
     t2 = Thread(target=TianMaoReader.Reading,
                 args=(food[1], con, warp, storage[1]))
     t1.run()
     t2.run()
     #Threads synchronization
     con.acquire()
     while warp.__len__() < 2:
         print(warp.__len__())
         con.wait()
     con.release()
     result = []
     for re in storage:
         for item in re:
             result.append(item)
     result.sort(key=lambda Store: Store.attr['score'], reverse=True)
     return result
Beispiel #2
0
 def __init__(self, this, attr):
     if isinstance(attr, dict) == False or ('no' in attr == False) or (
             'text' in attr == False) or (isinstance(this, int) == False):
         raise ParamError('Error Param for initializing Answer.')
     self.no = int(attr['no'])
     self.this = this
     self.next = int(attr['next'])
     self.text = attr['text']
Beispiel #3
0
    def __init__(self,name,nutrition):
        self.__error = False
        if(isinstance(nutrition, dict)== False):
            self.__error = True
            raise ParamError('Error Param for initializing Fruit.')
        self.attr = {'name':name,'nutrition': {}, 'score':0}
        #for i in nutrition.keys():
            #print(float(nutrition.get(i)))
            #if((isinstance(nutrition.get(i), float) == False) and (isinstance(nutrition.get(i), int) == False)):
            #    raise ParamError('Error Param('+str(nutrition.get(i))+str(type(nutrition.get(i)))+') for Fruit!('+i+')')

        self.attr['nutrition'] = nutrition
Beispiel #4
0
 def __init__(self, name, price, like, sale, food, url):
     self.error = False
     if (isinstance(name, str) == False):
         self.error = True
         raise ParamError('attribute \'name\' must be \'str\'!')
     if (isinstance(price, float) == False) and (isinstance(price, int)
                                                 == False):
         self.error = True
         raise ParamError(
             'attribute \'price\' must be \'float\' or \'int\'!')
     if (isinstance(like, int) == False):
         self.error = True
         raise ParamError('attribute \'like\' must be \'int\'!')
     if (isinstance(sale, int) == False):
         self.error = True
         raise ParamError('attribute \'sale\' must be \'int\'!')
     if (isinstance(food, Food) == False):
         self.error = True
         raise ParamError('attribute \'food\' must be \'Food\'!')
     if (isinstance(url, str) == False):
         self.error = True
         raise ParamError('attribute \'url\' must be \'str\'!')
     self.attr = {'name': name, 'Performance': {}, 'score': 0, 'url': url}
     self.attr['Performance'] = {'price': price, 'like': like, 'sale': sale}
     self.fruit = food
     # Assess the shop
     for i in self.attr['Performance'].keys():
         if (Store.weight.get(i) == None):
             print('Default value:', i)
             return
         self.attr['score'] += Store.weight.get(
             i) * self.attr['Performance'].get(i)
     if (self.fruit.attr['worked'] == False):
         print('Warning:This Store contains uninitialized data.')
     self.attr['score'] += self.fruit.attr['score']
Beispiel #5
0
 def Calculate(self, trend):
     if isinstance(trend, Trend) == False:
         raise ParamError("Error Param for Food::Calculate().")
     #Calculating the score each kind of fruit with collected trendency
     self.attr['score'] = 0
     for i in self.attr['nutrition'].keys():
         if (trend.weight.get(i) == None):
             raise BaseException('Default value:', i)
             self.attr['score'] = -9999
             return -9999
         self.attr['score'] += float(trend.weight.get(i)) * float(
             self.attr['nutrition'].get(i))
     self.attr['worked'] = True
     return self.attr['score']
Beispiel #6
0
 def __init__(self, no, text):
     if isinstance(no, int) == False or isinstance(text, str) == False:
         raise ParamError('Error Param for initializing Question.')
     self.no = no
     self.text = text