Weather casting with Machine Learning (SVM and SRNN).
Dependencies: EthernetInterface GraphicHandler NTPClient SRNN SVM SensorModule mbed-rtos mbed
Diff: main_util.cpp
- Revision:
- 5:b61f3f5b0fc8
- Parent:
- 3:5add3759e08a
--- a/main_util.cpp Thu Feb 19 13:53:12 2015 +0000 +++ b/main_util.cpp Thu Feb 19 19:21:16 2015 +0000 @@ -1,8 +1,22 @@ #include "main_util.hpp" +void update_srnn_sample(float* sample_queue, float* new_data) +{ + // 古いデータの消去, データのシフト + for (int i = 0; i < DIM_SIGNAL * LEN_DATA_SEQUENCE; i++) { + if ( i < DIM_SIGNAL * (LEN_DATA_SEQUENCE-1) ) + sample_queue[i] = sample_queue[i+DIM_SIGNAL]; + } + + // 末尾に新データを追加 + memcpy(&(sample_queue[DIM_SIGNAL * (LEN_DATA_SEQUENCE-1)]), new_data, sizeof(float) * DIM_SIGNAL); +} + +// ファイルのオープンチェック(いや、fopenをラップしろよサーセン) void check_file_open(FILE* file_p, const char* file_name) { - printf("[cnt:%d] %s : %p \r\n", open_count++, file_name, file_p); + // static int open_count; + // printf("[cnt:%d] %s : %p \r\n", open_count++, file_name, file_p); if ( file_p == NULL ) { fprintf( stderr, "Error : file %s open faild. \r\n", file_name ); fflush( stderr ); @@ -10,8 +24,8 @@ } } -// データ系列ファイルの行数をLEN_DATA_SEQUENCEまで切り詰める -void truncate_data_file(void) +// データ系列ファイルの行数をmaxlineまで切り詰める +void truncate_data_file(int maxline) { FILE* dat_file_fp; const char tmp_file_name[] = "/local/TMP_DAT.CSV"; @@ -23,15 +37,13 @@ line = 0; while(fgets(trunc_buf_str, BUF_SIZE, dat_file_fp) != NULL) { line++; - // printf("line %d : %s\r\n", line, trunc_buf_str); } - // printf("current num of line : %d \r\n", line); fclose( dat_file_fp ); // 切り詰め開始 - if ( line > LEN_DATA_SEQUENCE ) { + if ( line > maxline ) { FILE* tmp_fp; - diff_line = (line - LEN_DATA_SEQUENCE); + diff_line = (line - maxline); dat_file_fp = fopen(SEQUENCE_DATA_NAME, "r"); // rewind( dat_file_fp ); check_file_open( dat_file_fp, SEQUENCE_DATA_NAME ); @@ -66,7 +78,5 @@ // テンポラリの削除 remove( tmp_file_name ); - // free( tmp_fp ); } - // free( dat_file_fp ); } \ No newline at end of file