Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // export a function
- const fs = require('fs');
- const path = require('path');
- const math = require('mathjs');
- // to create new directories
- const mkdirp = require('mkdirp');
- // retrieve the variable values of the HTTP query string
- const querystring = require('querystring');
- // to use TomTomService actions
- const TomtomService = require('../services/TomTomService');
- const JobLogPlugin = require('../jobplugins/joblog');
- // converts a callback-based function to a Promise-based one
- const { promisify } = require('util');
- const writeFile = promisify(fs.writeFile);
- const createFolder = promisify(mkdirp);
- /* function which creates an AddressArray and returns the File
- function createArrayObjekte (createArrayObjekt){
- // creates an AddressArray in which Addresses can get pushed in
- let arrayObjekt = [];
- for (let i=0; i<createArrayObjekt.length; i++){
- arrayObjekt = ({
- addrnr: createArrayObjekt[i].addrnr,
- addrname1: createArrayObjekt[i].addrname1,
- addrname2: createArrayObjekt[i].addrname2,
- color: createArrayObjekt[i].color,
- long: createArrayObjekt[i].positiony,
- lat: createArrayObjekt[i].positionx ,
- addstreet: createArrayObjekt[i].addrstreet,
- addrstate: createArrayObjekt[i].addrstate,
- addrzip: createArrayObjekt[i].addrzip,
- addrcity: createArrayObjekt[i].addrcity,
- addrregion: createArrayObjekt[i].addrregion,
- });
- }*/
- function prüfungEmpty (prüfungsWertLong, prüfungsWertLat){
- if ((prüfungsWertLong !== 0) && (prüfungsWertLat !== 0)){
- return berechnenEntfernung (prüfungsWertLong, prüfungsWertLat);
- }
- return "Longitude oder latitude (oder beides) wurde nicht angegeben";
- }
- function prüfungValueLatOderLong (prüfungsVariableLat,prüfungsVariableLong){
- if ((prüfungsVariableLat === null) || (prüfungsVariableLat === undefined) || (prüfungsVariableLat === 0)) {
- let prüfungsVariableLat = 0;
- return prüfungEmpty(prüfungsVariableLat, prüfungsVariableLong);
- }
- if ((prüfungsVariableLong === null) || (prüfungsVariableLong === undefined) || (prüfungsVariableLong === 0)) {
- let prüfungsVariableLong = 0;
- return prüfungEmpty(prüfungsVariableLat, prüfungsVariableLong);
- }
- return prüfungEmpty(prüfungsVariableLat, prüfungsVariableLong);
- }
- function gettingLongAndLat (jsonObject){
- let getLongLatArray = [];
- for (let i = 0; i < jsonObject.length; i++){
- getLongLatArray.push({
- //jsonObject[i].addrnr + " " + jsonObject[i].positiony + " " + jsonObject[i].positionx});
- addrnr: jsonObject[i].addrnr,
- LongAndLat: prüfungValueLatOderLong (jsonObject[i].positiony, jsonObject[i].positionx),
- });
- listeBis50km (prüfungValueLatOderLong (jsonObject[i].positiony, jsonObject[i].positionx), getLongLatArray);
- listeVon50kmBis100km (prüfungValueLatOderLong (jsonObject[i].positiony, jsonObject[i].positionx),getLongLatArray);
- }
- //console.log(getLongLatArray);
- }
- function berechnenEntfernung (jsonLat,jsonLong){
- let vergleichswertLat = 51719734 ;
- let vergleichswertLong = 8753052;
- let e = math.e;
- let R = 6371*e*e*e; // metres
- let f1 = umrechnenToRadians(vergleichswertLat);
- let f2 = umrechnenToRadians(jsonLat);
- let ?f = umrechnenToRadians(jsonLat-vergleichswertLat);
- let ?? = umrechnenToRadians(jsonLong-vergleichswertLong);
- let a = math.sin(?f/2) * math.sin(?f/2) +
- math.cos(f1) * math.cos(f2) *
- math.sin(??/2) * math.sin(??/2);
- let c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
- let d = R * c;
- let kmEntfernung = d / 1000;
- let kmEntfernungMathFloor = math.floor(kmEntfernung);
- return {
- kmEntfernungMathFloor,
- };
- }
- function listeBis50km (berechneteKmEntfernung, benötigesObjekt){
- let i = 50;
- let listeBis50kmArray = [];
- if (i > berechneteKmEntfernung){
- listeBis50kmArray.push({
- benötigesObjekt
- });
- }
- }
- function listeVon50kmBis100km (berechneteKmEntfernung, benötigesObjekt){
- let i = 50;
- let k = 100;
- let listeVon50kmBis100kmArray = [];
- if (berechneteKmEntfernung >= i && berechneteKmEntfernung <= k){
- listeVon50kmBis100kmArray.push({
- benötigesObjekt
- });
- }
- }
- function umrechnenToRadians (umrechnungsWert){
- let pi = math.PI;
- return umrechnungsWert * (pi / 180);
- }
- module.exports = {
- name: 'LuftlinienMessung',
- perform: async ({ job, systemSource, systemTarget, options }) => {
- sails.log(`Get Data from webfleet...`);
- const qs = querystring.parse(systemSource.query);
- // ttsConfig: übergibt die EinloggDaten
- const ttsConfig = {
- username: systemSource.username,
- password: systemSource.password,
- ...qs,
- };
- const TTS = new TomtomService(ttsConfig);
- try {
- let addressesJson = await TTS.showAddressReportExtern();
- /*console.log("addressesJson.length inc");
- console.log(addressesJson.length);*/
- let jsonString = JSON.stringify(addressesJson);
- let addressesArray = [];
- addressesArray = JSON.parse(jsonString);
- //let addressesArrayLength = addressesArray.length;
- for (let i of addressesJson){
- gettingLongAndLat(addressesJson);
- }
- }
- catch (e) {
- sails.log.error('Fehler beim generieren der Daten:');
- sails.log.error(e);
- throw e;
- }
- //let first = addressArray[0];
- //console.log(first);
- //if (addressesJson===addressesJson2){
- /*for (let i = 0; i < addressesJson.length; i++){
- getLongLatArray = addressesJson[i].addrnr + " " + addressesJson[i].positiony + " " + addressesJson[i].positionx;}
- console.log(getLongLatArray);*/
- //console.log(addressesJson);
- /*let jsonString = JSON.stringify(addressesJson);
- let AddressArray = [];
- AddressArray = JSON.parse(jsonString);
- console.log(AddressArray);
- createArrayObjekte(AddressArray);*/
- /*let addressesArray = JSON.parse(addressesJson);
- console.log(addressesArray);
- //console.log(addresses);
- //let addressesObj = JSON.parse(addresses);
- console.log(addressesJson);*/
- /*}
- catch (e) {
- sails.log.error('Fehler beim generieren der Daten:');
- sails.log.error(e);
- throw e;
- }*/
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement