52 lines
1.5 KiB
Plaintext
52 lines
1.5 KiB
Plaintext
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Collections;
|
|
|
|
namespace BCG
|
|
{
|
|
[DataStreamUserRepresentation("timeBucket")]
|
|
public class TimeBucketStream : ViewStream, IStreamMapper
|
|
{
|
|
private ViewStream _src;
|
|
private readonly string _time_stamp_col;
|
|
private IBlueTableSchema _schema;
|
|
private uint _bucket_size_seconds;
|
|
|
|
public TimeBucketStream(ViewStream input, string time_stamp_col, uint bucket_size_seconds)
|
|
{
|
|
_time_stamp_col = time_stamp_col;
|
|
_bucket_size_seconds = bucket_size_seconds;
|
|
}
|
|
|
|
#region IStreamMapper Members
|
|
public IBlueTableSchema getOutputSchema(IBlueTableSchema input_schema)
|
|
{
|
|
IBlueTableSchema rv = input_schema;
|
|
//rv = BlueDataUtility.remove_columns(rv, _time_stamp_col);
|
|
rv = BlueDataUtility.add_column(rv, "bucket_number", typeof(int));
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IDynamicStreamMapper Members
|
|
|
|
public IBlueRow map(IBlueRow row)
|
|
{
|
|
DateTime ts = row.get<DateTime>(_time_stamp_col);
|
|
TimeSpan time_of_day = (ts - ts.Date)
|
|
int seconds = Convert.ToInt32(time_of_day.TotalSeconds);
|
|
int buckets = seconds / _bucket_size_seconds;
|
|
int bucket_number = Math.Floor(buckets);
|
|
MutableBlueRow rv = new MutableBlueRow(row, getOutputSchema(row.schema))
|
|
rv.setValue("bucket_number", bucket_number);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|