bool operator< (const QTreeWidgetItem &other) const
    {
        if (other.type() != srt_row_type_) return QTreeWidgetItem::operator< (other);
        const SrtRowTreeWidgetItem *other_row = static_cast<const SrtRowTreeWidgetItem *>(&other);

        switch (treeWidget()->sortColumn()) {
        case SRT_COLUMN_INDEX:
            return procedure_->index < other_row->procedure_->index;
        case SRT_COLUMN_CALLS:
            return procedure_->stats.num < other_row->procedure_->stats.num;
        case SRT_COLUMN_MIN:
            return nstime_cmp(&procedure_->stats.min, &other_row->procedure_->stats.min) < 0;
        case SRT_COLUMN_MAX:
            return nstime_cmp(&procedure_->stats.max, &other_row->procedure_->stats.max) < 0;
        case SRT_COLUMN_AVG:
        {
            double our_avg = get_average(&procedure_->stats.tot, procedure_->stats.num);
            double other_avg = get_average(&other_row->procedure_->stats.tot, other_row->procedure_->stats.num);
            return our_avg < other_avg;
        }
        case SRT_COLUMN_SUM:
            return nstime_cmp(&procedure_->stats.tot, &other_row->procedure_->stats.tot) < 0;
        default:
            break;
        }

        return QTreeWidgetItem::operator< (other);
    }
