Esempio n. 1
0
 def run(self, edit):
     preferences=utils.get_preferences()
     if(preferences==None):return
     if(preferences.get("user")==None):preferences["user"]={}
     listKeys=list(preferences["user"].keys())
     print("estas son  : ",listKeys)
     for key in preferences["project"].keys():
         print(preferences["project"][key])
         listKeys+=list(preferences["project"][key].keys())
     utils.select(listKeys)
Esempio n. 2
0
def update_training_plan(user, today):
    """
    Method:
    1. Update MpW
    2. Update Days per Week
    3. Combine identically as when producing initial training plan

    Output re-writes 'planned_training.csv' file.
    """

    preferences = utils.get_preferences(user)

    recent_logged_training = utils.get_recent_logged_training(user, 3, today)
    recent_planned_training = utils.get_recent_planned_training(user, 3, today)

    training_plan = utils.get_all_planned_training(user)

    previous_training = training_plan[training_plan.run_date <= today]
    previous_training.run_date = previous_training.\
        run_date.apply(lambda x: x.date())
    previous_training.week_start = previous_training.\
        week_start.apply(lambda x: x.date())

    # Generate summary statistics from planned training and logged training:
    summary = lib.generate_week_summary_stats(recent_planned_training,
                                              recent_logged_training, today)
    training_plan_summary = lib.retrieve_summary_stats(training_plan, today)

    # Update MpW and days per week:
    # MAKE THIS MORE RIGOROUS
    updated_miles_per_week = update_miles_per_week(
        preferences, summary, training_plan_summary.miles.tolist())

    if updated_miles_per_week == 'No update':
        return 'No update'
    updated_days_per_week = update_days_per_week(
        summary, training_plan_summary.run_date.tolist())

    run_vector = utils.get_run_vector(preferences)

    # Combine these with function taken from `generate_plan` python script:
    future_training = generate_plan.\
        combine_miles_days(updated_miles_per_week, updated_days_per_week,
                           preferences, run_vector, today)

    updated_training_plan = pd.concat([previous_training, future_training])

    updated_training_plan.\
        to_csv('main/users/{}/planned_training.csv'.format(user), index=False)

    return updated_training_plan
Esempio n. 3
0
def update_plan(user, inputdate):
    # If training logged is within 20% of planned
    # then keep the same training plan
    today = pd.to_datetime(inputdate).date()
    today = max(today, date.today())

    logged_training = utils.get_all_logged_training(user)
    planned_training = utils.get_all_planned_training(user)

    preferences = utils.get_preferences(user)

    if len(planned_training[planned_training.run_date == today]) == 1 and \
            preferences['difficulty'] == 1:
        planned_run = list(
            planned_training[planned_training.run_date == today].miles)[0]
        logged_run = list(
            logged_training[logged_training.run_date == today].miles)[0]

        if abs((planned_run - logged_run) / planned_run) <= 0.2:
            return True

    update_training_plan(user, today)
    return True
Esempio n. 4
0
        else:
            solution[a1 //
                     2][a1 %
                        2], solution[a2 //
                                     2][a2 %
                                        2] = solution[a2 //
                                                      2][a2 %
                                                         2], solution[a1 //
                                                                      2][a1 %
                                                                         2]
            no_progress_round += 1

    return solution


if __name__ == "__main__":
    n, m, _, preferences = utils.get_preferences("data/sample_2.txt")

    assert n % 2 == 0

    solution = solve_2_roommates_greedy(n, m, preferences)
    score = utils.compute_score(preferences, solution)
    print(f"Found a solution with a greedy algorithm of score {score}\n")
    utils.save_solution("output/solution_" + str(score) + ".txt", solution)

    solution = solve_2_roommates_conv(n, m, preferences)
    score = utils.compute_score(preferences, solution)

    print(f"Found a solution with a score of {score}")

    utils.save_solution("output/solution_" + str(score) + ".txt", solution)
Esempio n. 5
0
import utils
import sys

if __name__ == "__main__":
    filename = sys.argv[1]
    preferences = sys.argv[2]

    with open(filename) as file:
        header = file.readline()

        N = header.rstrip("\n").split("=")[1]

        n, m, _, preferences = utils.get_preferences(preferences)

        placed = [False for _ in range(n)]
        solution = []

        line = file.readline().rstrip("\n").split()
        for i in range(n):
            if not placed[i]:
                solution.append([])
                for j in range(n):
                    if line[(i * n) + j] == '1' and not placed[j]:
                        print(f"Placing {j} in {solution[-1]} ({(i*n)+j})")
                        placed[j] = True
                        solution[-1].append(j)

        print(solution)

        score = utils.compute_score(preferences, solution)
    while no_chgt_group_size < parameters["group_sizes_conv"]:
        new_group_size = generate_group_sizes(n, m_min, m_max)
        no_chgt_group_size += 1

        while no_chgt < parameters["create_solution_conv"]:
            new_solution, new_score = create_solution(n, preferences,
                                                      new_group_size)
            no_chgt += 1

            if new_score < actual_score:
                actual_score = new_score
                solution = new_solution
                group_sizes = new_group_size
                no_chgt = 0
                no_chgt_group_size = 0

    return solution, group_sizes


if __name__ == "__main__":
    n, m_min, m_max, preferences = utils.get_preferences("data/sample_2.txt")

    solution, group_sizes = solve_m_roommates(n, m_min, m_max, preferences)
    score = utils.compute_score_att(preferences, solution, group_sizes)

    print(f"Found a solution with a score of {score}")

    utils.save_solution_att(
        "output/solution_" + str(m_min) + "_" + str(m_max) + "_" + str(score) +
        ".txt", solution, group_sizes)
Esempio n. 7
0
    print(error)


def on_close(ws):
    print("### closed ###")


def on_open(ws):
    print('### opened ###')


while True:
    print('start websocket {}'.format(name))
    time.sleep(1)

    pairs = get_preferences()['pairs']
    print(pairs)

    try:
        subs = ''
        for pair in pairs:
            subs += pair.replace('_', '').lower() + '@trade/'
        if subs != '':
            print(subs)
            ws = websocket.WebSocketApp(
                "wss://stream.binance.com:9443/stream?streams={}".format(
                    subs.strip('/')),
                on_open=on_open,
                on_message=on_message,
                on_error=on_error,
                on_close=on_close)