Lean  $LEAN_TAG$
DataMonitorReport.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using Newtonsoft.Json;
18 using QuantConnect.Util;
19 using System;
20 using System.Collections.Generic;
21 using System.Linq;
22 
23 namespace QuantConnect
24 {
25  /// <summary>
26  /// Report generated by the <see cref="IDataMonitor"/> class that contains information about data requests
27  /// </summary>
28  public class DataMonitorReport
29  {
30  /// <summary>
31  /// Gets the number of data files that were requested and successfully fetched
32  /// </summary>
33  [JsonProperty(PropertyName = "succeeded-data-requests-count")]
34  public long SucceededDataRequestsCount { get; set; }
35 
36  /// <summary>
37  /// Gets the number of data files that were requested but could not be fetched
38  /// </summary>
39  [JsonProperty(PropertyName = "failed-data-requests-count")]
40  public long FailedDataRequestsCount { get; set; }
41 
42  /// <summary>
43  /// Gets the number of universe data files that were requested and successfully fetched
44  /// </summary>
45  [JsonProperty(PropertyName = "succeeded-universe-data-requests-count")]
46  public long SucceededUniverseDataRequestsCount { get; set; }
47 
48  /// <summary>
49  /// Gets the number of universe data files that were requested but could not be fetched
50  /// </summary>
51  [JsonProperty(PropertyName = "failed-universe-data-requests-count")]
52  public long FailedUniverseDataRequestsCount { get; set; }
53 
54  /// <summary>
55  /// Gets the number of data files that were requested
56  /// </summary>
57  [JsonProperty(PropertyName = "total-data-requests-count")]
58  public long TotalRequestsCount
59  {
61  }
62 
63  /// <summary>
64  /// Fets the percentage of data requests that could not be satisfied
65  /// </summary>
66  [JsonProperty(PropertyName = "failed-data-requests-percentage")]
67  public double FailedDataRequestsPercentage
68  {
69  get { return GetPercentage(TotalRequestsCount, FailedDataRequestsCount); }
70  }
71 
72  /// <summary>
73  /// Gets the number of universe data files that were requested
74  /// </summary>
75  [JsonProperty(PropertyName = "total-universe-data-requests-count")]
77  {
79  }
80 
81  /// <summary>
82  /// Fets the percentage of universe data requests that could not be satisfied
83  /// </summary>
84  [JsonProperty(PropertyName = "failed-universe-data-requests-percentage")]
86  {
88  }
89 
90  /// <summary>
91  /// Rates at which data requests were made per second
92  /// </summary>
93  [JsonProperty(PropertyName = "data-request-rates")]
94  public IReadOnlyList<double> DataRequestRates { get; set; }
95 
96  /// <summary>
97  /// Initializes an empty instance of the <see cref="DataMonitorReport"/> class
98  /// </summary>
100  {
101  }
102 
103  /// <summary>
104  /// Initializes a new instance of the <see cref="DataMonitorReport"/> class
105  /// </summary>
106  /// <param name="succeededDataRequestsCount">Number of data paths that were requested and successfuly served</param>
107  /// <param name="failedDataRequestsCount">Number of data paths that were requested but could not be served</param>
108  /// <param name="succeededUniverseDataRequestsCount">Number of universe data paths that were requested and successfuly served</param>
109  /// <param name="failedUniverseDataRequestsCount">Number of universe data paths that were requested but could not be served</param>
110  /// <param name="dataRequestRates">Rates at which data requests were made per second</param>
111  public DataMonitorReport(long succeededDataRequestsCount,
112  long failedDataRequestsCount,
113  long succeededUniverseDataRequestsCount,
114  long failedUniverseDataRequestsCount,
115  IReadOnlyList<double> dataRequestRates)
116  {
117  SucceededDataRequestsCount = succeededDataRequestsCount;
118  FailedDataRequestsCount = failedDataRequestsCount;
119  SucceededUniverseDataRequestsCount = succeededUniverseDataRequestsCount;
120  FailedUniverseDataRequestsCount = failedUniverseDataRequestsCount;
121  DataRequestRates = dataRequestRates;
122  }
123 
124  private static double GetPercentage(long total, long value)
125  {
126  if (total == 0)
127  {
128  return 0;
129  }
130 
131  return Math.Round(value / (double)total * 100);
132  }
133  }
134 }