Changeset 78c6ae6 in observatorio for simulacion


Ignore:
Timestamp:
Oct 22, 2014, 6:00:54 PM (10 years ago)
Author:
Alejandro <amujica@…>
Branches:
simulacion
Children:
18610a4
Parents:
512ad64
Message:

pendiente de correccion de conversion de numeros a cadenas

Location:
simulacion/SimEscenariosEconomicos
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • simulacion/SimEscenariosEconomicos/common.C

    r7941763 r78c6ae6  
    213213std::string numtostrRec(const real & num, const char & thousandSep) {
    214214
    215     if (num < 1000) {
     215    if (num < 1000.0) {
    216216
    217217        std::stringstream sstr;
     
    222222    }
    223223
    224     real aux = num / 1000;
     224    real aux = num / 1000.0;
    225225
    226226    long long intPart = (long long) aux;
     
    236236    std::string str = sstr.str();
    237237
    238     if (aux < 100.0L)
     238    if (aux < 100.0L) {
    239239        str = "0" + str;
    240 
    241     if (aux < 10.0L)
     240    }
     241
     242    if (aux < 10.0L) {
    242243        str = "0" + str;
     244    }
    243245
    244246    return numtostrRec(intPart, thousandSep) + thousandSep + str;
     
    276278
    277279    if (strDec.size() > 2)
    278         ret += decSep + strDec.substr(2, strDec.size() - 2);
     280        ret += decSep +  strDec.substr(2, strDec.size() - 2);
    279281
    280282    return sign + ret;
  • simulacion/SimEscenariosEconomicos/ioManager.H

    r512ad64 r78c6ae6  
    437437                        scode << input.id;
    438438
    439                         if (productInfo.nationality == "V")
     439                        if (productInfo.companyRif.size() > 0)
    440440                          scode << productInfo.companyRif;
    441441                        else
     
    14281428                c1.levels.for_each(AddLevelToStr(str1));
    14291429
    1430                 str1.append(c1.rif);
     1430                if (c1.nationality == "E") {
     1431                    str1.append(c1.companyName);
     1432                } else {
     1433                    str1.append(c1.rif);
     1434                }
    14311435            }
    14321436
     
    14411445                c2.levels.for_each(AddLevelToStr(str2));
    14421446
    1443                 str2.append(c2.rif);
     1447                if (c2.nationality == "E") {
     1448                    str2.append(c2.companyName);
     1449                } else {
     1450                    str2.append(c2.rif);
     1451                }
    14441452            }
    14451453
     
    14511459
    14521460    typedef Map <ClusterByPlantInfo, NodeSet,
    1453                          ClusterByPlantInfoCmp> ClusterMap;
     1461                 ClusterByPlantInfoCmp> ClusterMap;
    14541462
    14551463    /// Functor para escribir información completa de un nodo en un dot.
  • simulacion/SimEscenariosEconomicos/productionNetwork.H

    r7941763 r78c6ae6  
    132132
    133133    bool operator () (const Company & c1, const Company & c2) {
    134         return c1.getRif() < c2.getRif();
     134
     135        const std::string & str1 = c1.getNationality() == "E"
     136                                   ? c1.getName() : c1.getRif();
     137
     138        const std::string & str2 = c2.getNationality() == "E"
     139                                   ? c2.getName() : c2.getRif();
     140
     141        return str1 < str2;
    135142    }
    136143};
  • simulacion/SimEscenariosEconomicos/queries.C

    r7941763 r78c6ae6  
    495495
    496496real computeInputProportionFromSupplier(const std::string & supplierRif,
    497                                           const size_t & inputId,
    498                                           const std::string & year) {
    499 
    500     AutoConnection conn;
    501 
    502     DBQuery query(conn);
    503 
    504     StrQuery strQuery;
    505 
    506     strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::RIF));
     497                                        const std::string & supplierName,
     498                                        const std::string & nationality,
     499                                        const size_t & inputId,
     500                                        const std::string & year) {
     501
     502    AutoConnection conn;
     503
     504    DBQuery query(conn);
     505
     506    StrQuery strQuery;
     507
     508    const std::string & to_compare = nationality == "E" ?
     509                                     supplierName : supplierRif;
     510
     511    if (nationality == "E") {
     512        strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::NAME));
     513    } else {
     514        strQuery.addSelect(concatas(DB::SUPPLIER_TABLE_NAME, DB::RIF));
     515    }
    507516    strQuery.addSelect(concatas(DB::INPUT_SUPPLIER_TABLE_NAME,
    508517                                DB::BOUGHT_QUANTITY));
     
    531540    while (query.next()) {
    532541
    533         if (supplierRif == query.getValue(0))
     542        if (to_compare == query.getValue(0)) {
    534543            suppliedQuantity = std::atof(query.getValue(1));
     544        }
    535545
    536546        sum += std::atof(query.getValue(1));
     
    541551
    542552real computeProportionByTariffCode(const std::string & tariffCode,
    543                                      const std::string & rif,
    544                                      const size_t & productId,
    545                                      const std::string & year) {
     553                                   const std::string & rif,
     554                                   const size_t & productId,
     555                                   const std::string & year) {
    546556
    547557    AutoConnection conn;
     
    605615
    606616    std::string rif;
     617    std::string companyName;
     618    std::string nationality;
    607619
    608620    if (src->getType() == PRODUCT_GOOD) {
     
    611623
    612624        rif = product->getProducerPlant()->getOwnerCompany()->getRif();
     625        companyName = product->getProducerPlant()->getOwnerCompany()->getName();
     626        nationality =
     627            product->getProducerPlant()->getOwnerCompany()->getNationality();
    613628
    614629    } else {
     
    617632
    618633        rif = input->getProviderCompany()->getRif();
     634        companyName = input->getProviderCompany()->getName();
     635        nationality = input->getProviderCompany()->getNationality();
    619636    }
    620637
    621638    real proportionFromSupplier =
    622         computeInputProportionFromSupplier(rif, info.inputId, year);
     639        computeInputProportionFromSupplier(rif, companyName, nationality,
     640                                           info.inputId, year);
    623641
    624642    real proportionByTariffCode =
Note: See TracChangeset for help on using the changeset viewer.