source: observatorio/simulacion/ModuloDinamico/compute_exchange.C

simulacion
Last change on this file was 4b459a7, checked in by Alejandro <amujica@…>, 9 years ago

Modulo de calculo de divisas por producto y envoltorio python

  • Property mode set to 100644
File size: 1.9 KB
Line 
1# include <limits>
2# include <iostream>
3
4# include <dbProperties.H>
5
6# include <compute_exchange.H>
7
8double compute_exchange_by_product(const unsigned long long & product_id,
9                                   const char * const year,
10                                   const double & exchange_type,
11                                   const char * const host,
12                                   const char * const port,
13                                   const char * const dbname,
14                                   const char * const username,
15                                   const char * const password)
16{
17  DBProperties & dbProp = DBProperties::getInstance();
18
19  dbProp.setHost(host);
20  dbProp.setPort(port);
21  dbProp.setDbname(dbname);
22  dbProp.setUser(username);
23  dbProp.setPassword(password);
24
25  IO_Manager io_manager;
26
27  const int levels_up = std::numeric_limits<int>::max();
28
29  const int levels_down = 0;
30
31  char * const xml_root = "temp.xml";
32
33  io_manager.create_xml_root_file(year, product_id, levels_up, levels_down,
34                                  xml_root);
35
36  double ret_val = 0.0;
37
38  try
39  {
40    Graph graph;
41
42    io_manager.build_graph(xml_root, graph);
43
44    for (Graph::Node_Iterator it(graph); it.has_current(); it.next())
45      {
46        Graph::Node * node = it.get_current();
47
48        if (node->get_info()->get_type() != IMPORTED_PRODUCT)
49          continue;
50
51        for (Graph::Node_Arc_Iterator arc_it(node); arc_it.has_current();
52             arc_it.next())
53          {
54            Graph::Arc * arc = arc_it.get_current();
55
56            IP_Relationship & ip_rel = arc->get_info();
57
58            ret_val += (ip_rel.get_bought_quantity() *
59                        ip_rel.get_purchase_price()) / exchange_type;
60          }
61      }
62  }
63  catch (const std::exception & e)
64  {
65    std::cout << "Excepción capturada: " << e.what() << std::endl;
66  }
67
68  remove(xml_root);
69
70  return ret_val; 
71}
72
Note: See TracBrowser for help on using the repository browser.