Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/generate report #127

Merged
merged 135 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
7642090
changes to support calculated data and report editing
banders Dec 7, 2023
498b991
added new report-calc-service and started integrating with the file-u…
banders Dec 7, 2023
a80dcd6
Merge branch 'main' into feature/save-initial-report-data
banders Dec 7, 2023
bdd8b73
export function createSampleRow(..) because it is useful to tests in …
banders Dec 7, 2023
ce6669a
export an additional interface and a constant so they can be used by …
banders Dec 7, 2023
16d6d1a
added some functions to prepare CSV data for performing the required …
banders Dec 8, 2023
03d2820
data model changes. most to accommodate calculated data.
banders Dec 8, 2023
200ccac
renamed
banders Dec 8, 2023
67aeb65
refactored the GENDER_CODES constant constant to better handle multip…
banders Dec 8, 2023
e1beb9e
implemented the calculations for mean and median hourly pay gaps (for…
banders Dec 8, 2023
0db2295
new unit tests for the ColumnStats helper class
banders Dec 8, 2023
d6c6130
misc bug fixes
banders Dec 12, 2023
388e8ec
new unit tests
banders Dec 12, 2023
3d02838
recreated the calculated_data table as a key-value table. various sma…
banders Dec 12, 2023
3b0f7bc
refreshed prisma schema to match current data model
banders Dec 12, 2023
06ae264
fixed the naics_code and employee_count_range_id send to the backend …
banders Dec 12, 2023
80fa052
added code to insert a new draft report into the database.
banders Dec 12, 2023
f5d21c5
slight change to calculation_code table. added audit columns to calc…
banders Dec 12, 2023
545fefd
refreshed prisma model to match database
banders Dec 12, 2023
c744b53
new function to fetch a list of calculation codes and their correspon…
banders Dec 12, 2023
21c8d07
made naming of some objects and their properties more consistent
banders Dec 12, 2023
08f880a
save calculated data to the database
banders Dec 12, 2023
fbda1a9
Merge branch 'main' into feature/save-initial-report-data
sukanya-rath Dec 12, 2023
db211d6
Merge branch 'main' into feature/save-initial-report-data
banders Dec 12, 2023
c95b9b6
Merge branch 'feature/save-initial-report-data' of https://github.com…
banders Dec 12, 2023
0363556
modified the POST file-upload endpoint to overwrite an existing draft…
banders Dec 12, 2023
932395d
omit user_id from check for existing report
banders Dec 12, 2023
edafd52
Merge branch 'main' into feature/generate-report
banders Dec 12, 2023
cf766d6
added new dependencies for producing the report: puppeteer, d3, ejs
banders Dec 13, 2023
b7395b6
changes to show the draft report inline below the input form (this is…
banders Dec 13, 2023
31fd112
file-upload endpoint now returns an HTML report on success
banders Dec 13, 2023
39cb8d7
add HTML report generation
banders Dec 13, 2023
562553d
wrap long line labels on the vertical axis
banders Dec 13, 2023
b13d9a0
replace fake chart data with real, uploaded data
banders Dec 13, 2023
2d66766
restricted custom styles to the pay-transparency report (so they don'…
banders Dec 13, 2023
7251faa
added navigation between 'stages'
banders Dec 13, 2023
8d21aa2
resolved merge conflicts
banders Dec 13, 2023
9877b8e
moved /templates folder out of /src
banders Dec 13, 2023
a043228
adjusted relative paths to report template files
banders Dec 13, 2023
abf6608
changed how template paths are defined
banders Dec 13, 2023
d32e19d
bug fix in median hourly pay gap calculation
banders Dec 13, 2023
347f875
changed template path
banders Dec 13, 2023
6beb509
added copyfile as dev dependency
banders Dec 13, 2023
60562b7
changed path to template
banders Dec 13, 2023
9d7c810
adjust build script to copy templates
banders Dec 13, 2023
602e434
added env var for template_path
banders Dec 13, 2023
9f5e1c5
moved templates into src
banders Dec 13, 2023
46cd0de
adjust template path
banders Dec 13, 2023
143918b
added template path config
banders Dec 13, 2023
fc9b6c3
updated puppeteer version
banders Dec 13, 2023
0eb9938
new file to configure puppeteer browser intall path
banders Dec 13, 2023
502f002
changed puppeteer cache dir
banders Dec 13, 2023
3e6b0f2
remove --ignore-scripts
banders Dec 13, 2023
d4ff2b9
copy puppeteer cache dir into dist
banders Dec 13, 2023
0ef9fca
bump dependency version
banders Dec 13, 2023
a9cf0a1
updated puppeteer config
banders Dec 13, 2023
74c9ebf
removed statement to copy cache dir
banders Dec 13, 2023
17e3d98
create .cache dir
banders Dec 13, 2023
044d5a4
add chromium to deployment container
banders Dec 13, 2023
1de0449
copy cache into deployment container
banders Dec 13, 2023
e2cdfa3
don't create cache dir
banders Dec 13, 2023
e947386
copy cache from build container
banders Dec 13, 2023
6865626
install chromium
banders Dec 13, 2023
93493ab
set download folder for chromium
banders Dec 13, 2023
8221500
changed pupeteer browser path
banders Dec 13, 2023
3c36cb9
download chrome browser and copy to deployment container
banders Dec 13, 2023
7ce7029
use a different browser version for puppeteer
banders Dec 14, 2023
d9c2773
changed deployment image to node alpine (so we have access to a packa…
banders Dec 14, 2023
c2d71c9
use chromium from outside puppeteer
banders Dec 14, 2023
0c727ff
whitespace
banders Dec 14, 2023
91ef7fd
changed to a single stage build
banders Dec 14, 2023
72324a6
use chrome downloaded by puppeteer
banders Dec 14, 2023
136e6b3
adjust puppeteer launch params
banders Dec 14, 2023
56f8fa2
change to non-puppeteer chromium browser
banders Dec 14, 2023
7e7691f
removed unneeded puppeteer config file.
banders Dec 14, 2023
3e3af66
merged in main
banders Dec 14, 2023
ceab649
sanitize HTML report returned by postSubmission(...)
banders Dec 14, 2023
0a0acd0
fix report template path
banders Dec 14, 2023
e3dbab2
remove dependency on chart.js (we've switched to d3 for charts)
banders Dec 14, 2023
a761421
fixed code smells
banders Dec 14, 2023
d2f2392
ensure jests runs unit tests on ts and js files
banders Dec 15, 2023
6b60df3
bump dependency version
banders Dec 15, 2023
37f21e4
export constants so they can be accessed in unit tests
banders Dec 15, 2023
c66ae71
reorganized the file to make it easier to unit test
banders Dec 15, 2023
dd2eefa
fix code smells
banders Dec 15, 2023
3d371d1
new unit test for horizontalBarChart (function used in generating rep…
banders Dec 15, 2023
abeba5b
merge with main
banders Dec 15, 2023
50d2890
share TEMPLATE_PATH env var with unit tests
banders Dec 15, 2023
dac7e4c
undo last change.
banders Dec 15, 2023
482ec7c
added default value for server:templatePath var
banders Dec 15, 2023
bddfdaa
export constant to support unit tests
banders Dec 16, 2023
fe654b9
changed type of CalculatedAmount.value from string to number
banders Dec 16, 2023
60fe5d3
new unit tests
banders Dec 16, 2023
81ca154
disable lint
banders Dec 16, 2023
3ef7e71
include templates
banders Dec 16, 2023
9b7d8fc
disable lint
banders Dec 16, 2023
afc2565
Merge branch 'main' into feature/generate-report
banders Dec 16, 2023
c13e1b1
Merge branch 'main' of https://github.com/bcgov/fin-pay-transparency
banders Dec 18, 2023
c567d41
resolved merge conflicts
banders Dec 18, 2023
1b7ba45
resolved merge conflicts
banders Dec 18, 2023
7a73ee0
resolved merge conflcits
banders Dec 18, 2023
b37b980
resolved merge conflcits
banders Dec 18, 2023
cc57f9c
resolved merge conflicts
banders Dec 18, 2023
879d7b8
fixed package-lock
banders Dec 18, 2023
da74c7a
drop 'not null' constraints on table pay_transparency_calculated_data…
banders Dec 18, 2023
625c048
adjust puppeteer startup args to avoid console popups
banders Dec 18, 2023
e5df359
Merge branch 'main' of https://github.com/bcgov/fin-pay-transparency
banders Dec 18, 2023
0e7dcf5
resolved merge conflicts
banders Dec 18, 2023
d6db1ef
re-enable puppeteer sandbox, but remove some of the other launch args…
banders Dec 18, 2023
cff385d
added calculations for overtime pay gap and overtime hours gap. adde…
banders Dec 19, 2023
bbc0f6e
fixed type error
banders Dec 19, 2023
17941fc
fixed the report end date that is saved to the database
banders Dec 19, 2023
df262bb
formatting
banders Dec 19, 2023
20d2bb8
added footnotes
banders Dec 19, 2023
b9ff2f4
rename calculation codes
banders Dec 19, 2023
99d01d9
added bonus pay calculations, tests and charts (in the report)
banders Dec 19, 2023
51c5bc6
export some values needed for unit tests
banders Dec 20, 2023
c730805
new unit tests for report-service
banders Dec 20, 2023
1fffa46
fixed references to calculation values
banders Dec 20, 2023
72f852b
fixed references to calculation values
banders Dec 20, 2023
08dc713
optional chaining for calculation values
banders Dec 20, 2023
788f8a9
Merge branch 'main' of https://github.com/bcgov/fin-pay-transparency
banders Dec 20, 2023
8a99c56
Merge branch 'main' into feature/generate-report
banders Dec 20, 2023
3d7285b
fixed bug: wrong charts were showed in the bonus pay area. convert c…
banders Dec 20, 2023
98a42bd
changed some calculations to produce percentages instead of fractions…
banders Dec 20, 2023
d87036e
show 'user comments' near the top of the report
banders Dec 20, 2023
0e7f88a
change how color are passed into the function that draws charts. the…
banders Dec 20, 2023
e2aba40
Merge branch 'main' of https://github.com/bcgov/fin-pay-transparency
banders Dec 20, 2023
5cda6e1
resolve merge conflicts
banders Dec 20, 2023
52047a3
fixed tests
banders Dec 20, 2023
fb737db
hide user_comments when null
banders Dec 21, 2023
b35d3e7
removed text that was accidently pasted into the file
banders Dec 21, 2023
1bd34a4
pass emptystring instead of null for some multi-part form data params…
banders Dec 21, 2023
47f29ed
removed empty method
banders Dec 21, 2023
f17b1e6
Merge branch 'main' into feature/generate-report
sukanya-rath Dec 21, 2023
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
8 changes: 3 additions & 5 deletions backend/src/templates/report.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
Transparency Report. Depends on d3.js (i.e. must run from a page
with d3.js included).
@data is an array of objects with this format
{label: "MY_LABEL", value: NUMERIC_VAL_HERE}
@colors is an array of hex colors. length of this array should match
length of data array
{label: "MY_LABEL", value: NUMERIC_VAL_HERE, color: "HEX_COLOR"}
*/
function horizontalBarChart(data, colors, numberFormat = '$0.2f') {
function horizontalBarChart(data, numberFormat = '$0.2f') {
const barHeight = 37;
const marginTop = 0;
const marginRight = 110;
Expand Down Expand Up @@ -57,7 +55,7 @@ function horizontalBarChart(data, colors, numberFormat = '$0.2f') {
.selectAll()
.data(data)
.join('rect')
.attr('fill', (d, i) => color(i))
.attr('fill', (d, i) => d.color)
.attr('x', x(0))
.attr('y', (d) => y(d.label))
.attr('width', (d) => x(d.value) - x(0))
Expand Down
18 changes: 6 additions & 12 deletions backend/src/templates/report.script.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@ describe('horizontalBarChart', () => {
//Define the data and colors that we'll show in the bar chart
const params = {
chartData: [
{ label: 'Male', value: 1.0 },
{ label: 'Feale', value: 0.92 },
{ label: 'Non-binary', value: 0.97 },
{ label: 'Unknown', value: 1.01 },
],
chartColors: [
'#1c3664', //Male
'#1b75bb', //Female
'#00a54f', //Non-binary
'#444444', //Unknown
{ label: 'Male', value: 1.0, color: '#1c3664' },
{ label: 'Feale', value: 0.92, color: '#1b75bb' },
{ label: 'Non-binary', value: 0.97, color: '#00a54f' },
{ label: 'Unknown', value: 1.01, color: '#444444' },
],
};

Expand All @@ -51,7 +45,7 @@ describe('horizontalBarChart', () => {
const numberFormat = '0.2f'; //don't apply formatting to numbers
document.getElementById('chart').appendChild(
// @ts-ignore
horizontalBarChart(params.chartData, params.chartColors, numberFormat),
horizontalBarChart(params.chartData, numberFormat),
);
}, params);

Expand All @@ -75,7 +69,7 @@ describe('horizontalBarChart', () => {

await browser.close();

expect(barColors).toEqual(params.chartColors);
expect(barColors).toEqual(params.chartData.map((d) => d.color));
expect(genderCategoryLabels).toEqual(params.chartData.map((d) => d.label));
expect(payGapLabels.map((d) => parseFloat(d))).toEqual(
params.chartData.map((d) => d.value),
Expand Down
166 changes: 81 additions & 85 deletions backend/src/templates/report.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,92 +156,88 @@
<div class="page">
<h1 class="text-primary mb-4">Pay Transparency Report</h1>

<p class="text-tertiary ">
Note: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pretium fermentum elementum. Quisque
varius
libero
eu mi rhoncus, non congue eros convallis. Pellentesque dictum auctor dolor, ac gravida mi convallis a. Mauris
enim
mauris,
efficitur aliquet lacus ac, suscipit sollicitudin mauris.
</p>

<h2 class="text-primary mb-4">Employer details</h3>

<table class="employer-details table" role="presentation" style="width:100%">
<tr>
<td class="table-header">Employer:</td>
<td>
<%= report.companyName %>
</td>
</tr>
<tr>
<td class="table-header">Address:</td>
<td>
<%= report.companyAddress %>
</td>
</tr>
<tr>
<td class="table-header">Time Period:</td>
<td>
<%= report.reportStartDate %> - <%= report.reportEndDate %>
</td>
</tr>
<tr>
<td class="table-header">NAICS Code:</td>
<td>
<%= report.naicsCode %> - <%= report.naicsLabel %>
</td>
</tr>
<tr>
<td class="table-header">Number of Employees:</td>
<td>
<%= report.employeeCountRange %>
</td>
</tr>
</table>

<div class="header-block mb-4">
<div class="header-circle">
<svg xmlns="http://www.w3.org/2000/svg" width="55" height="55" fill="currentColor"
class="bi bi-clock text-primary" viewBox="0 0 16 16">
<path d="M8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71z" />
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m7-8A7 7 0 1 1 1 8a7 7 0 0 1 14 0" />
</svg>
</div>
<div class="header-block-title flex-fill">
<h2 class="mb-0">Hourly pay</h2>
</div>
</div>
<% if (report.comments) { %>
<p class="text-tertiary">
<%= report.comments %>
</p>
<% } %>

<h2 class="text-primary mb-4">Employer details</h3>

<table class="employer-details table" role="presentation" style="width:100%">
<tr>
<td class="table-header">Employer:</td>
<td>
<%= report.companyName %>
</td>
</tr>
<tr>
<td class="table-header">Address:</td>
<td>
<%= report.companyAddress %>
</td>
</tr>
<tr>
<td class="table-header">Time Period:</td>
<td>
<%= report.reportStartDate %> - <%= report.reportEndDate %>
</td>
</tr>
<tr>
<td class="table-header">NAICS Code:</td>
<td>
<%= report.naicsCode %> - <%= report.naicsLabel %>
</td>
</tr>
<tr>
<td class="table-header">Number of Employees:</td>
<td>
<%= report.employeeCountRange %>
</td>
</tr>
</table>

<table role="presentation">
<tr>
<td class="pe-2">
<h4>Mean hourly pay gap<sup>1</sup></h4>
<div id="mean-hourly-pay-gap-chart"></div>
</td>
<td>
<h4>Median hourly pay gap<sup>2</sup></h4>
<div id="median-hourly-pay-gap-chart"></div>
</td>
</tr>
</table>

<div class="explanatory-notes">
<h4>Explanatory notes</h4>
<div class="footnote">
<div class="footnote-number">1.</div>
<div>&quot;Mean hourly pay gap&quot; refers to the differences in pay
between gender groups calculated by average pay. Hourly pay does
not include bonuses and overtime.</div>
</div>
<div class="footnote">
<div class="footnote-number">2.</div>
<div>&quot;Median hourly pay gap&quot; refers to the differences in pay
between gender groups calculated by the mid range of pay for
each group. Hourly pay does not include bonuses and overtime.</div>
</div>
</div>
<div class="header-block mb-4">
<div class="header-circle">
<svg xmlns="http://www.w3.org/2000/svg" width="55" height="55" fill="currentColor"
class="bi bi-clock text-primary" viewBox="0 0 16 16">
<path d="M8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71z" />
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m7-8A7 7 0 1 1 1 8a7 7 0 0 1 14 0" />
</svg>
</div>
<div class="header-block-title flex-fill">
<h2 class="mb-0">Hourly pay</h2>
</div>
</div>

<table role="presentation">
<tr>
<td class="pe-2">
<h4>Mean hourly pay gap<sup>1</sup></h4>
<div id="mean-hourly-pay-gap-chart"></div>
</td>
<td>
<h4>Median hourly pay gap<sup>2</sup></h4>
<div id="median-hourly-pay-gap-chart"></div>
</td>
</tr>
</table>

<div class="explanatory-notes">
<h4>Explanatory notes</h4>
<div class="footnote">
<div class="footnote-number">1.</div>
<div>&quot;Mean hourly pay gap&quot; refers to the differences in pay
between gender groups calculated by average pay. Hourly pay does
not include bonuses and overtime.</div>
</div>
<div class="footnote">
<div class="footnote-number">2.</div>
<div>&quot;Median hourly pay gap&quot; refers to the differences in pay
between gender groups calculated by the mid range of pay for
each group. Hourly pay does not include bonuses and overtime.</div>
</div>
</div>

</div>

Expand Down
Loading