Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. // export a function
  2. const fs = require('fs');
  3. const path = require('path');
  4. const math = require('mathjs');
  5.  
  6. // to create new directories
  7. const mkdirp = require('mkdirp');
  8.  
  9. // retrieve the variable values of the HTTP query string
  10. const querystring = require('querystring');
  11.  
  12. // to use TomTomService actions
  13. const TomtomService = require('../services/TomTomService');
  14.  
  15. const JobLogPlugin = require('../jobplugins/joblog');
  16.  
  17. // converts a callback-based function to a Promise-based one
  18. const { promisify } = require('util');
  19.  
  20. const writeFile = promisify(fs.writeFile);
  21. const createFolder = promisify(mkdirp);
  22.  
  23.  
  24. /* function which creates an AddressArray and returns the File
  25. function createArrayObjekte (createArrayObjekt){
  26.  
  27. // creates an AddressArray in which Addresses can get pushed in
  28. let arrayObjekt = [];
  29. for (let i=0; i<createArrayObjekt.length; i++){
  30. arrayObjekt = ({
  31. addrnr: createArrayObjekt[i].addrnr,
  32. addrname1: createArrayObjekt[i].addrname1,
  33. addrname2: createArrayObjekt[i].addrname2,
  34. color: createArrayObjekt[i].color,
  35. long: createArrayObjekt[i].positiony,
  36. lat: createArrayObjekt[i].positionx ,
  37. addstreet: createArrayObjekt[i].addrstreet,
  38. addrstate: createArrayObjekt[i].addrstate,
  39. addrzip: createArrayObjekt[i].addrzip,
  40. addrcity: createArrayObjekt[i].addrcity,
  41. addrregion: createArrayObjekt[i].addrregion,
  42. });
  43. }*/
  44.  
  45.  
  46. function prüfungEmpty (prüfungsWertLong, prüfungsWertLat){
  47.  
  48. if ((prüfungsWertLong !== 0) && (prüfungsWertLat !== 0)){
  49.  
  50. return berechnenEntfernung (prüfungsWertLong, prüfungsWertLat);
  51. }
  52.  
  53.  
  54. return "Longitude oder latitude (oder beides) wurde nicht angegeben";
  55.  
  56. }
  57.  
  58. function prüfungValueLatOderLong (prüfungsVariableLat,prüfungsVariableLong){
  59.  
  60. if ((prüfungsVariableLat === null) || (prüfungsVariableLat === undefined) || (prüfungsVariableLat === 0)) {
  61.  
  62. let prüfungsVariableLat = 0;
  63.  
  64. return prüfungEmpty(prüfungsVariableLat, prüfungsVariableLong);
  65. }
  66.  
  67.  
  68. if ((prüfungsVariableLong === null) || (prüfungsVariableLong === undefined) || (prüfungsVariableLong === 0)) {
  69.  
  70. let prüfungsVariableLong = 0;
  71.  
  72. return prüfungEmpty(prüfungsVariableLat, prüfungsVariableLong);
  73. }
  74.  
  75.  
  76. return prüfungEmpty(prüfungsVariableLat, prüfungsVariableLong);
  77.  
  78.  
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85. function gettingLongAndLat (jsonObject){
  86.  
  87. let getLongLatArray = [];
  88.  
  89. for (let i = 0; i < jsonObject.length; i++){
  90.  
  91. getLongLatArray.push({
  92.  
  93. //jsonObject[i].addrnr + " " + jsonObject[i].positiony + " " + jsonObject[i].positionx});
  94. addrnr: jsonObject[i].addrnr,
  95. LongAndLat: prüfungValueLatOderLong (jsonObject[i].positiony, jsonObject[i].positionx),
  96. });
  97.  
  98. listeBis50km (prüfungValueLatOderLong (jsonObject[i].positiony, jsonObject[i].positionx), getLongLatArray);
  99. listeVon50kmBis100km (prüfungValueLatOderLong (jsonObject[i].positiony, jsonObject[i].positionx),getLongLatArray);
  100. }
  101.  
  102. //console.log(getLongLatArray);
  103. }
  104.  
  105. function berechnenEntfernung (jsonLat,jsonLong){
  106.  
  107. let vergleichswertLat = 51719734 ;
  108. let vergleichswertLong = 8753052;
  109.  
  110. let e = math.e;
  111. let R = 6371*e*e*e; // metres
  112. let f1 = umrechnenToRadians(vergleichswertLat);
  113. let f2 = umrechnenToRadians(jsonLat);
  114. let ?f = umrechnenToRadians(jsonLat-vergleichswertLat);
  115. let ?? = umrechnenToRadians(jsonLong-vergleichswertLong);
  116.  
  117. let a = math.sin(?f/2) * math.sin(?f/2) +
  118. math.cos(f1) * math.cos(f2) *
  119. math.sin(??/2) * math.sin(??/2);
  120. let c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));
  121.  
  122. let d = R * c;
  123. let kmEntfernung = d / 1000;
  124. let kmEntfernungMathFloor = math.floor(kmEntfernung);
  125.  
  126. return {
  127. kmEntfernungMathFloor,
  128. };
  129.  
  130. }
  131.  
  132. function listeBis50km (berechneteKmEntfernung, benötigesObjekt){
  133.  
  134. let i = 50;
  135. let listeBis50kmArray = [];
  136.  
  137. if (i > berechneteKmEntfernung){
  138.  
  139. listeBis50kmArray.push({
  140. benötigesObjekt
  141. });
  142.  
  143. }
  144. }
  145.  
  146. function listeVon50kmBis100km (berechneteKmEntfernung, benötigesObjekt){
  147.  
  148. let i = 50;
  149. let k = 100;
  150. let listeVon50kmBis100kmArray = [];
  151.  
  152. if (berechneteKmEntfernung >= i && berechneteKmEntfernung <= k){
  153.  
  154. listeVon50kmBis100kmArray.push({
  155. benötigesObjekt
  156. });
  157.  
  158. }
  159. }
  160.  
  161. function umrechnenToRadians (umrechnungsWert){
  162.  
  163. let pi = math.PI;
  164. return umrechnungsWert * (pi / 180);
  165.  
  166. }
  167.  
  168.  
  169. module.exports = {
  170. name: 'LuftlinienMessung',
  171. perform: async ({ job, systemSource, systemTarget, options }) => {
  172. sails.log(`Get Data from webfleet...`);
  173.  
  174. const qs = querystring.parse(systemSource.query);
  175.  
  176. // ttsConfig: übergibt die EinloggDaten
  177. const ttsConfig = {
  178. username: systemSource.username,
  179. password: systemSource.password,
  180. ...qs,
  181. };
  182.  
  183. const TTS = new TomtomService(ttsConfig);
  184.  
  185. try {
  186. let addressesJson = await TTS.showAddressReportExtern();
  187.  
  188. /*console.log("addressesJson.length inc");
  189. console.log(addressesJson.length);*/
  190.  
  191. let jsonString = JSON.stringify(addressesJson);
  192.  
  193. let addressesArray = [];
  194. addressesArray = JSON.parse(jsonString);
  195.  
  196.  
  197. //let addressesArrayLength = addressesArray.length;
  198.  
  199.  
  200.  
  201. for (let i of addressesJson){
  202. gettingLongAndLat(addressesJson);
  203. }
  204.  
  205. }
  206. catch (e) {
  207. sails.log.error('Fehler beim generieren der Daten:');
  208. sails.log.error(e);
  209. throw e;
  210. }
  211.  
  212.  
  213.  
  214. //let first = addressArray[0];
  215. //console.log(first);
  216.  
  217.  
  218. //if (addressesJson===addressesJson2){
  219.  
  220. /*for (let i = 0; i < addressesJson.length; i++){
  221.  
  222. getLongLatArray = addressesJson[i].addrnr + " " + addressesJson[i].positiony + " " + addressesJson[i].positionx;}
  223.  
  224. console.log(getLongLatArray);*/
  225.  
  226.  
  227.  
  228.  
  229. //console.log(addressesJson);
  230.  
  231. /*let jsonString = JSON.stringify(addressesJson);
  232. let AddressArray = [];
  233. AddressArray = JSON.parse(jsonString);
  234. console.log(AddressArray);
  235.  
  236. createArrayObjekte(AddressArray);*/
  237. /*let addressesArray = JSON.parse(addressesJson);
  238. console.log(addressesArray);
  239. //console.log(addresses);
  240.  
  241. //let addressesObj = JSON.parse(addresses);
  242. console.log(addressesJson);*/
  243.  
  244. /*}
  245. catch (e) {
  246. sails.log.error('Fehler beim generieren der Daten:');
  247. sails.log.error(e);
  248. throw e;
  249. }*/
  250. }
  251. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement