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 

Quote
// 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) {

// READ REALTIME FILE
//
// 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      
$("#wsforecast").html(vp2stats[6])   
      

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);
set_ajax_obs("ajaxuvword",uvword);
set_ajax_obs("gizmouvword",uvword);





function ajax_getUVrange ( uv ) { // code simplified by FourOhFour on wxforum.net
   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
$("#tempTH").html(rawdataextras[0]);
$("#TtempTH").html(rawdataextras[1]);
$("#tempTL").html(rawdataextras[2]);
$("#TtempTL").html(rawdataextras[3]);
$("#apptempTH").html(rawdataextras[4]);
$("#TapptempTH").html(rawdataextras[5]);   
$("#apptempTL").html(rawdataextras[6]);
$("#TapptempTL").html(rawdataextras[7]);   
$("#feelslikeTH").html(rawdataextras[8]);
$("#TfeelslikeTH").html(rawdataextras[9]);   
$("#TfeelslikeTL").html(rawdataextras[10]);   
$("#feelslikeTL").html(rawdataextras[11]);
$("#temprange").html(rawdataextras[12]);   
$("#avgtemp").html(rawdataextras[13]);
$("#humidexTH").html(rawdataextras[14]);   
$("#ThumidexTH").html(rawdataextras[15]);   
$("#wchillTL").html(rawdataextras[16]);
$("#TwchillTL").html(rawdataextras[17]);
$("#heatindexTH").html(rawdataextras[18]);
$("#TheatindexTH").html(rawdataextras[19]);
$("#humTH").html(rawdataextras[20]);   
$("#ThumTH").html(rawdataextras[21]);   
$("#humTL").html(rawdataextras[22]);
$("#ThumTL").html(rawdataextras[23]);
$("#solarTH").html(rawdataextras[24]);
$("#TsolarTH").html(rawdataextras[25]);
$("#SunshineHours").html(rawdataextras[26]);
$("#UVTH").html(rawdataextras[27]);   
$("#TUVTH").html(rawdataextras[28]);   
$("#wgustTM").html(rawdataextras[29]);
$("#TwgustTM").html(rawdataextras[30]);
$("#windTM").html(rawdataextras[31]);
$("#Tbeaufort").html(rawdataextras[32]);   
$("#TwindTM").html(rawdataextras[33]);
$("#windrun").html(rawdataextras[34]);
$("#domwindbearing").html(rawdataextras[35]);
$("#domwinddir").html(rawdataextras[36]);
$("#rfall").html(rawdataextras[37]);
$("#rrateTM").html(rawdataextras[38]);
$("#TrrateTM").html(rawdataextras[39]);
$("#hourlyrainTH").html(rawdataextras[40]);
$("#ThourlyrainTH").html(rawdataextras[41]);
$("#ConsecutiveRainDays").html(rawdataextras[42]);
$("#ConsecutiveDryDays").html(rawdataextras[43]);
$("#pressTH").html(rawdataextras[44]);
$("#TpressTH").html(rawdataextras[45]);
$("#pressTL").html(rawdataextras[46]);
$("#TpressTL").html(rawdataextras[47]);
$("#time").html(rawdataextras[48]);
$("#dewpointTL").html(rawdataextras[49]);
$("#TdewpointTL").html(rawdataextras[50]);
$("#dewpointTH").html(rawdataextras[51]);
$("#TdewpointTH").html(rawdataextras[52]);
$("#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").hide();
   }
else
   {
   $("#forecast").show();
   }
$("#forecast").html("" + fdesc);   
   
   
   
tick_counter=update_seconds;
}
else
{
tick_counter--;
$("#refresh_in").html(tick_counter);
}
}







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