private static IDictionary <string, object> MakeGraphJSONDictionary(PreparedDataPoints dataPoints, decimal?suggestedMaxY) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("labels", dataPoints.Labels); List <IDictionary <string, object> > dataSets = new List <IDictionary <string, object> >(); foreach (DataSet dataSet in dataPoints.DataSets) { IDictionary <string, object> dataSetDictionay = new Dictionary <string, object>(); dataSetDictionay.Add("data", dataSet.Values); dataSetDictionay.Add("pointRadius", 0); dataSets.Add(dataSetDictionay); } dictionary.Add("datasets", dataSets); if (suggestedMaxY.HasValue) { dictionary.Add("suggestedMaxY", suggestedMaxY.Value); } return(dictionary); }
// For input graphs public IDictionary <string, object> GetData(string graphId, decimal median, decimal dispersion, decimal skew) { if (dispersion <= 0m) { // avoid divide by zero dispersion = 0.00000001m; } InputGraph graph; // Get from static data switch (graphId) { case GraphIds.INCOME_ID: graph = IncomeGraph.INSTANCE; break; case GraphIds.RANGE_REQUIREMENT_ID: graph = RangeRequirementsGraph.INSTANCE; break; case GraphIds.PROPENSITY_ID: graph = EVPurchasePropensityGraph.INSTANCE; break; default: throw new NotImplementedException(); } PreparedDataPoints dataPoints = graph.GenerateDataPoints(median, dispersion, skew, graph.MaxXValue); return(MakeGraphJSONDictionary(dataPoints, graph.SuggestedMaxY)); }
public StatsGraphModel(string graphId, string title, string subTitle, PreparedDataPoints dataPoints) : base(graphId, title, subTitle) { if (dataPoints == null) { throw new ArgumentNullException(); } this.DataPoints = dataPoints; }
// For compute market share graph public IDictionary <string, object> ComputeMarketForecast( string graphId, decimal incomeMedian, decimal incomeDispersion, decimal incomeSkew, decimal percentageOfWageForCarCost) { ForecastInput input = new ForecastInput( GetAll <Vehicle>(typeof(Vehicle)), new InputGraphSelection(incomeMedian, incomeDispersion, incomeSkew), percentageOfWageForCarCost); LineGraph lineGraph = EVMarketForecastGraph.INSTANCE.GetAllSingleLine(input); PreparedDataPoints dataPoints = PreparedDataPoints.VerifyAndCompute(lineGraph); return(MakeGraphJSONDictionary(dataPoints, null)); }
public void TestPrepareSameLength() { List <Line> lines = new List <Line>(); Line norway = new Line( "Norway", Color.Green, new DataSeries( new DataPoint(2019.01m, 3.8m, "https://gronnkontakt.no/2019/02/elbilsalget-i-januar"), new DataPoint(2019.02m, 40.7m, "https://www.elbil24.no/nyheter/her-er-vinnerne-og-taperne/70831731"), new DataPoint(2019.03m, 58.4m, "https://elbil.no/norway-reaches-historic-electric-car-market-share", "https://www.electrive.com/2019/04/02/58-4-of-all-new-vehicles-in-norway-are-purely-electric") )); lines.Add(norway); Line china = new Line( "China", Color.Blue, new DataSeries( new DataPoint(2019.01m, 4.8m, "https://insideevs.com/news/343009/in-january-plug-in-ev-car-sales-in-china-almost-tripled"), new DataPoint(2019.02m, 4.3m, "https://insideevs.com/news/343600/plug-in-electric-car-sales-increased-in-china-in-february"), new DataPoint(2019.03m, 5.8m, "https://insideevs.com/news/346882/march-2019-sales-china") )); lines.Add(china); PreparedDataPoints dataPoints = PreparedDataPoints.VerifyAndCompute( new LineGraph( "Test lines", "Subtitle", new DataPointFormat(Encoding.YEAR_MONTH, Encoding.NUMBER), lines ) ); Assert.IsNotNull(dataPoints); }
internal static StatsGraphModel VerifyAndComputeStatsModel(string graphId, LineGraph lineGraph) { PreparedDataPoints dataPoints = PreparedDataPoints.VerifyAndCompute(lineGraph); return(new StatsGraphModel(graphId, lineGraph.Title, lineGraph.SubTitle, dataPoints)); }