Exemplo n.º 2
0
static void
rtd_draw(void *arg)
{
	rtd_data_t* rtd_data = (rtd_data_t*)arg;
	rtd_t* rtd = (rtd_t*)rtd_data->user_data;
	gchar* tmp_str;
	guint i, j;

	/* printing results */
	printf("\n");
	printf("=====================================================================================================\n");
	printf("%s Response Time Delay (RTD) Statistics:\n", rtd->type);
	printf("Filter for statistics: %s\n", rtd->filter ? rtd->filter : "");
	if (rtd_data->stat_table.num_rtds == 1)
	{
		printf("Duplicate requests: %u\n", rtd_data->stat_table.time_stats[0].req_dup_num);
		printf("Duplicate responses: %u\n", rtd_data->stat_table.time_stats[0].rsp_dup_num);
		printf("Open requests: %u\n", rtd_data->stat_table.time_stats[0].open_req_num);
		printf("Discarded responses: %u\n", rtd_data->stat_table.time_stats[0].disc_rsp_num);
		printf("Type    | Messages   |    Min RTD    |    Max RTD    |    Avg RTD    | Min in Frame | Max in Frame |\n");
		for (i=0; i<rtd_data->stat_table.time_stats[0].num_timestat; i++) {
			if (rtd_data->stat_table.time_stats[0].rtd[i].num) {
				tmp_str = val_to_str_wmem(NULL, i, rtd->vs_type, "Other (%d)");
				printf("%s | %7u    | %8.2f msec | %8.2f msec | %8.2f msec |  %10u  |  %10u  |\n",
						tmp_str, rtd_data->stat_table.time_stats[0].rtd[i].num,
						nstime_to_msec(&(rtd_data->stat_table.time_stats[0].rtd[i].min)), nstime_to_msec(&(rtd_data->stat_table.time_stats[0].rtd[i].max)),
						get_average(&(rtd_data->stat_table.time_stats[0].rtd[i].tot), rtd_data->stat_table.time_stats[0].rtd[i].num),
						rtd_data->stat_table.time_stats[0].rtd[i].min_num, rtd_data->stat_table.time_stats[0].rtd[i].max_num
				);
				wmem_free(NULL, tmp_str);
			}
		}
	}
	else
	{
		printf("Type    | Messages   |    Min RTD    |    Max RTD    |    Avg RTD    | Min in Frame | Max in Frame | Open Requests | Discarded responses | Duplicate requests | Duplicate responses\n");
		for (i=0; i<rtd_data->stat_table.num_rtds; i++) {
			for (j=0; j<rtd_data->stat_table.time_stats[i].num_timestat; j++) {
				if (rtd_data->stat_table.time_stats[i].rtd[j].num) {
					tmp_str = val_to_str_wmem(NULL, i, rtd->vs_type, "Other (%d)");
					printf("%s | %7u    | %8.2f msec | %8.2f msec | %8.2f msec |  %10u  |  %10u  |  %10u  |  %10u  | %4u (%4.2f%%) | %4u (%4.2f%%)  |\n",
							tmp_str, rtd_data->stat_table.time_stats[i].rtd[j].num,
							nstime_to_msec(&(rtd_data->stat_table.time_stats[i].rtd[j].min)), nstime_to_msec(&(rtd_data->stat_table.time_stats[i].rtd[j].max)),
							get_average(&(rtd_data->stat_table.time_stats[i].rtd[j].tot), rtd_data->stat_table.time_stats[i].rtd[j].num),
							rtd_data->stat_table.time_stats[i].rtd[j].min_num, rtd_data->stat_table.time_stats[i].rtd[j].max_num,
							rtd_data->stat_table.time_stats[i].open_req_num, rtd_data->stat_table.time_stats[i].disc_rsp_num,
							rtd_data->stat_table.time_stats[i].req_dup_num,
							rtd_data->stat_table.time_stats[i].rtd[j].num?((double)rtd_data->stat_table.time_stats[i].req_dup_num*100)/(double)rtd_data->stat_table.time_stats[i].rtd[j].num:0,
							rtd_data->stat_table.time_stats[i].rsp_dup_num,
							rtd_data->stat_table.time_stats[i].rtd[j].num?((double)rtd_data->stat_table.time_stats[i].rsp_dup_num*100)/(double)rtd_data->stat_table.time_stats[i].rtd[j].num:0
					);
					wmem_free(NULL, tmp_str);
				}
			}
		}
	}
	printf("=====================================================================================================\n");
}
Exemplo n.º 3
0
static void
megacostat_draw(void *pms)
{
	megacostat_t *ms=(megacostat_t *)pms;
	int i;

	/* printing results */
	printf("\n");
	printf("=====================================================================================================\n");
	printf("MEGACO Response Time Delay (RTD) Statistics:\n");
	printf("Filter for statistics: %s\n",ms->filter?ms->filter:"");
        printf("Duplicate requests: %u\n",ms->req_dup_num);
        printf("Duplicate responses: %u\n",ms->rsp_dup_num);
        printf("Open requests: %u\n",ms->open_req_num);
        printf("Discarded responses: %u\n",ms->disc_rsp_num);
        printf(" Type   | Messages   |    Min RTD    |    Max RTD    |    Avg RTD    | Min in Frame | Max in Frame |\n");
        for(i=0;i<NUM_TIMESTATS;i++) {
        	if(ms->rtd[i].num) {
        		printf("%5s   | %7u    | %8.2f msec | %8.2f msec | %8.2f msec |  %10u  |  %10u  |\n",
        			val_to_str(i,megaco_message_type,"Other"),ms->rtd[i].num,
				nstime_to_msec(&(ms->rtd[i].min)), nstime_to_msec(&(ms->rtd[i].max)),
				get_average(&(ms->rtd[i].tot), ms->rtd[i].num),
				ms->rtd[i].min_num, ms->rtd[i].max_num
			);
		}
	}
        printf("=====================================================================================================\n");
}
Exemplo n.º 4
0
static void
megacostat_draw(void *pms)
{
    megacostat_t *ms=(megacostat_t *)pms;
    int i;
    char *str[7];

    for(i=0; i<7; i++) {
        str[i]=g_malloc(sizeof(char[256]));
    }

    /* clear list before printing */
    gtk_clist_clear(ms->table);

    for(i=0; i<NUM_TIMESTATS; i++) {
        /* nothing seen, nothing to do */
        if(ms->rtd[i].num==0) {
            continue;
        }

        g_snprintf(str[0], sizeof(char[256]), "%s", val_to_str(i,megaco_message_type,"Other"));
        g_snprintf(str[1], sizeof(char[256]), "%d", ms->rtd[i].num);
        g_snprintf(str[2], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(ms->rtd[i].min)));
        g_snprintf(str[3], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(ms->rtd[i].max)));
        g_snprintf(str[4], sizeof(char[256]), "%8.2f msec", get_average(&(ms->rtd[i].tot), ms->rtd[i].num));
        g_snprintf(str[5], sizeof(char[256]), "%6u", ms->rtd[i].min_num);
        g_snprintf(str[6], sizeof(char[256]), "%6u", ms->rtd[i].max_num);
        gtk_clist_append(ms->table, str);
    }

    gtk_widget_show(GTK_WIDGET(ms->table));
    for(i=0; i<7; i++) {
        g_free(str[i]);
    }
}
Exemplo n.º 5
0
static void
megacostat_draw(void *pms)
{
	megacostat_t *ms=(megacostat_t *)pms;
	int i;
	char str[3][256];
	GtkListStore *store;
	GtkTreeIter iter;

	/* clear list before printing */
  	store = GTK_LIST_STORE(gtk_tree_view_get_model(ms->table));
  	gtk_list_store_clear(store);

	for(i=0;i<NUM_TIMESTATS;i++) {
		/* nothing seen, nothing to do */
		if(ms->rtd[i].num==0){
			continue;
		}

		g_snprintf(str[0], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(ms->rtd[i].min)));
		g_snprintf(str[1], sizeof(char[256]), "%8.2f msec", nstime_to_msec(&(ms->rtd[i].max)));
		g_snprintf(str[2], sizeof(char[256]), "%8.2f msec", get_average(&(ms->rtd[i].tot), ms->rtd[i].num));
		gtk_list_store_append(store, &iter);
		gtk_list_store_set(store, &iter,
			0, val_to_str(i,megaco_message_type,"Other"),
			1, ms->rtd[i].num,
			2, str[0],
			3, str[1],
			4, str[2],
			5, ms->rtd[i].min_num,
			6, ms->rtd[i].max_num,
			-1);
	}
}
 QList<QVariant> rowData() {
     return QList<QVariant>() << type_ << timestat_->rtd->num
                              << nstime_to_sec(&timestat_->rtd->min) << nstime_to_sec(&timestat_->rtd->max)
                              << get_average(&timestat_->rtd->tot, timestat_->rtd->num) / 1000.0
                              << timestat_->rtd->min_num << timestat_->rtd->max_num
                              << timestat_->open_req_num << timestat_->disc_rsp_num
                              << timestat_->req_dup_num << timestat_->rsp_dup_num;
 }
Exemplo n.º 7
0
void average_of_per_set(const unsigned int num, const unsigned int size,
        const double number_set[num][size], double average[num])
{
    unsigned int i = 0;

    for (i = 0; i < num; i++)
    {
        average[i] = get_average(number_set[i], size);
    }
}
Exemplo n.º 8
0
int main(int argc, char** argv) {
	int nflats = 3;
	std::stringstream ss1;
	srand(time(NULL));
	ss1 << "flat" << rand()%1000 << "_";
	std::string flatTestName = ss1.str() + "test";
	std::string flatName = ss1.str();
	
	double exptime = 0.5;
	std::string iso = "200";
	double satVal = 16384;
	//	double satVal=3000;
	double thresVal = satVal/3;
	int ret;

	CameraController c;
	//take a flat with minimal exposure time, double exposure until threshold exceeded
	while(1) {
		ret = c.capture_to_file(flatTestName, exptime, iso);
		if (ret != GP_OK) {
			std::cout << "Error while capturing image" << std::endl;
			return ret;
		}
		double rval = get_average(flatTestName+"R.fits");
		double gval = get_average(flatTestName+"G.fits");
		double bval = get_average(flatTestName+"B.fits");
		std::cout << rval << " " << gval << " " << bval << std::endl;
		if (rval > thresVal && gval > thresVal && bval > thresVal) break;
		exptime *= 2;
	}
	//we've found a good value, so take flats
	for (int i=0; i < nflats; i++) {
		std::stringstream ss;
		ss << flatName << i;
		ret = c.capture_to_file(ss.str(), exptime, iso);
		if (ret != GP_OK) {
			std::cout << "Error while capturing image" << std::endl;
			return ret;
		}
	}
	return 0;
}
Exemplo n.º 9
0
	void sort_by_score(struct STUDENT * pstu)
	{
		int						i;
		int						j;
		float					temp;
		float					ave[5];

		for(i=0;i<5;i++)
			ave[i]=get_average(pstu+i);

		
		for(i=0;i<5;i++)
		{
			for(j=0;j<5;j++)
			{
				if(ave[i]>ave[j])
				{
					temp=ave[i];
					ave[i]=ave[j];
					ave[j]=temp;
				}
			}
		}

		printf("\nFrom the highest to the lowest : \n\n ");

		for(i=0;i<5;i++)
		{

			for(j=0;j<5;j++)
			{


				if(fabs(ave[i]-get_average(pstu+j))<=0.01)
				{
					print_string(pstu+j);
				}
			}
		}
		return ;
	}
