posted an update

Pseudo-code for Version 2 by Jim Beck // driver to test functions

include

int main() {

float segment_time, averaged_temp;

printf(“Hello World start\n”);

reset_readings();

time_temp_arr[0][0] = 5.0; time_temp_arr[1][0] = 72.0; time_temp_arr[0][1] = 605.0; time_temp_arr[1][1] = 78.0; time_temp_arr[0][2] = 630.0; time_temp_arr[1][2] = 84.0; num_readings = 3;

printf("%4d, %4.2f\n",heating_phase(&segment_time), segment_time); printf("%4d, %4.2f\n",cooling_phase(&segment_time), segment_time); printf("%4d, %4.2f\n",steady_state(&averaged_temp), averaged_temp); printf("%4d\n",throw_alert());

printf(“Hello World end\n”);

return 0;

} // end of test driver

//ambient_temp (Farenheit), used mostly to aid low-level heating situation float ambient_temp = 72.0;

// default time (in seconds), used to establish an "ignore readings" period to provide // a "settling" time, expressed in seconds; hence, first 10 minutes of readings to be ignored. global static initial_settling_time = 600.0;

// array holding time, temp reading pairs, assumed to be in seconds, degrees Farenheit. parameter MAX_READINGS; global static float time_temp_arr[2,MAX_READINGS]; global static int num_readings;

// this to be invoked at device startup, as well as when errant event has been determined that // might taint readings, such as device location being changed, wiping of stovetop, opening of a // house window, fan being turned on, etc. // With these invocations, sanctity of previous data is considered to be of lower importance // than the reporting of a weakly-determined condition. function reset_readings() { num_readings = 0; }

function add_reading() { if (num_readings >= MAX_READINGS) // should instead remove several of the earliest readings via left-shifting array values to create space return FALSE; else { // time_temp_arr[0][num_readings] = get_time_reading(); // time_temp_arr[1][num_readings] = get_temp_reading(); num_readings++; } }

// device considered in a heating phase if there exists a "sufficiently" steep positive slope or % of positive slopes between readings. logical function heating_phase( float segment_time; ) { int count, pos_slope_count, first_reading, last_reading; float temp_diff; // define the "percentage" of needed positively-sloped intervals in order to consider the range of values to be part of an overall period of "heating." // Also aids allowing an amount of possibly spurious readings to be ignored. float pos_slope_percentage = 0.80; // define what is considered to be an acceptable threshold slope to accept a range of temperature // readings to be in a "heating" phase // empirical collection showed approx. 0.6 degree Farenheit rise per 60 seconds in an Energy Star // range float heating_slope = 0.01;

count = 0;
pos_slope_count = 0;

for (i = 0; i< num_readings-1; i++) {
    if (time_temp_arr[0][i+1] > initial_settling_time) {
        count++;
        temp_diff = time_temp_arr[1][i+1] - time_temp_arr[1][i];
        if (temp_diff > 0.0) {
            pos_slope_count++;
            if (pos_slope_count == 1) first_reading = i;
            last_reading = i+1;
        }
    }
}  // end of i for loop

if (pos_slope_count == 0) return FALSE;

segment_time = time_temp_arr[0][last_reading] - time_temp_arr[0][first_reading];
overall_slope = (time_temp_arr[1][last_reading] - time_temp_arr[1][first_reading])          / segment_time;

if (float(pos_slope_count)/float(count) > pos_slope_percentage .AND.
 overall_slope > heating_slope) {
    return TRUE;
else
    return FALSE;
}

} // end of heating_phase function

// similar to heating_phase logic, rate of cooling expected to be much less that rate of heating // though, as well as negatively-sloped logical function cooling_phase() { int count, neg_slope_count, first_reading, last_reading; float temp_diff; // define the "percentage" of needed negatively-sloped intervals in order to consider the range of values to be part of an overall period of "cooling." // Also aids allowing an amount of possibly spurious readings to be ignored. float neg_slope_percentage = 0.80; // define what is considered to be an acceptable threshold slope to accept a range of temperature // readings to be in a "cooling" phase // empirical collection showed approx. 0.1 degree Farenheit drop per 60 seconds in an Energy // Star range float cooling_slope = -0.0016;

count = 0;
neg_slope_count = 0;

for (i = 0; i< num_readings-1; i++) {
    if (time_temp_arr[0][i+1] > initial_settling_time) {
        count++;
        temp_diff = time_temp_arr[1][i+1] - time_temp_arr[1][i];
        if (temp_diff < 0.0) {
            neg_slope_count++;
            if (neg_slope_count == 1) first_reading = i;
            last_reading = i+1;
        }
    }
}  // end of i for loop

if (neg_slope_count == 0) return FALSE;

overall_slope = (time_temp_arr[1][last_reading] - time_temp_arr[1][first_reading]) /
     (time_temp_arr[0][last_reading]-time_temp_arr[0][first_reading]);

if (float(neg_slope_count)/float(count) > neg_slope_percentage .AND.
 overall_slope < cooling_slope) {
    return TRUE;
else
    return FALSE;
}

} // end of cooling_phase fuinction

// is rate of temperature change very small, either as a gain or loss? // power could truly be OFF, or in a slow cooling mode, OR, power could be ON, with there being // a low-level amount of heating logical function steady_state( float averaged_temp; ) {

averaged_temp = 81.0;
return TRUE;

} // end of steady_state function

// system needs to be in heating phase for a specified time OR // the steady_state temp needs to be "sufficiently" above room ambient temperature // (use of above_ambient_temp setting, here at % degrees Farenheit). logical function throw_alert(){ // max_heating_interval is length of the heating_phase, expressed in seconds, below which is // not considered to be a reportable condition, set here to 30 minutes. float max_heating_interval = 1800.0; float above_ambient_temp = 5.0;

if ( (heating_phase(segment_time) .AND. segment_time > max_heating_interval) .OR.   (steady_state(averaged_temp) .AND.
    averaged_temp-ambient_temp > above_ambient_temp) )
    return TRUE;
else
    return FALSE;

} // end of throw_alert function

Log in or sign up for Devpost to join the conversation.