Author Topic: function to add colored heatColor UV  (Read 138 times)

0 Members and 1 Guest are viewing this topic.

Offline dazza

  • Member
  • *
  • Posts: 46
function to add colored heatColor UV
« on: May 20, 2022, 08:34:19 AM »
Hey sorry to bring this up and im probably wrong in asking but i never can get my head around java

but ive seen this amazing thing u can do with UV with the colour bands

but im trying to put this code in to my own custom realtimereader.js

but im getting stuck with putting it right and getting it to work

any help on this thanks?

here is the code so far sorry it a bit off mess but will tidy it up once ive done what im looking for 

// Edit the next three lines.  The first to note the location of your cumulus realtime.txt file on your web server
// the second line notes how often to refresh the display in seconds. 
var realtime_location="realtime.txt";
var realtime_location_extras="realtimeextras.txt";
var davis_stats_extras="davis_stats.txt";
var update_seconds=15;
var tick_counter=0;
var first_run=1;
setInterval('getlivedata()', 20);
function getlivedata() {
if (tick_counter <= 0) {

// Note: The realtime.txt file and parse it using a space
 var d = new Date();
 var realdata = $.ajax({url: realtime_location + "?" + d.getTime(), async: false, dataType: "html" }).responseText;
 var realdataextras = $.ajax({url: realtime_location_extras + "?" + d.getTime(), async: false, dataType: "html" }).responseText;
 var vp2stats = $.ajax({url: davis_stats_extras + "?" + d.getTime(), async: false, dataType: "html" }).responseText;

// if (realdataextras.indexOf(realtime_location_extras) == -1 ) {    // Removed temporarily for HTML strange characters
 var rawdataextras=realdataextras.split("~");
// if (realdata.indexOf(realtime_location) == -1 ) {     // Removed temporarily for HTML strange characters
 var rawdata=realdata.split(' ');
// if (davis_stats.indexOf(realtime_location_extras) == -1 ) {    // Removed temporarily for HTML strange characters
 var vp2stats=vp2stats.split("-");   
// Set all davisvp2stats IDs to their values      

var langUVWords = new Array (
 "None", "Low", "Medium", "High",
 "Very&nbsp;High", /* be sure to include &nbsp; for space */
 "Extreme" );

// UV Index      
var uv       = realtime[43];
set_ajax_obs("ajaxuv",uv) ;
set_ajax_obs("gizmouv",uv) ;
var uvword = ajax_getUVrange(uv);

function ajax_getUVrange ( uv ) { // code simplified by FourOhFour on
   var uvword = "Unspec.";
   if (uv <= 0) {
       uvword = langUVWords[0];
   } else if (uv < 3) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;"+langUVWords[1]+"&nbsp;</span>";
   } else if (uv < 6) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;"+langUVWords[2]+"&nbsp;</span>";
   } else if (uv < 8) {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;"+langUVWords[3]+"&nbsp;</span>";
   } else if (uv < 11) {
       uvword =  "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;"+langUVWords[4]+"&nbsp;</span>";
   } else {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #9999FF;\">&nbsp;"+langUVWords[5]+"&nbsp;</span>";
   return uvword;
} // end ajax_getUVrange function
 // Set all IDs to their values
$("#winddiricon").html('<img src="images/ajax-images/' + rawdataextras[53] + '.gif"align =center>');
$("#temptrendenglish").html('<img src="images/ajax-images/' + rawdataextras[54] + '.png"align =center>');
$("#presstrendenglish").html('<img src="images/ajax-images/' + rawdataextras[55] + '.png"align =center>');
$("#forecasticons").html('<img src="images/cumulus_icon/forecast_0_'  + rawdata[48] + '.png"align =right>');

 // Calculate the forecast
var fcast = rawdata[48];
if (fcast=="0"){var fdesc="unknown!";} else
if (fcast=="1"){var fdesc="Settled fine";} else
if (fcast=="2"){var fdesc="Fine weather";} else
if (fcast=="3"){var fdesc="Becoming fine";} else
if (fcast=="4"){var fdesc="Fine, becoming less settled";} else
if (fcast=="5"){var fdesc="Fine, possible showers";} else
if (fcast=="6"){var fdesc="Fairly fine, improving";} else
if (fcast=="7"){var fdesc="Fairly fine, possible showers early";} else
if (fcast=="8"){var fdesc="Fairly fine, showery later";} else
if (fcast=="9"){var fdesc="Showery early, improving";} else
if (fcast=="10"){var fdesc="Changeable, mending";} else
if (fcast=="11"){var fdesc="Fairly fine, showers likely";} else
if (fcast=="12"){var fdesc="Rather unsettled clearing later";} else
if (fcast=="13"){var fdesc="Unsettled, probably improving";} else
if (fcast=="14"){var fdesc="Showery, bright intervals";} else
if (fcast=="15"){var fdesc="Showery, becoming less settled";} else
if (fcast=="16"){var fdesc="Changeable, some precipitation";} else
if (fcast=="17"){var fdesc="Unsettled, short fine intervals";} else
if (fcast=="18"){var fdesc="Unsettled, precipitation later";} else
if (fcast=="19"){var fdesc="Unsettled, some precipitation";} else
if (fcast=="20"){var fdesc="Mostly very unsettled";} else
if (fcast=="21"){var fdesc="Occasional precipitation, worsening";} else
if (fcast=="22"){var fdesc="Precipitation at times, very unsettled";} else
if (fcast=="23"){var fdesc="Precipitation at frequent intervals";} else
if (fcast=="24"){var fdesc="Precipitation, very unsettled";} else
if (fcast=="25"){var fdesc="Stormy, may improve";} else
if (fcast=="26"){var fdesc="Stormy, much precipitation";} else
{ var fdesc="";}
if (fdesc == "" || fdesc == "unknown!") {
$("#forecast").html("" + fdesc);   

« Last Edit: May 20, 2022, 09:12:34 AM by dazza »