Atualização automática - 2026-06-24 10:36:19
This commit is contained in:
+52
-5
@@ -221,8 +221,19 @@ export const analyzeWithGemini = async (file: File, apiKey: string, model: strin
|
||||
|
||||
// Apply programmatic validation
|
||||
if (standardsContext && standardsContext.length > 0) {
|
||||
// Assume the first standard matched is the main one for now
|
||||
return data.map(report => validateCertificateAgainstStandard(report, standardsContext[0] as Standard));
|
||||
let matchedStandard = standardsContext[0] as Standard;
|
||||
if (data[0] && data[0].identification && data[0].identification.standards) {
|
||||
const certNorm = data[0].identification.standards.toLowerCase();
|
||||
const found = standardsContext.find(s =>
|
||||
(s.codigo && certNorm.includes(s.codigo.toLowerCase())) ||
|
||||
(s.id_norma && certNorm.includes(s.id_norma.toLowerCase().replace(/_/g, ' ')))
|
||||
);
|
||||
if (found) matchedStandard = found;
|
||||
}
|
||||
return data.map(report => {
|
||||
report.analysisSource = 'Banco Local';
|
||||
return validateCertificateAgainstStandard(report, matchedStandard);
|
||||
});
|
||||
}
|
||||
return data;
|
||||
} catch (e) {
|
||||
@@ -286,7 +297,19 @@ export const analyzeWithOpenAI = async (file: File, apiKey: string, model: strin
|
||||
|
||||
const dataJson = cleanAndParseJson(content) as ReportData[];
|
||||
if (standardsContext && standardsContext.length > 0) {
|
||||
return dataJson.map(report => validateCertificateAgainstStandard(report, standardsContext[0] as Standard));
|
||||
let matchedStandard = standardsContext[0] as Standard;
|
||||
if (dataJson[0] && dataJson[0].identification && dataJson[0].identification.standards) {
|
||||
const certNorm = dataJson[0].identification.standards.toLowerCase();
|
||||
const found = standardsContext.find(s =>
|
||||
(s.codigo && certNorm.includes(s.codigo.toLowerCase())) ||
|
||||
(s.id_norma && certNorm.includes(s.id_norma.toLowerCase().replace(/_/g, ' ')))
|
||||
);
|
||||
if (found) matchedStandard = found;
|
||||
}
|
||||
return dataJson.map(report => {
|
||||
report.analysisSource = 'Banco Local';
|
||||
return validateCertificateAgainstStandard(report, matchedStandard);
|
||||
});
|
||||
}
|
||||
return dataJson;
|
||||
};
|
||||
@@ -380,7 +403,19 @@ export const analyzeWithOllama = async (file: File, endpoint: string, model: str
|
||||
|
||||
const dataJson = cleanAndParseJson(content) as ReportData[];
|
||||
if (standardsContext && standardsContext.length > 0) {
|
||||
return dataJson.map(report => validateCertificateAgainstStandard(report, standardsContext[0] as Standard));
|
||||
let matchedStandard = standardsContext[0] as Standard;
|
||||
if (dataJson[0] && dataJson[0].identification && dataJson[0].identification.standards) {
|
||||
const certNorm = dataJson[0].identification.standards.toLowerCase();
|
||||
const found = standardsContext.find(s =>
|
||||
(s.codigo && certNorm.includes(s.codigo.toLowerCase())) ||
|
||||
(s.id_norma && certNorm.includes(s.id_norma.toLowerCase().replace(/_/g, ' ')))
|
||||
);
|
||||
if (found) matchedStandard = found;
|
||||
}
|
||||
return dataJson.map(report => {
|
||||
report.analysisSource = 'Banco Local';
|
||||
return validateCertificateAgainstStandard(report, matchedStandard);
|
||||
});
|
||||
}
|
||||
return dataJson;
|
||||
};
|
||||
@@ -444,7 +479,19 @@ export const analyzeWithOpenRouter = async (file: File, apiKey: string, model: s
|
||||
|
||||
const dataJson = cleanAndParseJson(content) as ReportData[];
|
||||
if (standardsContext && standardsContext.length > 0) {
|
||||
return dataJson.map(report => validateCertificateAgainstStandard(report, standardsContext[0] as Standard));
|
||||
let matchedStandard = standardsContext[0] as Standard;
|
||||
if (dataJson[0] && dataJson[0].identification && dataJson[0].identification.standards) {
|
||||
const certNorm = dataJson[0].identification.standards.toLowerCase();
|
||||
const found = standardsContext.find(s =>
|
||||
(s.codigo && certNorm.includes(s.codigo.toLowerCase())) ||
|
||||
(s.id_norma && certNorm.includes(s.id_norma.toLowerCase().replace(/_/g, ' ')))
|
||||
);
|
||||
if (found) matchedStandard = found;
|
||||
}
|
||||
return dataJson.map(report => {
|
||||
report.analysisSource = 'Banco Local';
|
||||
return validateCertificateAgainstStandard(report, matchedStandard);
|
||||
});
|
||||
}
|
||||
return dataJson;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,8 @@ import { ReportData, Standard, ComplianceItem } from '../types';
|
||||
*/
|
||||
function extractNumber(val: string): number | null {
|
||||
if (!val) return null;
|
||||
const match = val.match(/-?\d+(\.\d+)?/);
|
||||
const cleanVal = val.replace(/,/g, '.');
|
||||
const match = cleanVal.match(/-?\d+(\.\d+)?/);
|
||||
return match ? parseFloat(match[0]) : null;
|
||||
}
|
||||
|
||||
@@ -15,7 +16,16 @@ function extractNumber(val: string): number | null {
|
||||
*/
|
||||
function parseThickness(productDesc: string): number {
|
||||
if (!productDesc) return 0;
|
||||
const match = productDesc.match(/(\d+(\.\d+)?)\s*(mm)/i);
|
||||
|
||||
const cleanDesc = productDesc.replace(/,/g, '.');
|
||||
|
||||
// Try to find the pattern "num x num x num" (Thickness x Width x Length)
|
||||
const matchDimensions = cleanDesc.match(/(\d+(?:\.\d+)?)\s*(?:x|X|\*)\s*\d+(?:\.\d+)?\s*(?:x|X|\*)\s*\d+(?:\.\d+)?/);
|
||||
if (matchDimensions) {
|
||||
return parseFloat(matchDimensions[1]);
|
||||
}
|
||||
|
||||
const match = cleanDesc.match(/(\d+(\.\d+)?)\s*(mm)/i);
|
||||
if (match) return parseFloat(match[1]);
|
||||
return 0; // Default or unknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user