signalk-polar-performance-plugin 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,12 +37,12 @@ In the plugin configuration you can toggle the following options:
37
37
  - Plugin option to use SOG as boat speed
38
38
  - Wind angle for maximum speed at this wind speed
39
39
  - Fill up the ends of the polar diagram
40
+ - Visualisation of the polar diagram
40
41
 
41
42
  ### To-do list
42
43
  - Improved interpolation
43
44
  - Make moment to do calculation smarter/configurable
44
45
  - API to see JSON of polar
45
- - Visualisation of the polar diagram
46
46
  - Extrapolation of polar data
47
47
  - Create polar from live data
48
48
  -- Save polar info to file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-polar-performance-plugin",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "A plugin that calculates performance information based on a (CSV) polar diagram.",
5
5
  "main": "plugin/index.js",
6
6
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "homepage": "https://github.com/htool/signalk-polar-performance-plugin#readme",
19
19
  "keywords": [
20
+ "signalk-webapp",
20
21
  "signalk-node-server-plugin",
21
22
  "signalk-category-instruments",
22
23
  "signalk-category-chart-plotters"
package/plugin/index.js CHANGED
@@ -66,6 +66,20 @@ module.exports = function (app) {
66
66
  // Load polar table
67
67
  var polar = csvToPolarObject(options.csvTable)
68
68
  app.debug('polar: %s', JSON.stringify(polar))
69
+
70
+ plugin.registerWithRouter = function(router) {
71
+ // Will appear here; plugins/signalk-polar-performance-plugin/
72
+ app.debug("registerWithRouter")
73
+ router.get("/polar", (req, res) => {
74
+ res.contentType("application/json")
75
+ res.send(JSON.stringify(polar))
76
+ })
77
+ router.get("/chartData", (req, res) => {
78
+ res.contentType("application/json")
79
+ res.send(JSON.stringify(getChartData()))
80
+ })
81
+ }
82
+
69
83
 
70
84
  // Global variables
71
85
  var BSP, STW, TWA, targetTWA, TWS, HDG, port // Angles in rad, speed in m/s
@@ -497,7 +511,8 @@ module.exports = function (app) {
497
511
  // Now put some extra values at the beginning
498
512
  var topArray = []
499
513
  for (let angle = 0; angle < lowTWA; angle = angle + degToRad(5)) {
500
- let tbs = (angle / lowTWA) * Math.pow(Math.cos((-1*lowTWA + angle)*3),3) * lowTBS
514
+ let tbs = (angle / lowTWA) * Math.pow(Math.cos((-1*lowTWA + angle)*2),2) * lowTBS
515
+ if (tbs < 0 ) { tbs = 0 }
501
516
  let Obj = {'twa': angle, 'tbs': tbs}
502
517
  topArray.push(Obj)
503
518
  }
@@ -527,6 +542,41 @@ module.exports = function (app) {
527
542
  // app.debug(JSON.stringify(polar))
528
543
  return (polar)
529
544
  }
545
+
546
+ function getChartData () {
547
+ const color = ["#0000FF","#3300FF","#6600FF","#9900FF","#CC00FF","#FF00FF","#0033FF","#3333FF","#6633FF","#9933FF","#CC33FF","#FF33FF","#0066FF","#3366FF","#6666FF","#9966FF","#CC66FF","#FF66FF"]
548
+
549
+ var data = {
550
+ labels: [],
551
+ datasets: []
552
+ }
553
+ for (let angle = 0; angle <= 180; angle += 5) {
554
+ data.labels.push(angle)
555
+ }
556
+ for (let index = 0; index < polar.length -1; index++) {
557
+ // Add x axis label TWS
558
+ let tws = msToKts(polar[index].tws).toFixed(0)
559
+ let twaArray = polar[index].twa
560
+ data.datasets[index] = {
561
+ data: [],
562
+ pointRadius: [],
563
+ borderColor: color[index],
564
+ fill: false,
565
+ parsing: false,
566
+ label: tws + ' kts'
567
+ }
568
+ for (let twaIndex = 0; twaIndex <= twaArray.length-1; twaIndex++) {
569
+ let twaObj = twaArray[twaIndex]
570
+ let radius = 2
571
+ if (twaObj.twa == polar[index]['Beat angle'] || twaObj.twa == polar[index]['Run angle']) {
572
+ radius = 5
573
+ }
574
+ data.datasets[index].data.push({x: Math.round(radToDeg(twaObj.twa)), y: Number(msToKts(twaObj.tbs).toFixed(2))})
575
+ data.datasets[index].pointRadius.push(radius)
576
+ }
577
+ }
578
+ return data
579
+ }
530
580
  }
531
581
 
532
582
  plugin.stop = function () {
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
4
+ <script type='text/javascript' src='/jquery/dist/jquery.min.js'></script>
5
+ <title>Polar performance</title>
6
+ <body>
7
+
8
+ <canvas id="myChart" style="width:100%;max-width:1200px"></canvas>
9
+
10
+ <script>
11
+ $.getJSON("/plugins/signalk-polar-performance-plugin/chartData", function(json) {
12
+ showChart(json)
13
+ })
14
+
15
+ function showChart (data) {
16
+ console.log(data)
17
+
18
+ new Chart("myChart", {
19
+ type: "scatter",
20
+ data: data,
21
+ options: {
22
+ legend: {display: true},
23
+ spanGaps: true,
24
+ scales: {
25
+ x: {
26
+ type: 'linear'
27
+ },
28
+ xAxes: [{
29
+ scaleLabel: {
30
+ display: true,
31
+ labelString: 'True wind angle (TWA)'
32
+ }
33
+ }],
34
+ yAxes: [{
35
+ scaleLabel: {
36
+ display: true,
37
+ labelString: 'Target boat speed (POL SPD)'
38
+ }
39
+ }],
40
+ }
41
+ }
42
+ })
43
+ }
44
+ </script>
45
+