Exemplo n.º 10
0
void fill_glass_debug(int sel) {
  char* msg = "Filling...";
  char* msg2;
  int w;

  while (1) {
    w = get_average(100);
    sprintf(msg2, "%d", w);
    LCD_Clear();
    LCD_DrawString(2, 16, (u8*)msg, 10);
    LCD_DrawString(4, 16, (u8*)msg2, strlen(msg2));
    Delayms(100);
  }
}
    void draw() {
        setText(col_messages_, QString::number(timestat_->rtd->num));
        setText(col_min_srt_, QString::number(nstime_to_sec(&timestat_->rtd->min), 'f', 6));
        setText(col_max_srt_, QString::number(nstime_to_sec(&timestat_->rtd->max), 'f', 6));
        setText(col_avg_srt_, QString::number(get_average(&timestat_->rtd->tot, timestat_->rtd->num) / 1000.0, 'f', 6));
        setText(col_min_frame_, QString::number(timestat_->rtd->min_num));
        setText(col_max_frame_, QString::number(timestat_->rtd->max_num));
        setText(col_open_requests, QString::number(timestat_->open_req_num));
        setText(col_discarded_responses_, QString::number(timestat_->disc_rsp_num));
        setText(col_repeated_requests_, QString::number(timestat_->req_dup_num));
        setText(col_repeated_responses_, QString::number(timestat_->rsp_dup_num));

        setHidden(timestat_->rtd->num < 1);
    }
Exemplo n.º 12
0
double  get_variance( int array[], int N )
{
  double var = 0.000000;
  double ave;
  int i;

  ave = get_average(array, N);

  for (i = 0; i < N; i++) {
    var += (ave - array[i]) * (ave - array[i]);
  }

  return var / N;
}
Exemplo n.º 13
0
int main(void) {
  int c, nl, nw, nc, state;
  int i, j;
  int word_initial, word_final, len;
  int word_length[MAXLEN];
  int numbers[MAXNWORD];

  for( i = 0 ; i < MAXLEN ; ++i ) {
    word_length[i] = 0;
  }
  for( i = 0 ; i < MAXNWORD ; ++i ) {
    numbers[i] = 0;
  }

  state = OUT;
  nl = nw = nc = 0;
  while( ( c = getchar() ) != EOF ) {
    ++nc;

    if( c == ' ' || c == '\n' || c == '\t' ) {
      if( state == IN ) {
	word_final = nc;
	len = word_final - word_initial;
	++word_length[len];

	numbers[nw] = (nl+1)*len;
	//	printf( "nw = %d, nl = %d, len = %d, numbers = %d\n", nw, nl, len, numbers[nw] );
	++nw;
      }
      state = OUT;
    }
    else if( state == OUT ) {
      state = IN;
      word_initial = nc;
    }

    if( c == '\n' ) {
      ++nl;
    }
  }

  printf( "#line = %d #word = %d #character = %d\n", nl, nw, nc );
  printf( "max = %d, avg = %.3f, var = %.3f\n", get_max( numbers, nw ),
	  get_average( numbers, nw ), get_variance( numbers, nw ) );

  bubble_sort(numbers, nw);

  return;
}
    void draw() {
        setText(SRT_COLUMN_INDEX, QString::number(procedure_->index));
        setText(SRT_COLUMN_CALLS, QString::number(procedure_->stats.num));
        setText(SRT_COLUMN_MIN, QString::number(nstime_to_sec(&procedure_->stats.min), 'f', 6));
        setText(SRT_COLUMN_MAX, QString::number(nstime_to_sec(&procedure_->stats.max), 'f', 6));
        setText(SRT_COLUMN_AVG, QString::number(get_average(&procedure_->stats.tot, procedure_->stats.num) / 1000.0, 'f', 6));
        setText(SRT_COLUMN_SUM, QString::number(nstime_to_sec(&procedure_->stats.tot), 'f', 6));

        for (int col = 0; col < columnCount(); col++) {
            if (col == SRT_COLUMN_PROCEDURE) continue;
            setTextAlignment(col, Qt::AlignRight);
        }

        setHidden(procedure_->stats.num < 1);
    }
    bool operator< (const QTreeWidgetItem &other) const
    {
        if (other.type() != rtd_time_stat_type_) return QTreeWidgetItem::operator< (other);
        const RtdTimeStatTreeWidgetItem *other_row = static_cast<const RtdTimeStatTreeWidgetItem *>(&other);

        switch (treeWidget()->sortColumn()) {
        case col_messages_:
            return timestat_->rtd->num < other_row->timestat_->rtd->num;
        case col_min_srt_:
            return nstime_cmp(&timestat_->rtd->min, &other_row->timestat_->rtd->min) < 0;
        case col_max_srt_:
            return nstime_cmp(&timestat_->rtd->max, &other_row->timestat_->rtd->max) < 0;
        case col_avg_srt_:
        {
            double our_avg = get_average(&timestat_->rtd->tot, timestat_->rtd->num);
            double other_avg = get_average(&other_row->timestat_->rtd->tot, other_row->timestat_->rtd->num);
            return our_avg < other_avg;
        }
        case col_min_frame_:
            return timestat_->rtd->min_num < other_row->timestat_->rtd->min_num;
        case col_max_frame_:
            return timestat_->rtd->max_num < other_row->timestat_->rtd->max_num;
        case col_open_requests:
            return timestat_->open_req_num < other_row->timestat_->open_req_num;
        case col_discarded_responses_:
            return timestat_->disc_rsp_num < other_row->timestat_->disc_rsp_num;
        case col_repeated_requests_:
            return timestat_->req_dup_num < other_row->timestat_->req_dup_num;
        case col_repeated_responses_:
            return timestat_->rsp_dup_num < other_row->timestat_->rsp_dup_num;
        default:
            break;
        }

        return QTreeWidgetItem::operator< (other);
    }
