Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e4243a8
[statistics] Cleanup filters and add Registration Date
skarya22 Jul 30, 2025
3f14d60
Fix line length
skarya22 Jul 30, 2025
8355dd0
Add subtitles to dashboard panels
skarya22 Jul 31, 2025
ab499d1
Fix formatting
skarya22 Jul 31, 2025
69994e2
Fix tests
skarya22 Jul 31, 2025
c45fa23
Fix issue with visit filter + console warning + date_registered
skarya22 Aug 13, 2025
22e7083
Reorganize and add age distribution
skarya22 Aug 14, 2025
c3b9c24
Fix php formatting
skarya22 Aug 14, 2025
8f148d6
Just trying to make phan happy
skarya22 Aug 14, 2025
49b9729
Add % to age chart and bigger subtitle
skarya22 Sep 3, 2025
7389b4b
Add project size charts + Generalize helpers
jeffersoncasimir Sep 15, 2025
90534f7
Add SQL patch + RB
jeffersoncasimir Sep 15, 2025
1612603
Rename 'Project Size' to 'Dataset Size'
jeffersoncasimir Sep 15, 2025
a40e1c7
Fint php lint
jeffersoncasimir Sep 16, 2025
81204c2
Remove commented code
jeffersoncasimir Sep 16, 2025
3c2159a
Fix conflict
jeffersoncasimir Sep 16, 2025
93f133c
Compliance changes
jeffersoncasimir Sep 17, 2025
86c1a80
Lint fixes
jeffersoncasimir Sep 17, 2025
30e5592
Static fixes
jeffersoncasimir Sep 17, 2025
d0aa6bb
Satisfy linter
jeffersoncasimir Sep 17, 2025
683709d
Satisfy linter
jeffersoncasimir Sep 17, 2025
08f6a54
Corrected merge change
jeffersoncasimir Oct 20, 2025
d3ce416
Remove console.log
jeffersoncasimir Oct 20, 2025
eed888b
Rebase to aces/main
jeffersoncasimir Oct 27, 2025
0c89da1
Fix failing static tests
jeffersoncasimir Oct 27, 2025
f14630c
Fix failing static tests
jeffersoncasimir Oct 27, 2025
cf24d8c
Fix null scenario
jeffersoncasimir Oct 27, 2025
f3e66dc
Fix null scenario
jeffersoncasimir Oct 27, 2025
15842fa
Make strings translatable
jeffersoncasimir Oct 29, 2025
dccac10
Revert unecessary changes
jeffersoncasimir Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,35 @@ INSERT INTO StatisticsTabs (ModuleName, SubModuleName, Description, OrderNo) VAL
('statistics', 'stats_behavioural', 'Behavioural Statistics', 3),
('statistics', 'stats_MRI', 'Imaging Statistics', 4);


-- ********************************
-- statistics
-- ********************************


CREATE TABLE `cached_data_type` (
`CachedDataTypeID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) UNIQUE NOT NULL,
PRIMARY KEY (`CachedDataTypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


INSERT INTO `cached_data_type` (`Name`) SELECT 'projects_disk_space';


CREATE TABLE `cached_data` (
`CachedDataID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`CachedDataTypeID` INT(10) UNSIGNED NOT NULL,
`Value` TEXT NOT NULL,
`LastUpdate` TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`CachedDataID`),
CONSTRAINT `FK_cached_data_type` FOREIGN KEY (`CachedDataTypeID`)
REFERENCES `cached_data_type` (`CachedDataTypeID`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- ********************************
-- server_processes tables
-- ********************************
Expand Down Expand Up @@ -2688,4 +2717,4 @@ CREATE TABLE `redcap_notification` (
`handled_dt` datetime NULL,
PRIMARY KEY (`id`),
KEY `i_redcap_notif_received_dt` (`received_dt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21 changes: 21 additions & 0 deletions SQL/New_patches/2025_09_11_add_data_cache_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Create cached_data_type table to track different types of cached data
CREATE TABLE `cached_data_type` (
`CachedDataTypeID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(255) UNIQUE NOT NULL,
PRIMARY KEY (`CachedDataTypeID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Create cached_data table to track cached data
CREATE TABLE `cached_data` (
`CachedDataID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`CachedDataTypeID` INT(10) UNSIGNED NOT NULL,
`Value` TEXT NOT NULL,
`LastUpdate` TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`CachedDataID`),
CONSTRAINT `FK_cached_data_type` FOREIGN KEY (`CachedDataTypeID`)
REFERENCES `cached_data_type` (`CachedDataTypeID`)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `cached_data_type` (`Name`) SELECT 'projects_disk_space';
26 changes: 17 additions & 9 deletions modules/statistics/jsx/widgets/helpers/chartBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const formatBarData = (data) => {
return processedData;
};

const createPieChart = (columns, id, targetModal, colours) => {
const createPieChart = (columns, id, targetModal, colours, units = null, showPieLabelRatio = true) => {
let newChart = c3.generate({
bindto: targetModal ? targetModal : id,
data: {
Expand All @@ -92,13 +92,22 @@ const createPieChart = (columns, id, targetModal, colours) => {
pie: {
label: {
format: function(value, ratio, id) {
return value + "("+Math.round(100*ratio)+"%)";
if (units) {
value = `${value} ${units}`;
}
if (showPieLabelRatio) {
value = `${value} (${(ratio * 100).toFixed(0)}%)`;
}
return value;
}
}
},
tooltip: {
format: {
value: function (value, ratio) {
if (units) {
value = `${value} ${units}`;
}
return `${value} (${(ratio * 100).toFixed(0)}%)`;
},
},
Expand All @@ -107,7 +116,7 @@ const createPieChart = (columns, id, targetModal, colours) => {
return newChart;
}

const createBarChart = (t, labels, columns, id, targetModal, colours, dataType) => {
const createBarChart = (labels, columns, id, targetModal, colours, dataType, yLabel) => {
let newChart = c3.generate({
bindto: targetModal ? targetModal : id,
data: {
Expand All @@ -130,11 +139,11 @@ const createBarChart = (t, labels, columns, id, targetModal, colours, dataType)
axis: {
x: {
type: 'category',
categories: labels,
categories: labels,
},
y: {
label: {
text: t('Candidates registered', { ns: 'statistics'}),
text: yLabel,
position: 'inner-top'
},
},
Expand Down Expand Up @@ -167,6 +176,7 @@ const createLineChart = (data, columns, id, label, targetModal, titlePrefix) =>
}
}
}

let newChart = c3.generate({
size: {
height: targetModal && 500,
Expand Down Expand Up @@ -226,10 +236,8 @@ const createLineChart = (data, columns, id, label, targetModal, titlePrefix) =>

name = nameFormat(d[i].name);
value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index);

// Calculate percentage based on grand total of entire dataset
let percentage = grandTotal > 0 ? ((d[i].value / grandTotal) * 100).toFixed(1) : 0;

bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id);

text += "<tr class='" + $$.CLASS.tooltipName + "-" + d[i].id + "'>";
Expand Down Expand Up @@ -313,9 +321,9 @@ const setupCharts = async (t, targetIsModal, chartDetails, totalLabel) => {
}
let chartObject = null;
if (chart.chartType === 'pie') {
chartObject = createPieChart(columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours);
chartObject = createPieChart(columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours, chart.units, chart.showPieLabelRatio);
} else if (chart.chartType === 'bar') {
chartObject = createBarChart(t, labels, columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours, chart.dataType);
chartObject = createBarChart(labels, columns, `#${chartID}`, targetIsModal && '#dashboardModal', colours, chart.dataType, chart.yLabel);
} else if (chart.chartType === 'line') {
chartObject = createLineChart(chartData, columns, `#${chartID}`, chart.label, targetIsModal && '#dashboardModal', chart.titlePrefix);
}
Expand Down
6 changes: 6 additions & 0 deletions modules/statistics/jsx/widgets/recruitment.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Recruitment = (props) => {
dataType: 'pie',
label: 'Age (Years)',
options: {pie: 'pie', bar: 'bar'},
yLabel: t('Candidates registered', {ns: 'statistics'}),
legend: 'under',
chartObject: null,
},
Expand All @@ -42,6 +43,7 @@ const Recruitment = (props) => {
dataType: 'pie',
label: 'Ethnicity',
options: {pie: 'pie', bar: 'bar'},
yLabel: t('Candidates registered', {ns: 'statistics'}),
legend: 'under',
chartObject: null,
},
Expand All @@ -55,6 +57,7 @@ const Recruitment = (props) => {
label: 'Participants',
legend: '',
options: {pie: 'pie', bar: 'bar'},
yLabel: t('Candidates registered', {ns: 'statistics'}),
chartObject: null,
},
'siterecruitment_bysex': {
Expand All @@ -64,6 +67,7 @@ const Recruitment = (props) => {
dataType: 'bar',
legend: 'under',
options: {bar: 'bar', pie: 'pie'},
yLabel: t('Candidates registered', {ns: 'statistics'}),
chartObject: null,
},
},
Expand All @@ -75,6 +79,7 @@ const Recruitment = (props) => {
dataType: 'line',
legend: '',
options: {line: 'line'},
yLabel: t('Candidates registered', {ns: 'statistics'}),
chartObject: null,
},
},
Expand Down Expand Up @@ -149,6 +154,7 @@ const Recruitment = (props) => {
setChartDetails);
};

// Helper functions to calculate totals for each view
const getTotalProjectsCount = () => {
return Object.keys(json['recruitment'] || {})
.filter((key) => key !== 'overall').length;
Expand Down
76 changes: 72 additions & 4 deletions modules/statistics/jsx/widgets/studyprogression.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const StudyProgression = (props) => {
legend: 'under',
options: {line: 'line'},
chartObject: null,
titlePrefix: 'Month',
yLabel: t('Candidates registered', {ns: 'statistics'}),
titlePrefix: t('Month', {ns: 'loris'}),
},
},
'total_recruitment': {
Expand All @@ -58,7 +59,25 @@ const StudyProgression = (props) => {
legend: '',
options: {line: 'line'},
chartObject: null,
titlePrefix: 'Month',
yLabel: t('Candidates registered', {ns: 'statistics'}),
titlePrefix: t('Month', {ns: 'loris'}),
},
},
'project_sizes': {
'size_byproject': {
sizing: 11,
title: t('Dataset size breakdown by project', {ns: 'statistics'}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also not in the locale files

filters: '',
chartType: 'pie',
dataType: 'pie',
label: t('Size (GB)', {ns: 'statistics'}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this in the .po file, nor .pot file

units: t('GB', {ns: 'loris'}),
showPieLabelRatio: false,
legend: '',
options: {pie: 'pie', bar: 'bar'},
chartObject: null,
yLabel: t('Size (GB)', {ns: 'statistics'}),
titlePrefix: t('Project', {ns: 'loris'}),
},
},
});
Expand Down Expand Up @@ -173,9 +192,16 @@ const StudyProgression = (props) => {
{showChart('total_scans', 'scans_bymonth')}
</div>
) : (
<p>There have been no scans yet.</p>
<p>{t('There have been no scans yet.', {ns: 'statistics'})}</p>
),
title: title('Site Scans'),
subtitle: t(
'Total Scans: {{count}}',
{
ns: 'statistics',
count: json['studyprogression']['total_scans'],
}
),
onToggleFilters: () => setShowFiltersScans((prev) => !prev),
},
{
Expand Down Expand Up @@ -212,11 +238,53 @@ const StudyProgression = (props) => {
{showChart('total_recruitment', 'siterecruitment_bymonth')}
</div>
) : (
<p>There have been no candidates registered yet.</p>
<p>
{t(
'There have been no candidates registered yet.',
{ns: 'statistics'}
)}
</p>
),
title: title('Site Recruitment'),
onToggleFilters: () => showFiltersBreakdown((prev) => !prev),
},
{
content:
Object.keys(json['options']['projects']).length > 0 ? (
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: '10px',
}}
>
<div className="btn-group" style={{marginBottom: '10px'}}>
</div>
{showFiltersBreakdown && (
<QueryChartForm
Module={'statistics'}
name={'studyprogression'}
id={'studyprogressionProjectSizesForm'}
data={props.data}
callback={(formDataObj) => {
updateFilters(formDataObj, 'project_sizes');
}}
/>
)}
{showChart('project_sizes', 'size_byproject')}
</div>
) : (
<p>{t('There is no data yet.', {ns: 'statistics'})}</p>
),
title: title('Project Dataset Sizes'),
subtitle: t(
'Total Size: {{count}} GB',
{
ns: 'statistics',
count: json['studyprogression']['total_size'] ?? -1,
}
),
},
]}
/>
</>
Expand Down
42 changes: 42 additions & 0 deletions modules/statistics/php/charts.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class Charts extends \NDB_Page
return $this->_handleSiteLineData($request);
case 'agedistribution_line':
return $this->_handleAgeDistributionByProject($request);
case 'size_byproject':
return $this->_handleProjectSizeBreakdown();
default:
return new \LORIS\Http\Response\JSON\NotFound();
}
Expand Down Expand Up @@ -831,4 +833,44 @@ class Charts extends \NDB_Page
}
return $data;
}

/**
* Handle an incoming request for project size breakdown.
*
* @return ResponseInterface
*/
private function _handleProjectSizeBreakdown()
{
$DB = \NDB_Factory::singleton()->database();
$user = \NDB_Factory::singleton()->user();
$projects = $user->getProjects();

$cachedSizeData = json_decode(
html_entity_decode(
$DB->pselectOne(
"SELECT Value
FROM cached_data
JOIN cached_data_type USING (CachedDataTypeID)
WHERE Name='projects_disk_space'",
[]
) ?? ''
),
true
);

$projectData = [];
if (!is_null($cachedSizeData)) {
foreach ($projects as $project) {
$projectName = $project->getName();
if (in_array($projectName, array_keys($cachedSizeData))) {
$projectData[] = [
'label' => $projectName,
...$cachedSizeData[$projectName],
];
}
}
}

return (new \LORIS\Http\Response\JsonResponse($projectData));
}
}
Loading
Loading