Example #1
0
def main():
    # Setting pattern for redis
    pattern = 'factorial:'

    # Searching for parameters passed in the terminal
    ap = ArgumentParser()
    ap.add_argument("-a", "--address", required=True, help="address for connection with redis")
    ap.add_argument("-p", "--port", required=True, help="port for connection with redis")
    args = vars(ap.parse_args())

    # Instantiating an object that connects to a redis database using the parameters passed
    db = Database(host=args['address'], port=int(args['port']), db=0)
    print("--- Welcome to Factorial Calculator ---")
    while True:
        number = input("Please enter a non negative integer number: ")

        # Checking if the entered string is alphanumeric or, if it is a number, less than 0
        try:
            if number.isalpha() == True or int(number) < 0:
                print("You didn't write non negative integer!")
            else:
                # Checking if the number has already been calculated and is in the cache
                if(db.get(pattern + number) is None):
                    print("--- Calculating factorial ---")
                    result = factorial(int(number))
                    print(result)
                    # Setting result in cache
                    db[pattern + number] = result
                else:
                    print("--- Fetching result in cache ---")
                    print(db[pattern + number].decode())
        except ValueError:
                print("You didn't write non negative integer!")
Example #2
0
def get_importance(db: Database, tournament_id, left_team,
                   right_team) -> List[dict]:
    key = get_importance_key(tournament_id, left_team, right_team)
    data = db.get(key)
    if data is not None:
        data = json.loads(data)
    return data
Example #3
0
def get_sim_log(db: Database, tournament_id, left_team,
                right_team) -> List[str]:
    key = get_sim_log_key(tournament_id, left_team, right_team)
    data = db.get(key)
    if data is not None:
        data = json.loads(data)
    return data
Example #4
0
def get_map(db: Database, tournament_id, left_team, right_team) -> str:
    key = get_map_key(tournament_id, left_team, right_team)
    return db.get(key)
Example #5
0
def get_prediction(db: Database, tournament_id, left_team,
                   right_team) -> float:
    data = db.get(get_prediction_key(tournament_id, left_team, right_team))
    if data is not None:
        data = float(data)
    return data
Example #6
0
def get_predictions(db: Database, tournament_id) -> Optional[Predictions]:
    data = db.get(get_predictions_key(tournament_id))
    if data is not None:
        data = Predictions.from_json(data)
    return data
Example #7
0
def get_current_match(db: Database):
    data = db.get(CURRENT_MATCH_KEY)
    if data is not None:
        data = tuple(data.split(' '))
    return data
Example #8
0
def get_current_tournament_id(db: Database):
    return db.get(CURRENT_TOURNAMENT_KEY)