Exemplo n.º 16
0
int ped_check(const char* dirname,const char* outname,const int test_round_start,const int test_round_stop)
{
    gROOT->Reset();

    Float_t sigma_avg[4];
    Int_t round_id;

    TFile *fileout=new TFile(Form("%s/%s",dirname,outname),"RECREATE");
    TTree *tree_out=new TTree("ped_sigma_avg","Pedestal Sigma Average");
    tree_out->Branch("round_id",&round_id,"round_id/I");
    tree_out->Branch("xpos",sigma_avg,"xpos/F");
    tree_out->Branch("xneg",sigma_avg+1,"xneg/F");
    tree_out->Branch("ypos",sigma_avg+2,"ypos/F");
    tree_out->Branch("yneg",sigma_avg+3,"yneg/F");

    char ped_filename[]="hv.root";
    char dir[256];
    char filename[256];
    for(round_id=test_round_start;round_id<=test_round_stop;round_id++){
        sprintf(dir,"%s/test%d",dirname,round_id);
        if(!(gSystem->OpenDirectory(dir))){
            printf("Warning! : dir not exists '%s'\n",dir);
            return -1;
        }

        sprintf(dir,"%s/test%d/analyze",dirname,round_id);
        if(!(gSystem->OpenDirectory(dir))){
            printf("Warning! : dir not exists '%s'\n",dir);
            return -1;
        }

        sprintf(filename,"%s/test%d/analyze/hv/%s",dirname,round_id,ped_filename);
        get_average(filename,sigma_avg);
        tree_out->Fill();
    }

    fileout->cd();
    tree_out->Write();
    delete fileout;

    return 0;
}
int main() {
	int hour, min, sec, frames_received, i, watering_time = 0, pin = WORK_PIN;
	struct frame frames[FRAMES_TO_GET], frame_average;
	bool no_frames;
    
	//prepare gpio
	gpio_ready(&pin);

	//set default frame to empty
	frame_init(empty_frame);
	
	//initialize frame array
	for(i = 0; i < FRAMES_TO_GET; i++)
		frame_init(frames[i]);
		
	//initialize average frame
	frame_init(frame_average);
	
	//waiting loop
	while(1) {
	
		//get the time
		get_time(&hour, &min, &sec);

		//check if it's time to water the plants
		if(sec == WATERING_TIME_SEC_1) {
			
			//get all frames from FRAMES_TO_GET to the most recent frame
			if((frames_received = get_last_frames(FILE_NAME, FRAMES_TO_GET, frames)) == 0) {
				printf("No frames received\n");
				sleep(PAUSE_TIME);
				no_frames = true;
				
				continue;
			} else {
				no_frames = false;
				
				//get average of all frame data
				frame_average = get_average(frames, FRAMES_TO_GET);
				
				//calculate how much time should be spent watering based on frame data
				watering_time = decide_watering_time(frame_average);
				
				//open valve
				write_to_pin(pin, watering_time);
				sleep(PAUSE_TIME);
			}

		}
		
		//if no frames again, then assume system failure and turn off all valves
		if(no_frames && (sec == WATERING_TIME_SEC_RETRY) ) {
			if((frames_received = get_last_frames(FILE_NAME, FRAMES_TO_GET, frames)) == 0) {
				printf("NO FRAMES AGAIN PLEASE CHECK IF XBEES ARE DEAD!!!\n");
				turn_off_all_pins();
				
				continue;

			} else {
				no_frames = false;
				frame_average = get_average(frames, FRAMES_TO_GET);
				watering_time = decide_watering_time(frame_average);
				write_to_pin(pin, watering_time);
				sleep(PAUSE_TIME);
			}
		}
	}
		
}
 QList<QVariant> rowData() {
     return QList<QVariant>() << QString(procedure_->procedure) << procedure_->index << procedure_->stats.num
                              << nstime_to_sec(&procedure_->stats.min) << nstime_to_sec(&procedure_->stats.max)
                              << get_average(&procedure_->stats.tot, procedure_->stats.num) / 1000.0
                              << nstime_to_sec(&procedure_->stats.tot);
 }
Exemplo n.º 19
0
void write_cleaned_tap(struct block_list_element* blocks,
                       struct audiotap *input_handle,
                       enum wav2prg_bool need_v2,
                       const char* filename,
                       uint8_t machine,
                       uint8_t videotype,
                       struct wav2prg_display_interface *wav2prg_display_interface,
                       struct display_interface_internal *display_interface_internal)
{
  /* tolerance = NULL, need_new_tolerances = true: nothing is being cleaned at this time
     tolerance = NULL, need_new_tolerances = false: we are between two syncs in the middle of one block
     tolerance not NULL, need_new_tolerances = false: we are cleaning one block
     tolerance not NULL, need_new_tolerances = true: we finished cleaning one block and we are cleaning its trailing tone
     When need_new_tolerances = true, current_block points to the block which will be cleaned next */
  struct block_list_element* current_block;
  uint32_t sync = 0;
  const struct tolerances *tolerance = NULL;
  enum wav2prg_bool need_new_tolerances = wav2prg_true;
  uint32_t accumulated_pulses = 0, num_accumulated_pulses = 0;
  uint8_t num_pulse_lengths;
  int16_t *deviations = NULL;
  struct audiotap *output_handle;
  uint32_t display_progress = 0xffffffff;
  uint32_t min_length_non_noise_pulse = MIN_LENGTH_NON_NOISE_PULSE_DEFAULT;
  uint32_t max_length_non_pause_pulse = MAX_LENGTH_NON_PAUSE_PULSE_DEFAULT;

  current_block = blocks;
  if (need_v2){
    min_length_non_noise_pulse /= 2;
    max_length_non_pause_pulse /= 2;
  }
  if (!audio2tap_seek_to_beginning(input_handle))
    return;

