Created
July 12, 2016 14:37
-
-
Save eni23/1e5736229a1b97bba633564792f356c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
float buffer[16] = { | |
22.66, | |
22.67, | |
22.15, | |
22.85, | |
21.90, | |
21.90, | |
24.01, | |
24.05, | |
24.59, | |
24.88, | |
24.90, | |
25.01, | |
25.05, | |
25.11, | |
25.19, | |
25.58 | |
}; | |
/* | |
float buffer[16] = { | |
26.66, | |
25.67, | |
25.15, | |
24.85, | |
24.10, | |
23.90, | |
23.04, | |
23.05, | |
22.59, | |
21.88, | |
21.00, | |
20.03, | |
20.01, | |
19.21, | |
19.19, | |
18.58 | |
};*/ | |
void print_buffer(){ | |
for (int i=0; i<16; i++){ | |
printf("%f\n", buffer[i]); | |
} | |
} | |
void get_divi(){ | |
printf("DIVI\n=====\n" ); | |
float diff[16]; | |
float tot = 0; | |
for (int i = 0; i<15; i++){ | |
diff[i] = buffer[i+1] - buffer[i]; | |
tot+=diff[i]; | |
} | |
for (int i=0; i<15; i++){ | |
printf("#%i, diff=%f, curr=%f prev=%f\n", i, diff[i], buffer[i], buffer[i+1]); | |
} | |
tot = (tot/15); | |
float tt = (buffer[16] - buffer[0] / 16); | |
if (tot>0){ | |
printf("\ntrend=falling\n"); | |
} | |
if (tot<0){ | |
printf("\ntrend=rising\n"); | |
} | |
printf("variance=%f trend=%f\n\n", tot, tt); | |
} | |
int get_trend(){ | |
float base = buffer[0]; | |
float max = base; | |
float min = base; | |
int upper = 0; | |
int lower = 0; | |
float upf; | |
float lowf; | |
int g=1; | |
printf("\n\nENI_TREND\n=====\n" ); | |
for (int i=15; i>0; i--){ | |
if (buffer[i]>base){ | |
if (max<buffer[i]){ | |
max = buffer[i]; | |
} | |
lowf += ((float) (buffer[i]-base) * (1*g) ); | |
lower+=(1*g); | |
printf("#%i dir=lower lowc=%i lowf=%f\n", i, lower, lowf); | |
} | |
if (buffer[i]<base){ | |
if (min>buffer[i]){ | |
min = buffer[i]; | |
} | |
upf += ((float) (base-buffer[i]) * (1*g) ); | |
upper+=(1*g); | |
printf("#%i dir=upper lowc=%i lowf=%f\n", i, upper, upf); | |
} | |
g++; | |
} | |
float max_range = (max - base); | |
float min_range = (base - min); | |
if (upf>lowf){ | |
printf("\ntrend=rising\n" ); | |
} | |
if (lowf>upf){ | |
printf("\ntrend=falling\n" ); | |
} | |
printf("lowf=%f upf=%f\n", lowf, upf); | |
printf("lower=%i upper=%i\n", lower, upper); | |
printf("min=%f max=%f\n", min, max); | |
printf("min_range=%f max_range=%f\n\n\n", min_range, max_range); | |
} | |
int main(void){ | |
get_trend(); | |
get_divi(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment