Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
feat(reports): update fields
Browse files Browse the repository at this point in the history
 - fall back to data_type for data_categories
  • Loading branch information
alex-wilmer committed Apr 21, 2016
1 parent e3467b9 commit f444fe9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
4 changes: 2 additions & 2 deletions app/scripts/projects/tests/projects.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ describe('Projects:', function () {
expect(ProjectsService.ds.get).to.have.been.calledOnce;
expect(ProjectsService.ds.get).to.have.been.calledWith(1);
}));

it('title of table should match spec', inject(function (ProjectsService) {
assert.equal(ProjectsService.getTableHeading(),'Case count per data type');
assert.equal(ProjectsService.getTableHeading(),'Case count per Data Category');
}));
});
});
62 changes: 34 additions & 28 deletions app/scripts/reports/reports.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,39 @@ module ngApp.reports.controllers {
import IProjectsService = ngApp.projects.services.IProjectsService;
import ILocationService = ngApp.components.location.services.ILocationService;

export interface ID3Entry {
key: string;
values: {
file_count: number;
file_size: number;
project_name: string;
};
}

export interface IReportsController {
reports: IReports;
byProject: any;
byDisease: any;
byProgram: any;
byDataType: any;
bySubtype: any;
byDataCategory: any;
byStrat: any;
byDataAccess: any;
byUserType: any;
byLocation: any;
dataNest(key: string): any;
}

class ReportsController implements IReportsController {
reports: IReports;
byProject: any;
byDisease: any;
byProgram: any;
byDataType: any;
bySubtype: any;
byStrat: any;
byDataAccess: any;
byUserType: any;
byLocation: any;
byProject: [ID3Entry];
byDisease: [ID3Entry];
byProgram: [ID3Entry];
byDataType: [ID3Entry];
byDataCategory: [ID3Entry];
byStrat: [ID3Entry];
byDataAccess: [ID3Entry];
byUserType: [ID3Entry];
byLocation: [ID3Entry];

/* @ngInject */
constructor(public reports: IReports, private CoreService: ICoreService,
Expand All @@ -38,12 +47,12 @@ module ngApp.reports.controllers {
CoreService.setPageTitle("Reports");

if (reports.hits.length) {
var dataNoZeros = _.reject(reports.hits, (hit) => { return hit.count === 0 && hit.size ===0; });
var dataNoZeros = reports.hits.filter(hit => hit.count && hit.size)
this.byProject = this.dataNest("project_id").entries(dataNoZeros);
this.byDisease = this.dataNest("disease_type").entries(dataNoZeros);
this.byProgram = this.dataNest("program").entries(dataNoZeros);
this.byDataType = this.dataNest("data_categories").entries(this.reduceBy(dataNoZeros, "data_categories"));
this.bySubtype = this.dataNest("data_type").entries(this.reduceBy(dataNoZeros, "data_types"));
this.byDataCategory = this.dataNest("data_category").entries(this.reduceBy(dataNoZeros, "data_categories"));
this.byDataType = this.dataNest("data_type").entries(this.reduceBy(dataNoZeros, "data_types"));
this.byStrat = this.dataNest("experimental_strategy").entries(this.reduceBy(dataNoZeros, "experimental_strategies"));
this.byDataAccess = this.dataNest("access").entries(this.reduceBy(dataNoZeros, "data_access"));
this.byUserType = this.dataNest("user_access_type").entries(this.reduceBy(dataNoZeros, "user_access_types"));
Expand All @@ -59,24 +68,21 @@ module ngApp.reports.controllers {

dataNest(key: string): any {
return d3.nest()
.key(function(d){return d[key]})
.rollup(function(d){
return {
file_count: d3.sum(d.map(function(x){return x.count})),
file_size: d3.sum(d.map(function(x){return x.size})),
project_name:d[0].disease_type
}
})
.sortValues(function(a,b){return a.file_count - b.file_count});
.key(d => d[key])
.rollup(d => {
return {
file_count: d3.sum(d.map(x => x.count)),
file_size: d3.sum(d.map(x => x.size)),
project_name: d[0].disease_type
}
})
.sortValues((a,b) => a.file_count - b.file_count);
}

reduceBy(data: any, key: string): any {
return _.reduce(data, (result, datum) => {
if (datum[key]) {
result = result.concat(datum[key]);
}
return result;
}, []);
return datum[key] ? result.concat(datum[key]) : result;
}, []);
}

}
Expand Down
4 changes: 3 additions & 1 deletion app/scripts/reports/reports.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module ngApp.reports.models {
id: string;
name: string;
charts: any;
count: number;
size: number;
}

}
}
14 changes: 7 additions & 7 deletions app/scripts/reports/reports.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ module ngApp.reports.services {
}

getReports(params: Object = {}): ng.IPromise<IReports> {
if (params.hasOwnProperty("fields")) {
params["fields"] = params["fields"].join();
if (params.fields) {
params.fields = params.fields.join();
}

if (params.hasOwnProperty("expand")) {
params["expand"] = params["expand"].join();
if (params.expand) {
params.expand = params.expand.join();
}

if (params.hasOwnProperty("facets")) {
params["facets"] = params["facets"].join();
if (params.facets) {
params.facets = params.facets.join();
}

var size = 999999;
Expand All @@ -42,7 +42,7 @@ module ngApp.reports.services {
timeout: abort.promise
})
.get("", angular.extend(defaults, params)).then((response): IReports => {
return response["data"];
return response.data;
});
return prom;
}
Expand Down
12 changes: 6 additions & 6 deletions app/scripts/reports/templates/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ <h2>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title" data-translate>
Downloads by Data Type
Downloads by Data Category
</h4>
</div>
<table class="table table-striped table-hover table-condensed table-bordered table-responsive">
<thead>
<tr>
<th data-translate>
Data Type
Data Category
</th>
<th class="text-right" data-translate>
# Requests
Expand All @@ -181,7 +181,7 @@ <h4 class="panel-title" data-translate>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="project in rsc.byDataType | orderBy:'values.file_count':true ">
<tr data-ng-repeat="project in rsc.byDataCategory | orderBy:'values.file_count':true ">
<th>
{{ project.key }}
</th>
Expand All @@ -201,14 +201,14 @@ <h4 class="panel-title" data-translate>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title" data-translate>
Downloads by Data Subtype
Downloads by Data Type
</h4>
</div>
<table class="table table-striped table-hover table-condensed table-bordered table-responsive">
<thead>
<tr>
<th data-translate>
Data Subtype
Data Type
</th>
<th class="text-right" data-translate>
# Requests
Expand All @@ -219,7 +219,7 @@ <h4 class="panel-title" data-translate>
</tr>
</thead>
<tbody>
<tr ng-repeat='p in rsc.bySubtype'>
<tr ng-repeat='p in rsc.byDataType'>
<th>
{{ p.key }}
</th>
Expand Down

0 comments on commit f444fe9

Please sign in to comment.