Exemplo n.º 1
0
static void processFile(const boost::filesystem::path &path, int hrsOffset, result_t &results)
{
    std::string fn = path.string();
    std::time_t t = boost::filesystem::last_write_time(path);

    boost::posix_time::ptime lwt = boost::posix_time::from_time_t(t);
    lwt = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(lwt);
    lwt += boost::posix_time::time_duration(hrsOffset, 0, 0, 0);

    StatusReport statusReport(fn);

    std::ifstream in(fn.c_str());
    Json json;
    while (!in.eof())
    {
        char c;
        in.get(c);
        json.nextChar(c);
    }

    map_t::const_iterator itor = json.getMap().find("eventlog");
    if (itor != json.getMap().end())
    {
        std::vector<std::string> v;
        json.getArray(itor->second, v);
        if (v.size() > 1) 
        {   // more than just labels
            std::vector<std::string> labels;
            json.getArray(v[0], labels);
            std::map<int, int> colMap;
            for (int j = 0; j < (int)NUM_COLUMNS; j++)
            {
                std::string l; l += '"'; l += Columns[j]; l += '"';
                for (int k = 0; k < labels.size(); k++)
                {
                    if (labels[k] == l)
                        colMap[j] = k;
                }
            }
            if (colMap.size() == (int)NUM_COLUMNS)
            {   // every column we expect appears?
                for (int i = 1; i < v.size(); i++)
                {
                    std::vector<std::string> vals;
                    json.getArray(v[i], vals);
                    if (vals.size() == labels.size())
                    {   // this record has an entry for every label?
                        boost::posix_time::time_duration todFile = lwt.time_of_day();
                        int todHors = todFile.hours();
                        int todMins = todFile.minutes();
                        int hrs = atoi(vals[colMap[HOUR]].c_str());
                        int min = atoi(vals[colMap[MINUTE]].c_str());
                        boost::posix_time::time_duration tod(hrs, min, 0, 0), delta;
                        delta = tod - todFile;
                        const int minMin = 2;
                        if (delta.total_seconds() > (minMin * 60)) // assume rolled over midnight
                            delta -= boost::posix_time::time_duration(24,0,0,0);
                        long ts = delta.total_seconds();
                        const int maxMin = 120;
                        if ((ts > (minMin * 60)) || (ts < (maxMin * -60)))
                        {
                            std::ostringstream oss;
                            oss << "Time label (" << hrs << ':' << min << ") not in window " << maxMin << "min before file stamp ("
                                << todHors << ':' << todMins << ") ts=" << ts;    
                            statusReport.report(oss.str());
                            continue;
                        }
                        boost::posix_time::ptime tstamp = lwt + delta;
                        results[tstamp] = Event(vals[colMap[RELAY]].c_str(), 
                            vals[colMap[TEMPERATURE]].c_str(),
                            vals[colMap[TARGET_TEMPERATURE]].c_str(), 
                            vals[colMap[HUMIDITY]].c_str(),
                            path.filename().string());
                    }
                }
            }
        }
    }
    else statusReport.report("No eventlog in json");
}
Exemplo n.º 2
0
void boatUpdate(boat b, int keepDir, double timedif)
{
    double anchorRatio;
    if (b->extra->timeStuckLeft > 0) {  /*Se o barco esta encalhado */
        b->extra->timeStuckLeft -= timedif;
        b->tex.color = b->extra->color / 2;
        /* Torna o bote mais escuro - note que os valores para R e G sempre sao pares para lidar com isso */

        if (b->extra->timeStuckLeft <= 0) {
            if (b->extra->life >= 0) {
                b->extra->timeStuckLeft = 0;
                b->pos = b->extra->respawnPoint;
                b->vel = vectorCreate(0, 0);
                b->acc = vectorCreate(0, 0);
                b->dir = PI/2;
                b->tex.color = b->extra->color;
                /* Retornando a cor original, ja que o bote muda de cor quando encalhado */
            } else
                b->toBeRemoved = 1;
        }
        return;
    }
    /*Verificando se ja deve ganahr uma vida nova*/
    if (b->extra->points >=
        b->extra->extraLivesCount * b->extra->extraLifeScore) {
        b->extra->life++;
        b->extra->extraLivesCount++;
    }
    /*Le teclado*/
    boatReadKeyboard(b);
    if (b->extra->isAccel && !b->extra->isAnchored) {
        b->acc.x = -b->extra->accel * cos(b->dir) * b->extra->isAccel;
        b->acc.y = -b->extra->accel * sin(b->dir) * b->extra->isAccel;
    } else
        b->acc = vectorCreate(0, 0);
    if (b->extra->isAnchored)
        anchorRatio = b->extra->anchorMultiplier;
    else
        anchorRatio = 1;
    b->acc.x = b->acc.x - b->vel.x * b->extra->friction * anchorRatio;
    b->acc.y = b->acc.y - b->vel.y * b->extra->friction * anchorRatio;
    b->vel = vectorSum(b->vel, vectorMulDouble(b->acc, timedif));
    b->pos = vectorSum(b->pos, vectorMulDouble(b->vel, timedif));
    if (!b->extra->isAnchored)
        b->dir += b->extra->isTurning * b->extra->turnRate * timedif;
    objectQuadUpdate(b);
    /*Resgate de pessoas*/
    if (b->extra->isAnchored
        && distanceBetweenPoints(b->pos,
                                 shipPos) <= b->extra->unloadDistance) {
        if (b->extra->personList != NULL) {
            if (b->extra->unloadTimeLeft <= 0.0) {
                debugDouble("b->extra->unloadtimeleft",
                            b->extra->unloadTimeLeft);
                rescuePerson(b);
                b->extra->unloadTimeLeft = b->extra->unloadTime;
            } else
                b->extra->unloadTimeLeft =
                    b->extra->unloadTimeLeft - timedif;
        }
    } else
        b->extra->unloadTimeLeft = b->extra->unloadTime;
    /*Fala o que precisa ser mostrado no display*/
    statusReport(b->extra->player, b->extra->name, b->extra->life,
                        b->extra->points, b->extra->peopleHeld);
}