Implement a function to calculate the moving average of a time-series stream without using high-level libraries. Define moving_average(values, window_size), where values is a list of numbers and window_size is a positive integer. Return a list whose element at index i is the average of the most recent window_size values, or all available values when fewer than window_size have arrived. Return an empty list for an empty input.
def moving_average(values, window_size):