JS script error: csv variables already defined in hardware config but shows undefined when running

As you can see in the pictures, the csv values are already defined as the alongside variables but in the later picture, after deploying and viewing the device, It shows error that the variable is undefined.
The Code:

//defining prev variables only once in function
var myFunc = function func(){
    if( myFunc.fired ) return;
    myFunc.fired = true;
    var prev_ph_value = ph_value;
    var prev_turb_value = tds_value;
    var prev_tds_value = turb_value;
    var prev_temp_value = temp_value;
};

myFunc(); //running the function

//setting anomalous values
if (ph_value >= prev_ph_value){
    var anomalous_ph_value = ph_value - prev_ph_value;
}
else{
    var anomalous_ph_value = prev_ph_value - ph_value;
}

if (turb_value >= prev_turb_value){
    var anomalous_turb_value = turb_value - prev_turb_value;
}
else{
    var anomalous_turb_value = prev_turb_value - turb_value;
}

if (tds_value >= prev_tds_value){
    var anomalous_tds_value = tds_value - prev_tds_value;
}
else{
    var anomalous_tds_value = prev_tds_value - tds_value;
}

if (temp_value >= prev_temp_value){
    var anomalous_temp_value = temp_value - prev_temp_value;
}
else{
    var anomalous_temp_value = prev_temp_value - temp_value;
}

//making line charts
var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('Time','pH');
Graph3.plotChart('time_stamp','ph_value','anomalous_ph_value');

var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('Time','TDS(ppm)->');
Graph3.plotChart('time_stamp','tds_value','anomalous_tds_value');

var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('Time','Turbidity(NTU)');
Graph3.plotChart('time_stamp','turb_value','anomalous_turb_value');

var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('Time','Temperature(*C)');
Graph3.plotChart('time_stamp','temp_value','anomalous_temp_value');

var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('Time','Battery Voltage(Volt)');
Graph3.plotChart('time_stamp','bat_volt');

var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('Time','Solar Power(Watts)');
Graph3.plotChart('time_stamp','solar_pow');

//setting prev. values
var prev_ph_value = ph_value;
var prev_turb_value = turb_value;
var prev_tds_value = tds_value;
var prev_temp_value = temp_value;

a43905054b2a313f89163fe691eceb60d2dff94e_2_690x367
a20b40a2d371c58451a0ccb686ee7a48d631d2a5_2_690x367

@electronicspro I do not see any declaration of the variable ph_value. Have you declared it elsewhere in the code?

I think it is already declared alongside the csv table…

@electronicspro Can you please share where it was declared?

Here:
a43905054b2a313f89163fe691eceb60d2dff94e_2_690x367
Ok so let me try to explain what I want to do… I have 4 water sensors, battery voltage and solar power sent to bolt wifi module using uart communication, then it is sent to bolt cloud where I want to make anomalous value based on difference between previous reading sent earlier (for the first time it will be same as the first reading received) and readings received(except battery voltage and solar power) and plot the two values on a line chart. I am not much familiar with ML right now hence I chose the simple way to detect any anomalous value. Hope you got it. If you can help improve the code in any way, it will really be appreciated.

Hi @electronicspro

What you are trying to achieve via javascript is a pretty high level functionality that is currently not available with the Bolt Cloud.

We will surely inform you once such a system is made available.