import warnings


def no_of_events(tweet_file, t_observation, t_prediction, time_factor=1):
    """
    calculate the number of retweets at the observation time (=t_observation) and at the final time of prediction (=t_prediction)
    :param tweet_file: data file
    :param t_observation: observation time
    :param t_prediction: final time of prediction
    :param time_factor: factor to convert the time unit in seconds
    :return: tuple, the number of retweets at an observation time and at the final time
    """
    event_t_obs = 0
    event_t_pred = 0

    with open(tweet_file, "r") as in_file:
        first = next(in_file)  # to remove the first line in the data file
        for num, line in enumerate(in_file, 0):  # 0 to remove the original tweet  # change to 1 to add original tweet
            values = line.split(" ")
            if float(values[0]) <= (t_observation * time_factor):
                event_t_obs = num
            if float(values[0]) <= (t_prediction * time_factor):
                event_t_pred = num

    if event_t_obs == 0:
        warnings.warn("No event have occurred till the observation time. The file WILL BE IGNORED")
        print("Ignored File Name:", tweet_file)
    else:
        return event_t_obs, event_t_pred