Esempio n. 1
0
	/**
	 *  \brief Draw, Call back from the GLMoblet.
	 */
	void draw()
	{
		mDTime.tick(); // update delta time ticker. our fps timer (resets for every tick call)
		MoGraph::Scene &scene = mGraph->getScene();	// get scene information
		const int iGridZ = scene.getGridZ(); // need to be able to read the grid size
		const int iGridX = scene.getGridX();
		const int sz = iGridX * iGridZ;

		mGraph->setValues(mTables,sz); // set the value array to the Graph to read from
		mGraph->setColors(mColors,sz); // set the color array to the Graph to read from

		mGraph->draw(); // Draw the whole graph system


		// DRAW ADDITIONAL TEXT ON SCREEN (Orthogonal projections)
		//---------------------------------------------------------------------
		glm::vec4 col(1.0f,1.0f,1.0f,1.0f);	// White color
		glm::vec3 pos(0.0f,0.0f,10.0f); // set screen position upper left corner 0,0.. note need z depth value for order.
		float sy = (0.6f*(float)scene.getWidth())/320.0f; // scale size regardless to resolution our reference resolution is 320..
		mText.setScale(sy,sy);

		char buf[64]; // create text string
		sprintf ( buf, "FPS=%.2f ms=%d",mDTime.currentFps(),mDTime.getElapsed());
		mText.drawText(buf,pos,col); // call drawText
	}
Esempio n. 2
0
DTime Task::totalTimeCurrentDay() const {
    DateTime today = DateTime::today();
    DateTime tomorrow = today.addDays(1);
    DTime totalTime;
    if (childCount() == 0) {
        for (vector<TaskLog*>::iterator iterLog = _logs->begin(); iterLog != _logs->end(); iterLog++) {
            TaskLog* log = *iterLog;
            if (*log->start >= today) {
                if (*log->end < tomorrow) {
                    totalTime.add((*log->end) - (*log->start));
                } else {
                    totalTime.add((*log->end) - tomorrow);
                }
            }
        }
    } else {
        vector<Task*> subtasks = children();
        for (vector<Task*>::iterator iter = subtasks.begin(); iter != subtasks.end(); iter++) {
            Task* sub = *iter;
            totalTime.add(sub->totalTimeCurrentDay());
        }
    }
    return totalTime;

}
Esempio n. 3
0
void* producer(void* arg) {
	NetworkOutputStream* nos = new NetworkOutputStream();
	int socket = nos->open("localhost", _port);

	printf("Producer started\n");
	Logger* log = getLogger(NULL);
	log->info("Producer starter");
	log->startTimeRecord();
	if (socket > 0) {
		NetworkInputStream* nis = new NetworkInputStream(socket);

		std::auto_ptr<CommandWriter> writer(new CommandWriter(nos));

		for (int x = 0; x < MAX_INSERT; x++) {
			std::auto_ptr<InsertCommand> cmd(new InsertCommand());

			BSONObj* obj = new BSONObj();
			std::auto_ptr<std::string> guid(uuid());
			obj->add("_id", guid->c_str());
			char* temp = (char*)malloc(2000);
			memset(temp, 0, 2000);
			memset(temp, 'a', 1999);
			int len = strlen(temp);
			obj->add("content", temp);
			free(temp);
			cmd->setBSON(obj);
			std::string db("mydb");
			cmd->setDB(db);
			std::string ns("myns");
			cmd->setNameSpace(ns);
			cmd->setOptions(new BSONObj());
			writer->writeCommand(cmd.get());

			int result = nis->readInt();

			EXPECT_EQ(result, 1);
			if (result != 1) {
				break;
			}
		}
		nis->close();
	} else {
		printf("Socket is 0");
	}
	log->info("Producer end");
	log->stopTimeRecord();

	DTime time = log->recordedTime();
	if (time.totalSecs() > 0) {
		log->info("Producer time: %d secs. Operations per sec: %d", time.totalSecs(), MAX_INSERT / time.totalSecs());
	} else {
		EXPECT_TRUE(false) << "Something was wrong network could not execute " << MAX_INSERT << " in 0 secs.";
	}
}
Esempio n. 4
0
DTime Task::totalTime() const {
    DTime result;
    for (vector<TaskLog*>::iterator iterLog = _logs->begin(); iterLog != _logs->end(); iterLog++) {
        TaskLog* log = *iterLog;
        result.add((*log->end) - (*log->start));
    }
    vector<Task*> subtasks = children();
    for (vector<Task*>::iterator iter = subtasks.begin(); iter != subtasks.end(); iter++) {
        Task* sub = *iter;
        result.add(sub->totalTime());
    }
    return result;
}
Esempio n. 5
0
TEST(testUtil, testLogger) {
	// Test timer
	//
	Logger* log = getLogger(NULL);
	log->startTimeRecord();
	Thread::sleep(3000);
	log->stopTimeRecord();

	DTime time = log->recordedTime();

	long secs = time.totalSecs();

	EXPECT_TRUE(secs > 2);
	EXPECT_TRUE(secs < 4);
}
Esempio n. 6
0
DatabaseQuery* Draw::GetDataToFetch() {
	const DTime& start_time = m_index.GetStartTime();
	assert(start_time.IsValid());

	PeriodType period = start_time.GetPeriod();

	int d = m_values.m_view.Start();

	DatabaseQuery* q = NULL;

	if (m_draw_info == NULL)
		return q;

	if (GetEnable() == false)
		return q;

	bool no_max_probes = !m_draw_info->IsValid() || m_draw_info->GetParam()->GetIPKParam()->GetFormulaType() == TParam::LUA_AV;
	for (size_t i = 0; i < m_values.len(); ++i) {
		ValueInfo &v = m_values.Get(i);

		if (v.state != ValueInfo::EMPTY) 
			continue;
		
		DTime pt = GetDTimeOfIndex(i - d);
		if (period == PERIOD_T_DAY)
			v.max_probes = 1;
		else if (no_max_probes)
			v.max_probes = 0;
		else {
			DTime ptn = pt + m_index.GetDateRes() + m_index.GetTimeRes();
			v.max_probes = (ptn.GetTime() - pt.GetTime()).GetMinutes() / 10;
		}

		v.state = ValueInfo::PENDING;
		
		if (q == NULL)
			q = CreateDataQuery(m_draw_info, period, m_draw_no);
		AddTimeToDataQuery(q, pt.GetTime().GetTicks());
	}

	return q;
}
Esempio n. 7
0
	/**
	 *  \brief Draw, Call back from the GLMoblet.
	 */
	void draw()
	{
		mDTime.tick(); // update delta time ticker. our fps timer (resets for every tick call)
		MoGraph::Scene &scene = mGraph->getScene();	// get scene information
		const int iGridZ = scene.getGridZ(); // need to be able to read the grid size
		const int iGridX = scene.getGridX();
		const int sz = iGridX * iGridZ;
		float dt = static_cast<float>(mDTime.getElapsed())*0.001f; // calculate a delta time factor for omega
		mOmega += dt; // accumulate the omega used for sin/cos func

		if (mOmega > M_PI*2.0f)	// for high precision make sure omega 0..2*PI
			mOmega -= M_PI*2.0f; // wrapping a x value is also faster not to use large values in sin(x).

		const float f = 2.5f/255.0f; // prepare for a scale value of result being max 2.5f
		for(int j=0; j<iGridZ; j++)	// Build the data arrays for colors and for tables.
		{
			const float jcos = 2.0f + cos(j*0.3f+mOmega); // calculate the Depth Wave with cos
			for(int i=0; i<iGridX; i++)
			{
				const int id 	= j*iGridX+i;
				Color *c 		= (Color *)&mLogoH.getData()[id];
				mTables[id] 	= (float)c->r * f + (sin(i*0.3f+mOmega) + jcos); // generate a sine wave and add depth wave
			}
		}

		mGraph->setValues(mTables,sz); // set the value array to the Graph to read from
		mGraph->setColors(mColors,sz); // set the color array to the Graph to read from

		mGraph->draw();	// Draw the whole graph system


		// DRAW ADDITIONAL TEXT ON SCREEN (Orthogonal projections)
		//---------------------------------------------------------------------
		glm::vec4 col(1.0f,1.0f,1.0f,1.0f);	// White color
		glm::vec3 pos(0.0f,0.0f,10.0f);	// set screen position upper left corner 0,0.. note need z depth value for order.
		float sy = (0.6f*(float)scene.getWidth())/320.0f; // scale size regardless to resolution our reference resolution is 320..
		mText.setScale(sy,sy);

		char buf[64]; // create text string
		sprintf ( buf, "FPS=%.2f ms=%d",mDTime.currentFps(),mDTime.getElapsed());
		mText.drawText(buf,pos,col); // call drawText
	}
