-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* police testing * correct demo data * fix csv * CODEOWNERS
- Loading branch information
Showing
13 changed files
with
187 additions
and
49 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 4 additions & 25 deletions
29
src/site/stages/build/drupal/static-data-files/vaPoliceData/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
src/site/stages/build/drupal/static-data-files/vaPoliceData/police-contact.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
facility_id,contact_name,contact_number | ||
vha_011,Abc Jameson,1234567899 | ||
vha_021,Xyz Adamson,1123456799 | ||
VISN,Facility API ID,Contact Name,Contact Number |
8 changes: 1 addition & 7 deletions
8
src/site/stages/build/drupal/static-data-files/vaPoliceData/police-events.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
date_range,facility_id,a,b,c | ||
2021-01-01:2021-12-31,vha_011,2,3,4 | ||
2022-01-01:2022-12-31,vha_011,3,4,5 | ||
2023-01-01:2023-10-10,vha_011,1,1,1 | ||
2021-01-01:2021-12-31,vha_021,1,3,1 | ||
2022-01-01:2022-12-31,vha_021,2,0,1 | ||
2023-01-01:2023-10-10,vha_021,0,1,0 | ||
VISN,Facility API ID,Facility Name,MM/YYYY,Number of service calls (officer initiated and response to calls),Traffic and parking tickets,Non-traffic (criminal) tickets,Arrests,Complaints and investigations,Numbers of sustained allegations,Numbers of disciplinary actions |
95 changes: 95 additions & 0 deletions
95
src/site/stages/build/drupal/static-data-files/vaPoliceData/postProcessPolice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
const csv = require('csvtojson'); | ||
|
||
function processJsonPoliceData(unprocessedJson) { | ||
const processedJSON = { | ||
VISN: null, | ||
facilityAPIId: '', | ||
facilityName: '', | ||
date: '', | ||
numServiceCalls: null, | ||
trafficParkingTickets: null, | ||
criminalTickets: null, | ||
arrests: null, | ||
complaintsInvestigations: null, | ||
sustainedAllegations: null, | ||
disciplinaryActions: null, | ||
}; | ||
for (const [key, value] of Object.entries(unprocessedJson)) { | ||
switch (key) { | ||
case 'VISN': | ||
processedJSON.VISN = parseInt(value, 10); | ||
break; | ||
case 'Facility API ID': | ||
processedJSON.facilityAPIId = value; | ||
break; | ||
case 'Facility Name': | ||
processedJSON.facilityName = value; | ||
break; | ||
case 'MM/YYYY': | ||
processedJSON.date = value; | ||
break; | ||
case 'Number of service calls (officer initiated and response to calls)': | ||
processedJSON.numServiceCalls = parseInt(value, 10); | ||
break; | ||
case 'Traffic and parking tickets': | ||
processedJSON.trafficParkingTickets = parseInt(value, 10); | ||
break; | ||
case 'Non-traffic (criminal) tickets': | ||
processedJSON.criminalTickets = parseInt(value, 10); | ||
break; | ||
case 'Arrests': | ||
processedJSON.arrests = parseInt(value, 10); | ||
break; | ||
case 'Complaints and investigations': | ||
processedJSON.complaintsInvestigations = parseInt(value, 10); | ||
break; | ||
case 'Numbers of sustained allegations': | ||
processedJSON.sustainedAllegations = parseInt(value, 10); | ||
break; | ||
case 'Numbers of disciplinary actions': | ||
processedJSON.disciplinaryActions = parseInt(value, 10); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
return processedJSON; | ||
} | ||
|
||
async function postProcessPolice(queryResult) { | ||
const processedJSON = { | ||
data: { | ||
statistics: {}, // keys:facilityAPIId, values: array of objects in processed format | ||
contacts: {}, | ||
}, | ||
}; | ||
const [contact, ...events] = queryResult; | ||
if (!contact || !events || events.length === 0) { | ||
throw new Error( | ||
'Police data files must have at least one contact file and one events file.', | ||
); | ||
} | ||
const contactData = await csv().fromString(contact); | ||
const eventsData = await Promise.all( | ||
events.map(eventsFile => csv().fromString(eventsFile)), | ||
); // each file has its own header, but JSON's are the same | ||
const processedEventsData = eventsData.flat().map(processJsonPoliceData); // convert keys to usable format | ||
for (const processedEventsDataEntry of processedEventsData) { | ||
if (processedJSON.data.statistics[processedEventsDataEntry.facilityAPIId]) { | ||
processedJSON.data.statistics[ | ||
processedEventsDataEntry.facilityAPIId | ||
].push(processedEventsDataEntry); | ||
} else { | ||
processedJSON.data.statistics[processedEventsDataEntry.facilityAPIId] = [ | ||
processedEventsDataEntry, | ||
]; | ||
} | ||
} | ||
|
||
processedJSON.data.contacts = contactData; | ||
|
||
// TODO: Process jsonEvents and Join data with contact info for a Facility Police Page content | ||
return processedJSON; | ||
} | ||
module.exports.postProcessPolice = postProcessPolice; | ||
module.exports.processJsonPoliceData = processJsonPoliceData; |
3 changes: 0 additions & 3 deletions
3
src/site/stages/build/drupal/static-data-files/vaPoliceData/pre-contact-police.csv
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/site/stages/build/drupal/static-data-files/vaPoliceData/pre-events-police.csv
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/site/stages/build/drupal/tests/police/download.unit.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* eslint-disable @department-of-veterans-affairs/axe-check-required */ | ||
import path from 'path'; | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { processCurlDataFile } from '../../static-data-files/generate'; | ||
import { postProcessPolice } from '../../static-data-files/vaPoliceData/postProcessPolice'; | ||
|
||
const { pathToFileURL } = require('url'); | ||
const getCurlClient = require('../../static-data-files/fetchApi'); | ||
|
||
/* This is not a FE test but a unit test. */ | ||
describe('process police csv files', () => { | ||
it('should have an error if the police-contact.csv file is missing', async () => { | ||
const client = getCurlClient({ | ||
'drupal-user': '[email protected]', | ||
'drupal-password': 'drupal8', | ||
'drupal-max-parallel-requests': 10, | ||
}); | ||
expect( | ||
processCurlDataFile( | ||
{ | ||
description: 'Curl', | ||
filename: 'test-police.json', | ||
query: [ | ||
pathToFileURL( | ||
path.join( | ||
__dirname, | ||
'./fixtures/non-existant-police-contact.csv', | ||
), | ||
).toString(), | ||
pathToFileURL( | ||
path.join(__dirname, './fixtures/non-existant-police.csv'), | ||
).toString(), | ||
], | ||
postProcess: postProcessPolice, | ||
}, | ||
client, | ||
), | ||
).to.be.rejectedWith(Error); | ||
}); | ||
it('should process files', async () => { | ||
const client = getCurlClient({ | ||
'drupal-user': '[email protected]', | ||
'drupal-password': 'drupal8', | ||
'drupal-max-parallel-requests': 10, | ||
}); | ||
const processedDataFile = await processCurlDataFile( | ||
{ | ||
description: 'Curl', | ||
filename: 'test-police.json', | ||
query: [ | ||
pathToFileURL( | ||
path.join(__dirname, './fixtures/police-contact.csv'), | ||
).toString(), | ||
pathToFileURL( | ||
path.join(__dirname, './fixtures/police.csv'), | ||
).toString(), | ||
], | ||
postProcess: postProcessPolice, | ||
}, | ||
client, | ||
); | ||
const keys = Object.keys(processedDataFile.data.data.statistics); | ||
expect(keys).to.contain('avha_635'); | ||
expect(keys).to.contain('avha_523A5'); | ||
expect(processedDataFile.data.data.statistics.avha_635).to.be.an('array'); | ||
expect(processedDataFile.data.data.statistics.avha_523A5).to.be.an('array'); | ||
expect(processedDataFile.data.data.statistics.avha_635[0].VISN).to.be.equal( | ||
19, | ||
); // that way we know processing succeeded | ||
expect( | ||
processedDataFile.data.data.statistics.avha_523A5[0].VISN, | ||
).to.be.equal(1); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
src/site/stages/build/drupal/tests/police/fixtures/police-contact.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VISN,Facility API ID,Contact Name,Contact Number | ||
19,avha_635,Abc Jameson,12345689 | ||
1,avha_523A5,Zyz Adamson,1123456799 |
3 changes: 3 additions & 0 deletions
3
src/site/stages/build/drupal/tests/police/fixtures/police.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VISN,Facility API ID,Facility Name,MM/YYYY,Number of service calls (officer initiated and response to calls),Traffic and parking tickets,Non-traffic (criminal) tickets,Arrests,Complaints and investigations,Numbers of sustained allegations,Numbers of disciplinary actions | ||
19,avha_635,Oklahoma City VA Medical Center,12/2023,4000,100,100,600,50,10,2 | ||
1,avha_523A5,Brockton VA Medical Center,12/2023,5200,220,325,752,78,8,3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters