QString QueryBufferItem::toolTip(int column) const
{
    // pretty much code duplication of IrcUserItem::toolTip() but inheritance won't solve this...
    Q_UNUSED(column);
    QStringList toolTip;

    toolTip.append(tr("<b>Query with %1</b>").arg(bufferName()));

    if (_ircUser) {
        if (_ircUser->userModes() != "") toolTip[0].append(QString(" (+%1)").arg(_ircUser->userModes()));
        if (_ircUser->isAway()) {
            toolTip[0].append(QString(" (away%1)").arg(!_ircUser->awayMessage().isEmpty() ? (QString(" ") + _ircUser->awayMessage()) : QString()));
        }
        if (!_ircUser->realName().isEmpty()) toolTip.append(_ircUser->realName());
        if (!_ircUser->ircOperator().isEmpty()) toolTip.append(QString("%1 %2").arg(_ircUser->nick()).arg(_ircUser->ircOperator()));
        if (!_ircUser->suserHost().isEmpty()) toolTip.append(_ircUser->suserHost());
        if (!_ircUser->whoisServiceReply().isEmpty()) toolTip.append(_ircUser->whoisServiceReply());

        toolTip.append(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!")+1));

        if (_ircUser->idleTime().isValid()) {
            QDateTime now = QDateTime::currentDateTime();
            QDateTime idle = _ircUser->idleTime();
            int idleTime = idle.secsTo(now);
            toolTip.append(tr("idling since %1").arg(secondsToString(idleTime)));
        }
        if (_ircUser->loginTime().isValid()) {
            toolTip.append(tr("login time: %1").arg(_ircUser->loginTime().toString()));
        }

        if (!_ircUser->server().isEmpty()) toolTip.append(tr("server: %1").arg(_ircUser->server()));
    }

    return QString("<p> %1 </p>").arg(toolTip.join("<br />"));
}
Beispiel #2
0
			std::string eta(uint64_t i) const
			{
				double const timeelapsed = rtc.getElapsedSeconds();
				double const timeperelement = timeelapsed / i;
				double const restsize = n-i;
				double const resttime = restsize*timeperelement;	
				return secondsToString(resttime);
			}
Beispiel #3
0
void Playlist::print() {
    char buffer[max(TIME_STRING_LENGTH, MAX_SCRIPT_ADDRESS_LENGTH) + 1];
    AutoplayStructure autoplaySettings;

    getAutoplaySettings(&autoplaySettings);

    if(secondsToString(timeNowSecondsSinceMidnight(), buffer)) {
        Serial.print(buffer);
        Serial.print(' ');
    }
    Serial.print(F("playlist "));
    Serial.print(playlistIndex);

    Serial.print(F(" chirp "));
    Serial.print(playIndex);
    Serial.print(F(" of "));
    Serial.println(nChirps);

    bool porta = READ_FROM_PLAYLIST(porta) != 0;
    Serial.print(porta ? F("portamento") : F("plain"));

    Serial.print(F(" vol "));
    Serial.print(READ_FROM_PLAYLIST(volume));

    Serial.print(F(" order "));
    Serial.print(autoplaySettings.order);

    Serial.print(F(" interval "));
    Serial.println(autoplaySettings.interval);

    if(readScriptAddress(buffer)) {
        Serial.print('#');
        Serial.print(buffer);
        Serial.print(F(" update "));
        Serial.println(READ_FROM_PLAYLIST(updateFlags));
    }

    if(autoplaySettings.count) {
        Serial.print(F("autoplay "));
        minutesToString(autoplaySettings.startMinute, buffer);
        Serial.print(buffer);

        if(autoplaySettings.count > 1) {
            Serial.print(' ');
            minutesToString(autoplaySettings.repeatMinutes, buffer);
            Serial.print(buffer);

            Serial.print(' ');
            Serial.print(autoplaySettings.count);
        }
        Serial.println();
    }
}
  void update(T newvalue) {
    // Nothing to update if already maxed out.
    if (done) return;
    endTime = osQueryPerfomance();
    
    // Abort if at least 1 second didn't elapse, unless newvalue will get us to 100%.
    if ( ((endTime-prevTime)/1000000.0 < 1.0) && (newvalue < n) ) return;
    prevTime = endTime;
    float dt = (endTime-startTime)/1000000.0;
    //if (dt < 1) return; // Was meant to avoid division by zero when time was in whole numbers.
    cur = newvalue;
    char pctstr[8];
    float Pct = ((double)cur)/n;
    sprintf(pctstr, "%3d%%", (int)(100*Pct));
    std::string out;
    out.reserve(80);
    out.append(pctstr);
    // Seconds.
    std::string tstr;
    out.append(" | ");
    secondsToString( (unsigned int)dt, tstr);
    out.append(tstr);
    int pad, newwidth;
    if (Pct >= 1.0) {
      // Print overall time and newline.
      out.append(" |  00:00:00 | ");
      commaNumber(n, tstr);
      pad = procColWidth-tstr.size()-unitsWidth-1;
      if (pad > 0) out.append(pad, ' ');
      out.append(tstr);
      out.append(" ");
      out.append(units);
      out.append(" | ");
      pad = unprocColWidth-1-unitsWidth-1;
      if (pad > 0) out.append(pad, ' ');
      out.append("0 ");
      out.append(units);
      out.append(" | ");
      commaNumber( (unsigned int)(n/dt), tstr);
      out.append(tstr);
      out.append(" ");
      out.append(units);
      out.append("/s");
      
      newwidth = out.size();
      if (newwidth < width)
        out.append(width-newwidth,' ');

      // Store length of this string so we know how much to blank out later.
      width = newwidth;
      out.append("\n");
      printf("%s", out.c_str());
      fflush(stdout);
      done = 1;
    } else {
      float eta=0.;
      if (Pct > 0.0) {
        eta = dt*(1.0-Pct)/Pct;
      }
      out.append(" |  ");
      secondsToString((unsigned int)eta, tstr);
      out.append(tstr);
      out.append(" | ");
      commaNumber(cur, tstr);
      pad = procColWidth-tstr.size()-unitsWidth-1;
      if (pad > 0) out.append(pad,' ');
      out.append(tstr);
      out.append(" ");
      out.append(units);
      out.append(" | ");
      commaNumber(n-cur, tstr);
      pad = unprocColWidth-tstr.size()-unitsWidth-1;
      if (pad > 0) out.append(pad,' ');
      out.append(tstr);
      out.append(" ");
      out.append(units);
      out.append(" | ");
      eta = cur/dt;
      if (eta > 1.0)
        commaNumber((unsigned int)eta, tstr);
      else {
        std::ostringstream stm;
        stm << eta;
        tstr = stm.str();
      }
      out.append(tstr);
      out.append(" ");
      out.append(units);
      out.append("/s");    
      // Pad end with spaces to overwrite previous string that may have been longer.
      newwidth = out.size();
      if (newwidth < width)
        out.append(width-newwidth,' ');
        
      width = newwidth;
      out.append("\r");
      printf("%s", out.c_str());
      fflush(stdout);
    }
  }
Beispiel #5
0
static void
printStatus(sabdb *stats, int mode, int dbwidth, int uriwidth)
{
	sabuplog uplog;
	char *e;

	if ((e = msab_getUplogInfo(&uplog, stats)) != NULL) {
		fprintf(stderr, "status: internal error: %s\n", e);
		free(e);
		return;
	}

	if (mode == 1) {
		/* short one-line (default) mode */
		char state = '\0';
		char locked = '\0';
		char uptime[12];
		char avg[8];
		char info[32];
		char *dbname;
		char *uri;

		switch (stats->state) {
			case SABdbStarting:
				state = 'B';
			break;
			case SABdbRunning:
				state = 'R';
			break;
			case SABdbCrashed:
				state = 'C';
			break;
			case SABdbInactive:
				state = 'S';
			break;
			default:
				state = ' ';
			break;
		}
		/* override if locked for brevity */
		if (stats->locked == 1)
			locked = 'L';

		info[0] = '\0';
		if (stats->state == SABdbStarting) {
			struct tm *t;
			t = localtime(&uplog.laststart);
			strftime(info, sizeof(info), "starting up since %Y-%m-%d %H:%M:%S", t);
		} else if (uplog.lastcrash != -1 &&
				stats->state != SABdbRunning &&
				uplog.crashavg1 == 1)
		{
			struct tm *t;
			t = localtime(&uplog.lastcrash);
			strftime(info, sizeof(info), "crashed on %Y-%m-%d %H:%M:%S", t);
		}

		switch (stats->state) {
			case SABdbRunning:
			case SABdbStarting:
				secondsToString(uptime, time(NULL) - uplog.laststart, 1);
				break;
			case SABdbCrashed:
				secondsToString(uptime, time(NULL) - uplog.lastcrash, 1);
				break;
			case SABdbInactive:
				if (uplog.laststop != -1) {
					secondsToString(uptime, time(NULL) - uplog.laststop, 1);
					break;
				} /* else fall through */
			default:
				uptime[0] = '\0';
				break;
		}

		/* cut too long names */
		dbname = malloc(sizeof(char) * (dbwidth + 1));
		abbreviateString(dbname, stats->dbname, dbwidth);
		uri = malloc(sizeof(char) * (uriwidth + 1));
		abbreviateString(uri,
				info[0] != '\0' ? info : stats->uri ? stats->uri : "",
				uriwidth);
		/* dbname | state | health | uri/crash */
		printf("%-*s  %c%c%3s", dbwidth, dbname,
				locked ? locked : state, locked ? state : ' ', uptime);
		free(dbname);
		if (uplog.startcntr) {
			secondsToString(avg, uplog.avguptime, 1);
			printf("  %3d%% %3s",
					100 - (uplog.crashcntr * 100 / uplog.startcntr), avg);
		} else {
			printf("           ");
		}
		printf("  %-*s\n", uriwidth, uri);
		free(uri);
	} else if (mode == 2) {
		/* long mode */
		char *state;
		sablist *entry;
		char up[32];
		struct tm *t;

		switch (stats->state) {
			case SABdbStarting:
				state = "starting up";
			break;
			case SABdbRunning:
				state = "running";
			break;
			case SABdbCrashed:
				state = "crashed";
			break;
			case SABdbInactive:
				state = "stopped";
			break;
			default:
				state = "unknown";
			break;
		}

		printf("%s:\n", stats->dbname);
		printf("  connection uri: %s\n", stats->uri);
		printf("  database name: %s\n", stats->dbname);
		printf("  state: %s\n", state);
		printf("  locked: %s\n", stats->locked == 1 ? "yes" : "no");
		entry = stats->scens;
		printf("  scenarios:");
		if (entry == NULL) {
			printf(" (none)");
		} else while (entry != NULL) {
			printf(" %s", entry->val);
			entry = entry->next;
		}
		printf("\n");
		printf("  start count: %d\n  stop count: %d\n  crash count: %d\n",
				uplog.startcntr, uplog.stopcntr, uplog.crashcntr);
		if (stats->state == SABdbRunning) {
			secondsToString(up, time(NULL) - uplog.laststart, 999);
			printf("  current uptime: %s\n", up);
		}
		secondsToString(up, uplog.avguptime, 999);
		printf("  average uptime: %s\n", up);
		secondsToString(up, uplog.maxuptime, 999);
		printf("  maximum uptime: %s\n", up);
		secondsToString(up, uplog.minuptime, 999);
		printf("  minimum uptime: %s\n", up);
		if (uplog.lastcrash != -1) {
			t = localtime(&uplog.lastcrash);
			strftime(up, 32, "%Y-%m-%d %H:%M:%S", t);
		} else {
			sprintf(up, "(unknown)");
		}
		printf("  last start with crash: %s\n", up);
		if (uplog.laststart != -1) {
			t = localtime(&uplog.laststart);
			strftime(up, 32, "%Y-%m-%d %H:%M:%S", t);
		} else {
			sprintf(up, "(unknown)");
		}
		printf("  last start: %s\n", up);
		if (uplog.laststop != -1) {
			t = localtime(&uplog.laststop);
			strftime(up, 32, "%Y-%m-%d %H:%M:%S", t);
		} else {
			sprintf(up, "(unknown)");
		}
		printf("  last stop: %s\n", up);
		printf("  average of crashes in the last start attempt: %d\n",
				uplog.crashavg1);
		printf("  average of crashes in the last 10 start attempts: %.2f\n",
				uplog.crashavg10);
		printf("  average of crashes in the last 30 start attempts: %.2f\n",
				uplog.crashavg30);
	} else {
		/* this shows most used properties, and is shown also for modes
		 * that are added but we don't understand (yet) */
		char buf[64];
		char up[32];
		char min[8], avg[8], max[8];
		struct tm *t;
		size_t off = 0;
		/* dbname, status -- since, crash averages */

		switch (stats->state) {
			case SABdbStarting:
				snprintf(buf, sizeof(buf), "starting ");
				off = sizeof("starting ") - 1;
				/* fall through */
			case SABdbRunning:
				t = localtime(&uplog.laststart);
				strftime(buf + off, sizeof(buf) - off,
						"up since %Y-%m-%d %H:%M:%S, ", t);
				secondsToString(up, time(NULL) - uplog.laststart, 999);
				strcat(buf, up);
			break;
			case SABdbCrashed:
				t = localtime(&uplog.lastcrash);
				strftime(buf, sizeof(buf), "crashed on %Y-%m-%d %H:%M:%S", t);
			break;
			case SABdbInactive:
				snprintf(buf, sizeof(buf), "not running");
			break;
			default:
				snprintf(buf, sizeof(buf), "unknown");
			break;
		}
		if (stats->locked == 1)
			strcat(buf, ", locked");
		printf("database %s, %s\n", stats->dbname, buf);
		printf("  crash average: %d.00 %.2f %.2f (over 1, 15, 30 starts) "
				"in total %d crashes\n",
				uplog.crashavg1, uplog.crashavg10, uplog.crashavg30,
				uplog.crashcntr);
		secondsToString(min, uplog.minuptime, 1);
		secondsToString(avg, uplog.avguptime, 1);
		secondsToString(max, uplog.maxuptime, 1);
		printf("  uptime stats (min/avg/max): %s/%s/%s over %d runs\n",
				min, avg, max, uplog.stopcntr);
	}
}
Beispiel #6
0
			std::string elapsed() const
			{
				return secondsToString ( rtc.getElapsedSeconds() );
			}
QVariant ScheduleModel::data(const QModelIndex &index, int role) const
{
    QVariant res;

    if(index.row() != rowCount()-1)
    {
        auto dtCome = m_times[index.row()].first;
        auto dtLeave = m_times[index.row()].second;

        if(!(dtCome == dtLeave && dtCome.time() == QTime(0,0)))
        {
            //measurement error fix
            dtCome = dtCome.addSecs(-5*60);
            dtLeave = dtLeave.addSecs(5*60);
        }

        auto diffSecs = dtCome.secsTo(dtLeave);
        QTime diffTime = QTime(0,0).addSecs(diffSecs);
        QTime needToWork;
        auto holidayData = m_holidays.find(dtCome.date());
        if(holidayData != m_holidays.end())
        {
            if(holidayData.value() == HOLIDAY)
                needToWork = QTime(0,0);
            else if(holidayData.value() == SHORT_DAY)
                needToWork = QTime(7,30);
            else
                needToWork = QTime(8,30);
        }
        else
        {
            if(dtCome.date().dayOfWeek() == 6 || dtCome.date().dayOfWeek() == 7)
                needToWork = QTime(0,0);
            else
                needToWork = QTime(8,30);
        }

        QString resultString;
        if(index.column() == COL_RESULT)
        {
            //SKIP -> current day, no result yet
            if(dtCome.date() == QDateTime::currentDateTime().date())
                return res;
        }


        if(role == Qt::DisplayRole)
        {
            switch(index.column())
            {
            case COL_COME:
                if(dtCome.isValid())
                    res = dtCome.toString();
                break;
            case COL_LEAVE:
                if(dtLeave.isValid())
                    res = dtLeave.toString();
                break;
            case COL_DIFF:
                if(dtCome.isValid() && dtLeave.isValid())
                {
                    res = diffTime.toString();
                }
                break;
            case COL_RESULT:

                if(diffTime < needToWork)
                {
                    diffTime = QTime(0,0).addSecs(QTime(0,0).secsTo(needToWork) - QTime(0,0).secsTo(diffTime));
                    resultString += "-";
                }
                else if(diffTime > needToWork)
                {
                    diffTime = QTime(0,0).addSecs(QTime(0,0).secsTo(diffTime) - QTime(0,0).secsTo(needToWork));
                }
                else
                    diffTime = QTime(0,0);
                res = resultString + diffTime.toString();
            }
        }
        else
        if(index.column() == COL_DIFF && role == ROLE_DIFF)
        {            
            res = diffSecs;
        }
        else
        if(index.column() == COL_RESULT && role == ROLE_RESULT)
        {            
            auto resSecs = QTime(0,0).secsTo(needToWork) - diffSecs;
            res = resSecs;
        }
        else
        if((index.column() == COL_COME || index.column() == COL_LEAVE) && role == ROLE_DATETIME)
        {
            if(index.column() == COL_COME)
                res = dtCome.toTime_t();
            else
                res = dtLeave.toTime_t();
        }
    }
    else
    {
        if(role == Qt::DisplayRole)
        {
            unsigned int sum = 0, temp = 0;
            int result = 0, tempResult = 0;
            bool ok = false;
            switch(index.column())
            {
            //Last row
            case COL_LEAVE:
                res = tr("Sum:");
                break;
            case COL_DIFF:
            {
                for(auto i = 0; i < rowCount() - 1; ++i)
                {
                    temp = data(this->index(i, COL_DIFF), ROLE_DIFF).toUInt(&ok);
                    if(ok)
                        sum += temp;
                }                
                res = secondsToString(sum);
                break;
            }
            case COL_RESULT:
                for(auto i = 0; i < rowCount() - 1; ++i)
                {
                    tempResult = data(this->index(i, COL_RESULT), ROLE_RESULT).toInt(&ok);
                    if(ok)
                        result += tempResult;
                }
                //if result < 0 it's overwork
                result *= -1;

                res = secondsToString(result);
                break;

            }
        }
    }
//    else
//        res = QAbstractItemModel::data(index, role);
    return res;
}