  audio2tap_enable_disable_halfwaves(input_handle, need_v2);
  /* When using WAV files and halfwaves, in some corner cases the first halfwave can be later
     than the beginning of the first block */
  if (need_v2 && current_block != NULL && current_block->syncs[0].start_sync > 0){
    uint32_t raw_pulse, even_more_raw_pulse;
    int32_t pos;
    /* Check first halfwave */
    if (audio2tap_get_pulses(input_handle, &raw_pulse, &even_more_raw_pulse) != AUDIOTAP_OK)
      return;
    /* Check where first halfwave ends */
    pos = audio2tap_get_current_pos(input_handle);
    /* Rewind to the beginning of file. This has the side effect of disabling halfwave reading */
    if (!audio2tap_seek_to_beginning(input_handle))
      return;
    if (pos <= current_block->syncs[0].start_sync)
    /* Normal situation, restore halfwave reading. */
      audio2tap_enable_disable_halfwaves(input_handle, 1);
    else{
    /* the first halfwave is later than the beginning of the first block, do not restore halfwave reading
       and read first full wave, thus moving to the beginning of the first block. */
      if (audio2tap_get_pulses(input_handle, &raw_pulse, &even_more_raw_pulse) != AUDIOTAP_OK)
        return;
    }
  }
  if (tap2audio_open_to_tapfile3(&output_handle, filename, need_v2 ? 2 : 1, machine, videotype) != AUDIOTAP_OK)
    return;
  while(!audio2tap_is_eof(input_handle)){
    int32_t pos = audio2tap_get_current_pos(input_handle);
    uint32_t raw_pulse, even_more_raw_pulse;
    enum wav2prg_bool accumulate_this_pulse;
    uint32_t new_display_progress = pos / 8192;
    enum wav2prg_bool between_2_blocks_needing_opposite_waveforms = wav2prg_false;
    enum wav2prg_bool pulse_was_tolerance_checked = wav2prg_false;

    if (new_display_progress != display_progress){
      display_progress = new_display_progress;
      wav2prg_display_interface->progress(display_interface_internal, pos);
    }
    while(current_block != NULL){
      if (sync >= current_block->num_of_syncs){
        if (current_block->next != NULL
         && current_block->opposite_waveform != current_block->next->opposite_waveform
           )
          between_2_blocks_needing_opposite_waveforms = wav2prg_true;
        current_block = current_block->next;
        sync = 0;
        need_new_tolerances = wav2prg_true;
      }
      else if (pos < current_block->syncs[sync].end)
        break;
      else
        sync++;
    }
    if(need_new_tolerances
    && current_block != NULL
    && pos >= current_block->syncs[sync].start_sync){
      tolerance = get_existing_tolerances(current_block->num_pulse_lengths, current_block->thresholds);
      num_pulse_lengths = current_block->num_pulse_lengths;
      deviations = current_block->pulse_length_deviations;
      need_new_tolerances = wav2prg_false;
      if(need_v2)
        audio2tap_enable_disable_halfwaves(input_handle, 0);
    }
    else if(need_new_tolerances
    && between_2_blocks_needing_opposite_waveforms){
      tolerance = NULL;
      if(need_v2)
        audio2tap_enable_disable_halfwaves(input_handle, 1);
    }
    if (audio2tap_get_pulses(input_handle, &raw_pulse, &even_more_raw_pulse) != AUDIOTAP_OK)
      break;
    accumulate_this_pulse = wav2prg_false;
    if(tolerance != NULL){
      uint8_t pulse;

      pulse_was_tolerance_checked = wav2prg_true;
      if (!get_pulse_in_measured_ranges(raw_pulse,
                                tolerance,
                                num_pulse_lengths,
                                &pulse)){
        tolerance = NULL;
        if(need_v2){
          audio2tap_enable_disable_halfwaves(input_handle, 1);
        }
      }
      else if (pulse < num_pulse_lengths){
        raw_pulse = get_average(tolerance, pulse);
        if (deviations)
          raw_pulse += deviations[pulse];
      }
    }
    if (tolerance == NULL &&
         (raw_pulse < min_length_non_noise_pulse
       || raw_pulse > max_length_non_pause_pulse)){
      accumulated_pulses += raw_pulse;
      num_accumulated_pulses++;
      if (need_v2 && pulse_was_tolerance_checked)
        num_accumulated_pulses++;
      accumulate_this_pulse = wav2prg_true;
    }
    if (!accumulate_this_pulse){
      if (accumulated_pulses){
        tap2audio_enable_halfwaves(output_handle, need_v2 && (num_accumulated_pulses % 2) != 0);
        tap2audio_set_pulse(output_handle, accumulated_pulses);
        accumulated_pulses = 0;
        num_accumulated_pulses = 0;
      }
      tap2audio_enable_halfwaves(output_handle, need_v2 && !pulse_was_tolerance_checked);
      tap2audio_set_pulse(output_handle, raw_pulse);
    }
  }
  tap2audio_enable_halfwaves(output_handle, need_v2 && (num_accumulated_pulses % 2) != 0);
  if (accumulated_pulses)
    tap2audio_set_pulse(output_handle, accumulated_pulses);
  tap2audio_close(output_handle);
}
Exemplo n.º 20
0
void fill_liquid(int valve, int target_weight) {
  set_valve_status(valve, 1);
  while(get_average(10) <= target_weight);
  set_valve_status(valve, 0);
}
Exemplo n.º 21
0
  /* This function does bulk of the forward phase heavylifting */
  void operator()() {
    /* Some variables that determine when to stop */
    const double SENTINEL = std::numeric_limits<double>::min();
    double best_gain  = SENTINEL;
    double prev_cost  = SENTINEL;
    double best_confidence = SENTINEL;

    /** 
     * Add each of the forced candidates to the list of selected candidates 
     * and compute an initial model so that we can compute residual later 
     */
    if (0<forced.size()) {
      typename SetContainer::iterator first = forced.begin();
      while (first != forced.end()) {
        add_group (*first);
        selected.push_back (*first);
        ++first;
      }
      Solver::solve (test_A, x, y, lambda, M, (N*selected.size())); 
      best_gain = prev_cost = 
         CostFunctor::cost (test_A, y, x, lambda, M, (N*selected.size())); 
      best_confidence = ConfidenceFunctor::confidence 
                           (test_A, y, y_inv, x, M, N*(1+selected.size())); 
    }

    /**
     * each iteration corresponds to picking one group. we need to only 
     * pick the remaining groups --- we have already included all forced ones.
     */
    const int num_iters = MAX_ITERS-selected.size();
    for (int iter = 0; iter<num_iters; ++iter) {
#if USE_PFUNC
      task root_task;
      attribute root_attribute (false /*nested*/, false /*grouped*/);
#endif

      double iter_time = micro_time();

      /* Compute the residual for this iteration */
      CostFunctor::residual (test_A, x, y, r, M, (selected.size()*N));

      /* evaluate all the candidates, get the best */
      Evaluator evaluator 
        (&A, &r, &kpi_weights, &factorizer, &map, &filter, lambda, M, N);
#if USE_PFUNC
      ReduceType evaluate (my_space, evaluator, *global_taskmgr);
      pfunc::spawn (*global_taskmgr, root_task, root_attribute, evaluate);
      pfunc::wait (*global_taskmgr, root_task);
#else
      evaluator (my_space);
#endif
      /* reduce with the global minimum */
      value_type local_best = evaluator.get_result();
      value_type global_best = find_global_min (local_best);

      /* Create the new model and some statistics about this model */
      add_group (global_best.first);
      Solver::solve (test_A, x, y, lambda, M, N*(1+selected.size())); 
      const double cost = 
        CostFunctor::cost (test_A, x, y, lambda, M, N*(1+selected.size())); 
      const double gain = ((SENTINEL==prev_cost)?(cost):(prev_cost-cost));
      const double confidence = ConfidenceFunctor::confidence 
                           (test_A, y, y_inv, x, M, N*(1+selected.size())); 

      /* Check to see if this is the optimal confidence. If so, variance */
      if ((SENTINEL==best_confidence) || 
          (compare (confidence,best_confidence))) {
        best_confidence = confidence;
        variance = CostFunctor::cost 
          (test_A, x, y, 0.0/*NO REGUL*/, M, N*(1+selected.size())); 
      }

      /* Check if we need to stop --- if so, don't add current candidate */
      if (stop (best_gain, gain, confidence)) {
        if (ROOT==mpi_rank && 2<debug) {
          printf ("stopping at iteration %d\n", iter);
          printf ("cost = %lf, gain = %lf, confidence = %lf\n", 
                            cost, gain, confidence);
        }
        break;
      } 

      if (ROOT==mpi_rank && 2<debug) 
        printf ("selecting %d with cost = %lf, local best = %d, cost = %lf\n",
          global_best.first, cost, local_best.first, local_best.second);

      /* Add to the list of selected KPIs */
      selected.push_back (global_best.first); 

      /* Set up gain and prev_cost */
      prev_cost = cost;
      if (gain>best_gain) best_gain=gain;

      iter_time = micro_time()-iter_time;
      if (mpi_rank==ROOT && 2<debug) {
        printf ("Iteration %d: %lf (per sec)\n", 
             iter, (mpi_size*(my_space.end()-my_space.begin()))/iter_time);
      }
    }

    /**
     * Compute the intercept for this model.
     * 1. Initialize the intercept to be the non-lagged column sum of the KPI.
     * 2. Subtract beta[i]*avg of each of the lagged columns of the predictors.
     *
     * NOTE: Not everyone has this KPI! So, the owner of this KPI should take
     * the initiative to work out the intercept and send it to everyone.
     */
    intercept = get_average (target);
    for (size_t i=0; i<selected.size(); ++i) for (int j=0; j<N; ++j) 
      intercept -= ((x[(i*N)+j]) * get_average (selected[i], j));
  }
