Changeset 5c51ff9 in observatorio


Ignore:
Timestamp:
Apr 27, 2015, 12:02:38 PM (9 years ago)
Author:
Alejandro <amujica@…>
Branches:
simulacion
Children:
ac8ea81
Parents:
a0523b8
Message:

Modificado para que se cree una sola conexion a la base de datos para todas las consultas en lote

Location:
simulacion/SimEscenariosEconomicos
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • simulacion/SimEscenariosEconomicos/indicatorGenerator.C

    r7bbc686 r5c51ff9  
    4040
    4141
    42 void ProductionIndicatorGenerator::writeProductLine(
     42void ProductionIndicatorGenerator::writeProductLine(AutoConnection & conn,
    4343    Graph::Node * node, std::ofstream & file,
    4444    Map <long, PlantLocation> & mapPlantLocation,
     
    7373    if (ptrCiiu == NULL) {
    7474
    75         std::string ciiu = getCiiu(rif);
     75        std::string ciiu = getCiiu(conn, rif);
    7676
    7777        ptrCiiu = mapCompanyCiiu.insert(rif, ciiu);
     
    120120}
    121121
    122 real computeGeneratedEmployment(Graph::Node * node, const std::string & rif,
    123                                const std::string & year,
    124                                const real & amountDiff) {
     122real computeGeneratedEmployment(AutoConnection & conn, Graph::Node * node,
     123                                const std::string & rif,
     124                                const std::string & year,
     125                                const real & amountDiff) {
    125126
    126127    real generatedEmployment = 0;
     
    131132         node->type == ROOT) and good->getType() == PRODUCT_GOOD) {
    132133
    133         real staffNumber = getOperatingStaffNumber(rif, year);
    134 
    135         real totalAmount = getTotalAmount(rif, year);
     134        real staffNumber = getOperatingStaffNumber(conn, rif, year);
     135
     136        real totalAmount = getTotalAmount(conn, rif, year);
    136137
    137138        generatedEmployment = staffNumber * amountDiff / totalAmount;
     
    142143
    143144
    144 void ProductionIndicatorGenerator::writeInputLine(
     145void ProductionIndicatorGenerator::writeInputLine(AutoConnection & conn,
    145146    Graph & graph, Graph::Arc * arc, std::ofstream & file,
    146147    Map <long, PlantLocation> & mapPlantLocation,
     
    178179    if (ptrCiiu == NULL) {
    179180
    180         std::string ciiu = getCiiu(rif);
     181        std::string ciiu = getCiiu(conn, rif);
    181182
    182183        ptrCiiu = mapCompanyCiiu.insert(rif, ciiu);
     
    214215    const real amount = quantity * arc->get_info().price;
    215216
    216     real employment = computeGeneratedEmployment(node, rif, year, amount);
     217    real employment = computeGeneratedEmployment(conn, node, rif, year, amount);
    217218
    218219    char sep = 0;
     
    261262
    262263bool ProductionIndicatorGenerator::writeProductInputsIndicators(
     264    AutoConnection & conn,
    263265    Graph & graph, const std::string & path, const std::string & year) {
    264266
     
    354356            node->get_info()->getType() == INPUT_GOOD) {
    355357
    356             writeProductLine(node, file, mapPlantLocation, mapCompanyCiiu);
     358            writeProductLine(conn, node, file, mapPlantLocation,
     359                             mapCompanyCiiu);
    357360
    358361            writeEmptyInput(file);
     
    371374                continue;
    372375
    373             writeProductLine(node, file, mapPlantLocation, mapCompanyCiiu);
    374 
    375             writeInputLine(graph, arc, file, mapPlantLocation,
     376            writeProductLine(conn, node, file, mapPlantLocation,
     377                             mapCompanyCiiu);
     378
     379            writeInputLine(conn, graph, arc, file, mapPlantLocation,
    376380                           mapCompanyCiiu, year);
    377381        }
     
    384388}
    385389
    386 void ProductionIndicatorGenerator::writeProductionInfo(Graph & graph,
     390void ProductionIndicatorGenerator::writeProductionInfo(AutoConnection & conn,
     391                                                       Graph & graph,
    387392                                                       Graph::Node * node,
    388393                                                       const std::string & year,
     
    490495
    491496    real generatedEmployment =
    492         computeGeneratedEmployment(node, COMPANY(good)->getRif(), year,
     497        computeGeneratedEmployment(conn, node, COMPANY(good)->getRif(), year,
    493498                                   amountDiff);
    494499
     
    513518}
    514519
    515 bool ProductionIndicatorGenerator::writeProductIndicators(
     520bool ProductionIndicatorGenerator::writeProductIndicators(AutoConnection & conn,
    516521    Graph & graph, const std::string & path, const std::string & year) {
    517522
     
    610615            continue;
    611616
    612         writeProductLine(node, file, mapPlantLocation, mapCompanyCiiu);
    613 
    614         writeProductionInfo(graph, node, year, file);
     617        writeProductLine(conn, node, file, mapPlantLocation, mapCompanyCiiu);
     618
     619        writeProductionInfo(conn, graph, node, year, file);
    615620    }
    616621
     
    624629                                                   const std::string & year) {
    625630
    626     bool res = writeProductInputsIndicators(graph, path, year);
    627 
    628     res = res and writeProductIndicators(graph, path, year);
     631    AutoConnection conn;
     632
     633    bool res = writeProductInputsIndicators(conn, graph, path, year);
     634
     635    res = res and writeProductIndicators(conn, graph, path, year);
    629636
    630637    if (not res)
  • simulacion/SimEscenariosEconomicos/indicatorGenerator.H

    r7bbc686 r5c51ff9  
    7474     * @param mapPlantLocation buffer con ciiu de las empresas.
    7575     */
    76      void writeProductLine(Graph::Node * node, std::ofstream & file,
     76     void writeProductLine(AutoConnection & conn,
     77                           Graph::Node * node, std::ofstream & file,
    7778                           Map <long, PlantLocation> & mapPlantLocation,
    7879                           Map <std::string, std::string> &
     
    8687     * @param mapPlantLocation buffer con ciiu de las empresas.
    8788     */
    88     void writeInputLine(Graph & graph,
     89    void writeInputLine(AutoConnection & conn, Graph & graph,
    8990                        Graph::Arc * arc, std::ofstream & file,
    9091                        Map <long, PlantLocation> & mapPlantLocation,
     
    105106     * @param fileName nombre del archivo sobre el cual se va a escribir.
    106107     */
    107     bool writeProductInputsIndicators(Graph & graph, const std::string & path,
     108    bool writeProductInputsIndicators(AutoConnection & conn, Graph & graph,
     109                                      const std::string & path,
    108110                                      const std::string & year);
    109111
    110     void writeProductionInfo(Graph & graph, Graph::Node * node,
    111                              const std::string & year, std::ofstream & file);
     112    void writeProductionInfo(AutoConnection & conn, Graph & graph,
     113                             Graph::Node * node, const std::string & year,
     114                             std::ofstream & file);
    112115
    113     bool writeProductIndicators(Graph & graph, const std::string & path,
     116    bool writeProductIndicators(AutoConnection & conn, Graph & graph,
     117                                const std::string & path,
    114118                                const std::string & year);
    115119
  • simulacion/SimEscenariosEconomicos/ioManager.H

    r76e705a r5c51ff9  
    379379     *         recorrido en amplitud.
    380380     */
    381     void buildGraphUpstream(Graph & g, DynListQueue <Graph::Node *> & queue,
     381    void buildGraphUpstream(AutoConnection & conn, Graph & g,
     382                            DynListQueue <Graph::Node *> & queue,
    382383                            const size_t & maxLevelUpstream,
    383384                            const std::string & year, size_t & numNodes) {
     
    397398            List <size_t> inputsIds;
    398399
    399             listInputIds(good->getId(), year, inputsIds);
     400            listInputIds(conn, good->getId(), year, inputsIds);
    400401
    401402            for (List <size_t>::Iterator iit(inputsIds); iit.has_current();
     
    406407                List <InputInfo> inputs;
    407408
    408                 listInputs(inputId, year, inputs);
     409                listInputs(conn, inputId, year, inputs);
    409410
    410411                for (List <InputInfo>::Iterator it(inputs);
     
    415416                    List <ProductInfo> products;
    416417
    417                     productInfoFromInput(input, products);
     418                    productInfoFromInput(conn, input, products);
    418419
    419420                    bool isInput = false;
     
    486487                        } else {
    487488
    488                             getProducedQuantityAndPrice(productInfo, year);
     489                            getProducedQuantityAndPrice(conn, productInfo,
     490                                                        year);
    489491
    490492                            ptrSrc = productMap.search(productInfo.productId);
     
    504506
    505507                        arcInfo.price =
    506                             getAcquisitionPrice(src->get_info().get(),
     508                            getAcquisitionPrice(conn, src->get_info().get(),
    507509                                                input.id, year);
    508510                        arcInfo.inputId = input.id;
    509511
    510                         setArcMeasurementUnit(arcInfo);
     512                        setArcMeasurementUnit(conn, arcInfo);
    511513
    512514                        arcInfo.reqQuantity =
    513                             getUnitarianRequest(arcInfo.inputId,
     515                            getUnitarianRequest(conn, arcInfo.inputId,
    514516                                                tgt->get_info()->getId());
    515517
    516                         computeArcQuantityUpstream(src->get_info().get(),
     518                        computeArcQuantityUpstream(conn, src->get_info().get(),
    517519                                                   tgt->get_info().get(),
    518520                                                   year, arcInfo);
     
    708710     *         recorrido en amplitud.
    709711     */
    710      void buildGraphDownstream(Graph & g, DynListQueue <Graph::Node *> & queue,
     712     void buildGraphDownstream(AutoConnection & conn, Graph & g,
     713                               DynListQueue <Graph::Node *> & queue,
    711714                               const size_t & maxLevelDownstream,
    712715                               const std::string & year, size_t & numNodes) {
     
    724727                computeNodeQuantity(g, src);
    725728                computeUsageInputQuantities(g, src);
    726                 getProducedQuantityAndPrice(good, year);
     729                getProducedQuantityAndPrice(conn, good, year);
    727730            }
    728731
    729732            List <Aleph::pair<ProductInfo, long>> requesters;
    730             listRequesters(good, year, requesters);
     733            listRequesters(conn, good, year, requesters);
    731734
    732735            Tree <long> & levels = src->levels;
     
    758761                arcInfo.inputId = currentPair.second;
    759762
    760                 setArcMeasurementUnit(arcInfo);
     763                setArcMeasurementUnit(conn, arcInfo);
    761764
    762765                arcInfo.reqQuantity =
    763                     getUnitarianRequest(arcInfo.inputId,
     766                    getUnitarianRequest(conn, arcInfo.inputId,
    764767                                        tgt->get_info()->getId());
    765768
    766769                arcInfo.price =
    767                     getAcquisitionPrice(src->get_info().get(),
     770                    getAcquisitionPrice(conn, src->get_info().get(),
    768771                                        arcInfo.inputId, year);
    769772
    770                 computeArcQuantityDownstream(good, tgt->get_info().get(),
     773                computeArcQuantityDownstream(conn, good, tgt->get_info().get(),
    771774                                             year, arcInfo);
    772775
     
    779782                    computeNodeQuantity(g, tgt);
    780783                    computeUsageInputQuantities(g, tgt);
    781                     getProducedQuantityAndPrice(tgt->get_info().get(), year);
     784                    getProducedQuantityAndPrice(conn, tgt->get_info().get(),
     785                                                year);
    782786                }
    783787            }
     
    815819        DynListQueue <Graph::Node *> downstreamQueue;
    816820
     821        AutoConnection conn;
     822
    817823        for (size_t i = 0; i < roots.size(); ++i) {
    818824
    819825            const size_t & id = roots.access(i);
    820826
    821             ProductInfo info = loadInfoByProductId(id);
     827            ProductInfo info = loadInfoByProductId(conn, id);
    822828
    823829            if (info.productId == -1) {
     
    830836            }
    831837
    832             getProducedQuantityAndPrice(info, year);
     838            getProducedQuantityAndPrice(conn, info, year);
    833839
    834840            info.quantity = info.totalQuantity;
     
    844850
    845851        if (maxLevelUpstream > 0)
    846             buildGraphUpstream(g, upstreamQueue, maxLevelUpstream, year,
     852            buildGraphUpstream(conn, g, upstreamQueue, maxLevelUpstream, year,
    847853                               numNodes);
    848854
    849855        if (maxLevelDownstream > 0)
    850             buildGraphDownstream(g, downstreamQueue, maxLevelDownstream, year,
    851                                  numNodes);
     856            buildGraphDownstream(conn, g, downstreamQueue, maxLevelDownstream,
     857                                 year, numNodes);
    852858    }
    853859
  • simulacion/SimEscenariosEconomicos/queries.C

    rfaed520 r5c51ff9  
    3535# include <queries.H>
    3636# include <dbQuery.H>
    37 # include <autoConnection.H>
    3837
    3938# include <strQuery.H>
     
    9392}
    9493
    95 ProductInfo loadInfoByProductId(const size_t & id) {
    96 
    97     AutoConnection conn;
     94ProductInfo loadInfoByProductId(AutoConnection & conn, const size_t & id) {
    9895
    9996    DBQuery query(conn);
     
    171168}
    172169
    173 void listInputIds(const size_t & productId, const std::string & year,
    174                   List <size_t> & inputIds) {
    175 
    176     AutoConnection conn;
     170void listInputIds(AutoConnection & conn, const size_t & productId,
     171                  const std::string & year, List <size_t> & inputIds) {
    177172
    178173    DBQuery query(conn);
     
    197192}
    198193
    199 void listInputs(const size_t & inputId, const std::string & year,
    200                 List <InputInfo> & inputs) {
    201 
    202     AutoConnection conn;
     194void listInputs(AutoConnection & conn, const size_t & inputId,
     195                const std::string & year, List <InputInfo> & inputs) {
    203196
    204197    DBQuery query(conn);
     
    315308        long supplierId = std::atol(query.getValue(0));
    316309
    317         inputInfo.origCountry = getOrigCountry(supplierId);
    318         inputInfo.procCountry = getProcCountry(supplierId);
     310        inputInfo.origCountry = getOrigCountry(conn, supplierId);
     311        inputInfo.procCountry = getProcCountry(conn, supplierId);
    319312
    320313        inputs.append(inputInfo);
     
    322315}
    323316
    324 void productInfoFromInput(const InputInfo & inputInfo,
     317void productInfoFromInput(AutoConnection & conn, const InputInfo & inputInfo,
    325318                          List <ProductInfo> & list) {
    326 
    327     AutoConnection conn;
    328319
    329320    DBQuery query(conn);
     
    354345
    355346    while (query.next())
    356         list.append(loadInfoByProductId(
     347        list.append(loadInfoByProductId(conn,
    357348            std::atol(query.getValue(concat(DB::PRODUCT_TABLE_NAME, DB::ID,
    358349                      '_')))));
    359350}
    360351
    361 void listProductsId(Good * good, const std::string & year,
     352void listProductsId(AutoConnection & conn, Good * good,
     353                    const std::string & year,
    362354                    List <Aleph::pair<long, long>> & list) {
    363 
    364     AutoConnection conn;
    365355
    366356    DBQuery query(conn);
     
    413403}
    414404
    415 void listRequesters(Good * good, const std::string & year,
     405void listRequesters(AutoConnection & conn, Good * good,
     406                    const std::string & year,
    416407                    List <Aleph::pair<ProductInfo, long>> & list) {
    417408
    418409    List <Aleph::pair <long, long>> ids;
    419410
    420     listProductsId(good, year, ids);
     411    listProductsId(conn, good, year, ids);
    421412
    422413    for(List <Aleph::pair<long, long>>::Iterator it(ids); it.has_current();
     
    425416        Aleph::pair <long, long> & p = it.get_current();
    426417
    427         ProductInfo info = loadInfoByProductId(p.first);
     418        ProductInfo info = loadInfoByProductId(conn, p.first);
    428419
    429420        list.append(Aleph::pair<ProductInfo, long>(info, p.second));
     
    431422}
    432423
    433 void getProducedQuantityAndPrice(const long & id, const std::string & year,
     424void getProducedQuantityAndPrice(AutoConnection & conn, const long & id,
     425                                 const std::string & year,
    434426                                 real & producedQuantity, real & price) {
    435 
    436     AutoConnection conn;
    437427
    438428    DBQuery query(conn);
     
    462452}
    463453
    464 void getProducedQuantityAndPrice(Good * good, const std::string & year) {
     454void getProducedQuantityAndPrice(AutoConnection & conn, Good * good,
     455                                 const std::string & year) {
    465456
    466457    real producedQuantity = 0.0;
     
    468459    real price = 0.0;
    469460
    470     getProducedQuantityAndPrice(good->getId(), year, producedQuantity, price);
     461    getProducedQuantityAndPrice(conn, good->getId(), year, producedQuantity,
     462                                price);
    471463
    472464    good->setTotalQuantity(producedQuantity);
     
    475467}
    476468
    477 void getProducedQuantityAndPrice(ProductInfo & info, const std::string & year) {
    478 
    479     getProducedQuantityAndPrice(info.productId, year, info.totalQuantity,
     469void getProducedQuantityAndPrice(AutoConnection & conn, ProductInfo & info,
     470                                 const std::string & year) {
     471
     472    getProducedQuantityAndPrice(conn, info.productId, year, info.totalQuantity,
    480473                                info.unitarianPrice);
    481474}
    482475
    483 real getUnitarianRequest(const size_t & inputId, const size_t & productId) {
    484 
    485     AutoConnection conn;
     476real getUnitarianRequest(AutoConnection & conn, const size_t & inputId,
     477                         const size_t & productId) {
    486478
    487479    DBQuery query(conn);
     
    509501}
    510502
    511 real computeInputProportionFromSupplier(const std::string & supplierRif,
     503real computeInputProportionFromSupplier(AutoConnection & conn,
     504                                        const std::string & supplierRif,
    512505                                        const std::string & supplierName,
    513506                                        const std::string & nationality,
    514507                                        const size_t & inputId,
    515508                                        const std::string & year) {
    516 
    517     AutoConnection conn;
    518509
    519510    DBQuery query(conn);
     
    565556}
    566557
    567 real computeProportionByTariffCode(const std::string & tariffCode,
     558real computeProportionByTariffCode(AutoConnection & conn,
     559                                   const std::string & tariffCode,
    568560                                   const std::string & rif,
    569561                                   const size_t & productId,
    570562                                   const std::string & year) {
    571 
    572     AutoConnection conn;
    573563
    574564    DBQuery query(conn);
     
    626616}
    627617
    628 void computeArcQuantityUpstream(Good * src, Good * tgt,
     618void computeArcQuantityUpstream(AutoConnection & conn, Good * src, Good * tgt,
    629619                                const std::string & year, ArcInfo & info) {
    630620
     
    652642
    653643    real proportionFromSupplier =
    654         computeInputProportionFromSupplier(rif, companyName, nationality,
     644        computeInputProportionFromSupplier(conn, rif, companyName, nationality,
    655645                                           info.inputId, year);
    656646
    657647    real proportionByTariffCode =
    658         computeProportionByTariffCode(src->getTariffCode(), rif,
     648        computeProportionByTariffCode(conn, src->getTariffCode(), rif,
    659649                                      src->getId(), year);
    660650
     
    665655}
    666656
    667 real getDeclaredBoughtQuantity(const std::string & rif, const long & inputId,
    668                                  const std::string & year) {
    669 
    670     AutoConnection conn;
     657real getDeclaredBoughtQuantity(AutoConnection & conn, const std::string & rif,
     658                               const long & inputId, const std::string & year) {
    671659
    672660    DBQuery query(conn);
     
    703691}
    704692
    705 real computePorportionByProductInput(const long & inputId,
    706                                        const size_t & productId,
    707                                        const std::string & year) {
    708 
    709     AutoConnection conn;
     693real computePorportionByProductInput(AutoConnection & conn,
     694                                     const long & inputId,
     695                                     const size_t & productId,
     696                                     const std::string & year) {
    710697
    711698    DBQuery query(conn);
     
    753740}
    754741
    755 real computeProportionByTartiffCode(const std::string & rif,
    756                                       const std::string & tariffCode,
    757                                       const long & productId,
    758                                       const std::string & year) {
    759 
    760     AutoConnection conn;
     742real computeProportionByTartiffCode(AutoConnection & conn,
     743                                    const std::string & rif,
     744                                    const std::string & tariffCode,
     745                                    const long & productId,
     746                                    const std::string & year) {
    761747
    762748    DBQuery query(conn);
     
    811797}
    812798
    813 void computeArcQuantityDownstream(Good * src, Good * tgt,
     799void computeArcQuantityDownstream(AutoConnection & conn, Good * src, Good * tgt,
    814800                                  const std::string & year, ArcInfo & arcInfo) {
    815801
    816802    real proportionByProductInput =
    817         computePorportionByProductInput(arcInfo.inputId, tgt->getId(), year);
     803        computePorportionByProductInput(conn, arcInfo.inputId, tgt->getId(),
     804                                        year);
    818805
    819806
     
    824811
    825812    real declaredQuantity =
    826         getDeclaredBoughtQuantity(rif, arcInfo.inputId, year);
     813        getDeclaredBoughtQuantity(conn, rif, arcInfo.inputId, year);
    827814
    828815    real proportion = src->getQuantity() / src->getTotalQuantity();
    829816
    830817    real proportionByTartiffCode =
    831         computeProportionByTartiffCode(rif, src->getTariffCode(), src->getId(),
    832                                        year);
     818        computeProportionByTartiffCode(conn, rif, src->getTariffCode(),
     819                                       src->getId(), year);
    833820
    834821    arcInfo.quantity = declaredQuantity * proportion *
     
    839826
    840827    arcInfo.reqQuantity =
    841         getUnitarianRequest(arcInfo.inputId, tgt->getId());
    842 }
    843 
    844 real getAcquisitionPrice(Good * good, const long & id,
    845                            const std::string & year) {
    846 
    847     AutoConnection conn;
     828        getUnitarianRequest(conn, arcInfo.inputId, tgt->getId());
     829}
     830
     831real getAcquisitionPrice(AutoConnection & conn, Good * good, const long & id,
     832                         const std::string & year) {
    848833
    849834    DBQuery query(conn);
     
    878863}
    879864
    880 std::string getCountry(const long & supplierId, const std::string & field) {
    881 
    882     AutoConnection conn;
     865std::string getCountry(AutoConnection & conn, const long & supplierId,
     866                       const std::string & field) {
    883867
    884868    DBQuery query(conn);
     
    908892}
    909893
    910 std::string getOrigCountry(const long & supplierId) {
    911     return getCountry(supplierId, DB::ORIG_COUNTRY_ID);
    912 }
    913 
    914 std::string getProcCountry(const long & supplierId) {
    915     return getCountry(supplierId, DB::PROC_COUNTRY_ID);
    916 }
    917 
    918 void listSuggestedSuppliers(const std::string & tariffCode,
     894std::string getOrigCountry(AutoConnection & conn, const long & supplierId) {
     895    return getCountry(conn, supplierId, DB::ORIG_COUNTRY_ID);
     896}
     897
     898std::string getProcCountry(AutoConnection & conn, const long & supplierId) {
     899    return getCountry(conn, supplierId, DB::PROC_COUNTRY_ID);
     900}
     901
     902void listSuggestedSuppliers(AutoConnection & conn,
     903                            const std::string & tariffCode,
    919904                            const std::string & year,
    920905                            List<ProductInfo> & list) {
    921 
    922     AutoConnection conn;
    923906
    924907    DBQuery query(conn);
     
    949932        long productId = std::atol(query.getValue(0));
    950933
    951         ProductInfo info = loadInfoByProductId(productId);
    952 
    953         getProducedQuantityAndPrice(info, year);
     934        ProductInfo info = loadInfoByProductId(conn, productId);
     935
     936        getProducedQuantityAndPrice(conn, info, year);
    954937
    955938        list.append(info);
     
    957940}
    958941
    959 void listRealProductId(const long & id, const std::string & year,
    960                        List<long> & ids) {
    961 
    962     AutoConnection conn;
     942void listRealProductId(AutoConnection & conn, const long & id,
     943                       const std::string & year, List<long> & ids) {
    963944
    964945    DBQuery query(conn);
     
    1000981}
    1001982
    1002 std::string getInputName(const long & id) {
    1003 
    1004     AutoConnection conn;
     983std::string getInputName(AutoConnection & conn, const long & id) {
    1005984
    1006985    DBQuery query(conn);
     
    10241003}
    10251004
    1026 PlantLocation getPlantLocation(const long & id) {
    1027 
    1028     AutoConnection conn;
     1005PlantLocation getPlantLocation(AutoConnection & conn, const long & id) {
    10291006
    10301007    DBQuery query(conn);
     
    10711048}
    10721049
    1073 std::string getCiiu(const std::string & rif) {
    1074 
    1075     AutoConnection conn;
     1050std::string getCiiu(AutoConnection & conn, const std::string & rif) {
    10761051
    10771052    DBQuery query(conn);
     
    11021077}
    11031078
    1104 real getOperatingStaffNumber(const std::string & rif,
     1079real getOperatingStaffNumber(AutoConnection & conn, const std::string & rif,
    11051080                             const std::string & year) {
    1106 
    1107     AutoConnection conn;
    11081081
    11091082    DBQuery query(conn);
     
    11471120}
    11481121
    1149 real getTotalAmount(const std::string & rif, const std::string & year) {
    1150 
    1151     AutoConnection conn;
     1122real getTotalAmount(AutoConnection & conn, const std::string & rif,
     1123                    const std::string & year) {
    11521124
    11531125    DBQuery query(conn);
     
    11921164}
    11931165
    1194 void listCompaniesLike(const std::string & company,
     1166void listCompaniesLike(AutoConnection & conn, const std::string & company,
    11951167                       List <CompanyRifName> & list) {
    1196 
    1197     AutoConnection conn;
    11981168
    11991169    DBQuery query(conn);
     
    12441214}
    12451215
    1246 void listProductsByCompany(const std::string & rif,
     1216void listProductsByCompany(AutoConnection & conn, const std::string & rif,
    12471217                           List <ProductIdName> & list) {
    1248 
    1249     AutoConnection conn;
    12501218
    12511219    DBQuery query(conn);
     
    12871255}
    12881256
    1289 void setArcMeasurementUnit(ArcInfo & info) {
    1290 
    1291     AutoConnection conn;
     1257void setArcMeasurementUnit(AutoConnection & conn, ArcInfo & info) {
    12921258
    12931259    DBQuery query(conn);
     
    13171283}
    13181284
    1319 void getProductionYears(const long productId, List<std::string> & years) {
    1320 
    1321     AutoConnection conn;
     1285void getProductionYears(AutoConnection & conn, const long productId,
     1286                        List<std::string> & years) {
    13221287
    13231288    DBQuery query(conn);
  • simulacion/SimEscenariosEconomicos/queries.H

    r7941763 r5c51ff9  
    3232
    3333# include <common.H>
     34# include <autoConnection.H>
    3435
    3536/** Encierra una cadena entre comillas simples.
     
    129130 * @return Objeto ProductInfo con toda la información del producto consultado.
    130131 */
    131 ProductInfo loadInfoByProductId(const size_t & id);
     132ProductInfo loadInfoByProductId(AutoConnection & conn, const size_t & id);
    132133
    133134/** Carga la lista de id de los insumos para un producto dado.
     
    138139 *             de los insumos.
    139140 */
    140 void listInputIds(const size_t & productId, const std::string & year,
    141                   List <size_t> & inputIds);
     141void listInputIds(AutoConnection & conn, const size_t & productId,
     142                  const std::string & year, List <size_t> & inputIds);
    142143
    143144/** Carga a todos los proveedores de un insumo dado.
     
    147148 * @param[out] Lista de proveedores del insumo.
    148149 */
    149 void listInputs(const size_t & inputId, const std::string & year,
    150                 List <InputInfo> & inputs);
     150void listInputs(AutoConnection & conn, const size_t & inputId,
     151                const std::string & year, List <InputInfo> & inputs);
    151152
    152153
     
    157158 * @param[out] Lista de productos asociados al insumo.
    158159 */
    159 void productInfoFromInput(const InputInfo & inputInfo,
     160void productInfoFromInput(AutoConnection & conn, const InputInfo & inputInfo,
    160161                          List <ProductInfo> & list);
    161162
     
    168169 *              junto al id que se le asocia como insumo a good por cada uno.
    169170 */
    170 void listRequesters(Good * good, const std::string & year,
     171void listRequesters(AutoConnection & conn, Good * good,
     172                    const std::string & year,
    171173                    List <Aleph::pair<ProductInfo, long>> & list);
    172174
     
    178180 * @return cantidad de insumo para producir una unidad de producto.
    179181 */
    180 real getUnitarianRequest(const size_t & inputId, const size_t & productId);
     182real getUnitarianRequest(AutoConnection & conn, const size_t & inputId,
     183                         const size_t & productId);
    181184
    182185/** Carga la cantidad producida y el precio de un producto en un año dado.
     
    186189 * @param year año de la producción.
    187190 */
    188 void getProducedQuantityAndPrice(Good * good, const std::string & year);
     191void getProducedQuantityAndPrice(AutoConnection & conn, Good * good,
     192                                 const std::string & year);
    189193
    190194
     
    195199 * @param year año de la producción.
    196200 */
    197 void getProducedQuantityAndPrice(ProductInfo & info, const std::string & year);
     201void getProducedQuantityAndPrice(AutoConnection & conn, ProductInfo & info,
     202                                 const std::string & year);
    198203
    199204/** Calcula la cantidad que se le debe asignar a un arco que va hacia aguas
     
    205210 * @param[out] info Referencia a la información del arco
    206211 */
    207 void computeArcQuantityUpstream(Good * src, Good * tgt,
     212void computeArcQuantityUpstream(AutoConnection & conn, Good * src, Good * tgt,
    208213                                const std::string & year, ArcInfo & info);
    209214
     
    215220 * @return cantidad de insumo declarado.
    216221 */
    217 real getDeclaredBoughtQuantity(const std::string & rif, const long & inputId,
    218                                  const std::string & year);
     222real getDeclaredBoughtQuantity(AutoConnection & conn, const std::string & rif,
     223                               const long & inputId, const std::string & year);
    219224
    220225/** Calcula la cantidad que se le debe asignar a un arco que va hacia aguas
     
    227232 * @param[in] year año de la relación.
    228233 */
    229 void computeArcQuantityDownstream(Good * src, Good * tgt,
     234void computeArcQuantityDownstream(AutoConnection & conn, Good * src, Good * tgt,
    230235                                  const std::string & year, ArcInfo & arcInfo);
    231236
     
    238243 * @return precio de compra del insumo.
    239244 */
    240 real getAcquisitionPrice(Good * good, const long & id,
    241                            const std::string & year);
     245real getAcquisitionPrice(AutoConnection & conn, Good * good, const long & id,
     246                         const std::string & year);
    242247
    243248/** Consulta el país de origen de una empresa.
     
    246251 * @return nombre del país de origen.
    247252 */
    248 std::string getOrigCountry(const long & supplierId);
     253std::string getOrigCountry(AutoConnection & conn, const long & supplierId);
    249254
    250255/** Consulta el país de procedencia de una empresa.
     
    253258 * @return nombre del país de procedencia.
    254259 */
    255 std::string getProcCountry(const long & supplierId);
     260std::string getProcCountry(AutoConnection & conn, const long & supplierId);
    256261
    257262/** Carga una lista de posibles proveedores para un insumo.
     
    261266 * @param[out] list Lista de posibles proveedores.
    262267 */
    263 void listSuggestedSuppliers(const std::string & tariffCode,
     268void listSuggestedSuppliers(AutoConnection & conn,
     269                            const std::string & tariffCode,
    264270                            const std::string & year,
    265271                            List<ProductInfo> & list);
     
    271277 * @param[out] ids lista de id de los productos.
    272278 */
    273 void listRealProductId(const long & id, const std::string & year,
    274                        List<long> & ids);
     279void listRealProductId(AutoConnection & conn, const long & id,
     280                       const std::string & year, List<long> & ids);
    275281
    276282/** Consulta el nombre de un insumo.
     
    279285 * @return nombre del insumo.
    280286 */
    281 std::string getInputName(const long & id);
     287std::string getInputName(AutoConnection & conn, const long & id);
    282288
    283289/** Consulta la ubicación de una planta.
     
    293299 * @return valor del CIIU de la actividad económica.
    294300 */
    295 std::string getCiiu(const std::string & rif);
     301std::string getCiiu(AutoConnection & conn, const std::string & rif);
    296302
    297303/** Consulta la cantidad de emplados operativos de una unidad económica.
     
    301307 *  @return cantidad de empleados en la unidad económica.
    302308 */
    303 real getOperatingStaffNumber(const std::string & rif, const std::string & year);
     309real getOperatingStaffNumber(AutoConnection & conn, const std::string & rif,
     310                             const std::string & year);
    304311
    305312/** Consulta el monto total producido por una empresa en un año dado.
     
    309316 *  @return monto total producido por la empresa.
    310317 */
    311 real getTotalAmount(const std::string & rif, const std::string & year);
     318real getTotalAmount(AutoConnection & conn, const std::string & rif,
     319                    const std::string & year);
    312320
    313321/** Extrae los años para los cuales existe una producción.
     
    316324 * @param[out] years Lista de años para los cuales hay producción declarada.
    317325 */
    318 void getProductionYears(const long productId, List<std::string> & years);
     326void getProductionYears(AutoConnection & conn, const long productId,
     327                        List<std::string> & years);
    319328
    320329struct CompanyRifName {
     
    329338 * @param[out] list Lista de pares (rif, nombre) de cada empresa coincidente.
    330339 */
    331 void listCompaniesLike(const std::string & company,
     340void listCompaniesLike(AutoConnection & conn, const std::string & company,
    332341                       List <CompanyRifName> & list);
    333342
     
    345354 * @param[out] list Lista de pares (id, nombre) de cada cada producto.
    346355 */
    347 void listProductsByCompany(const std::string & rif,
     356void listProductsByCompany(AutoConnection & conn, const std::string & rif,
    348357                           List <ProductIdName> & list);
    349358
    350 void setArcMeasurementUnit(ArcInfo & info);
     359void setArcMeasurementUnit(AutoConnection & conn, ArcInfo & info);
    351360
    352361# endif // QUERIES_H
  • simulacion/SimEscenariosEconomicos/simulator.C

    r6c79fb4 r5c51ff9  
    607607struct MakeSuggestions {
    608608
     609    AutoConnection & conn;
     610
    609611    Graph & g;
    610612
     
    619621    ArcsIndex & arcsIndex;
    620622
    621     MakeSuggestions(Graph & _g, Graph::Node * _tgt, SuggestionBuffer & _buffer,
     623    MakeSuggestions(AutoConnection & _conn,
     624                    Graph & _g, Graph::Node * _tgt, SuggestionBuffer & _buffer,
    622625                    const std::string & _year, MapProductNode & _mapProductNode,
    623626                    ArcsIndex & _arcsIndex)
    624         : g(_g), tgt(_tgt), buffer(_buffer), year(_year),
     627        : conn(_conn), g(_g), tgt(_tgt), buffer(_buffer), year(_year),
    625628          mapProductNode(_mapProductNode), arcsIndex(_arcsIndex) {
    626629
     
    639642            ptrSuggestions = buffer.insert(group.tariffCode, SuggestionList());
    640643
    641             listSuggestedSuppliers(group.tariffCode, year, *ptrSuggestions);
     644            listSuggestedSuppliers(conn, group.tariffCode, year,
     645                                   *ptrSuggestions);
    642646        }
    643647
     
    647651        List <long> ids;
    648652
    649         listRealProductId(id, year, ids);
     653        listRealProductId(conn, id, year, ids);
    650654
    651655        for (SuggestionList::Iterator it(*ptrSuggestions); it.has_current(); ){
     
    778782struct SuggestImport {
    779783
     784    AutoConnection & conn;
     785
    780786    Graph & g;
    781787
     
    784790    MapImports & map;
    785791
    786     SuggestImport(Graph & _g, Graph::Node * _tgt, MapImports & _map)
    787         : g(_g), tgt(_tgt), map(_map) {
     792    SuggestImport(AutoConnection & _conn,
     793                  Graph & _g, Graph::Node * _tgt, MapImports & _map)
     794        : conn(_conn), g(_g), tgt(_tgt), map(_map) {
    788795
    789796        // Empty
     
    802809
    803810            input->setQuantity(group.neededQuantity);
    804             input->setName(getInputName(id));
     811            input->setName(getInputName(conn, id));
    805812
    806813            Company company;
     
    882889    queue.put(start);
    883890
     891    AutoConnection conn;
     892
    884893    while (not queue.is_empty()) {
    885894
     
    900909        mapGroupArcs.for_each(PutSuppliersInQueue(g, queue));
    901910
    902         mapGroupArcs.for_each(MakeSuggestions(g, p, buffer, year,
     911        mapGroupArcs.for_each(MakeSuggestions(conn, g, p, buffer, year,
    903912                                              mapProductNode, arcsIndex));
    904913
    905         mapGroupArcs.for_each(SuggestImport(g, p, mapImports));
     914        mapGroupArcs.for_each(SuggestImport(conn, g, p, mapImports));
    906915
    907916    }
Note: See TracChangeset for help on using the changeset viewer.