'Build time series from StatsStore data.'

def _TimeSeriesFromData(self, data, attr=None):

    series = timeseries.Timeseries()
    for (value, timestamp) in data:
        if attr:
            try:
                series.Append(getattr(value, attr), timestamp)
            except AttributeError:
                raise ValueError(("Can't    find    attribute    %s    in    value    %s." % (attr, value)))
        else:
            if (hasattr(value, 'sum') or hasattr(value, 'count')):
                raise ValueError(("Can't    treat    complext    type    as    simple    value:    %s" % value))
            series.Append(value, timestamp)
    return series
