本文整理汇总了C#中Series.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Series.Clone方法的具体用法?C# Series.Clone怎么用?C# Series.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Series
的用法示例。
在下文中一共展示了Series.Clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Average
/// <summary>
/// Function that averages a series based on a defined Time-Interval
/// </summary>
/// <param name="s">Input Series</param>
/// <param name="tInterval">Averaging Time-Interval</param>
/// <returns></returns>
public static Series Average(Series s, TimeInterval tInterval)
{
Series rval = s.Clone();
if (s.Count == 0)
return rval;
// Define starting date of averaging process
DateTime t = new DateTime(s[0].DateTime.Year, s[0].DateTime.Month, s[0].DateTime.Day,
s[0].DateTime.Hour, 0, 0);
// Find which averaging process to accomplish
if (tInterval == TimeInterval.Daily)
{
// Define series time-interval
rval.TimeInterval = TimeInterval.Daily;
// Loop through the dates
while (t < s[s.Count - 1].DateTime.Date)
{
// Get the series subset based on the averaging time-interval
Series sTemp = s.Subset(t, t.AddDays(1));
// Average the values of the subset
DoAverage(rval, t, sTemp);
// Increment DateTime by averaging time-interval
t = t.AddDays(1);
}
}
// Ditto on the other processes below
else if (tInterval == TimeInterval.Monthly)
{
rval.TimeInterval = TimeInterval.Monthly;
while (t < s[s.Count - 1].DateTime.Date)
{
Series sTemp = s.Subset(t, t.AddMonths(1));
DoAverage(rval, t, sTemp);
t = t.AddMonths(1);
}
}
else if (tInterval == TimeInterval.Hourly)
{
rval.TimeInterval = TimeInterval.Hourly;
while (t < s.MaxDateTime)
{
Series sTemp = Math.Subset(s, new DateRange(t, t.AddHours(1)), false);
DoAverage(rval, t, sTemp);
t = t.AddHours(1);
}
}
else
{ throw new Exception("Time Interval " + tInterval.ToString() + " not supported!"); }
return rval;
}
示例2: DailyMin
public static Series DailyMin(Series source)
{
// return DailySubsetCalculator(source, Math.Min);
Series rval = source.Clone();
source.RemoveMissing(true);
if (source.Count > 0)
{
Point min = source[0];
min.DateTime = min.DateTime.Date;
for (int i = 0; i < source.Count; i++)
{
Point a = source[i];
a.DateTime = a.DateTime.Date;
if (min.DateTime.Date != a.DateTime.Date)
{
rval.Add(min);
min = a;
}
else if (a.Value < min.Value)
{
min.Value = a.Value;
}
if (i == source.Count - 1)
{
rval.Add(min);
}
}
}
rval.TimeInterval = TimeInterval.Daily;
return rval;
}
示例3: DailyMax
public static Series DailyMax(Series source)
{
Series rval = source.Clone();
source.RemoveMissing(true);
if (source.Count > 0)
{
Point max = source[0];
max.DateTime = max.DateTime.Date; // force to 00:00
for (int i = 0; i < source.Count; i++)
{
Point a = source[i];
a.DateTime = a.DateTime.Date;
if (max.DateTime.Date != a.DateTime.Date)
{
rval.Add(max);
max = a;
}
else if (a.Value > max.Value)
{
max.Value = a.Value;
}
if (i == source.Count - 1)
{
rval.Add(max);
}
}
}
rval.TimeInterval = TimeInterval.Daily;
return rval;
}
示例4: CheckSourceSeries
// Clears a violation if the series that is being checked has a missing value for the previous and current time-step
private static Series CheckSourceSeries(Series sourceS, Series checkS)
{
Series rval = checkS.Clone();
for (int i = 1; i < checkS.Count(); i++)
{
DateTime tprev = checkS[i - 1].DateTime;
DateTime t = checkS[i].DateTime;
if (checkS[t].Value < 0.0)
{
double checkVal1 = 0.0;
double checkVal2 = 0.0;
try
{
checkVal1 = sourceS[tprev].Value;
checkVal2 = sourceS[t].Value;
}
catch
{
checkVal1 = -99.0;
checkVal2 = -99.0;
}
if (checkVal1 < 0.0 || checkVal2 < 0.0)
rval.Add(t, 0.0);
else
rval.Add(checkS[t]);
}
else
{
rval.Add(checkS[t]);
}
}
return rval;
}
示例5: Pow
internal static Series Pow(Series s, double p)
{
Series rval = s.Clone();
Series.CopyAttributes(s, rval);
for (int i = 0; i < s.Count; i++)
{
Point pt = s[i];
if (pt.IsMissing)
{
rval.AddMissing(pt.DateTime);
}
else
{
double x = System.Math.Pow(pt.Value, p);
rval.Add(pt.DateTime, x);
}
}
return rval;
}
示例6: Subset
/// <summary>
/// returns subset of series based on months
/// </summary>
public static Series Subset(Series s, int[] months)
{
Series rval = s.Clone();
int sz = s.Count;
for (int i = 0; i < sz; i++)
{
Point pt = s[i];
if (Array.IndexOf(months, pt.DateTime.Month) >= 0)
{
rval.Add(pt);
}
}
return rval;
}
示例7: ShiftToYear
/// <summary>
/// usefull for comparing different periods of time.
/// Often the period of time is one year.
/// Modelers may model different years as scenarios.
/// </summary>
public static Series ShiftToYear(Series s, int year)
{
Series wySeries = s.Clone();
if (s.Count != 0)
{
int day = s[0].DateTime.Day;
int month = s[0].DateTime.Month;
DateTime t1;
if (day == 29 && month == 2 && !DateTime.IsLeapYear(year))
{
day = 28;
}
t1 = new DateTime(year, month, day);
TimeSpan ts = new TimeSpan(t1.Ticks - s[0].DateTime.Ticks);
if (s.TimeInterval == TimeInterval.Monthly)
{
int yearOffset = year - s[0].DateTime.Year;
for (int i = 0; i < s.Count; i++)
{
DateTime t = s[i].DateTime;
if (t.Month == 2 && t.Day == 29 && !DateTime.IsLeapYear(t.Year + yearOffset))
t = t.AddDays(-1);
DateTime newDate = new DateTime(t.Year+yearOffset, t.Month, t.Day);
wySeries.Add(newDate, s[i].Value, s[i].Flag);
}
}
else
{
wySeries = Math.Shift(s, ts);
}
// wySeries.Table.AcceptChanges();
Series.CopyAttributes(s, wySeries);
}
return wySeries;
}
示例8: Shift
/// <summary>
/// Shift the series in time
/// for Daily series timeOffset represents days
/// for Monthly series timeOffset represntes months
/// </summary>
public static Series Shift(Series s, int timeOffset)
{
Series rval = s.Clone();
if (timeOffset == 0)
return s.Copy();
for (int i = 0; i < s.Count; i++)
{
Point pt = s[i];
pt.Flag = PointFlag.Edited;
if (s.TimeInterval == TimeInterval.Daily)
{
pt.DateTime = pt.DateTime.AddDays(timeOffset);
}
else if (s.TimeInterval == TimeInterval.Monthly)
{// maintain end of month or first of month
bool eom = pt.DateTime.EndOfMonth() == pt.DateTime;
bool fom = pt.DateTime.FirstOfMonth() == pt.DateTime;
pt.DateTime = pt.DateTime.AddMonths(timeOffset);
if (eom)
pt.DateTime = pt.DateTime.EndOfMonth();
if (fom)
pt.DateTime = pt.DateTime.FirstOfMonth();
}
else
{
throw new NotImplementedException("time offset not implemented for "+s.TimeInterval);
}
rval.Add(pt);
}
return rval;
}
示例9: Round
/// <summary>
/// convert each double value to an integer
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static Series Round(Series s)
{
Series rval = s.Clone();
for (int i = 0; i < s.Count; i++)
{
Point pt = s[i];
pt.Value = System.Math.Round(pt.Value);
rval.Add(pt);
}
return rval;
}
示例10: Polynomial
/// <summary>
/// Compute a new Time Series based on input series s
/// and polynomial equation.
///
/// Returned series has a time range specified by t1 and t2.
/// Points outside the range of the polynomial equation (min,max)
/// are flaged as Point.MissingValueFlag
/// </summary>
/// <param name="s">input time Series</param>
/// <param name="poly">polynomial equation</param>
/// <param name="t1">starting time for new series</param>
/// <param name="t2">ending time for new series</param>
/// <returns>Time Series</returns>
public static Series Polynomial(Series s, PolynomialEquation poly,
DateTime t1, DateTime t2)
{
int sz = s.Count;
Series rval = s.Clone();
for (int i = 0; i < sz; i++)
{
Point point = s[i];
if (point.BoundedBy(t1, t2))
{
Point newPt;
if (point.BoundedBy(t1, t2, poly.Min, poly.Max))
{
newPt = new Point(point.DateTime, poly.Eval(point.Value), PointFlag.Computed);
}
else
{
newPt = new Point(point.DateTime, Point.MissingValueFlag, PointFlag.Missing);
}
rval.Add(newPt);
}
}
return rval;
}