void WeatherMgr::LoadFromDB() { //sLog.outString(" Loading Weather..."); // weather type 0= sunny / 1= fog / 2 = light_rain / 4 = rain / 8 = snow / ?? = sandstorm QueryResult* result = WorldDatabase.Query("SELECT zoneId,high_chance,high_type,med_chance,med_type,low_chance,low_type FROM weather"); if (!result) return; do { Field* fields = result->Fetch(); WeatherInfo* wi = new WeatherInfo; wi->m_zoneId = fields[0].GetUInt32(); wi->m_effectValues[0] = fields[1].GetUInt32(); // high_chance wi->m_effectValues[1] = fields[2].GetUInt32(); // high_type wi->m_effectValues[2] = fields[3].GetUInt32(); // med_chance wi->m_effectValues[3] = fields[4].GetUInt32(); // med_type wi->m_effectValues[4] = fields[5].GetUInt32(); // low_chance wi->m_effectValues[5] = fields[6].GetUInt32(); // low_type m_zoneWeathers[wi->m_zoneId] = wi; wi->_GenerateWeather(); } while (result->NextRow()); Log.Notice("WeatherMgr", "Loaded weather information for %u zones.", result->GetRowCount()); delete result; }
void WeatherMgr::LoadFromDB() { QueryResult *result = sDatabase.Query( "SELECT * FROM weather" ); if( !result ) { sLog.outString(" Query failed."); return; } uint32 total =(uint32) result->GetRowCount(); int num = 0; do { Field *fields = result->Fetch(); WeatherInfo *wi = new WeatherInfo; wi->m_zoneId = fields[0].GetUInt32(); wi->m_effectValues[0] = fields[1].GetUInt32(); wi->m_effectValues[1] = fields[2].GetUInt32(); wi->m_effectValues[2] = fields[3].GetUInt32(); wi->m_effectValues[3] = fields[4].GetUInt32(); wi->m_effectValues[4] = fields[5].GetUInt32(); m_zoneWeathers[wi->m_zoneId] = wi; wi->_GenerateWeather(); ++num; if(!(num % 15)) SetProgressBar(num, total, "Zone Weather"); } while( result->NextRow() ); delete result; ClearProgressBar(); }
void WeatherMgr::LoadFromDB() { sLog.outString(" Loading Weather..."); QueryResult *result = WorldDatabase.Query( "SELECT * FROM weather" ); if( !result ) { sLog.outString(" Query failed."); return; } // uint32 total =(uint32) result->GetRowCount(); // int num = 0; do { Field *fields = result->Fetch(); WeatherInfo *wi = new WeatherInfo; wi->m_zoneId = fields[0].GetUInt32(); wi->m_effectValues[0] = fields[1].GetUInt32(); wi->m_effectValues[1] = fields[2].GetUInt32(); wi->m_effectValues[2] = fields[3].GetUInt32(); wi->m_effectValues[3] = fields[4].GetUInt32(); wi->m_effectValues[4] = fields[5].GetUInt32(); m_zoneWeathers[wi->m_zoneId] = wi; wi->_GenerateWeather(); } while( result->NextRow() ); delete result; }
void WeatherMgr::LoadFromDB() { QueryResult *result = WorldDatabase.Query( "SELECT zoneId,high_chance,high_type,med_chance,med_type,low_chance,low_type FROM weather" ); if( !result ) return; Field *fields = result->Fetch(); WeatherInfo* wi = NULL; do { fields = result->Fetch(); wi = new WeatherInfo(); wi->m_zoneId = fields[0].GetUInt32(); wi->m_effectValues[0] = fields[1].GetUInt32(); // high_chance wi->m_effectValues[1] = fields[2].GetUInt32(); // high_type wi->m_effectValues[2] = fields[3].GetUInt32(); // med_chance wi->m_effectValues[3] = fields[4].GetUInt32(); // med_type wi->m_effectValues[4] = fields[5].GetUInt32(); // low_chance wi->m_effectValues[5] = fields[6].GetUInt32(); // low_type m_zoneWeathers[wi->m_zoneId] = wi; wi->_GenerateWeather(); } while( result->NextRow() ); Log.Notice("WeatherMgr", "Loaded weather information for %u zones.", result->GetRowCount()); delete result; }
void FiveDayForecast(wstring city) { WeatherInfo weather; Weather weatherI; auto result(async(SendRequest, L"forecast?q=" + city)); cls(); Center(16, true); cout << "Fetching data"; cursorPos = getCursorPos(); for (int i = 0; result.wait_for(span) != future_status::ready; i++) { SetConsoleCursorPosition(ConsoleH, cursorPos); switch (i % 4) { case 0: cout << " "; break; case 1: cout << ". "; break; case 2: cout << ".. "; break; case 3: cout << "..."; } if (i > 50) { Center(16, true); cout << " Fetch failed "; SetConsoleTextAttribute(ConsoleH, 240); Center(4, 4); cout << "Back"; SetConsoleTextAttribute(ConsoleH, 15); while (_getch() != 13); return; } } weather = ParseFiveDay(result.get()); if (weather.cityName.size() < 1) { Center(16, true); cout << " Fetch failed "; SetConsoleTextAttribute(ConsoleH, 240); Center(4, 4); cout << "Back"; SetConsoleTextAttribute(ConsoleH, 15); while (_getch() != 13); return; } int choice; for (;;) { choice = WeatherList(weather); if (choice != weather.ToDateTimeList().size()) { weatherI = TimeList(weather.ToDateTimeList()[choice], weather.cityName); if (weatherI.main != "back") PrintWeather(weatherI, weather.cityName); } else break; } }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget), m_pData(new Widget::Private()) { ui->setupUi(this); QComboBox *cityList = new QComboBox(this); cityList->addItem(tr("Beijing"), QLatin1String("Beijing, cn")); cityList->addItem(tr("Shanghai"), QLatin1String("Shanghai, cn")); cityList->addItem(tr("Nanjing"), QLatin1String("Nanjing, cn")); QLabel* cityLabel = new QLabel(tr("City:"), this); QPushButton *refreshButton = new QPushButton(tr("Refresh"), this); QHBoxLayout *cityListLayout = new QHBoxLayout; cityListLayout->setDirection(QBoxLayout::LeftToRight); cityListLayout->addWidget(cityLabel); cityListLayout->addWidget(cityList); cityListLayout->addWidget(refreshButton); QVBoxLayout *weatherLayout = new QVBoxLayout; weatherLayout->setDirection(QBoxLayout::TopToBottom); QLabel* cityNameLabel = new QLabel(this); weatherLayout->addWidget(cityNameLabel); QLabel *dateTimeLabel = new QLabel(this); weatherLayout->addWidget(dateTimeLabel); m_pData->descLabel = new QLabel(this); weatherLayout->addWidget(m_pData->descLabel); m_pData->iconLabel = new QLabel(this); weatherLayout->addWidget(m_pData->iconLabel); QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->addLayout(cityListLayout); mainLayout->addLayout(weatherLayout); resize(320, 120); setWindowTitle("Weather"); connect(m_pData->network, &NetWorker::finished, [=](QNetworkReply* reply){ switch(m_pData->replyMap.value(reply)) { case FetchWeatherInfo: { QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error); if(error.error == QJsonParseError::NoError){ if(!(jsonDoc.isNull() || jsonDoc.isEmpty()) && (jsonDoc.isObject())){ QVariantMap data = jsonDoc.toVariant().toMap(); WeatherInfo weather; weather.setCityName(data[QLatin1String("name")].toString()); QDateTime dateTime; dateTime.setTime_t(data[QLatin1String("dt")].toLongLong()); weather.setDateTime(dateTime); QVariantMap main = data[QLatin1String("main")].toMap(); weather.setTempertuare(main[QLatin1String("temp")].toFloat()); weather.setPressure(main[QLatin1String("pressure")].toFloat()); weather.setHumidity(main[QLatin1String("humidity")].toFloat()); QVariantList detaiList = data[QLatin1String("weather")].toList(); WeatherDetailList details; foreach (QVariant w, detaiList) { QVariantMap wm = w.toMap(); WeatherDetail *detail = new WeatherDetail; detail->setDesc(wm[QLatin1String("description")].toString()); detail->setIcon(wm[QLatin1Literal("icon")].toString()); details.append(detail); } weather.setDetails(details); cityNameLabel->setText(weather.cityName()); dateTimeLabel->setText(weather.dateTime().toString(Qt::DefaultLocaleLongDate)); m_pData->descLabel->setText(weather.details().at(0)->desc()); qDebug()<<weather; } else{ QMessageBox::critical(this, "Error","Parse Reply Error!"); } } }