Skip to content

Strict range filtering (year range fix) #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions app/cmd/cli/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const cmdArgumentsDefinition = [
multiple: true,
type: String,
description: 'Define what range should be performed for each visualization from the configuration object. If not defined, the tool will perform visualization for all defined ranges. Each range is identified by its "id" value.'
},
{
name: 'strictFilter',
defaultOption: false,
type: Boolean,
description: 'If set, the tool will perform visualization only for the ranges defined in the rangeFilter argument and not for whole folder content (incremental approach).'
}
];

Expand Down
17 changes: 16 additions & 1 deletion app/modules/io/csv-data-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ const readAllCsvFilesForVisualization = async (visualization) => {
return csvItems.flatMap(item => item);
}

const readFilteredCsvFilesForVisualization = async (visualization, range) => {
CONSOLE_LOG.info(`Reading extracted data for visualization (${visualization.id})`);
let files = fs.readdirSync(visualization.output)
let csvItems = [];
for (const file of files) {
const label = file.match(/\d{4}-\d{2}-\d{2}/g)[0];
if (range.filterKeys.some(key => key === label)) {
let csvContent = await csv().fromFile(path.resolve(visualization.output, file));
csvItems.push(mapLabel(file, csvContent));
}
}
return csvItems.flatMap(item => item);
}

const mapLabel = (file, csvContent) => {
return csvContent.map(item => {
// use YYYY-MM-DD from file name as a label value - data per BD
Expand All @@ -23,5 +37,6 @@ const mapLabel = (file, csvContent) => {
}

module.exports = {
readAllCsvFilesForVisualization
readAllCsvFilesForVisualization,
readFilteredCsvFilesForVisualization
}
10 changes: 8 additions & 2 deletions app/modules/service/visualize-service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { updateSection, updatePage } = require("../bookkit/client/bookkit-client");
const createUu5String = require("../bookkit/visualization/visualization");
const { readAllCsvFilesForVisualization } = require("../io/csv-data-reader");
const { readAllCsvFilesForVisualization, readFilteredCsvFilesForVisualization } = require("../io/csv-data-reader");
const { CONSOLE_LOG } = require("../logger/logger");
const {download} = require("../archive-data-downloader/archive-data-downloader-helper");
const { emptyDir } = require("../io/fs-helper");
Expand All @@ -18,7 +18,13 @@ const _processRanges = async (cmdArgs, configuration, visualization, token) => {
for (const [index, range] of visualization.ranges.entries()) {
CONSOLE_LOG.info(`Processing range id: ${range.id} (${index+1} of ${visualization.ranges.length})`);
let command = await download(visualization, range, cmdArgs);
let data = await readAllCsvFilesForVisualization(visualization);
let data = [];
if (cmdArgs.strictFilter) {
CONSOLE_LOG.info("Running in strict filter mode.");
data = await readFilteredCsvFilesForVisualization(visualization, range);
} else {
data = await readAllCsvFilesForVisualization(visualization);
}
let uu5StringContent = createUu5String(visualization, range, data, command);
CONSOLE_LOG.info(`Uploading data into bookkit.`);
await updateSection(configuration.bookkit.uri, visualization.pageCode, range.sectionCode, uu5StringContent, token);
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@ Define what visualization should be performed from the configuration object. If
### --rangeFilter string[]
Define what range should be performed for each visualization from the configuration object. If not defined, the tool will perform visualization for all defined ranges. Each range is identified by its "id" value.

### --strictFilter
If set, the tool will perform visualization only for the ranges defined in the rangeFilter argument and not for whole folder content (incremental approach).

## Logs
logs are automatically stored to the ```%HOME%/.archive-data-visualizer/logs``` folder