Esempio n. 8
0
DTime TimeIndex::AdjustToPeriodSpan(const DTime &time) const {
	wxDateTime dt = time.GetTime();

	if (m_number_of_values == default_units_count[time.GetPeriod()] * PeriodMult[time.GetPeriod()]) {
		switch (time.GetPeriod()) {
			case PERIOD_T_DECADE :
			case PERIOD_T_YEAR :
				dt.SetMonth(wxDateTime::Jan);
			case PERIOD_T_MONTH :
				dt.SetDay(1);
				dt.SetHour(0);
				break;
			case PERIOD_T_WEEK:
			case PERIOD_T_SEASON :
				dt.SetToWeekDayInSameWeek(wxDateTime::Mon);
			case PERIOD_T_DAY :
				dt.SetHour(0);
				dt.SetMinute(0);
				break;
			case PERIOD_T_30MINUTE :
				dt.SetMinute(dt.GetMinute() / 30 * 30);
				dt.SetSecond(0);
				break;
			case PERIOD_T_5MINUTE :
				dt.SetMinute(dt.GetMinute() / 3 * 3);
				dt.SetSecond(0);
				break;
			case PERIOD_T_MINUTE :
			case PERIOD_T_30SEC :
				dt.SetSecond(dt.GetSecond() / 30 * 30);
				break;
			case PERIOD_T_OTHER:
			case PERIOD_T_LAST:
				assert(false);
		}
		return DTime(time.GetPeriod(), dt);
	} else {
		DTime ret(time);
		return ret.AdjustToPeriodStart();
	}
}
Esempio n. 9
0
DTime Task::totalTimeCurrentWeek() const {
    DateTime startDayWeek = DateTime::startDayOfWeek();
    DateTime startDayOfNextWeek = DateTime::startDayOfNextWeek();
    DTime totalTime;
    if (childCount() == 0) {
        for (vector<TaskLog*>::iterator iterLog = _logs->begin(); iterLog != _logs->end(); iterLog++) {
            TaskLog* log = *iterLog;
            if ((*(log->start) >= startDayWeek) &&
                (*(log->end) < startDayOfNextWeek)) {
                totalTime.add((*log->end) - (*log->start));
            }
        }
    } else {
        vector<Task*> subtasks = children();
        for (vector<Task*>::iterator iter = subtasks.begin(); iter != subtasks.end(); iter++) {
            Task* sub = *iter;
            totalTime.add(sub->totalTimeCurrentWeek());
        }
    }
    return totalTime;
}
Esempio n. 10
0
		void testFind(int port, int top = 10000000) {
			DjondbConnection* conn = DjondbConnectionManager::getConnection("localhost", port);

			if (!conn->open()) {
				cout << "Not connected" << endl;
				exit(0);
			}

			Logger* log = getLogger(NULL);

			log->startTimeRecord();
			log->info("Testing find performance over: %d finds.", top);
			for (int x = 0; x < top; x++) {
				BSONArrayObj* arr = conn->executeQuery("select top 1 * from db:testperformance");
				if (arr->length() == 0) {
					log->info("Error an id was not found");
					exit(1);
				}
				delete arr;
			}
			log->stopTimeRecord();

			DTime time = log->recordedTime();

			cout << "Total find secs: " << time.totalSecs() << endl;
			if (time.totalSecs() > 0) {
				log->info("Found %d: throughtput: %d.", top, (top / time.totalSecs()));
			} else {
				log->info("Found :%d, throughtput too high to be measured", top);
			}
			if ((time.totalSecs() > 0) && ((top / time.totalSecs()) < 16000))  {
				log->info("Performance is not good enough");
			}
		}
Esempio n. 11
0
void TimeScene::drawTime(DateTime currentDay, DTime time, QModelIndex index, int groupLevel) {
    QSize size = sizeHint(index);
    int bordermargin = (size.height() * .1) / 2;

    QBrush b;
    QPen pen(QColor(0, 0, 150));
    QBrush textBrush;
    if (groupLevel == 2) {
        b = QBrush(Qt::white);
        pen = QPen(QColor(0, 0, 150));
        textBrush = QBrush(Qt::darkBlue);
    }
    if (groupLevel == 1) {
        b = QBrush(Qt::lightGray);
        pen = QPen(QColor(0, 0, 50));
        textBrush = QBrush(Qt::blue);
    }
    if (groupLevel == 0) {
        b = QBrush(Qt::darkGray);
        pen = QPen(QColor(100, 100, 200));
        textBrush = QBrush(Qt::white);
    }

    int daysToStart = _startDate.daysTo(currentDay);
    int x1 = daysToStart * _dayWidth;
    int y1 = _currentY + bordermargin;
    int x2 = x1 + _dayWidth;
    int y2 = _currentY + size.height() - bordermargin;

//    QGraphicsRectItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b);
    QRect rect(x1, y1, (x2 - x1), (y2 - y1));
    GraphicsRectItem* item = new GraphicsRectItem(rect, index);
    this->addItem(item);
    item->setPen(pen);
    item->setBrush(b);
    item->setZValue(1);
    item->setAcceptHoverEvents(true);

    connect(item, SIGNAL(itemHoverEnter(QModelIndex)), this, SLOT(receiveItemHoverEnter(QModelIndex)));
    connect(item, SIGNAL(itemHoverLeave(QModelIndex)), this, SLOT(receiveItemHoverLeave(QModelIndex)));

    QFont font("Arial", 8);

    font.setBold((groupLevel <= 1));
    font.setItalic((groupLevel == 0));

    QGraphicsSimpleTextItem* text = addSimpleText(time.toQString(), font);
    text->setBrush(textBrush);
    text->setPos(x1 + 2, y1 + 1);
    text->setVisible(true);
    text->setZValue(1);
}
Esempio n. 12
0
TEST(testUtil, testTimes)
{
	// Testing diff
	DTime t(15, 40, 0);
	DTime t2(16, 20, 0);
	DTime res = t2 - t;

	EXPECT_TRUE((res.hour() == 0) && (res.minutes() == 40) && (res.seconds() == 0));

	res = t2 - 200;
	EXPECT_TRUE((res.hour() == 16) && (res.minutes() == 16) && (res.seconds() == 40));
	// teting add
}
Esempio n. 13
0
		void testTimes()
		{
			// Testing diff
			DTime t(15, 40, 0);
			DTime t2(16, 20, 0);
			DTime res = t2 - t;

			TEST_ASSERT((res.hour() == 0) && (res.minutes() == 40) && (res.seconds() == 0));

			res = t2 - 200;
			TEST_ASSERT((res.hour() == 16) && (res.minutes() == 16) && (res.seconds() == 40));
			// teting add
		}
Esempio n. 14
0
void XYDialog::OnDateChange(wxCommandEvent &event) {
	wxButton *button;
	DTime *time;

	if (event.GetId() == XY_START_TIME) {
		button = wxDynamicCast(FindWindow(XY_START_TIME), wxButton);
		time = &m_start_time;
	} else {
		button = wxDynamicCast(FindWindow(XY_END_TIME), wxButton);
		time = &m_end_time;
	}

	DateChooserWidget *dcw = 
		new DateChooserWidget(
				this,
				_("Select date"),
				1,
				-1,
				-1,
				1
		);

	wxDateTime wxtime = time->GetTime();
	
	bool ret = dcw->GetDate(wxtime);
	dcw->Destroy();

	if (ret == false)
		return;

	*time = DTime(m_period, wxtime);
	time->AdjustToPeriod();

	button->SetLabel(FormatTime(time->GetTime(), m_period));

}
Esempio n. 15
0
int TimeIndex::GetIndex(const DTime& time, int *dist) const {
	int i, d;
	if (!m_time.IsValid() || !time.IsValid()) {
		i = -1, d = 0;
	} else {
		i = d = m_time.GetDistance(time);

		if (d < 0 || d >= (int)m_number_of_values)
			i = -1;
	}
	if (dist)
		*dist = d;

	return i;
}
Esempio n. 16
0
		void testCommand(int port, int top = 10000000) {
			DjondbConnection* conn = DjondbConnectionManager::getConnection("localhost", port);

			if (!conn->open()) {
				cout << "Not connected" << endl;
				exit(0);
			}

			Logger* log = getLogger(NULL);

			log->startTimeRecord();
			log->info("Testing command performance over: %d executions.", top);
			for (int x = 0; x < top; x++) {
				std::vector<std::string>* dbs = conn->dbs();
				if (dbs == NULL) {
					log->info("Test command failed and returned NULL");
					exit(1);
				}
				if (dbs->size() == 0) {
					log->info("Test command failed and returned 0 elements");
					exit(1);
				}
				delete dbs;
			}
			log->stopTimeRecord();

			DTime time = log->recordedTime();

			cout << "Total secs: " << time.totalSecs() << endl;
			if (time.totalSecs() > 0) {
				log->info("Executed %d: throughtput: %d.", top, (top / time.totalSecs()));
			} else {
				log->info("Executed %d, throughtput too high to be measured", top);
			}
			if ((time.totalSecs() > 0) && ((top / time.totalSecs()) < 5000))  {
				log->info("Performance is not good enough");
			}
		}
Esempio n. 17
0
int DTime::GetDistance(const DTime &t) const {
	assert(IsValid());
	assert(t.IsValid());

	if (GetPeriod() != t.GetPeriod()) {
		wxLogError(_T("our period: %d, his period: %d"), GetPeriod(), t.GetPeriod());
		assert(false);
	}

	const wxDateTime& _t0 = GetTime();
	const wxDateTime& _t = t.GetTime();

	int ret = -1;

	switch (GetPeriod()) {
		case PERIOD_T_DECADE:
			ret = _t.GetYear() - _t0.GetYear();
			break;
		case PERIOD_T_YEAR:
			ret = _t.GetYear() * 12 + _t.GetMonth()
				- _t0.GetYear() * 12 - _t0.GetMonth();
			break;
		case PERIOD_T_MONTH: 
			ret = (_t - _t0).GetHours();
			//acount for daylight saving time
			switch (ret % 24) {
				case 1:
					ret -= 1;
					break;
				case 23:
					ret += 1;
					break;
				case -1:
					ret += 1;
					break;
				case -23:
					ret -= 1;
					break;
			}
			ret /= 24;
			break;
		case PERIOD_T_DAY:
			ret = (_t - _t0).GetMinutes() / 10;
			break;
		case PERIOD_T_30MINUTE:
			ret = ((_t - _t0).GetSeconds() / 10).ToLong();
			break;
		case PERIOD_T_5MINUTE:
			ret = ((_t - _t0).GetSeconds()).ToLong();
			break;
		case PERIOD_T_MINUTE:
			ret = ((_t - _t0).GetMilliseconds() / 500).ToLong();
			break;
		case PERIOD_T_30SEC:
			ret = ((_t - _t0).GetMilliseconds() / 100).ToLong();
			break;
		case PERIOD_T_WEEK:
			ret = (_t - _t0).GetHours() / 8;
			if (_t0.IsDST() != _t.IsDST()) {
				if (_t0 < _t && _t.IsDST())
					ret += 1;
				else if (_t < _t0 && _t0.IsDST())
					ret -= 1;
			}
			break;
		case PERIOD_T_SEASON: 
			ret = (_t - _t0).GetDays() / 7;
			if (_t0.IsDST() != _t.IsDST()) {
				if (_t0 < _t && _t.IsDST())
					ret += 1;
				else if (_t < _t0 && _t0.IsDST())
					ret -= 1;
			}
			break;
		default:
			assert(false);
	}

	return ret;
}
Esempio n. 18
0
bool DTime::IsBetween(const DTime& t1, const DTime& t2) const {
	if (t1.IsValid() && t2.IsValid())
		return t1 <= *this && t2 > *this;
	else
		return false;
}
Esempio n. 19
0
		void testPerfomance(int port, int top = 10000000) {
			DjondbConnection* conn = DjondbConnectionManager::getConnection("localhost", port);

			if (!conn->open()) {
				cout << "Not connected" << endl;
				exit(0);
			}

			// 1k inserts
			//
			Logger* log = getLogger(NULL);

			log->info("Testing performance over: %d inserts.", top);
			std::vector<std::string>* names = generateNames(top);
			std::vector<std::string*>* ids = new std::vector<std::string*>();
			log->startTimeRecord();
			for (int x = 0; x < top; x++) {
				BSONObj obj;
				char* text = (char*)malloc(1001);
				memset(text, 0, 1001);
				memset(text, 'a', 1000);

				std::string* id = uuid();
				obj.add("_id", id->c_str());
				int test = rand() % 100;
				if (test > 30) {
					ids->push_back(id);
				} else {
					delete id;
				}
				obj.add("t", x);

				obj.add("text", text);
				obj.add("name", const_cast<char*>(names->at(x).c_str()));

				conn->insert("db", "testperformance", obj);
				free(text);
				// every 10 % will print a message showing the progress
				if ((x % (top / 10)) == 0) {
					DTime timeTemp = log->recordedTime();
					int progress = (x * 100) / top;
					if (timeTemp.totalSecs() > 0) {
						log->info("Inserted %d: throughtput: %d per sec. %d comnpleted", x, (x / timeTemp.totalSecs()), progress);
					} else {
						log->info("Inserted :%d, throughtput too high to be measured. %d completed.", x, progress);
					}
				}
			}

			log->stopTimeRecord();

			DTime time = log->recordedTime();

			cout << "Total secs: " << time.totalSecs() << endl;
			if (time.totalSecs() > 0) {
				log->info("Inserted %d: throughtput: %d.", top, (top / time.totalSecs()));
			} else {
				log->info("Inserted %d, throughtput too high to be measured", top);
			}
			if ((time.totalSecs() > 0) && ((top / time.totalSecs()) < 16000))  {
				log->info("Performance is not good enough");
			}


			conn->close();

			delete log;
		}
Esempio n. 20
0
void Draw::PrintTime(const DTime& s) {
	wxLogWarning(_T("%s"), s.Format().c_str());
}
Esempio n. 21
0
	/**
	 * init call backed from GLMoblet
	 */
	void init()
	{
		/*
		 * Graph object needs to be allocated and then initiated,
		 * Font is a separate system but is required in the graph for rendering text in 3D
		 * RenterText is an independent text renderer flat on screen. but very same class is being used in Graph as well
		 * can handle both orthogonal projection see drawText and drawText3D
		 */

		mWidth 		= (int)(EXTENT_X(maGetScrSize())); // Screen Resolution
		mHeight 	= (int)(EXTENT_Y(maGetScrSize()));
		mGraph 		= new MoGraph::Graph(); // Create MoGraph::Graph class
		mFont 		= new BMFont(); // Create Font class

		// Initiate the RenderText system that will be used in Graph
		std::vector<MAHandle> fontTexArray;
		fontTexArray.push_back(R_BOX_TEXTURE);

		mFont->Init(R_BOX_FNT, fontTexArray); // Initiate font where to get its resources (.fnt) file generated from BMFont and the bitmap texture that contains the aphabet
		mText.init(mWidth,mHeight,mFont); // initiate the text system by setting a Font & Screen dimensions

		mDTime.setDesiredFps(50.0f); // set up the DTime used for calculating FPS
		setPreferredFramesPerSecond(50); // set preferred fps for the Moblet

		// initiate Graph by setting up a grid sz in X & Z ,
		// also grid in Y with grid step,
		// additional info like fit to screen, screen resolutions.

		MoGraph::GraphDesc desc;

		desc.scrWidth = mWidth; // screen width
		desc.scrHeight = mHeight; // screen height
		desc.gridX = 32; // amount of bars in X axis
		desc.gridZ = 32; // amount of bars in Z axis (depth)
		desc.gridYLines = 0; // amount of horisontal lines to be displayed in graph
		desc.gridStepYLines = 1.0f; // the step Y position between the lines
		desc.gridStepValue = 1.0f; // the step value for the displayed numbers for line
		desc.gridDecimals = 1; // use amount of decimals e.g 0="1", 1="1.0", 2="1.00", 3="1.000" etc..
		desc.gridOffsetStartLine = -1; // offset where to start horisontal lines from requires OFFSET_GRIDS to be set. see flagGridLines enums
		desc.gridOffsetStartValue = -2.0f; // offset startin value can be other then zero, requires OFFSET_GRIDS to be set.
		desc.bFitScreen = true; // fit graph to screen (default)
		desc.flagGridLines = MoGraph::DEFAULT_GRIDS; // MoGraph::OFFSET_GRIDS .. MoGraph::MIRRORED_GRIDS;
		desc.bUseGridValue = false; // switch to turn on/off grid values
		desc.font = mFont; // use Font for text rendering in Graph such as values titles etc.

		if (!mGraph->init(&desc))
			maPanic(1,"Failed to initiate Graph");

		glm::vec4 bkcolor(0.2f, 0.2f, 0.2f, 1.0f);
		mGraph->setBGColor(bkcolor); // additional set background color

		// TEXT MANIPULATION IN GRAPH
		// Text strings in the graph has a default setup.
		// everything is built upon the Text structs that are pushed to an
		// std::vector<Text>   Text array
		// We can change the existing setup by changing the strings...
		std::vector<MoGraph::Text> &textArray = mGraph->getScene().getTextMgr().getTextArray();
		std::vector<MoGraph::Line> &lineArray = mGraph->getScene().getAxisMgr().getLineArray();
		// and we can also push new ones to the table for more text in the graph...
		// you can add as many as you please... fps issue in the end.

		// Clear any existing texts created by the graph system.
		textArray.clear();
		lineArray.clear();

		float scale = mGraph->getScene().getGridX()/500.0f;

		// create additional example text
		MoGraph::Text text;
		text.mColor 	= glm::vec4(1.0f,1.0f,1.0f,1.0f);
		text.mPos 		= glm::vec3(0.0f,10.0f,0.0f);
		text.mRotate 	= glm::vec3(0.0f,0.0f,0.0f); // Rotation in degrees
		text.mScale 	= glm::vec2(scale,scale);
		text.mTextFlagX = MoGraph::Text::CENTER_X;
		text.mText 		= "MoGraph";
		textArray.push_back(text);

		mLogo.init(R_MOSYNC_LOGO);	// load and access picture data
		mLogoH.init(R_MOSYNC_HEIGHT);

		// Prepare the colors for the Graph.
		// colors are static so we only need to build them once.
		const int iGridZ 		= desc.gridZ; // need to be able to read the grid size
		const int iGridX 		= desc.gridX;
		const int sz			= iGridX * iGridZ;

		if (mTables == 0) // check if array already is allocated
			mTables = new float[sz]; // allocate an array for set data to the Bars.
		if (mColors == 0) // check if array already is allocated
			mColors = new glm::vec4[sz]; // allocate an array for color table

		const float f = 1.0f/255.0f;
		for(int j=0; j<iGridZ; j++)	// Build the data arrays for colors and for tables.
		{
			for(int i=0; i<iGridX; i++)
			{
				const int id = j*iGridX+i;
				Color *c = (Color *)&mLogo.getData()[id];
				mColors[id]	= glm::vec4((float)c->r*f, (float)c->g*f, (float)c->b*f, 1.0f);	// set color gradients
			}
		}
	}
Esempio n. 22
0
void LogScene::getTaskItem(const QModelIndex &index) {
    Task* task = _model->task(index);

    Calendar* calendar = task->project()->projectDefaultCalendar();
    int hoursInDay = calendar->endHour().hour() - calendar->startHour().hour();
    std::vector<TaskLog*>* logs =task->logs();
    double startHour = 0;//calendar->startHour().hour();
    double endHour = 24;//calendar->endHour().hour() + 1;
    double minuteSize = (double)24*BLOCKSIZE / (double)((endHour - startHour) * 60);
    int red = 0;
    for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) {
        TaskLog* log = *iter;

        QSize size = sizeHint(index);

        int bordermargin = (size.height() * .4) / 2;

        int daysToStart = _startDate.daysTo(*log->start);
        double x1 = (double)daysToStart * (double)_dayWidth;
        DTime logStartTime = log->start->time();
        double y1 = (double)(logStartTime.totalMinutes() - (startHour*60)) * minuteSize;

        double x2 = (daysToStart + 1) * (double)_dayWidth;
        DTime logEndTime = log->end->time();
        if (log->end->getDay() != log->start->getDay()) {
            logEndTime = DTime(23, 59, 59);
        }
        double y2 = (double)(logEndTime.totalMinutes() - (startHour*60)) * minuteSize;

        QBrush b(task->taskColor());//QImage(":/img/task_bar.png"));//(QPixmap(":/img/task_bar.png"));
        red += 20;
        QColor penColor((task->taskColor().red() < 100) ? 0: (task->taskColor().red() - 100),
                        (task->taskColor().green() < 100) ? 0: (task->taskColor().green() - 100),
                        (task->taskColor().blue() < 100) ? 0: (task->taskColor().blue() - 100));
        QPen pen(penColor);
        if (log->activeLog) {
            pen.setWidth(3);
        }

        QGraphicsItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b);
        item->setZValue(1);
        if ((y2 - y1) > 20) {
            QFont f("Arial", 8);
            f.setWeight(QFont::Light);
            QBrush brush(penColor);

            std::string description = *task->shortDescription();
            int textY = y1 + 5;
            while (description.length() > 0) {
                std::string label;
                if (description.length() > 15) {
                    label = description.substr(0, 15);
                    description = description.substr(15);
                    if ((label.at(label.length() - 1) != ' ') &&
                        (description.at(0) != ' ')) {
                        int pos;
                        if ((pos = label.rfind(' ')) != std::string::npos) {
                            description = label.substr(pos) + description;
                            label = label.substr(0, pos);
                        }
                    }
                } else {
                    label = description;
                    description = "";
                }
                label = label.erase(label.find_last_not_of(" \n\r\t")+1);
                description = description.erase(description.find_last_not_of(" \n\r\t")+1);
                if ((textY + 20) < y2) {
                    QGraphicsSimpleTextItem* text = this->addSimpleText(tr(label.c_str()));
                    text->setPos(x1 + 10, textY);
                    //text->rotate(90);
                    text->setVisible(true);
                    text->setBrush(brush);
                    text->setFont(f);
                    text->setZValue(2);
                    textY += 15;
                } else {
                    break;
                }
            }
        }
        _currentY += sizeHint(index).height();
    }
    delete(logs);
}
Esempio n. 23
0
	/**
	 * init call backed from GLMoblet
	 */
	void init()
	{
		/*
		 * Graph object needs to be allocated and then initiated,
		 * Font is a separate system but is required in the graph for rendering text in 3D
		 * RenterText is an independent text renderer flat on screen. but very same class is being used in Graph as well
		 * can handle both orthogonal projection see drawText and drawText3D
		 */

		int gridX = 10;
		int gridY = 4;

		mWidth = (int)(EXTENT_X(maGetScrSize()));
		mHeight = (int)(EXTENT_Y(maGetScrSize()));
		mGraph = new MoGraph::Graph(); // Create MoGraph::Graph class
		mFont = new BMFont(); // Create Font class
		mNameTable.resize(gridX * gridY);

		// Initiate the RenderText system that will be used in Graph
		std::vector<MAHandle> fontTexArray;
		fontTexArray.push_back(R_BOX_TEXTURE);

		mFont->Init(R_BOX_FNT, fontTexArray); // Initiate font where to get its resources (.fnt) file generated from BMFont and the bitmap texture that contains the aphabet
		mText.init(mWidth,mHeight,mFont); // initiate the text system by setting a Font & Screen dimensions

		mDTime.setDesiredFps(50.0f); // set up the DTime used for calculating FPS
		setPreferredFramesPerSecond(50); // set preferred fps for the Moblet

		// initiate Graph by setting up a grid sz in X & Z ,
		// also grid in Y with grid step,
		// additional info like fit to screen, screen resolutions.
		mScaleBarHeight = 0.25f;

		MoGraph::GraphDesc desc;
		desc.scrWidth = mWidth; // screen width
		desc.scrHeight = mHeight; // screen height
		desc.gridX = gridX; // amount of bars in X axis
		desc.gridZ = gridY; // amount of bars in Z axis (depth)
		desc.gridYLines = 16; // amount of horisontal lines to be displayed in graph
		desc.gridStepYLines = 0.5f; // the step Y position between the lines
		desc.gridStepValue = 0.5f/mScaleBarHeight; // the step value for the displayed numbers for line
		desc.gridDecimals = 1; // use amount of decimals e.g 0="1", 1="1.0", 2="1.00", 3="1.000" etc..
		desc.gridOffsetStartLine = -1; // offset where to start horisontal lines from requires OFFSET_GRIDS to be set. see flagGridLines enums
		desc.gridOffsetStartValue = -2.0f; // offset startin value can be other then zero, requires OFFSET_GRIDS to be set.
		desc.bFitScreen = true; // fit graph to screen (default)
		desc.flagGridLines = MoGraph::DEFAULT_GRIDS; // MoGraph::OFFSET_GRIDS .. MoGraph::MIRRORED_GRIDS;
		desc.bUseGridValue = true; // switch to turn on/off grid values
		desc.font = mFont; // use Font for text rendering in Graph such as values titles etc.

		if (!mGraph->init(&desc)) // initiates graph
			maPanic(1,"Failed to initiate Graph");

		glm::vec4 bkcolor(0.2f, 0.2f, 0.2f, 1.0f); // set background color
		mGraph->setBGColor(bkcolor); // additional set background color

		// TEXT MANIPULATION IN GRAPH
		// Text strings in the graph has a default setup.
		// everything is built upon the Text structs that are pushed to an
		// std::vector<Text>   Text array
		// We can change the existing setup by changing the strings...
		std::vector<MoGraph::Text> &textArray = mGraph->getScene().getTextMgr().getTextArray();
	//	std::vector<MoGraph::Line> &lineArray = mGraph->getScene().getAxisMgr().getLineArray();
		// and we can also push new ones to the table for more text in the graph...
		// you can add as many as you please... fps issue in the end.
		const float scale = mGraph->getScene().getScaleFactor();
		const float ss = 0.75f;
		glm::vec2 scaleAxisText = glm::vec2(scale*ss,scale*ss);

		textArray[0].mColor = glm::vec4(124.0f/255.0f, 175.0f/255.0f,	0.0f,	1.0f);
		textArray[0].mPos.y -= 0.3f;
		textArray[0].mText = "Connecting..."; // Graph title text. we also use it for connection status
		textArray[0].mTextFlagX = MoGraph::Text::CENTER_LEFT;
		textArray[0].mTextFlagY = MoGraph::Text::CENTER_TOP;
		textArray[0].mScale	= glm::vec2(scale*0.8,scale*0.8);

		textArray[1].mScale = scaleAxisText; // Y-AXIS
		textArray[1].mTextFlagX = MoGraph::Text::CENTER_X;
		textArray[1].mTextFlagY = MoGraph::Text::CENTER_TOP;

		textArray[2].mPos.x	+= 0.1f;
		textArray[2].mText = "Shares";
		textArray[2].mScale = scaleAxisText; // X-AXIS
		textArray[2].mTextFlagX = MoGraph::Text::CENTER_LEFT;
		textArray[2].mTextFlagY = MoGraph::Text::CENTER_TOP;

		textArray[textArray.size()-1].mPos.x += 0.1f;
		textArray[textArray.size()-1].mScale = scaleAxisText; // Z-AXIS (last entry before user storage! due to z being optional)
		textArray[textArray.size()-1].mTextFlagX = MoGraph::Text::CENTER_RIGHT;
		textArray[textArray.size()-1].mTextFlagY = MoGraph::Text::CENTER_TOP;

		// create additional example text

		MoGraph::Text text;
		text.mColor = glm::vec4(1.0f,1.0f,1.0f,1.0f);
		text.mPos = glm::vec3(0.0f,10.0f,0.0f);
		text.mRotate = glm::vec3(0.0f,0.0f,0.0f);		// Rotation in degrees
		text.mScale = glm::vec2(scale,scale);
		text.mTextFlagX = MoGraph::Text::CENTER_X;
		text.mText = "MoGraph";

		textArray.push_back(text);

		// Prepare the colors for the Graph.
		// colors are static so we only need to build them once.
		const int iGridZ = desc.gridZ;		// need to be able to read the grid size
		const int iGridX = desc.gridX;
		const int sz = iGridX * iGridZ;

		if (mTables == 0)					// check if array already is allocated
			mTables = new float[sz];		// allocate an array for set data to the Bars.
		if (mColors == 0)					// check if array already is allocated
			mColors = new glm::vec4[sz];	// allocate an array for color table

		for(int j=0; j<iGridZ; j++)			// Build the data arrays for colors and for tables.
		{
			for(int i=0; i<iGridX; i++)
			{
				const int id = j*iGridX+i;
				mColors[id]	= glm::vec4(0.0f, 1.0f, 1.0f, 1.0f);			// set color gradients
				mTables[id]	= 1.0f;
			}
		}

		// Start the HTTP request.
		mSharesData = NULL;
		lprintfln("@@@ MOSYNC BEFORE REQUEST");
		MAUtil::String url = "http://finance.google.com/finance/info?client=ig&q=NASDAQ:MSFT,NASDAQ:FB,NASDAQ:ERIC,NASDAQ:BBRY,NYSE:NOK,NASDAQ:YHOO,NASDAQ:INTC,NASDAQ:CSCO,NASDAQ:ORCL,NASDAQ:NVDA";

		int res = mHttp.create(url.c_str(),HTTP_GET);
		if(res < 0)
		{
			lprintfln("@@@@@@@@@@@@@@@@ unable to connect - %i\n", res);
		}
		else
		{
			mHttp.finish();
		}
	}
Esempio n. 24
0
 QVariant TaskItem::data(int column, int role) const
 {
     if (_type == BLANK) {
         return QVariant();
     }
     if (column == 1) {
         if (role == Qt::DisplayRole) {
             return QVariant();
         }
     } else {
         if (role != Qt::DisplayRole) {
             return QVariant();
         }
     }
     switch(column) {
     case 0:
         if (_type == PROJECT) {
             return QString(_project->name()->c_str());
         }
         if (_type == TASK) {
             return QString(_task->shortDescription()->c_str());
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             return "Projects";
         }
     case 1:
         // Closed
         switch (_type) {
         case PROJECT:
         case NONE:
         case SUMMARY:
             return QVariant();
         case TASK:
             return QVariant(_task->isClosed() ? Qt::Checked : Qt::Unchecked);
             return false;
         }
     case 2:
         if (_type == PROJECT) {
             return _project->totalTime().toQString();
         }
         if (_type == TASK) {
             return _task->totalTime().toQString();
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             DTime totalTime;
             for (std::vector<Project*>::const_iterator iter = _allprojects.begin(); iter != _allprojects.end(); iter++) {
                 Project *prj = *iter;
                 totalTime = totalTime + prj->totalTime();
             }
             return totalTime.toQString();
         }
     case 3:
         if (_type == PROJECT) {
             return _project->totalTimeCurrentWeek().toQString();
         }
         if (_type == TASK) {
             return _task->totalTimeCurrentWeek().toQString();
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             DTime totalTime;
             for (vector<Project*>::const_iterator iter = _allprojects.begin(); iter != _allprojects.end(); iter++) {
                 Project* prj = *iter;
                 totalTime = totalTime + prj->totalTimeCurrentWeek();
             }
             return totalTime.toQString();
         }
     case 4:
         if (_type == PROJECT) {
             return _project->totalTimeCurrentDay().toQString();
         }
         if (_type == TASK) {
             return _task->totalTimeCurrentDay().toQString();
         }
         if (_type == NONE) {
             return itemData.at(column);
         }
         if (_type == SUMMARY) {
             DTime totalTime;
             for (vector<Project*>::const_iterator iter = _allprojects.begin(); iter != _allprojects.end(); iter++) {
                 Project* prj = *iter;
                 totalTime = totalTime + prj->totalTimeCurrentDay();
             }
             return totalTime.toQString();
         }
     default:
         return QVariant();
     }
 }