Ejemplo n.º 1
0
 def combine_duplicate_ingredients(self):
     ingredients_dict = {}
     for ingredient in self.ingredients:
         if ingredient in ingredients_dict:
             ingredients_dict[ingredient.name] += ingredient.amount.quantity
         else:
             ingredients_dict[ingredient.name] = ingredient.amount.quantity
     ingredient_arr = []
     for key in ingredients_dict:
         ingredient_arr.append(
             Ingredient(key, Amount(ingredients_dict[key], "oz")))
     self.ingredients = ingredient_arr
Ejemplo n.º 2
0
def read_files(folder):
    txt_files = glob.glob(folder + "/*.txt")
    return_recipes = []
    for i in range(len(txt_files)):
        with open(txt_files[i]) as f:
            temp = f.readlines()
            ingredient_temp = []
            for line in temp:
                line_split = line.split(" ", 2)
                line_split[2] = line_split[2][:-1]
                amount_temp = Amount(float(line_split[0]), line_split[1])
                ingredient_temp.append(Ingredient(line_split[2], amount_temp))
                inspiring_ingredients[line_split[
                    2]] = 1  #creating the inspiring set list of all possible ingredients
            recipe_temp = Recipe(ingredient_temp)
            recipe_temp.name_recipe()
            return_recipes.append(recipe_temp)
    return return_recipes
Ejemplo n.º 3
0
def add_ingredient(recipe):
    random_ingredient = random.choice(list(inspiring_ingredients))
    new_ingredient = Ingredient(random_ingredient,
                                Amount(rand.randint(1, 10), "oz"))
    recipe.add_elements_to_ingredients([new_ingredient])
    return recipe
Ejemplo n.º 4
0
from recipe import *
from Ingredient import *
txt_files = glob.glob("input/*.txt")

recipes = []

for i in range(len(txt_files)):
    with open(txt_files[i]) as f:
        temp = f.readlines()
        # print("lines", temp, "\n\n\n")
        ingredient_temp = []
        for line in temp:
            line_split = line.split(" ", 2)
            line_split[2] = line_split[2][:-1]
            # print("linesplit", line_split, "\n")
            amount_temp = Amount(float(line_split[0]), line_split[1])
            ingredient_temp.append(Ingredient(line_split[2], amount_temp))
        recipe_temp = Recipe(ingredient_temp)
        recipes.append(recipe_temp)

for recipe in recipes:
    print(recipe)
    print()

# temp = Amount(10, "oz")
# print(temp)
#
# temp2 = Ingredient("beef", temp)
# print(temp2)
#
# temp3 = Recipe([temp2])
Ejemplo n.º 5
0
        dataListX.append(index)
        amounts.append(data['amount'])

        priceUtil.add(data, index)

        KDJ.calKDJ(data, index)
        K.append(KDJ.getLastK())
        D.append(KDJ.getLastD())
        J.append(KDJ.getLastJ())

        bollFlag = True
        kdjFlag = True
        amountFlag = True
        # kdjFlag = KDJ.judgeSell(index)
        bollFlag = Boll.judgeBoll(data, index)
        amountFlag = Amount.judgeAmount(data, index)
        sellFlag = TradeUtil.canSell(symbols, close, bi, env)
        print(index, " bollFlag=", bollFlag, " amountFlag=", amountFlag,
              " sellFlag=", sellFlag, " close=", close)
        if kdjFlag and bollFlag and amountFlag and sellFlag:
            sellX.append(index)
            sellY.append(close)
            tradeModel = TradeModel(close, index, 10, 0, symbols)
            fileUtil.write(tradeModel.getValue(), "sell" + symbols)
            fileUtil.write(('0 {} {} {}').format(
                close, 10, time.strftime("%Y-%m-%d %H:%M:%S",
                                         time.localtime())),
                           "record" + symbols)

        canBuyLists = TradeUtil.getBuyModel(symbols, close, "dev")
Ejemplo n.º 6
0
            test = huobi.get_kline(symbols, '1min', 1)
            test['data'].reverse()
            logging.info(test['data'])

            data = test['data'][0]

            if lastId != data['id']:

                close = lastDate['close']
                bollFlag = True
                kdjFlag = True
                amountFlag = True
                priceUtil.add(lastDate, count)
                # kdjFlag = KDJ.judgeSell(index)
                bollFlag = Boll.judgeBoll(lastDate, count)
                amountFlag = Amount.judgeAmount(lastDate, count)
                sellFlag = TradeUtil.canSell(symbols, close, bi, env)

                logging.info(priceUtil.amounts[-5:])
                logging.info(
                    ('bollFlag={} amountFlag={} sellFlag={} \n').format(
                        bollFlag, amountFlag, sellFlag))
                if kdjFlag and bollFlag and amountFlag and sellFlag:
                    TradeUtil.sell(env, symbols, close)

                canBuyLists = TradeUtil.getBuyModel(symbols, close, env)

                for buyRecord in canBuyLists:
                    #买入
                    TradeUtil.sendBuy(env, buyRecord)
Ejemplo n.º 7
0
def test_equalities():
    assert_true(
        Amount('length', 'meters', 5) == Amount('length', 'kilometers', 0.005))
    assert_true(Amount('time', 'seconds', 60) == Amount('time', 'minutes', 1))
Ejemplo n.º 8
0
def test_conversion():
    assert_true(Amount('time', 'seconds', 60).convert('minutes') == 1.0)