Skip to content

Commit

Permalink
Merge pull request dimagi#105 from tstalka/Corporate_Dashboard
Browse files Browse the repository at this point in the history
246595: Corporate Dashboard - Added Second Y Axis
  • Loading branch information
tstalka authored Mar 13, 2017
2 parents 9b50b39 + bf3271d commit 9503a47
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 11 deletions.
64 changes: 64 additions & 0 deletions src/classes/CorporateDashboardController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
public without sharing class CorporateDashboardController {

public Boolean refreshing { get; set;}
public List<DoubleLineChartData> performanceData { get; set;}

public CorporateDashboardController() {
this.refreshing = false;
Expand All @@ -27,4 +28,67 @@ public without sharing class CorporateDashboardController {
public void resetRefreshFlag() {
this.refreshing = false;
}

public List<DoubleLineChartData> getData() {
this.performanceData = new List<DoubleLineChartData>();
Boolean error = false;
String message = '';
try {
Reports.reportResults results = Reports.ReportManager.runReport('00Ob00000047rxW', true);
Reports.Dimension dim = results.getGroupingsDown();
Map<String, Reports.AggregateColumn> columnsInfo = results.getReportExtendedMetadata().getAggregateColumnInfo();
Reports.GroupingValue groupingVal = dim.getGroupings()[0];

Set<String> labelIdx = new Set<String>();
for (Reports.AggregateColumn agColumn : columnsInfo.values()) {
labelIdx.add(agColumn.getLabel());
}

if (!labelIdx.contains('Avg Page Load') || !labelIdx.contains('Avg # of Submissions') || !labelIdx.contains('Avg Server Apdex')) {
error = true;
message = 'Cannot find Aggregates';
}

if (error == false) {
for (Reports.GroupingValue gValue : dim.getGroupings()) {
String monthName = gValue.getLabel();
String factMapKey = gValue.getKey() + '!T';

Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get(factMapKey);
System.debug(monthName + ' ' + (Decimal) factDetails.getAggregates()[0].getValue() + ' ' +(Decimal) factDetails.getAggregates()[1].getValue()
+ ' ' + (Decimal) factDetails.getAggregates()[2].getValue());
this.performanceData.add(new DoubleLineChartData(monthName, (Decimal) factDetails.getAggregates()[0].getValue(), (Decimal) factDetails.getAggregates()[1].getValue(),
(Decimal) factDetails.getAggregates()[2].getValue()));
}
}
} catch(Exception e) {
message = e.getMessage();
error = true;
}

if (error == true) {
System.debug('Cannot load performance data');
if (!Test.isRunningTest()) {
EmailHelper.sendEmail(BatchDefaultSettings__c.getOrgDefaults().Error_Emails__c.split(','), 'Cannot load performance data for Corporate Dashboard',
'report Id : 00Ob00000047rxW ' + message);
}
}

return this.performanceData;
}

public class DoubleLineChartData {

public String name { get; set; }
public Decimal avgPageLoad { get; set; }
public Decimal avgSubmissions { get; set; }
public Decimal avgServerApdex { get; set; }

public DoubleLineChartData(String name, Decimal avgPageLoad, Decimal avgSubmissions, Decimal avgServerApdex) {
this.name = name;
this.avgPageLoad = avgPageLoad;
this.avgSubmissions = avgSubmissions / 1000.00;
this.avgServerApdex = avgServerApdex;
}
}
}
Loading

0 comments on commit 9503a47

Please sign in to comment.