chore(logic): autoformat with prettier

This commit is contained in:
Paul Bienkowski 2020-11-17 18:07:32 +01:00
parent 79de852d91
commit 04f597cfb1
3 changed files with 100 additions and 114 deletions

View file

@ -1,11 +1,8 @@
class TrackInfo {
constructor(track,trackData)
{
constructor(track, trackData) {
this.track = track;
this.trackData = trackData;
}
}
module.exports = TrackInfo
module.exports = TrackInfo;

View file

@ -1,117 +1,107 @@
module.exports.addPointsToTrack = function addPointsToTrack(track, body)
{
module.exports.addPointsToTrack = function addPointsToTrack(track, body) {
var num = 0;
var start = 0;
var end = 0;
//console.log("len"+body.length);
//console.log("len"+body.length);
while (end < body.length) {
start = end;
while (body[end] != ";" && body[end] != "$" && end < body.length) {
while (body[end] != ';' && body[end] != '$' && end < body.length) {
end++;
}
if(body[end] == "$") // $ is replacing \n as newlines are not allowed in json strings
{
num=0;
if (body[end] == '$') {
// $ is replacing \n as newlines are not allowed in json strings
num = 0;
}
if(end < body.length)
{
var token = body.substr(start, end - start);
end++;
if(token.length>0)
{
//console.log(token);
//console.log("num:"+num);
//console.log("end:"+end);
if (end < body.length) {
var token = body.substr(start, end - start);
end++;
if (token.length > 0) {
//console.log(token);
//console.log("num:"+num);
//console.log("end:"+end);
if((num == 0) && (token == "Date"))
{
// we have a header line, ignore it for now, TODO parse it
if (end < body.length) {
while (body[end] != ";" && body[end] != "$" && end < body.length) {
end++;
if (num == 0 && token == 'Date') {
// we have a header line, ignore it for now, TODO parse it
if (end < body.length) {
while (body[end] != ';' && body[end] != '$' && end < body.length) {
end++;
}
start = end;
num = 100;
}
}
if (num == 0) {
track.trackData.points.push({
date: 'dummy',
time: '',
latitude: '',
longitude: '',
course: '',
speed: '',
d1: '',
d2: '',
flag: '',
private: '',
});
track.trackData.points[track.trackData.points.length - 1].date = token;
num++;
} else if (num == 1) {
track.trackData.points[track.trackData.points.length - 1].time = token;
num++;
} else if (num == 2) {
var f = parseFloat(token);
if (isNaN(f)) {
f = parseFloat(token.substring(0, 10));
}
if (isNaN(f)) {
f = 0.0;
}
track.trackData.points[track.trackData.points.length - 1].latitude = f;
num++;
} else if (num == 3) {
var f = parseFloat(token);
if (isNaN(f)) {
f = parseFloat(token.substring(0, 10));
}
if (isNaN(f)) {
f = 0.0;
}
track.trackData.points[track.trackData.points.length - 1].longitude = f;
num++;
} else if (num == 4) {
var f = parseFloat(token);
if (isNaN(f)) {
f = parseFloat(token.substring(0, 10));
}
if (isNaN(f)) {
f = 0.0;
}
track.trackData.points[track.trackData.points.length - 1].course = f;
num++;
} else if (num == 5) {
var f = parseFloat(token);
if (isNaN(f)) {
f = parseFloat(token.substring(0, 10));
}
if (isNaN(f)) {
f = 0.0;
}
track.trackData.points[track.trackData.points.length - 1].speed = f;
num++;
} else if (num == 6) {
track.trackData.points[track.trackData.points.length - 1].d1 = token;
num++;
} else if (num == 7) {
track.trackData.points[track.trackData.points.length - 1].d2 = token;
num++;
} else if (num == 8) {
track.trackData.points[track.trackData.points.length - 1].flag = token;
num++;
} else if (num == 9) {
track.trackData.points[track.trackData.points.length - 1].private = token;
num++;
}
start = end;
num=100;
}
}
if (num == 0) {
track.trackData.points.push({ date: "dummy", time: "", latitude: "", longitude: "", course: "", speed: "", d1: "", d2: "", flag: "", private: ""});
track.trackData.points[track.trackData.points.length - 1].date = token;
num++;
}
else if (num == 1) {
track.trackData.points[track.trackData.points.length - 1].time = token;
num++;
}
else if (num == 2) {
var f = parseFloat(token);
if(isNaN(f))
{
f = parseFloat(token.substring(0,10));
}
if(isNaN(f))
{
f=0.0;
}
track.trackData.points[track.trackData.points.length - 1].latitude = f;
num++;
}
else if (num == 3) {
var f = parseFloat(token);
if(isNaN(f))
{
f = parseFloat(token.substring(0,10));
}
if(isNaN(f))
{
f=0.0;
}
track.trackData.points[track.trackData.points.length - 1].longitude = f;
num++;
}
else if (num == 4) {
var f = parseFloat(token);
if(isNaN(f))
{
f = parseFloat(token.substring(0,10));
}
if(isNaN(f))
{
f=0.0;
}
track.trackData.points[track.trackData.points.length - 1].course = f;
num++;
}
else if (num == 5) {
var f = parseFloat(token);
if(isNaN(f))
{
f = parseFloat(token.substring(0,10));
}
if(isNaN(f))
{
f=0.0;
}
track.trackData.points[track.trackData.points.length - 1].speed = f;
num++;
}
else if (num == 6) {
track.trackData.points[track.trackData.points.length - 1].d1 = token;
num++;
}
else if (num == 7) {
track.trackData.points[track.trackData.points.length - 1].d2 = token;
num++;
}
else if (num == 8) {
track.trackData.points[track.trackData.points.length - 1].flag = token;
num++;
}
else if (num == 9) {
track.trackData.points[track.trackData.points.length - 1].private = token;
num++;
}
}
}
}
}
};

View file

@ -1,8 +1,7 @@
var {addPointsToTrack} = require('./tracks')
var { addPointsToTrack } = require('./tracks');
describe('addPointsToTrack', () => {
it('is a function', () => {
expect(typeof addPointsToTrack).toBe('function')
})
})
expect(typeof addPointsToTrack).toBe('function');
});
});