// Calls appropriate visitor for given element void visitElement(const Element& element) { Style style = context_.styleProvider.forElement(element, context_.quadKey.levelOfDetail); std::stringstream ss(*style.get(builderKeyId_)->value()); while (ss.good()) { std::string name; getline(ss, name, ','); element.accept(getBuilder(name)); } }
QString FightSheet::generateData() { Style *s = new Style( object->get("style").toInt(), keeper ); setReportFile(s->get("name").toLower() + ".html"); setReportPath("/../share/reports/fightsheet"); Wrestler *red = new Wrestler(object->get("red").toInt(), keeper); Geo *geo_r = new Geo(red->get("geo").toInt(), keeper); Wrestler *blue = new Wrestler(object->get("blue").toInt(), keeper); Geo *geo_b = new Geo(blue->get("geo").toInt(), keeper); Weight *wh = new Weight( object->get("weight").toInt(), keeper ); Competition *c = new Competition(object->get("competition").toInt(), keeper); Mat *mat = new Mat(object->get("mat").toInt(), keeper); CRound *cround = new CRound(object->get("cround").toInt(), keeper); CTour *ctour = new CTour(object->get("ctour").toInt(), keeper); QDate start = QDate::fromString(c->get("start"), QString("yyyy-MM-dd")); QDate stop = QDate::fromString(c->get("stop"), QString("yyyy-MM-dd")); QString date; if ( start.month() == stop.month() ) { date = QString("%1-%2/%3/%4").arg(start.day()).arg(stop.day()).arg(start.month()).arg(start.year()); } else { date = start.toString("dd/MM/yyyy") + " - " + stop.toString("dd/MM/yyyy"); } vars.insert("{red.title}", red->get("title")); vars.insert("{red.geo}", geo_r->get("title")); vars.insert("{blue.title}", blue->get("title")); vars.insert("{blue.geo}", geo_b->get("title")); vars.insert("{style}", s->get("name")); vars.insert("{weight}", wh->get("title")); vars.insert("{competition}", c->get("title")); vars.insert("{mat}", mat->get("title")); vars.insert("{round}", cround->get("title")); vars.insert("{place}", ctour->get("title")); vars.insert("{num}", object->get("num")); vars.insert("{date}", date); TQueryMap opt; opt.insert("competition", keeper->prepareParam(Equal, c->get("id"))); QList<QVariant> id_list; if ( red->get("id").toInt() > 0 ) id_list << red->get("id"); if ( blue->get("id").toInt() > 0 ) id_list << blue->get("id"); opt.insert("wrestler", keeper->prepareParam(And | InSet, id_list )); opt.insert("style", keeper->prepareParam(And | Equal, s->get("id"))); opt.insert("weight", keeper->prepareParam(And | Equal, wh->get("id"))); QList<QVariant> list = keeper->getListOfFields(OCompetitionWrestler, QStringList() << "wrestler" << "sorder", opt); for( int i = 0; i < list.size(); i++) { QStringList row = list.at(i).toStringList(); if ( red->get("id").toInt() == row.at(0).toInt() ) vars.insert("{red.num}", row.at(1)); if ( blue->get("id").toInt() == row.at(0).toInt() ) vars.insert("{blue.num}", row.at(1)); } delete red; delete geo_r; delete geo_b; delete blue; delete s; delete wh; delete mat; delete cround; delete ctour; delete c; return applyTemplateVars(loadTemplate(reportFile), vars); }
void PersonalScoreReport::genCompetition(int /*cid*/, int sid, int wid) { Weight *w = new Weight(wid, keeper); Style *s = new Style(sid, keeper); pVars.insert("{competition}", comp->get("title")); pVars.insert("{weight}", w->get("title")); pVars.insert("{style}", s->get("name")); TQueryMap opts; opts.insert("competition", keeper->prepareParam(Equal, comp->get("id"))); opts.insert("weight", keeper->prepareParam(And|Equal, wid)); opts.insert("style", keeper->prepareParam(And|Equal, sid)); opts.insert("order", QStringList() << "sorder asc" ); QList<QVariant> cwList = keeper->getListOfFields(OCompetitionWrestler, QStringList() << "wrestler" << "sorder", opts); int wrestlerCount = cwList.size(); opts.clear(); opts.insert("num", keeper->prepareParam(Less, wrestlerCount)); opts.insert("order", QStringList() << "num desc" ); opts.insert("limit", 1); // id, num CTour *ct = new CTour(opts, keeper); int tourNum = ct->get("num").toInt(); delete ct; QString fightQualify_tmpl = loadTemplate("fight-qualify.html"); QString fightRound_tmpl = loadTemplate("fight-round.html"); QString fightRoundLast_tmpl = loadTemplate("fight-round-last.html"); QString final_tmpl = loadTemplate("final.html"); int offset_num = 0; if ( tourNum == wrestlerCount ) offset_num = 0; else offset_num = (tourNum*2) - wrestlerCount; opts.clear(); opts.insert("num", keeper->prepareParam(Less, wrestlerCount)); opts.insert("order", QStringList() << "num desc" ); QList<Object*> tl = keeper->getObjectList(OCTour, opts); QList<Object*> tourList; for( int i = 0; i < tl.size(); i++ ) { Object *o = tl.at(i); if (o->get("num").toInt() > 0 ) { tourList.append(o); } } QList<QVariant> wrestlerIdList; QHash<QString,QString> wrestlerPosIdMap; QHash<QString,QString> wrestlerIdPosMap; for(int i = 0; i < cwList.size(); i++ ) { QStringList list = cwList.at(i).toStringList(); wrestlerIdList.append( list.at(0) ); wrestlerPosIdMap.insert( list.at(1), list.at(0) ); wrestlerIdPosMap.insert( list.at(0), list.at(1) ); } QList<Object*> wrestlerList; QHash<QString,Object*> wrestlerIdMap; QHash<QString,Object*> wrestlerNumMap; QHash<QString,Object*> geoMap; opts.clear(); opts.insert("id", keeper->prepareParam(InSet, wrestlerIdList)); opts.insert("order", QStringList() << "id asc" ); wrestlerList = keeper->getObjectList(OWrestler, opts); QList<QVariant> geoIdList; for( int z = 0; z < wrestlerList.size(); z++ ) { Object *obj = wrestlerList.at(z); wrestlerIdMap.insert(obj->get("id"), obj); wrestlerNumMap.insert( wrestlerPosIdMap[obj->get("id")], obj); if ( obj->get("geo").toInt() ) geoIdList.append(obj->get("geo")); } opts.clear(); opts.insert("id", keeper->prepareParam(InSet, geoIdList)); opts.insert("order", QStringList() << "id asc" ); geoMap = keeper->getObjectMap(OGeo, "id", opts); opts.clear(); opts.insert("competition", keeper->prepareParam(Equal, comp->get("id"))); opts.insert("weight", keeper->prepareParam(And|Equal, wid)); opts.insert("style", keeper->prepareParam(And|Equal, sid)); opts.insert("order", QStringList() << "id asc" ); QHash<QString,Object*> fightsMap = keeper->getObjectMap(OFight, "order", opts); opts.clear(); opts.insert("order", QStringList() << "id asc" ); QHash<QString,Object*> classifyMap = keeper->getObjectMap(OClassify, "id", opts); switch (tourNum) { case 4: page_tmpl = loadTemplate("page4.html"); break; case 8: page_tmpl = loadTemplate("page8.html"); break; case 16: page_tmpl = loadTemplate("page16.html"); break; case 32: page_tmpl = loadTemplate("page32.html"); break; case 64: page_tmpl = loadTemplate("page64.html"); break; default: break; } QMap<QString,QString> tVars; QStringList rows; // qualification int fightNum = 0; int j = 0; if ( wrestlerCount < (tourNum*2) ) { int wpos = 0; int fnum = tourList.at(j++)->get("num").toInt(); for( int i = 0; i < fnum; i++ ) { if ( offset_num > wpos++ ) { QStringList clist = cwList.at(i).toStringList(); Object *wrestler = wrestlerIdMap[ clist.at(0) ]; Object *geo = geoMap[ wrestler->get("geo") ]; tVars.insert("{red.num}", wrestlerIdPosMap[clist.at(0)]); tVars.insert("{red.classify}", ""); tVars.insert("{red.fio}", wrestler->get("title")); tVars.insert("{red.geo}", geo->get("title")); tVars.insert("{red.sum}", ""); tVars.insert("{red.p1}", ""); tVars.insert("{red.p2}", ""); tVars.insert("{red.p3}", ""); tVars.insert("{blue.num}", ""); tVars.insert("{blue.classify}", ""); tVars.insert("{blue.fio}", ""); tVars.insert("{blue.geo}", ""); tVars.insert("{blue.sum}", ""); tVars.insert("{blue.p1}", ""); tVars.insert("{blue.p2}", ""); tVars.insert("{blue.p3}", ""); } else { fightNum++; Object *fight = fightsMap[ QString::number(fightNum) ]; QString redClassify("0"); QString blueClassify("0"); if ( fight->get("classify").toInt() > 0 ) { Object *classify = classifyMap[fight->get("classify")]; if ( fight->get("winner").compare( fight->get("red") ) == 0 ) { redClassify = classify->get("win"); blueClassify = classify->get("fail"); } else { redClassify = classify->get("fail"); blueClassify = classify->get("win"); } } QStringList redScore = Object::toList(fight->get("red_score")); QStringList blueScore = Object::toList(fight->get("blue_score")); QString redScoreSum = QString::number(redScore.at(0).toInt() + redScore.at(1).toInt() + redScore.at(2).toInt()); QString blueScoreSum = QString::number(blueScore.at(0).toInt() + blueScore.at(1).toInt() + blueScore.at(2).toInt()); if ( wrestlerIdMap.contains( fight->get("red") ) ) { Object *wrestler = wrestlerIdMap[ fight->get("red") ]; Object *geo = geoMap[ wrestler->get("geo") ]; tVars.insert("{red.num}", wrestlerIdPosMap[ wrestler->get("id") ]); tVars.insert("{red.classify}", redClassify); tVars.insert("{red.fio}", wrestler->get("title")); tVars.insert("{red.geo}", geo->get("title")); tVars.insert("{red.sum}", redScoreSum); tVars.insert("{red.p1}", redScore.at(0)); tVars.insert("{red.p2}", redScore.at(1)); tVars.insert("{red.p3}", redScore.at(2)); } if ( wrestlerIdMap.contains( fight->get("blue") )) { Object *wrestler = wrestlerIdMap[ fight->get("blue") ]; Object *geo = geoMap[ wrestler->get("geo") ]; tVars.insert("{blue.num}", wrestlerIdPosMap[ wrestler->get("id") ]); tVars.insert("{blue.classify}", blueClassify); tVars.insert("{blue.fio}", wrestler->get("title")); tVars.insert("{blue.geo}", geo->get("title")); tVars.insert("{blue.sum}", blueScoreSum); tVars.insert("{blue.p1}", blueScore.at(0)); tVars.insert("{blue.p2}", blueScore.at(1)); tVars.insert("{blue.p3}", blueScore.at(2)); } } rows << applyTemplateVars(fightQualify_tmpl, tVars); tVars.clear(); if ( tourNum == 64 ) { if ( i == 15 ) { pVars.insert( QString("{fights:%1/4}").arg(fnum), rows.join("\n")); rows.clear(); } else if (i == 31) { pVars.insert( QString("{fights:%1/3}").arg(fnum), rows.join("\n")); rows.clear(); } else if (i == 47) { pVars.insert( QString("{fights:%1/2}").arg(fnum), rows.join("\n")); rows.clear(); } else if (i == 63) { pVars.insert( QString("{fights:%1/1}").arg(fnum), rows.join("\n")); rows.clear(); } } else if ( tourNum == 32 && i == (fnum/2)-1 ) { pVars.insert( QString("{fights:%1/2}").arg(fnum), rows.join("\n")); rows.clear(); } } pVars.insert( QString("{fights:%1}").arg(fnum), rows.join("\n")); rows.clear(); } for(; j<tourList.size(); j++ ) { int level = 0; bool last = false; QStringList lastData; switch (tourNum) { case 4: level = j; break; case 8: { if ( j < 3 ) level = j; else level = j - 2; if ( j == 2 ) last = true; break; } default: { if ( j < 4 ) level = j; else level = j - 3; if ( j == 3 ) last = true; break; } } int fnum = tourList.at(j)->get("num").toInt(); for( int i = 0; i < fnum; i++ ) { fightNum++; QString t = QString::number(fightNum); if ( !fightsMap.contains(t) ) { tVars.insert("{level}", QString::number(level)); tVars.insert("{red.num}", ""); tVars.insert("{red.classify}", ""); tVars.insert("{red.fio}", ""); tVars.insert("{red.geo}", ""); tVars.insert("{red.sum}", ""); tVars.insert("{red.p1}", ""); tVars.insert("{red.p2}", ""); tVars.insert("{red.p3}", ""); tVars.insert("{blue.num}", ""); tVars.insert("{blue.classify}", ""); tVars.insert("{blue.fio}", ""); tVars.insert("{blue.geo}", ""); tVars.insert("{blue.sum}", ""); tVars.insert("{blue.p1}", ""); tVars.insert("{blue.p2}", ""); tVars.insert("{blue.p3}", ""); rows << applyTemplateVars( j == 0 ? fightQualify_tmpl : last ? fightRoundLast_tmpl : fightRound_tmpl, tVars); tVars.clear(); } else { Object *fight = fightsMap[ QString::number(fightNum) ]; QString redClassify("0"); QString blueClassify("0"); if ( fight->get("classify").toInt() > 0 ) { Object *classify = classifyMap[fight->get("classify")]; if ( fight->get("winner").compare( fight->get("red") ) == 0 ) { redClassify = classify->get("win"); blueClassify = classify->get("fail"); } else { redClassify = classify->get("fail"); blueClassify = classify->get("win"); } } QStringList redScore = Object::toList(fight->get("red_score")); QStringList blueScore = Object::toList(fight->get("blue_score")); QString redScoreSum = QString::number(redScore.at(0).toInt() + redScore.at(1).toInt() + redScore.at(2).toInt()); QString blueScoreSum = QString::number(blueScore.at(0).toInt() + blueScore.at(1).toInt() + blueScore.at(2).toInt()); tVars.insert("{level}", QString::number(level)); if ( wrestlerIdMap.contains(fight->get("red")) ) { Object *wrestler = wrestlerIdMap[ fight->get("red") ]; Object *geo = geoMap[ wrestler->get("geo") ]; tVars.insert("{red.num}", wrestlerIdPosMap[ wrestler->get("id") ]); tVars.insert("{red.classify}", redClassify); tVars.insert("{red.fio}", wrestler->get("title")); tVars.insert("{red.geo}", geo->get("title")); tVars.insert("{red.sum}", redScoreSum); tVars.insert("{red.p1}", redScore.at(0)); tVars.insert("{red.p2}", redScore.at(1)); tVars.insert("{red.p3}", redScore.at(2)); } else { tVars.insert("{red.num}", ""); tVars.insert("{red.classify}", ""); tVars.insert("{red.fio}", ""); tVars.insert("{red.geo}", ""); tVars.insert("{red.sum}", ""); tVars.insert("{red.p1}", ""); tVars.insert("{red.p2}", ""); tVars.insert("{red.p3}", ""); tVars.clear(); } tVars.insert("{level}", QString::number(level)); if ( wrestlerIdMap.contains(fight->get("blue")) ) { Object *wrestler = wrestlerIdMap[ fight->get("blue") ]; Object *geo = geoMap[ wrestler->get("geo") ]; tVars.insert("{blue.num}", wrestlerIdPosMap[ wrestler->get("id") ]); tVars.insert("{blue.classify}", blueClassify); tVars.insert("{blue.fio}", wrestler->get("title")); tVars.insert("{blue.geo}", geo->get("title")); tVars.insert("{blue.sum}", blueScoreSum); tVars.insert("{blue.p1}", blueScore.at(0)); tVars.insert("{blue.p2}", blueScore.at(1)); tVars.insert("{blue.p3}", blueScore.at(2)); } else { tVars.insert("{blue.num}", ""); tVars.insert("{blue.classify}", ""); tVars.insert("{blue.fio}", ""); tVars.insert("{blue.geo}", ""); tVars.insert("{blue.sum}", ""); tVars.insert("{blue.p1}", ""); tVars.insert("{blue.p2}", ""); tVars.insert("{blue.p3}", ""); } if ( j == (tourList.size()-1) ) { Object *wrestler = wrestlerIdMap[ fight->get("winner") ]; Object *geo = geoMap[ wrestler->get("geo") ]; tVars.insert("{winner.num}", wrestlerIdPosMap[ wrestler->get("id") ]); tVars.insert("{winner.fio}", wrestler->get("title")); tVars.insert("{winner.geo}", geo->get("title")); rows << applyTemplateVars(final_tmpl, tVars); tVars.clear(); } else { if ( last ) { lastData << applyTemplateVars( fightRoundLast_tmpl, tVars); tVars.insert("{level}", QString::number(0)); rows << applyTemplateVars( fightQualify_tmpl, tVars); }else { rows << applyTemplateVars( j == 0 ? fightQualify_tmpl : fightRound_tmpl, tVars); } tVars.clear(); } } if ( tourNum == 64 ) { if (i == (fnum/4)-1) { pVars.insert( QString("{fights:%1/4}").arg(fnum), rows.join("\n")); QString k = QString("{fights:%1}").arg(fnum); QString a = pVars.contains(k) ? pVars[k] : QString(""); pVars.insert( k, a + rows.join("\n")); rows.clear(); if ( !lastData.isEmpty()) { pVars.insert( QString("{fights-last:%1/4}").arg(fnum), lastData.join("\n")); lastData.clear(); } } if (i == (fnum/2)-1) { pVars.insert( QString("{fights:%1/3}").arg(fnum), rows.join("\n")); QString k = QString("{fights:%1}").arg(fnum); QString a = pVars.contains(k) ? pVars[k] : QString(""); pVars.insert( k, a + rows.join("\n")); rows.clear(); if ( !lastData.isEmpty()) { pVars.insert( QString("{fights-last:%1/3}").arg(fnum), lastData.join("\n")); lastData.clear(); } } if (i == ((3*fnum)/4)-1) { pVars.insert( QString("{fights:%1/2}").arg(fnum), rows.join("\n")); QString k = QString("{fights:%1}").arg(fnum); QString a = pVars.contains(k) ? pVars[k] : QString(""); pVars.insert( k, a + rows.join("\n")); rows.clear(); if ( !lastData.isEmpty()) { pVars.insert( QString("{fights-last:%1/2}").arg(fnum), lastData.join("\n")); lastData.clear(); } } if (i == (fnum-1) ) { pVars.insert( QString("{fights:%1/1}").arg(fnum), rows.join("\n")); QString k = QString("{fights:%1}").arg(fnum); QString a = pVars.contains(k) ? pVars[k] : QString(""); pVars.insert( k, a + rows.join("\n")); rows.clear(); if ( !lastData.isEmpty()) { pVars.insert( QString("{fights-last:%1/1}").arg(fnum), lastData.join("\n")); lastData.clear(); } } } if ( tourNum == 32 ) { if( i == (fnum/2)-1 ) { pVars.insert( QString("{fights:%1/2}").arg(fnum), rows.join("\n")); QString k = QString("{fights:%1}").arg(fnum); QString a = pVars.contains(k) ? pVars[k] : QString(""); if ( last || fnum == 2 ) { pVars.insert( k, a + rows.join("\n")); } rows.clear(); if ( !lastData.isEmpty()) { pVars.insert( QString("{fights-last:%1/2}").arg(fnum), lastData.join("\n")); lastData.clear(); } } } } QString k = QString("{fights:%1}").arg(fnum); QString a = pVars.contains(k) ? pVars[k] : QString(""); pVars.insert( k, a + rows.join("\n")); rows.clear(); if ( !lastData.isEmpty()) { pVars.insert( QString("{fights-last:%1}").arg(fnum), lastData.join("\n")); lastData.clear(); } } qDeleteAll(fightsMap); qDeleteAll(geoMap); qDeleteAll(tl); qDeleteAll(wrestlerList); }