Skip to content

Instantly share code, notes, and snippets.

@GermanHoyos
Created November 17, 2022 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GermanHoyos/56715ba4d59d8887dcf96f49d972fb38 to your computer and use it in GitHub Desktop.
Save GermanHoyos/56715ba4d59d8887dcf96f49d972fb38 to your computer and use it in GitHub Desktop.
<!--
CODED BY: GERMAN HOYOS
EMAIL: german.hoyos@l3harris.com
-->
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: black;
color: black;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<div style="color:white"><h1>Use this file browser select a report:</h1></div>
<input type="file" name="inputfile" id="inputfile" >
<br>
<pre id="output"></pre>
<div id="addToMe"></div>
</body>
<script>
//Test is script is ran
console.log("script active");
let txtArr = "";
let dictionary = [];
//Use html5 FileReader to parse entire report
document.getElementById('inputfile').addEventListener('change',
function(){
var scanner = new FileReader();
scanner.onload = function(){
txtArr = scanner.result;
findKeyWords(txtArr);
};
scanner.readAsText(this.files[0]);
}
);
//Take string value from parser as argument
function findKeyWords(txtArr) {
//fill each Bucket with keywords from input report
//this will include data + meta data
const failBucket = /Fail/g, str_1 = txtArr;
const tbodBucket = /tbody>/g, str_2 = txtArr;
const mainBucket = /MainSequence/g, str_3 = txtArr;
//loop through meta data of failBucket and find its indexes
while ((match = failBucket.exec(str_1)) !== null) {
dictionary.push({
key: match.index,
value: match[0]
});
}
//loop through meta data of tbodBucket and find its indexes
while ((match = tbodBucket.exec(str_2)) !== null) {
dictionary.push({
key: match.index,
value: match[0]
});
}
//loop through meta data of mainBucket and find its indexes
while ((match = mainBucket.exec(str_3)) !== null) {
dictionary.push({
key: match.index,
value: match[0]
});
}
//sort dictionary based on key values (which match index values of stringafied report)
dictionary.sort(function(a, b){return a.key - b.key});
//console.log(dictionary);
//get index of 2nd and last "MainSequence" / call them "father" and "child"
let mainSeqCount = 0; // count how many times main happens
let mainFather = 0; // will equal start of fail search
let mainChild = 0; // will equal end of fail search
for (let i = 0; i < dictionary.length; i++) {
if (dictionary[i].value == 'MainSequence'){
mainSeqCount++;
//console.log(mainSeqCount);
if (mainSeqCount > 1 && mainSeqCount < 3){
mainFather = dictionary[i].key;
//console.log(mainFather);
}
if (mainSeqCount > 2){
mainChild = dictionary[i].key;
//console.log(mainChild);
}
}
}
//print everything between father and child
for (let i = 0; i < dictionary.length; i++) {
if (dictionary[i].key > mainFather && dictionary[i].key < mainChild){
//console.log(dictionary[i].key + " : " + dictionary[i].value);
}
}
//print only fails between father and child
//include the "tbody" before and after said "fail"
for (let i = 0; i < dictionary.length; i++) {
if (dictionary[i].key > mainFather && dictionary[i].key < mainChild){
if(dictionary[i].value == "Fail"){
console.log(
// dictionary[i - 1].key + " " + dictionary[i - 1].value + " " +
// dictionary[i].key + " : " + dictionary[i].value + " " +
// dictionary[i+ 1].key + " : " + dictionary[i + 1].value
);
}
}
}
//print to all char's from [tbody] -> [Fail] -> [tbody]
for (let i = 0; i < dictionary.length; i++) {
if (dictionary[i].key > mainFather && dictionary[i].key < mainChild){
if(dictionary[i].value == "Fail"){
let result = txtArr.substring( dictionary[i - 1].key, dictionary[i + 1].key );
//console.log(result); //this result is raw and non appended
}
}
}
//revert parsed data back to html code and display in window
//keep inmind certain factors
// father is missing " ...<table style="border-color:#000000;"><... "
// child is missing " ...tbody></table><br><div>... "
//there are 2 ways of doing this I can think of:
//1 -build the appropiate string with prepended and postpended values from above
//2 -do it on the fly by building the html from js
//1) appending string way:
for (let i = 0; i < dictionary.length; i++) {
if (dictionary[i].key > mainFather && dictionary[i].key < mainChild){
if(dictionary[i].value == "Fail"){
let result = '<table style="border-color:#000000;"><' + txtArr.substring( dictionary[i - 1].key, dictionary[i + 1].key ) + "tbody></table><br><div>"
console.log(result);
}
}
}
//parse to the DOM
var parser = new DOMParser();
for (let i = 0; i < dictionary.length; i++) {
if (dictionary[i].key > mainFather && dictionary[i].key < mainChild){
if(dictionary[i].value == "Fail"){
let result = '<table style="border-color:#000000;"><' + txtArr.substring( dictionary[i - 1].key, dictionary[i + 1].key ) + "<tbody></table><br><div>"
document.getElementById("addToMe").innerHTML += result;
}
}
}
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment