<commit_before>#include "stdsneezy.h"
#include "database.h"
#include "corporation.h"

int getAssets(int corp_id)
{
  int value=0, keepernum=0;
  TDatabase db(DB_SNEEZY);
  TObj *o=NULL;
  TRoom *room;
  TMonster *keeper;

  db.query("select in_room, keeper from shop where shop_nr in (select shop_nr from shopowned where corp_id=%i)", corp_id);
  
  while(db.fetchRow()){
    room=real_roomp(convertTo<int>(db["in_room"]));
    keepernum=convertTo<int>(db["keeper"]);

    for(TThing *tt=room->getStuff();tt;tt=tt->nextThing){
      if((keeper=dynamic_cast<TMonster *>(tt)) &&
	 keeper->mobVnum() == keepernum){
	for(TThing *t=keeper->getStuff();t;t=t->nextThing){
	  o=dynamic_cast<TObj *>(t);
	  value+=o->obj_flags.cost;
	}
        break;
      }
    }
  }

  return value;
}

sstring talenDisplay(int talens)
{
  float t;

  if(talens>1000000){
    t=(int)(talens/100000);
    return fmt("%.1fM") % (t/10.0);
  } else if(talens > 10000){
    t=(int)(talens/1000);
    return fmt("%ik") % (int)t;
  }

  return fmt("%i") % talens;
}

void corpListing(TBeing *ch, TMonster *me)
{
  TDatabase db(DB_SNEEZY);
  int corp_id=0, val=0, gold=0, shopval=0;
  multimap <int, sstring, std::greater<int> > m;
  multimap <int, sstring, std::greater<int> >::iterator it;
  
  db.query("select c.corp_id, c.name, sum(s.gold)+c.gold as gold, count(so.shop_nr) as shopcount from corporation c, shopowned so, shop s where c.corp_id=so.corp_id and so.shop_nr=s.shop_nr group by c.corp_id, c.name, c.gold order by gold desc");
  
  while(db.fetchRow()){
    corp_id=convertTo<int>(db["corp_id"]);
    gold=convertTo<int>(db["gold"]);
    shopval=convertTo<int>(db["shopcount"]) * 1000000;
    val=gold+getAssets(corp_id)+shopval;
   
    m.insert(pair<int,sstring>(val,fmt("%-2i| %s - %s talens, %s in assets") %
			       corp_id % db["name"] % 
			       talenDisplay(gold) % 
			       talenDisplay(getAssets(corp_id)+shopval)));
  }

  me->doTell(ch->getName(), "I know about the following corporations:");

  for(it=m.begin();it!=m.end();++it)
    me->doTell(ch->getName(), (*it).second);
}

void corpLogs(TBeing *ch, TMonster *me, sstring arg)
{
  TDatabase db(DB_SNEEZY);
  sstring buf, sb;
  int corp_id=0;

  db.query("select corp_id from corpaccess where lower(name)='%s'",
	   sstring(ch->getName()).lower().c_str());

  if(arg.empty()){
    if(db.fetchRow())
      corp_id=convertTo<int>(db["corp_id"]);

    if(db.fetchRow()){
      me->doTell(ch->getName(), "You must specify the ID of the corporation you wish to deposit the money for.");
      return;
    }
  } else {
    if(convertTo<int>(arg) == 0){
      me->doTell(ch->getName(), "You must specify the ID of the corporation you wish to deposit the money for.");
      return;
    }

    while(db.fetchRow()){
      if(convertTo<int>(db["corp_id"]) == convertTo<int>(arg)){
	corp_id=convertTo<int>(arg);
	break;
      }
    }
  }

  if(!corp_id){
      me->doTell(ch->getName(), "You must specify the ID of the corporation you wish to deposit the money for.");
      return;
  }
  

  db.query("select name, action, talens, corptalens, logtime from corplog where corp_id = %i order by logtime desc", corp_id);
  
  while(db.fetchRow()){
    buf = fmt("%s  %12s %10s %10s  Total: %s\n\r") %
      db["logtime"] % db["name"] % db["action"] %
      db["talens"] % db["corptalens"];
    sb += buf;
  }
  
  if (ch->desc)<commit_msg>fixed time display for corp logs<commit_after>#include "stdsneezy.h"
#include "database.h"
#include "corporation.h"

int getAssets(int corp_id)
{
  int value=0, keepernum=0;
  TDatabase db(DB_SNEEZY);
  TObj *o=NULL;
  TRoom *room;
  TMonster *keeper;

  db.query("select in_room, keeper from shop where shop_nr in (select shop_nr from shopowned where corp_id=%i)", corp_id);
  
  while(db.fetchRow()){
    room=real_roomp(convertTo<int>(db["in_room"]));
    keepernum=convertTo<int>(db["keeper"]);

    for(TThing *tt=room->getStuff();tt;tt=tt->nextThing){
      if((keeper=dynamic_cast<TMonster *>(tt)) &&
	 keeper->mobVnum() == keepernum){
	for(TThing *t=keeper->getStuff();t;t=t->nextThing){
	  o=dynamic_cast<TObj *>(t);
	  value+=o->obj_flags.cost;
	}
        break;
      }
    }
  }

  return value;
}

sstring talenDisplay(int talens)
{
  float t;

  if(talens>1000000){
    t=(int)(talens/100000);
    return fmt("%.1fM") % (t/10.0);
  } else if(talens > 10000){
    t=(int)(talens/1000);
    return fmt("%ik") % (int)t;
  }

  return fmt("%i") % talens;
}

void corpListing(TBeing *ch, TMonster *me)
{
  TDatabase db(DB_SNEEZY);
  int corp_id=0, val=0, gold=0, shopval=0;
  multimap <int, sstring, std::greater<int> > m;
  multimap <int, sstring, std::greater<int> >::iterator it;
  
  db.query("select c.corp_id, c.name, sum(s.gold)+c.gold as gold, count(so.shop_nr) as shopcount from corporation c, shopowned so, shop s where c.corp_id=so.corp_id and so.shop_nr=s.shop_nr group by c.corp_id, c.name, c.gold order by gold desc");
  
  while(db.fetchRow()){
    corp_id=convertTo<int>(db["corp_id"]);
    gold=convertTo<int>(db["gold"]);
    shopval=convertTo<int>(db["shopcount"]) * 1000000;
    val=gold+getAssets(corp_id)+shopval;
   
    m.insert(pair<int,sstring>(val,fmt("%-2i| %s - %s talens, %s in assets") %
			       corp_id % db["name"] % 
			       talenDisplay(gold) % 
			       talenDisplay(getAssets(corp_id)+shopval)));
  }

  me->doTell(ch->getName(), "I know about the following corporations:");

  for(it=m.begin();it!=m.end();++it)
    me->doTell(ch->getName(), (*it).second);
}

void corpLogs(TBeing *ch, TMonster *me, sstring arg)
{
  TDatabase db(DB_SNEEZY);
  sstring buf, sb;
  int corp_id=0;

  db.query("select corp_id from corpaccess where lower(name)='%s'",
	   sstring(ch->getName()).lower().c_str());

  if(arg.empty()){
    if(db.fetchRow())
      corp_id=convertTo<int>(db["corp_id"]);

    if(db.fetchRow()){
      me->doTell(ch->getName(), "You must specify the ID of the corporation you wish to deposit the money for.");
      return;
    }
  } else {
    if(convertTo<int>(arg) == 0){
      me->doTell(ch->getName(), "You must specify the ID of the corporation you wish to deposit the money for.");
      return;
    }

    while(db.fetchRow()){
      if(convertTo<int>(db["corp_id"]) == convertTo<int>(arg)){
	corp_id=convertTo<int>(arg);
	break;
      }
    }
  }

  if(!corp_id){
      me->doTell(ch->getName(), "You must specify the ID of the corporation you wish to deposit the money for.");
      return;
  }
  

  db.query("select name, action, talens, corptalens, logtime from corplog where corp_id = %i order by logtime desc", corp_id);
  
  while(db.fetchRow()){
    buf = fmt("%19.19s  %12s %10s %10s  Total: %s\n\r") %
      db["logtime"] % db["name"] % db["action"] %
      db["talens"] % db["corptalens"];
    sb += buf;
  }
  
  if (ch->desc)
{'fraction_non_alphanumeric': 0.18105480259281084, 'fraction_numerical': 0.01473187978786093, 'mean_word_length': 3.7178596247394022, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1065704', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2603, 'n_words': 542}