diff --git a/iPDC/inc/Kmeans.h b/iPDC/inc/Kmeans.h new file mode 100644 index 0000000..d6205dc --- /dev/null +++ b/iPDC/inc/Kmeans.h @@ -0,0 +1,16 @@ +/*Pavan Changes*/ +#include +// intial variables + +unsigned long long int count_A=500; +unsigned long long int count_B=500; +unsigned long long int count_C=500; +long double A=50; +long double B=49.5; +long double C=50.5; + +//function declaration +gboolean kmeans(struct data_frame *df,unsigned long long int *count_A,unsigned long long int *count_B, +unsigned long long int *count_C,long double *A,long double *B,long double *C); + +/*Pavan Changes*/ \ No newline at end of file diff --git a/iPDC/src/Kmeans.c b/iPDC/src/Kmeans.c new file mode 100644 index 0000000..af32a59 --- /dev/null +++ b/iPDC/src/Kmeans.c @@ -0,0 +1,29 @@ +/*Pavan Changes*/ + +#include "parser.h" +#include +#include + +gboolean kmeans(struct data_frame *df,unsigned long long int *count_A,unsigned long long int *count_B, +unsigned long long int *count_C,long double *A,long double *B,long double *C) +{ + float CURR_FREQ = to_intconvertor(df->dpmu[0]->freq); + long double diff_A = abs(*A-CURR_FREQ); + long double diff_B = abs(*B-CURR_FREQ); + long double diff_C = abs(*C-CURR_FREQ); + printf("A: %Lf, B: %Lf, C: %Lf\n",*A,*B,*C); + if(diff_A <= diff_B && diff_A <= diff_C){ + *A = ((*count_A*(*A))+CURR_FREQ)/(++*count_A); + return TRUE; + } + else if(diff_B < diff_C){ + *B = ((*count_B*(*B))+CURR_FREQ)/(++*count_B); + return FALSE; + } + else{ + *C = ((*count_C*(*C))+CURR_FREQ)/(++*count_C); + return FALSE; + } +} + +/*Pavan Changes*/ \ No newline at end of file diff --git a/iPDC/src/map_vis.c b/iPDC/src/map_vis.c index d35e723..e85ccbb 100644 --- a/iPDC/src/map_vis.c +++ b/iPDC/src/map_vis.c @@ -4,6 +4,7 @@ #include "parser.h" #include "osm-gps-map.h" #include "Attack_detect.h" +#include "Kmeans.h" gboolean update_images(gpointer* pars){ @@ -13,24 +14,16 @@ gboolean update_images(gpointer* pars){ return TRUE; } int freq = to_intconvertor(df->dpmu[0]->freq); - gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY); - - // if(parameters->g_last_image != 0){ - // osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); - // } - // if (freq > 300){ - // parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image); - // }else{ - // parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_red_image); - // } - if(parameters->g_last_image != 0){ - osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); - } - if (green){ - parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image); - }else{ - parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_red_image); - } + //gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY); + gboolean green = kmeans(df,&count_A,&count_B,&count_C,&A,&B,&C); + if(parameters->g_last_image != 0){ + osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); + } + if (green){ + parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image); + }else{ + parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_red_image); + } gtk_widget_queue_draw(GTK_WIDGET(parameters->util_map)); return TRUE; } \ No newline at end of file