Skip to content

Instantly share code, notes, and snippets.

@tcha-tcho
Created September 14, 2023 14:13
Show Gist options
  • Save tcha-tcho/6c25901ae87a4d8790999f262835bf9e to your computer and use it in GitHub Desktop.
Save tcha-tcho/6c25901ae87a4d8790999f262835bf9e to your computer and use it in GitHub Desktop.
comparing.html
<!doctype HTML>
<html>
<head>
<meta charset="UTF-8">
<!-- <script type="module" src="http://localhost:5000/tracker-net/us-central1/getHistory" /> -->
<!-- <script type="module" src="https://us-central1-tracker-net.cloudfunctions.net/getHistory" /> -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.15.3/xlsx.full.min.js" ></script>
<script type="module">
console.log("starting...")
import "http://localhost:5000/tracker-net/us-central1/getHistory";
// import "https://us-central1-tracker-net.cloudfunctions.net/getHistory";
const fileInput = document.getElementById('xls')
const imeiInput = document.getElementById('imei')
const out = document.getElementById('out');
const compare = (legacy, current) => {
// const results = History.struct(positions, [ "14/06/2023", "31/07/2023" ]);
// console.log(results);
let result = "Tamanho:";
result += "\n legado:"+legacy.length;
result += "\n novo:"+current.length;
out.innerHTML = result
};
window.readFile = () => {
const reader = new FileReader()
reader.onload = () => {
let result = "loading...";
out.innerHTML = result
var data = reader.result;
var workbook = XLSX.read( data, {
type: "binary"
});
var legacy = []
var name = fileInput.files[0].name.split("_2023_");
// object_history_report_2023_09_04_00_00_00_2023_09_04_23_59_00_1694637095.xls
var start = name[1].split("_");
start = start[1]+"/"+start[0]+"/2023"
var end = name[1].split("_");
end = end[1]+"/"+end[0]+"/2023"
workbook.SheetNames.forEach( sheet => {
let arrObj = XLSX.utils.sheet_to_json(workbook.Sheets[sheet], {header: 1});
arrObj = arrObj.filter(arr => arr.length > 2);
let header = arrObj.splice(0,1)[0];
arrObj = arrObj.map(arr => {
let obj = {};
arr.forEach((prop, i) => {
obj[header[i]] = prop;
});
return obj;
});
arrObj.forEach((obj,i) => {
let time = obj['Horário'].split(" ");
let date = time[0].split("-")
let dateLine = date[2]+"-"+date[1]+"-"+date[0]+"T"+time[1];
legacy[i] = {dt: new Date(dateLine).getTime()};
for (let prop in obj) {
if (shorten_names[prop]) {
legacy[i][shorten_names[prop]] = obj[prop];
} else {
legacy[i][prop] = obj[prop];
};
};
});
History.get({
imei: (imeiInput.value||"355322092240174").trim()
, start: start
, end: end
}).then(positions => {
positions = positions.map(pos => {
pos["Horário"] = new Date(pos.dt).toLocaleString();
return pos
});
compare(legacy, positions);
});
});
}
// start reading the file. When it is done, calls the onload event defined above.
reader.readAsBinaryString(fileInput.files[0])
}
// fileInput.addEventListener('change', readFile)
var shorten_names = {
"deviceId": "imei"
,"uniqueId": "imei"
,"": "ssid"
,"tid": "id"
,"in1": "in1"
,"in2": "in2"
,"in3": "in3"
,"out1": "out1"
,"blocked": "out1" // realocation
,"engine_hours": "eh"
,"engineHours": "eh"
,"out2": "out2"
,"out3": "out3"
,"odometer": "odo" // meters
,"power": "pwr" // vols –> use getPower
,"sat": "sat" // in use
,"distance": "dis" // meters
,"totalDistance": "tdis" // meters ,"type": "tp","versionFw": "vf"
,"versionHw": "vh"
,"latitude": "lat"
,"longitude": "lng"
,"protocol": "prot"
,"speed": "spd" // -> use getSpeed
,"valid": "ok"
,"time": "t"
,"deviceTime": "dt"
,"serverTime": "st"
,"fixTime": "ft"
,"alarm": "alrm"
,"alert": "alrt"
,"angle": "angle"
,"sequence": "seq"
,"outdated": "old"
,"altitude": "alt"
,"course": "cs"
,"address": "adr"
,"accuracy": "accu"
,"network": "net"
,"raw": "raw"
,"index": "idx"
,"hdop": "hdop"
,"vdop": "vdop"
,"pdop": "pdop"
,"satVisible": "satv"
,"rssi": "rssi"
,"gps": "gps"
,"roaming": "roam"
,"event": "evt"
,"status": "stat"
,"serviceOdometer": "srvodo" // meters
,"tripOdometer": "tripodo" // meters
,"hours": "hs"
,"steps": "steps"
,"heartRate": "heart"
,"input": "inpt"
,"output": "outpt"
,"image": "img"
,"video": "vid"
,"audio": "aud"
// The units for the below four KEYs currently vary.
// The preferred units of measure are specified in the comment for each.
,"battery": "batt" // volts
,"batteryLevel": "battlvl" // percentage
,"fuel": "fuel" // liters
,"fuelUsed": "fuelu" // liters
,"fuelConsumption": "fuelc" // liters/hour
,"ignition": "ign" // ign
,"flags": "flags"
,"antenna": "ant"
,"charge": "chg"
,"ip": "ip"
,"archive": "arch"
,"rpm": "rpm"
,"vin": "vin"
,"approximate": "approx"
,"throttle": "throttle"
,"motion": "mot"
,"armed": "armed"
,"geofence": "geofc"
,"acceleration": "acc"
,"deviceTemp": "devtmp" // celsius
,"coolantTemp": "cooltmp" // celsius
,"engineLoad": "engload"
,"operator": "op"
,"command": "comm"
// ,"blocked": "blkd" // out1
,"door": "door"
,"axleWeight": "axlwt"
,"gSensor": "gsnsr"
,"iccid": "iccid"
,"phone": "phone"
,"speedLimit": "spdlmt"
,"dtcs": "dtcs"
,"obdSpeed": "obdspd" // knots
,"obdOdometer": "obdodo" // meters
,"result": "res"
,"driverUniqueId": "drvuid"
// Start with 1 not 0
,"temp": "temp"
,"adc": "adc"
,"io": "io"
,"count": "cnt"
,"in": "in"
,"out": "out"
,"general": "gen"
,"sos": "sos"
,"vibration": "vib"
,"movement": "mov"
,"lowspeed": "lspd"
,"overspeed": "ospd"
,"fallDown": "fdwn"
,"lowPower": "lpwr"
,"lowBattery": "lbatt"
,"fault": "flt"
,"powerOff": "poff"
,"powerOn": "pon"
,"lock": "lck"
,"unlock": "ulck"
,"geofenceEnter": "geoin"
,"geofenceExit": "geoout"
,"gpsAntennaCut": "antcut"
,"accident": "accdnt"
,"tow": "tow"
,"idle": "idle"
,"highRpm": "hrpm"
,"hardAcceleration": "hrdacc"
,"hardBraking": "hrdbrk"
,"hardCornering": "hrdcorn"
,"laneChange": "lanec"
,"fatigueDriving": "ftgue"
,"powerCut": "pcut"
,"powerRestored": "pres"
,"jamming": "jamm"
,"temperature": "temp"
,"parking": "park"
,"bonnet": "bonn"
,"footBrake": "brake"
,"fuelLeak": "fleak"
,"tampering": "tamp"
,"removing": "rem"
,"test": "tst"
};
</script>
</head>
<body>
<div>
<p>Select local SMARTGPS XLS File:</p>
<input id="xls" type="file" accept=".xls">
</div>
<div>
<p>IMEI:</p>
<input id="imei" type="text" placeholder="355322092240174"/>
</div>
<div>
<button onclick="window.readFile()">Process</button>
</div>
<pre id="out"><p>File contents will appear here</p></pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment