šŸš€. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more →
Sign In

cif-parser

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cif-parser - npm Package Compare versions

Comparing version
1.1.2
to
1.2.0
res/20150621nointel-dep.pdf

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

+63
-6

@@ -34,11 +34,26 @@ /**

constructor(pdfFilePath, competitorName){
constructor(pdfFilePath, competitorName, unexpectedBikers, pdfFormat){
super();
this.pdfFilePath = pdfFilePath;
this.competitorName = competitorName;
this.unexpectedBikers = unexpectedBikers;
this.pdfFormat = pdfFormat;
}
console.log("File path: " + this.pdfFilePath)
generateJSON(){
// HUGGLY HACK: use enum and switch case
if (this.pdfFormat == "2015"){
this.generateJSON_2015();
return;
}
if (this.pdfFormat == "2017"){
this.generateJSON_2017();
return;
}
console.error("Specified pdfFormat " + this.pdfFormat + " is not managed");
return;
}
generateJSON(unexpectedBikers){
generateJSON_2015(){
// Read pdf file

@@ -49,2 +64,4 @@ let pdfParser = new PDFParser();

pdfParser.on("pdfParser_dataReady", pdfData => {
fs.writeFile("./res/result.json", JSON.stringify(pdfData));
/**

@@ -54,3 +71,3 @@ * Search X of name of this.competitorName

let xOfCompetitors = undefined;
let pathToCompetitor = jp.paths(pdfData, '$..R[?(@.T=="'+this.competitorName+'")]');
let pathToCompetitor = jp.paths(pdfData, '$..R[?(/^'+this.competitorName+'.*/.test(@.T))]');

@@ -61,3 +78,3 @@ if (pathToCompetitor.length == 0){

}
let pathToXOfCompetitor = pathToCompetitor[0].slice(0,6);

@@ -69,4 +86,42 @@ pathToXOfCompetitor[6] = "x";

/**
* Get all Y of all competitors
*/
let competitorNameFields = jp.nodes(pdfData, '$..Texts[?(@.x==' + xOfCompetitors + ')]');
let competitors = [{error: "To be done"}];
this.emit("cif_parser_dataReady", {"competitors":competitors});
});
pdfParser.loadPDF(this.pdfFilePath);
}
generateJSON_2017(){
// Read pdf file
let pdfParser = new PDFParser();
pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
pdfParser.on("pdfParser_dataReady", pdfData => {
fs.writeFile("./res/result.json", JSON.stringify(pdfData));
/**
* Search X of name of this.competitorName
*/
let xOfCompetitors = undefined;
let pathToCompetitor = jp.paths(pdfData, '$..R[?(@.T=="'+this.competitorName+'")]');
if (pathToCompetitor.length == 0){
console.error("ERROR: No competitor named \""+ this.competitorName + "\" found");
return;
}
let pathToXOfCompetitor = pathToCompetitor[0].slice(0,6);
pathToXOfCompetitor[6] = "x";
let queryToXValues = jp.stringify(pathToXOfCompetitor);
let pathsToXValues = jp.query(pdfData,queryToXValues);
xOfCompetitors = pathsToXValues[0];
/**
* Get all Y of all competitors

@@ -109,3 +164,3 @@ */

let thisBikerExpected = true;
unexpectedBikers.find((element) => {if (element.lastName == lastName && element.firstName == firstName) thisBikerExpected = false;});
this.unexpectedBikers.find((element) => {if (element.lastName == lastName && element.firstName == firstName) thisBikerExpected = false;});

@@ -229,2 +284,4 @@ if (! thisBikerExpected){

}
}
+1
-1
{
"name": "cif-parser",
"version": "1.1.2",
"version": "1.2.0",
"description": "Parse results of bike race published by FFC CIF",

@@ -5,0 +5,0 @@ "main": "main.js",

@@ -7,8 +7,8 @@ let CIF2JSON = require('./main.js');

*/
let pdfPath = "./res/saintange.pdf";
let competitorLastName = "BILLIOTTET";
let pdfPath = "./res/lagny.pdf";
let competitorLastName = "BALLUREAU";
let csvPath = './res/race-results.csv';
let cifParser = new CIF2JSON(pdfPath, competitorLastName);
let unexpectedBikers = [{lastName: "BONNEHORGNE", firstName: "Xavier"} , {lastName: "BUSATO", firstName: "Thierry"} , {lastName: "BERGER", firstName: "Mickaƫl"}];
let cifParser = new CIF2JSON(pdfPath, competitorLastName, unexpectedBikers, "2017");

@@ -39,2 +39,2 @@ let mode = "TEST" // TEST or INSERT

cifParser.generateJSON(unexpectedBikers);
cifParser.generateJSON();