Ero sivun ”Widget:JwCurrentCharts” versioiden välillä
Järvi-meriwikistä
(60 välissä olevaa versiota samalta käyttäjältä ei näytetä) | |||
Rivi 497: | Rivi 497: | ||
if ( memo.obscode == 'level' ) { | if ( memo.obscode == 'level' ) { | ||
− | |||
− | |||
memo.avgW = {}; | memo.avgW = {}; | ||
for (var o in memo.obsesA) { | for (var o in memo.obsesA) { | ||
Rivi 518: | Rivi 516: | ||
} | } | ||
− | obs = memo.obsesA[0]; | + | if ( memo.obsesA.length > 0 ) { |
− | + | obs = memo.obsesA[0]; | |
− | + | for (var r in memo.refs) { | |
− | + | ref = memo.refs[r]; | |
+ | break; | ||
+ | } | ||
+ | |||
+ | refdata = JSON.parse( ref.printouts.DataJSON ); | ||
+ | refn = refdata.val/100; | ||
+ | |||
+ | diff = obs.value - refn; | ||
+ | diff = Math.round( diff*100 ); | ||
+ | diffStr = diff.toString() + ' cm'; | ||
+ | if ( diff > 0 ) { diffStr = '+' + diffStr; } | ||
+ | } else { | ||
+ | diff = -999; | ||
+ | diffStr = ''; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
var levelsvg = '<?xml version="1.0" encoding="utf-8"?><svg role="img" aria-label="XXX" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 99.6;" xml:space="preserve"><style type="text/css">.st0{fill:#ccc;} .st1{fill:#0076B0;}</style>'; | var levelsvg = '<?xml version="1.0" encoding="utf-8"?><svg role="img" aria-label="XXX" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" style="enable-background:new 0 0 100 99.6;" xml:space="preserve"><style type="text/css">.st0{fill:#ccc;} .st1{fill:#0076B0;}</style>'; | ||
var levelclass = 'st0'; | var levelclass = 'st0'; | ||
+ | |||
if ( diff > 20 ) { levelclass = "st1"; } | if ( diff > 20 ) { levelclass = "st1"; } | ||
levelsvg += '<path class="' + levelclass + '" d="M46.8,1.2c1.9-1.5,4.5-1.5,6.4,0c3.9,3,8.7,5.1,13.5,5.1c4.7,0,9.6-2.1,13.4-5.1l0,0c2.1-1.7,4.9-1.5,6.8,0.3c2.5,2.3,5.6,4.1,8.8,4.9c3,0.8,4.8,4.1,4.2,7.5s-3.7,5.4-6.7,4.7c-4.3-1.1-7.8-3.2-10.1-4.9c-5,3-10.7,5.1-16.4,5.1c-5.5,0-10.5-1.9-14-3.7c-1-0.5-1.9-1-2.7-1.5c-0.8,0.5-1.7,1-2.7,1.5c-3.4,1.8-8.4,3.7-14,3.7c-5.7,0-11.4-2-16.4-5c-2.3,1.6-5.9,3.8-10.1,4.9c-3,0.8-6-1.3-6.7-4.7s1.2-6.7,4.2-7.5c3.1-0.8,6.3-2.6,8.8-4.9c1.9-1.9,4.7-2,6.8-0.3l0,0c3.9,3,8.8,5.1,13.5,5.1C38.1,6.3,42.9,4.2,46.8,1.2z"/>'; | levelsvg += '<path class="' + levelclass + '" d="M46.8,1.2c1.9-1.5,4.5-1.5,6.4,0c3.9,3,8.7,5.1,13.5,5.1c4.7,0,9.6-2.1,13.4-5.1l0,0c2.1-1.7,4.9-1.5,6.8,0.3c2.5,2.3,5.6,4.1,8.8,4.9c3,0.8,4.8,4.1,4.2,7.5s-3.7,5.4-6.7,4.7c-4.3-1.1-7.8-3.2-10.1-4.9c-5,3-10.7,5.1-16.4,5.1c-5.5,0-10.5-1.9-14-3.7c-1-0.5-1.9-1-2.7-1.5c-0.8,0.5-1.7,1-2.7,1.5c-3.4,1.8-8.4,3.7-14,3.7c-5.7,0-11.4-2-16.4-5c-2.3,1.6-5.9,3.8-10.1,4.9c-3,0.8-6-1.3-6.7-4.7s1.2-6.7,4.2-7.5c3.1-0.8,6.3-2.6,8.8-4.9c1.9-1.9,4.7-2,6.8-0.3l0,0c3.9,3,8.8,5.1,13.5,5.1C38.1,6.3,42.9,4.2,46.8,1.2z"/>'; | ||
Rivi 562: | Rivi 566: | ||
} else if ( diff > -20 ) { | } else if ( diff > -20 ) { | ||
levelsvg.replace( 'XXX', 'Vedenpinta matala' ); | levelsvg.replace( 'XXX', 'Vedenpinta matala' ); | ||
+ | } else if ( diff > -100 ) { | ||
+ | levelsvg.replace( 'XXX', 'Vedenpinta erittäin matala' ); | ||
} else { | } else { | ||
− | levelsvg.replace( 'XXX', ' | + | levelsvg.replace( 'XXX', 'Ei tuloksia' ); |
} | } | ||
Rivi 573: | Rivi 579: | ||
} else if ( memo.obscode == 'ice' ) { | } else if ( memo.obscode == 'ice' ) { | ||
− | + | ||
+ | var sites = {}; | ||
+ | var obsesA = []; | ||
+ | for ( var o in memo.obsesA ) { | ||
+ | obs = memo.obsesA[o]; | ||
+ | if ( typeof sites[ obs.printouts.SiteID[0] ] == 'undefined' ) { | ||
+ | sites[ obs.printouts.SiteID[0] ] = true; | ||
+ | obsesA.push( obs ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | memo.obsesA = obsesA; | ||
var ivalsum = 0; | var ivalsum = 0; | ||
+ | var ivalcount = 0; | ||
+ | var ivc = 0; | ||
+ | var ivalmin = 999; | ||
+ | var ivalmax = 0; | ||
+ | var ivalavg = -1; | ||
var icatsum = 0; | var icatsum = 0; | ||
var icount = 0; | var icount = 0; | ||
var icatcount = 0; | var icatcount = 0; | ||
− | + | console.log( memo.obsesA ); | |
for ( var o in memo.obsesA ) { | for ( var o in memo.obsesA ) { | ||
+ | |||
obs = memo.obsesA[o]; | obs = memo.obsesA[o]; | ||
iw = ( 7 - Math.round( ( today.getTime() - memo.obsesA[o].obsdatetime.getTime() ) / ( 24*60*60*1000 ) ) ); | iw = ( 7 - Math.round( ( today.getTime() - memo.obsesA[o].obsdatetime.getTime() ) / ( 24*60*60*1000 ) ) ); | ||
+ | |||
if ( obs.data.cat == '0' || obs.data.cat == '5' ) { | if ( obs.data.cat == '0' || obs.data.cat == '5' ) { | ||
icat = 0; | icat = 0; | ||
− | } else if ( obs.data.cat == ' | + | } else if ( obs.data.cat == '1' || obs.data.cat == '4' ) { |
icat = 0.5; | icat = 0.5; | ||
} else { | } else { | ||
icat = 1; | icat = 1; | ||
− | } | + | } |
+ | |||
+ | if ( obs.data.val > 0 ) { | ||
+ | ivc++; | ||
+ | ivalsum += iw * obs.data.val; | ||
+ | ivalcount += iw; | ||
+ | ivalmin = Math.min( ivalmin, obs.data.val ); | ||
+ | ivalmax = Math.max( ivalmax, obs.data.val ); | ||
+ | } | ||
+ | |||
icatsum += icat * iw; | icatsum += icat * iw; | ||
icount++; | icount++; | ||
− | icatcount | + | icatcount += iw; |
− | |||
− | |||
} | } | ||
+ | |||
if ( icount > 0 ) { | if ( icount > 0 ) { | ||
− | iavg = | + | |
− | if ( iavg | + | iavg = ( icatsum/icatcount ); |
− | + | ||
− | + | //console.log( iavg ); | |
+ | |||
+ | if ( iavg > 0.7 && ivc > 0 ) { | ||
+ | |||
+ | ivalavg = Math.round( ivalsum/ivalcount ); | ||
+ | ivalmin = Math.round( ivalmin ); | ||
+ | ivalmax = Math.round( ivalmax ); | ||
+ | //console.log( ivalavg ); | ||
+ | if ( ivalmax > ivalmin ) { | ||
+ | istr = ivalmin + '–' + ivalmax + ' cm'; | ||
+ | } else { | ||
+ | istr = ivalmin + ' cm'; | ||
+ | } | ||
+ | |||
+ | if ( ivc == 1 ) { | ||
+ | istr += '<br /><span>(' + memo.obsesA[0].obsdatetime.inRelationToToday(memo.lang).toLowerCase() + ')</span>'; | ||
+ | } else { | ||
+ | istr += '<br /><span class="smaller">('; | ||
+ | istr += '<button style="margin-left: -1px; padding: 0; font-size: 13px; margin-bottom: 3px; color: #59B500;" type="button" class="btn Xbtn-secondary Xbtn-info" data-toggle="tooltip" data-placement="top" title="" data-original-title="Perustuu yhteensä ' + icount + ' havaintoon ajanjaksolla: ' + memo.obsesA[ memo.obsesA.length-1 ].obsdatetime.toLocaleDateString() + '-' + memo.obsesA[0].obsdatetime.toLocaleDateString() + '."><span class="fontawesome"></span></button>'; | ||
+ | istr += ' ⋯' + memo.obsesA[0].obsdatetime.inRelationToToday(memo.lang).toLowerCase() + ')</span>'; | ||
+ | } | ||
+ | |||
− | |||
− | |||
} else { | } else { | ||
− | + | ||
− | + | if ( iavg < 0.25 || memo.obsesA[0].data.cat == '5' ) { istr = 'Ei jäätä'; } | |
− | istr += '<br /><span class="smaller">( | + | else if ( iavg < 0.75 ) { istr = 'Osittain jäässä'; } |
+ | else { istr = 'Yhtenäinen jääpeite'; } | ||
+ | |||
+ | if ( icount == 1 ) { | ||
+ | istr += '<br /><span>(' + memo.obsesA[0].obsdatetime.inRelationToToday(memo.lang).toLowerCase() + ')</span>'; | ||
+ | } else { | ||
+ | istr += '<br /><span class="smaller">('; | ||
+ | istr += '<button style="margin-left: -1px; padding: 0; font-size: 13px; margin-bottom: 3px; color: #59B500;" type="button" class="btn Xbtn-secondary Xbtn-info" data-toggle="tooltip" data-placement="top" title="" data-original-title="Perustuu yhteensä ' + icount + ' havaintoon ajanjaksolla: ' + memo.obsesA[ memo.obsesA.length-1 ].obsdatetime.toLocaleDateString() + '-' + memo.obsesA[0].obsdatetime.toLocaleDateString() + '."><span class="fontawesome"></span></button>'; | ||
+ | istr += ' ↦' + memo.obsesA[0].obsdatetime.inRelationToToday(memo.lang).toLowerCase() + ')</span>'; | ||
+ | } | ||
} | } | ||
} else { | } else { | ||
Rivi 622: | Rivi 682: | ||
var ry = 10; | var ry = 10; | ||
− | ic = 1; | + | //ic = 1; |
− | iavg = 0.5; | + | //iavg = 0.5; |
for ( var row=0; row<10; row++ ) { | for ( var row=0; row<10; row++ ) { | ||
Rivi 629: | Rivi 689: | ||
x = col * 10 + 1; | x = col * 10 + 1; | ||
y = row * 10 + 1; | y = row * 10 + 1; | ||
− | if ( | + | //console.log( 1 + ivalavg/10 ); |
− | + | if ( icount > 0 ) { | |
− | + | if ( ivalavg > 0 ) { | |
− | + | if ( row < ivalavg/10 ) { | |
− | + | aclass = 'ice1'; | |
− | + | } else { | |
+ | aclass = 'ice0'; | ||
+ | } | ||
} else { | } else { | ||
− | aclass = 'ice0'; | + | dist = Math.sqrt( Math.pow( (4.5-col), 2 ) + Math.pow( (4.5-row), 2 ) )/ Math.sqrt( 40.5 ); |
+ | if ( today.getMonth() > 0 && today.getMonth() < 6 ) { dist = 1- dist; } | ||
+ | random = (Math.random()-0.5)*0.25; | ||
+ | if ( ( (dist+random) > (1-iavg) ) ) { | ||
+ | aclass = 'ice1'; | ||
+ | } else { | ||
+ | aclass = 'ice0'; | ||
+ | } | ||
} | } | ||
} else { | } else { | ||
Rivi 672: | Rivi 741: | ||
} | } | ||
− | if ( | + | if ( tcsum > 0 ) { |
tavg = Math.round( tsum/tcsum*10 ) / 10; | tavg = Math.round( tsum/tcsum*10 ) / 10; | ||
tstr = tavg.toString().replace( '.', ',' ) + ' °C'; | tstr = tavg.toString().replace( '.', ',' ) + ' °C'; | ||
Rivi 744: | Rivi 813: | ||
for ( var o in memo.obsesA ) { | for ( var o in memo.obsesA ) { | ||
aw = ( 7 - Math.round( ( today.getTime() - memo.obsesA[o].obsdatetime.getTime() ) / ( 24*60*60*1000 ) ) ); | aw = ( 7 - Math.round( ( today.getTime() - memo.obsesA[o].obsdatetime.getTime() ) / ( 24*60*60*1000 ) ) ); | ||
− | asum += memo.obsesA[o].data.val * aw; | + | asum += memo.obsesA[o].data.val * aw; |
acsum = acsum + aw; | acsum = acsum + aw; | ||
ac++; | ac++; | ||
} | } | ||
− | if ( | + | if ( acsum > 0 ) { |
− | var aavg = asum/acsum; | + | |
+ | var aavg = asum/acsum; | ||
if ( aavg < 0.25 ) { astr = 'Ei sinilevää'; } | if ( aavg < 0.25 ) { astr = 'Ei sinilevää'; } | ||
else if ( aavg < 1.25 ) { astr = 'Hieman sinilevää'; } | else if ( aavg < 1.25 ) { astr = 'Hieman sinilevää'; } |