Пример #1
0
/*
 * Packages a JSON containing max, min and average temperatures and returns it for sending.
 * Returns "No data available." when temperature array is empty of there has been a problem receiving data.
 * Returns "Arudino Error!!!" if the Arudino is currently in an error state (such as when it is disconnected after starting).
 */
char* packageAvgJSON(){
      char* latest_temp = (char*) malloc(1000);
      if (latest_temp == NULL) {
            printf("\nAn error occurred while allocating memory for your request. Please try again.\n");
            return NULL;
      }
      if (arduinoError){
            sprintf(latest_temp, "{\n\"name\":\"Arudino Error!!!\"\n}\n");
      }
      else {
            if (nextTempPointer == 0 ){
                  if (temps[3599] == -274.0){
                        sprintf(latest_temp, "{\n\"name\":\"No data available.\"\n}\n");
                        return latest_temp;
                  }
            }
            else {
                  if (temps[nextTempPointer - 1] == -274.0){
                        sprintf(latest_temp, "{\n\"name\":\"No data available.\"\n}\n");
                        return latest_temp;
                  }     
            }
            double max = findMax();
            double min = findMin();
            double average = findAverage();
            printf("%f\n%f\n%f\n\n", max, min, average);
            if (cOrF == 'F') {
                  max = max * 9 / 5 + 32;
                  min = min * 9 / 5 + 32;
                  average = average * 9 / 5 + 32;
            }
            sprintf(latest_temp, "{\n\"name\":\"H: %.1f L: %.1f AVG: %.1f\"\n}\n", max, min, average);
      }
      return latest_temp;
}
Пример #2
0
//***************************************************************************************************************
float DeCalculator::getCoef(vector<float> obs, vector<float> qav) {
	try {
	
		//find average prob for this seqs windows
		float probAverage = findAverage(qav);
				
		//find observed average 
		float obsAverage = findAverage(obs);
			
		float coef = obsAverage / probAverage;
						
		return coef;
	}
	catch(exception& e) {
		m->errorOut(e, "DeCalculator", "getCoef");
		exit(1);
	}
}
Пример #3
0
int main(int argc, char **argv){
	char array[] = "asdfasdfasdfasdf";
	int *p = preProcess(array, 16);
	double *pd = preProcess2(array, 16);
	printf("find average 2 to 9: %d\n", findAverage(array, 16, 2, 9, p));
	printf("find average 2 to 9: %d\n", findAverage2(array, 16, 2, 9, pd));
	printf("find middle 2 to 9: %d\n", findMiddle(array, 16, 2, 9));
	return 1;
}
Пример #4
0
/**
* @brief  Находит наиболее вероятное значение.
* @detailed Находит распределение диапазонов величины в массиве с заданным шагом.
* Находит какой диапазон самый распространенный. Определяет среднее значение в этом диапазоне.
* @param  arr: Массив с данными.
* @param  data_size: Размер массива с данными.
* @param  step: Шаг диапазонов.
* @retval result: Наиболее вероятное значение. Среднее в наибольшем интервале.
*/
unsigned int my_filter(unsigned int * arr, unsigned int data_size, unsigned int step)
{
	//unsigned int im[SIZE_D];		// массив с подсчетами
	//unsigned int m[SIZE_D];		  // массив с диапазонами (хранит только начало диапазона)
	unsigned int iarr[SIZE_D];		// индекс начала диапазона в исходном массиве 
	unsigned char i, j;
	unsigned int iMaxEntryBegin;	// начало большего диапазона в исходном массиве
	unsigned int maxEntry; 			  // для поиска диапазона с большим количеством попаданий	
	unsigned int result;
	
	quickSort(&arr[0],0,STORE_SIZE-1);
	
	for (i = 0; i < SIZE_D; i++) {
		im[i] = 0;
		m[i] = 0;
	}
	j = 0;
	m[j] = arr[0];
	iarr[0] = 0;
	for (i = 0; i < data_size; i++) {
		if (arr[i] <= (m[j] + step)) {
			im[j]++;
		}
		else {
			if (j < (SIZE_D - 1)) {
				j++;
			}
			else {
				return 0;
			}
			m[j] = arr[i];
			iarr[j] = i;
			im[j]++;
		}
	}
	maxEntry = 0;
	for (i = 0; i < SIZE_D; i++) {
		if (maxEntry < im[i]) {
			maxEntry = im[i];
			iMaxEntryBegin = iarr[i];
		}
	}
	result = findAverage(&arr[iMaxEntryBegin], maxEntry);
	return result;
}
Пример #5
0
int main(int argc, char *args[]) {
    if(argc != 5) {
        printf("Insufficient arguments. Need 4 arguments. %d\n", argc);
        exit(1);
    }


    time_t t;
    srand((unsigned) time(&t));
    int m = 10000;
    int n = 1000;
    int n_threads = atoi(args[1]);
    Ops ops;
    ops_init(&ops, m, atof(args[2]), atof(args[3]), atof(args[4])); // Workout the number of operations of each type
    Byte *opsList = malloc(sizeof(Byte) * m);

    runDummyThreads(n_threads);
    buildOpsList(opsList, &ops, m); // Build a randomly ordered list of operations to be carried out

    int sample_size = 0;
    int test_samples = 20;
    float mutex_std = 0;
    float rwlock_std = 0;
    float serial_std = 0;

    // arrays for test sample memory size
    float *mutext_time = malloc(sizeof(float) * test_samples);
    float *rwlock_time = malloc(sizeof(float) * test_samples);  //=malloc(sizeof(float)*test_samples)
    float *serial_time = malloc(sizeof(float) * test_samples);

    //all three linked list impletation run
    for (int i = 0; i < test_samples; i++) {
        mutext_time[i] = linkedListMutex(opsList, n_threads, m, n);
        rwlock_time[i] = linkedListRWLock(opsList, n_threads, m, n);
        serial_time[i] = serialLinkedList(opsList, m, n);
    }

    //finding standard deviation of each linked list implementation
    mutex_std = std(mutext_time, test_samples);
    rwlock_std = std(rwlock_time, test_samples);
    serial_std = std(serial_time, test_samples);

    //find average of each linked list implementation
    float mutex_avg = findAverage(mutext_time, test_samples);
    float rwlock_avg = findAverage(rwlock_time, test_samples);
    float serial_avg = findAverage(serial_time, test_samples);

    //find sample size with 5% accurary and 95% confident interval
    int mutext_ss = findSampleSize(mutex_std, mutex_avg);
    printf("mutex sample_size %d\n", mutext_ss);
    int rwlock_ss = findSampleSize(rwlock_std, rwlock_avg);
    printf("rwlock sample_size %d\n", rwlock_ss);
    int serial_ss = findSampleSize(serial_std, serial_avg);
    printf("serial sample_size %d\n", serial_ss);

    // array with sample size
    float *mutext_time_case = malloc(sizeof(float) * mutext_ss);
    float *rwlock_time_case = malloc(sizeof(float) * rwlock_ss);  //=malloc(sizeof(float)*test_samples)
    float *serial_time_case = malloc(sizeof(float) * serial_ss);

    //mutex linked list implementation
    for (int i = 0; i < mutext_ss; i++) {
        mutext_time_case[i] = linkedListMutex(opsList, n_threads, m, n);
    }

    //rwlock linked list implementation
    for (int i = 0; i < rwlock_ss; i++) {
        rwlock_time_case[i] = linkedListRWLock(opsList, n_threads, m, n);
    }

    //serial linked list implementation
    for (int i = 0; i < serial_ss; i++) {
        serial_time_case[i] = serialLinkedList(opsList, m, n);
    }

    // final average time of each linked list implementation
    float final_mutex_avg = findAverage(mutext_time_case, mutext_ss);
    float final_rwlock_avg = findAverage(rwlock_time_case, rwlock_ss);
    float final_serial_avg = findAverage(serial_time_case, serial_ss);

    // final standard deviation values of each linked list implementation
    float final_mutex_std = std(mutext_time_case, mutext_ss);
    float final_rwlock_std = std(rwlock_time_case, rwlock_ss);
    float final_serial_std = std(serial_time_case, serial_ss);

    printf("mutex linked list average %f :  std %f\n", final_mutex_avg, final_mutex_std);
    printf("rwlock linked list average %f :  std %f\n", final_rwlock_avg, final_rwlock_std);
    printf("serial linked list average %f :  std %f\n", final_serial_avg, final_serial_std);

    return 0;
}