Ejemplo n.º 1
0
static void
add_data_for_status (E2kFreebusy *fb, GPtrArray *monthyears, GPtrArray *fbdatas, GArray *events)
{
	E2kFreebusyEvent evt;
	int i, monthyear;
	GByteArray *fbdata;
	unsigned char *p;
	struct tm tm;

	if (!monthyears || !fbdatas)
		return;

	memset (&tm, 0, sizeof (tm));
	for (i = 0; i < monthyears->len && i < fbdatas->len; i++) {
		monthyear = atoi (monthyears->pdata[i]);
		fbdata = fbdatas->pdata[i];

		tm.tm_year = (monthyear >> 4) - 1900;
		tm.tm_mon = (monthyear & 0xF) - 1;

		for (p = fbdata->data; p + 3 < fbdata->data + fbdata->len; p += 4) {
			tm.tm_mday = 1;
			tm.tm_hour = 0;
			tm.tm_min = p[0] + p[1] * 256;
			evt.start = e_mktime_utc (&tm);

			tm.tm_mday = 1;
			tm.tm_hour = 0;
			tm.tm_min = p[2] + p[3] * 256;
			evt.end = e_mktime_utc (&tm);

			g_array_append_val (events, evt);
		}
	}
	merge_events (events);
}
Ejemplo n.º 2
0
void eventor::find_events(void)
{
	std::cout << "# Locating event tracks, timestep: ";
	build_first_frame();
	// loop through the other time steps and the events within them
	for (int t=1; t<ex_list.size(); t++)
	{
		std::cout << t;
        std::cout.flush();
        // clear the queue of extremas yet to be added
		clear_queue();
		for (int e=0; e<ex_list.number_of_extrema(t); e++)
		{
			steering_extremum* svex_cand = ex_list.get(t, e);
			ex_queue.push(svex_cand);
		}
		// loop until no assignment has been made
		bool assigned = true;
		while (assigned)
		{
			assigned = false;
			// repeat for as many events currently in the queue
			int qsize = ex_queue.size();
			for (int q=0; q<qsize; q++)
			{
				// pop an event off the front of the queue
				steering_extremum* svex_cand = ex_queue.front();
				ex_queue.pop();	
				// loop over every track so far
				for (int k=0; k<event_list.get_number_of_event_tracks(); k++)
				{
					// get the event track from the list
					event_track* evt = event_list.get_event_track(k);
					// get the last event point from the event_track
					event_point* evp = evt->get_last_event();
					// only assign to tracks where the last timestep was the previous timestep
					if (evp->timestep != t-1)
						continue;
					// otherwise calculate the distance and the overlap
					FP_TYPE svex_cand_dist, svex_cand_overlap;
					evaluate_candidate_event(evp->svex, svex_cand, svex_cand_dist, svex_cand_overlap);
					// check against maximum distance and minimum overlap
					if (svex_cand_dist > sr || svex_cand_overlap < min_overlap)
						continue;
					// get the current candidate event, its distance and overlap
					event_point* cur_cand_event = evt->get_candidate_event();
					FP_TYPE cur_cand_dist = evt->get_candidate_distance();
					
					// if the new candidate distance is less than the current candidate
					// distance then assign and put the old candidate distance back into
					// the queue
					if (svex_cand_dist < cur_cand_dist)
					{
						event_point cand_evp;
						cand_evp.timestep = t;
						cand_evp.svex = svex_cand;
						evt->set_candidate_event(cand_evp, svex_cand_dist, svex_cand_overlap);
						// if it exists then put the current candidate distance back into the queue
						if (cur_cand_dist < 2e20)
							ex_queue.push(cur_cand_event->svex);
						assigned = true;
					}
				}
				// if not assigned then push point back onto queue
				if (not assigned)
					ex_queue.push(svex_cand);				
			}
		}
		// consolidate the tracks that have been added
		event_list.consolidate_event_tracks();
		// unassigned points left?
		for (int q=0; q<ex_queue.size(); q++)
		{
			steering_extremum* svex = ex_queue.front();
			ex_queue.pop();	
			// create a new track with the point
			event_point evp;
			evp.timestep = t;
			evp.svex = svex;
			// make an event_track and add the event
			event_track evt;
			evt.set_candidate_event(evp, 0.0, 0.0);
			evt.consolidate_candidate_event();
			// add the event_track to the event_track_list
			event_list.add_event_track(evt);			
		}
        int e = t;
        if (t == 0)
            std::cout << "\b";
        while (e > 0)
        {
            e = e / 10;
            std::cout << "\b";
        }		
	}
	std::cout << std::endl;
	// merge any events that occur over the same date, at the same location
	while (merge_events()){}
	// remove any short / short lived / slow moving tracks
	trim_tracks();
}