Exemplo n.º 22
0
	int main (void)
	{
		struct STUDENT			stu[5]={
			{1416001,"yang",'m',"hubei",{100,98,95,98,100}},
			{1416002,"huang",'m',"gansu",{94,96,95,100,97}},
			{1416003,"guo",'w',"hebei",{99,98,100,94,98}},
			{1416004,"pan",'m',"shanxi",{100,98,95,100,93}},
			{1416005,"liu",'w',"shanxi",{100,98,100,98,100}}
			};
		float					ave;
		int						i;
		struct STUDENT			*p;
		char					name[20];
		struct STUDENT			*m;

		for(i=0;i<5;i++)
		{
			printf("No %d\n",i);
			print_string(&stu[i]);
		}

			printf("Press ENTER to continue\n");
		printf("\n");

		getche();

		for(i=0;i<5;i++)
		{
			ave=get_average(&stu[i]);
			printf("The ave of No.%d:\t%f\n",i,ave);
		}

		printf("\n");

		printf("Press ENTER to continue \n");

		getche();

		while(1)
		{
			printf("Please input your find name :\n");
			printf("Press N to stop\n");
			gets(name);

			if(strcmp(name,"N")==0)
				break;
			p=find_by_name(stu,name);
			print_string(p);
		}

		printf("\nPress ENTER to continue\n\n");

		getche();

		printf("Who is found has the highest score is :\n");
		m=find_max(stu);
		print_string(m);

		printf("Press ENTER to continue \n");

		getche();

		sort_by_score(stu);

			return 0;
	}
Exemplo n.º 23
0
void main()
{
    int score[10] = {59, 99, 78, 90, 85, 88, 93, 9, 60, 77};
    get_average(score);
    getch();
}