Reputation: 825
I am relatively new to R, and it's the first time I am trying to use it to actually analyze some data. The problem is the following: I have a CSV file containing a log of the number of requests served a given system in the following form:
# Unix timestamp, number of requests
1354810257,241624
1354810258,244759
1354810259,245307
1354810260,248961
At the moment the file contains the information relative to a week period. Now I need to obtain a graph showing how many requests per second, per hour and per day the system is able to sustain.
Upvotes: 2
Views: 1036
Reputation: 825
I solved it using Python and matplotlib. The code is something similar to this:
import csv
from pylab import *
from itertools import groupby
def by_hour(value):
return value[0] // 3600
def plot_data_for(data, map_, reduce_):
keys = []
values = []
for k,v in groupby(data, key=map_):
keys.append(k)
values.append(reduce_(v))
return (keys, values)
times = []
requests = []
reader = csv.reader(open("results.csv"))
for row in reader:
times.append(int(row[0]))
requests.append(int(row[1]))
increments = map(lambda x: x[1] - x[0], zip(requests, requests[1:] + [requests[-1]]))
plot(*plot_data_for(zip(times, increments), by_hour, lambda values: sum(map(lambda x: x[1], values))))
Upvotes: 1