Skip to content

Commit d4a5b19

Browse files
committed
fixed interpolation of chart values
interpolation of following days should be based on the last value of a day, not on the maximum value
1 parent d029f89 commit d4a5b19

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/PostSharp.LicenseServer/Graph.aspx.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ protected override void OnLoad(EventArgs e)
5050
this.AxisMaximum = GraceMaximum.GetValueOrDefault();
5151
}
5252
}
53-
5453

55-
var q = from l in db.GetLeaseCountingPoints( LicenseId, startDate, endDate )
56-
group l by l.Time.Date
57-
into d select new { Date = d.Key, Count = d.Max(point => point.LeaseCount) };
54+
55+
var q = from l in db.GetLeaseCountingPoints(LicenseId, startDate, endDate)
56+
group l by l.Time.Date
57+
into d
58+
select
59+
new
60+
{
61+
Date = d.Key,
62+
Count = d.Max(point => point.LeaseCount),
63+
LastCount = d.OrderByDescending(point => point.Time).First().LeaseCount
64+
};
5865

5966
// Fill the array with data.
6067
this.Keys = new string[Days];
6168
this.Values = new string[Days];
69+
var lastValues = new int?[Days];
6270
foreach ( var point in q )
6371
{
6472
int day = (int) Math.Floor( point.Date.Subtract( startDate ).TotalDays );
@@ -69,16 +77,20 @@ group l by l.Time.Date
6977
}
7078

7179
if ( day < 0 )
72-
{
80+
{
7381
this.Values[0] = point.Count.ToString();
82+
lastValues[0] = point.LastCount;
7483
}
7584
else if ( day < Days )
76-
{
85+
{
7786
this.Values[day] = point.Count.ToString();
87+
lastValues[day] = point.LastCount;
7888
}
7989
}
8090

8191
// Do extrapolation of missing values.
92+
string lastValue = "0";
93+
8294
for ( int i = 0; i < Days; i++ )
8395
{
8496
DateTime date = startDate.AddDays( i );
@@ -90,13 +102,17 @@ group l by l.Time.Date
90102
{
91103
if (i > 0)
92104
{
93-
this.Values[i] = this.Values[i - 1] ?? "0";
105+
this.Values[i] = lastValue;
94106
}
95107
else
96108
{
97-
this.Values[0] = "0";
109+
this.Values[0] = lastValue;
98110
}
99111
}
112+
if ( lastValues[i] != null )
113+
{
114+
lastValue = lastValues[i].ToString();
115+
}
100116
}
101117

102118

0 commit comments

Comments
 (0)