Ejemplo n.º 1
0
void ResultFormatter::formatSimpleResultWithFortune(int64_t fortune) {
    _writer.StartObject();
    formatStatus(true);
    JSON_KEY(ResultStr::sFortune);
    _writer.Int64(fortune);
    _writer.EndObject();
}
Ejemplo n.º 2
0
// [start, end)
void ResultFormatter::formatRankResult(
    const LeaderBoardRank &rank, int64_t uid, uint32_t start, uint32_t end)
{
    _writer.StartObject();
    formatStatus(true);
    JSON_KEY(ResultStr::sRankInfo);
    _writer.StartArray();
    uint32_t cur = 0;
    int32_t rankValue = 0;
    for (auto &itr: rank.data) {
	if (cur >= start && cur < end) {
	    _writer.StartObject();
	    JSON_KEY(ResultStr::sUserID);
	    _writer.Int64(itr->uid);
	    JSON_KEY(ResultStr::sUserName);
	    JSON_STRING_VALUE(itr->name);
	    JSON_KEY(ResultStr::sUserCountry);
	    _writer.Int(itr->country);
	    JSON_KEY(ResultStr::sValue);
	    _writer.Int64(itr->value);
	    _writer.EndObject();
	}
	++cur;
	if (itr->uid == uid) {
	    rankValue = cur;
	}
    }
    _writer.EndArray();
    JSON_KEY(ResultStr::sMyRank);
    _writer.Int(rankValue);
    _writer.EndObject();
}
Ejemplo n.º 3
0
void ResultFormatter::formatSimpleResult(bool success, const std::string &err)
{
    _writer.StartObject();
    formatStatus(success);
    JSON_KEY(ResultStr::sMsg);
    JSON_STRING_VALUE(err);
    _writer.EndObject();
}
Ejemplo n.º 4
0
void ResultFormatter::formatSimpleResult(
    bool success, const std::string &key, bool value)
{
    _writer.StartObject();
    formatStatus(success);
    JSON_KEY(key);
    _writer.Bool(value);
    _writer.EndObject();
}
Ejemplo n.º 5
0
void ResultFormatter::formatResultWithCj(const GameContext &context) {
    _writer.StartObject();
    formatStatus(true);

    formatUser(context);

    JSON_KEY(ResultStr::sLoginInfo);
    formatLoginInfo(context);

    _writer.EndObject();
}
Ejemplo n.º 6
0
void ResultFormatter::formatFullFriendInfo(
    const FriendsList &friends, const FHistory &history)
{
    _writer.StartObject();
    formatStatus(true);
    formatFriendList(friends);
    // JSON_KEY("invite_count");
    // _writer.Int(history.inviteCount);
    // JSON_KEY("total_reward");	
    // _writer.Int64(history.totalReward);
    // JSON_KEY("cached_reward");	
    // _writer.Int64(history.rewardRemain);
    _writer.EndObject();
}    
Ejemplo n.º 7
0
void ResultFormatter::formatGameResult(GameContext &gc)
{
    _writer.StartObject();
    formatStatus(true);

    auto &uRes = gc.uRes;
    auto &ret = gc.gameInfo;
    JSON_KEY(ResultStr::sFortune);
    _writer.Int64(uRes.fortune);

    JSON_KEY(ResultStr::sEarnedInfo);
    _writer.StartArray();
    _writer.Int64(ret.earned.normal);
    _writer.Int64(ret.earned.roomPrize);
    _writer.Int64(ret.earned.hallPrize);
    _writer.EndArray();

    JSON_KEY(ResultStr::sUserResource);
    formatUserResource(uRes);

    JSON_KEY(ResultStr::sRatio);
    _writer.Int(ret.totalRatio);

    JSON_KEY(ResultStr::sGridsInfo);
    _writer.StartArray();
    auto len = ret.gridsData.size();
    for (size_t i = 0; i < len; ++i) {
        _writer.Int(ret.gridsData[i]);
    }
    _writer.EndArray();

    JSON_KEY(ResultStr::sFreeTimes);
    _writer.Int(ret.freeGameTimes);

    JSON_KEY(ResultStr::sUserAchievement);
    _writer.StartArray();
    for (auto &item: gc.newCj) {
        _writer.Int(item.aid);
    }
    _writer.EndArray();

    JSON_KEY(ResultStr::sTinyGame);
    _writer.StartArray();
    for (auto &item: gc.gameInfo.tinyResult) {
        _writer.Int(item);
    }
    _writer.EndArray();

    _writer.EndObject();
}
Ejemplo n.º 8
0
void ResultFormatter::formatOnlineInfo(
    const OnlineInfo &oInfo, int32_t curLevel, int32_t timeNeed)
{
    _writer.StartObject();
    formatStatus(true);
    JSON_KEY(ResultStr::sCurLevel);
    _writer.Int(curLevel);
    JSON_KEY(ResultStr::sTargetLevel);
    _writer.Int(oInfo.rewardLevel);
    JSON_KEY(ResultStr::sRecvReward);
    _writer.Bool(oInfo.recved);
    JSON_KEY(ResultStr::sValue);
    _writer.Int64(oInfo.rewardValue);
    JSON_KEY(ResultStr::sTimeRequired);
    _writer.Int(timeNeed);
    _writer.EndObject();
}
Ejemplo n.º 9
0
void ResultFormatter::formatGiftsInfo(const Gifts &gifts, int64_t giftsVal) {
    _writer.StartObject();
    formatStatus(true);
    // JSON_KEY("gifts");
    // _writer.StartArray();
    // for (auto itr = gifts.begin(); itr != gifts.end(); ++itr) {
    //     _writer.StartObject();
    //     JSON_KEY("uid");
    //     _writer.Int64((int64_t)(*itr)->master);
    //     JSON_KEY("received");
    //     _writer.Bool((int64_t)(*itr)->received);
    //     JSON_KEY("timestamp");
    //     _writer.Int64((*itr)->timestamp);
    //     _writer.EndObject();
    // }
    // _writer.EndArray();
    // JSON_KEY("value");
    // _writer.Int64(giftsVal);
    _writer.EndObject();
}
Ejemplo n.º 10
0
void ResultFormatter::formatFriendsInfo(const FriendsList &friends) {
    _writer.StartObject();
    formatStatus(true);
    formatFriendList(friends);
    _writer.EndObject();
}
Ejemplo n.º 11
0
void ResultFormatter::formatMailList(const UserMails &uMails)  {
    _writer.StartObject();
    formatStatus(true);
    formatMailsInfo(uMails);
    _writer.EndObject();
}
Ejemplo n.º 12
0
  void WorhpInternal::reset(){

    // Number of (free) variables
    worhp_o_.n = nx_;

    // Number of constraints
    worhp_o_.m = ng_;

    // Free existing Worhp memory (except parameters)
    bool p_init_backup = worhp_p_.initialised; 
    worhp_p_.initialised = false; // Avoid freeing the memory for parameters
    if (worhp_o_.initialised || worhp_w_.initialised || worhp_c_.initialised){
      WorhpFree(&worhp_o_, &worhp_w_, &worhp_p_, &worhp_c_);
    }
    worhp_p_.initialised = p_init_backup; 
  
    /// Control data structure needs to be reset every time
    worhp_c_.initialised = false;
    worhp_w_.initialised = false;
    worhp_o_.initialised = false;
    
    // Worhp uses the CS format internally, hence it is the preferred sparse matrix format.  
    worhp_w_.DF.nnz = nx_;
    if (worhp_o_.m>0) {
      worhp_w_.DG.nnz = jacG_.output().size();  // Jacobian of G
    } else {
      worhp_w_.DG.nnz = 0;
    }

    if (exact_hessian_ /*worhp_w_.HM.NeedStructure*/) { // not initialized

      // Get the sparsity pattern of the Hessian
      const Sparsity& spHessLag = this->spHessLag();
      const vector<int>& colind = spHessLag.colind();
      const vector<int>& row = spHessLag.row();

      // Get number of nonzeros in the lower triangular part of the Hessian including full diagonal
      worhp_w_.HM.nnz = nx_; // diagonal entries
      for(int c=0; c<nx_; ++c){
        for(int el=colind[c]; el<colind[c+1] && row[el]<c; ++el){
          worhp_w_.HM.nnz++; // strictly lower triangular part
        }
      }
    } else {
      worhp_w_.HM.nnz = 0;
    }

    /* Data structure initialisation. */
    WorhpInit(&worhp_o_, &worhp_w_, &worhp_p_, &worhp_c_);
    if (worhp_c_.status != FirstCall) {
      casadi_error("Main: Initialisation failed. Status: " << formatStatus(worhp_c_.status));
    }

    if (worhp_w_.DF.NeedStructure){
      for(int i=0; i<nx_; ++i){
        worhp_w_.DF.row[i] = i + 1; // Index-1 based    
      }
    }
  
    if (worhp_o_.m>0 && worhp_w_.DG.NeedStructure) {    
      // Get sparsity pattern. Note WORHP is column major
      const DMatrix & J = jacG_.output(JACG_JAC);
      
      int nz=0;
      const vector<int>& colind = J.colind();
      const vector<int>& row = J.row();
      for(int c=0; c<nx_; ++c){
        for(int el=colind[c]; el<colind[c+1]; ++el){
          int r = row[el];
          worhp_w_.DG.col[nz] = c + 1; // Index-1 based
          worhp_w_.DG.row[nz] = r + 1;
          nz++;
        }
      }
    }    

    if (worhp_w_.HM.NeedStructure) {
      // Get the sparsity pattern of the Hessian
      const Sparsity& spHessLag = this->spHessLag();
      const vector<int>& colind = spHessLag.colind();
      const vector<int>& row = spHessLag.row();

      int nz=0;
      
      // Upper triangular part of the Hessian (note CCS -> CRS format change)
      for(int c=0; c<nx_; ++c){
        for(int el=colind[c]; el<colind[c+1]; ++el){
          if(row[el]>c){
            worhp_w_.HM.row[nz] = row[el] + 1;
            worhp_w_.HM.col[nz] = c + 1;
            nz++;
          }
        }
      }
      
      // Diagonal always included
      for(int r=0; r<nx_; ++r){
        worhp_w_.HM.row[nz] = r + 1;
        worhp_w_.HM.col[nz] = r + 1;
        nz++;
      }
    }
  }