source: observatorio/simulacion/SimEscenariosEconomicos/common.C

simulacion
Last change on this file was 76e705a, checked in by Alejandro <amujica@…>, 10 years ago

Agregada a los graficos la leyenda con los parametros bajo los cuales son generados

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*
2  Copyright (C) 2012
3  Alejandro Mujica (amujica@cenditel.gob.ve)
4  Erwin Paredes (eparedes@cenditel.gob.ve)
5  José Ruiz (jruiz@cenditel.gob.ve)
6  Rodolfo Rangel (rrangel@cenditel.gob.ve)
7  Julie Vera (jvera@cenditel.gob.ve)
8 
9  CENDITEL Fundación Centro Nacional de Desarrollo e Investigación en
10  Tecnologías Libres
11 
12  Este programa es software libre; Usted puede usarlo bajo los términos de la
13  licencia de software GPL versión 2.0 de la Free Software Foundation.
14 
15  Este programa se distribuye con la esperanza de que sea útil, pero SIN
16  NINGUNA GARANTÍA; tampoco las implícitas garantías de MERCANTILIDAD o
17  ADECUACIÓN A UN PROPÓSITO PARTICULAR.
18  Consulte la licencia GPL para más detalles. Usted debe recibir una copia
19  de la GPL junto con este programa; si no, escriba a la Free Software
20  Foundation Inc. 51 Franklin Street,5 Piso, Boston, MA 02110-1301, USA.
21*/
22
23/*
24  Autor:             Alejandro J. Mujica
25  Fecha de creación: 22/07/2013
26  Este archivo contiene asignaciones de valores a constantes e implementación
27  de funciones y algunos tipos de datos utilitarios.
28*/
29
30# include <ctime>
31# include <cassert>
32# include <cstring>
33
34# include <common.H>
35# include <queries.H>
36
37const std::string DB::PRODUCT_TABLE_NAME = "produccion_producto";
38
39const std::string DB::INPUT_TABLE_NAME = "produccion_insumo";
40
41const std::string DB::PLANT_TABLE_NAME = "unidadecon_subunidad_economica";
42
43const std::string DB::COMPANY_TABLE_NAME = "unidadecon_unidad_economica";
44
45const std::string DB::COMPANY_ACTIVITY_CIIU_TABLE_NAME =
46    "unidadecon_actividad_ciiu";
47
48const std::string DB::PRODUCT_INPUT_TABLE_NAME = "produccion_producto_t_insumo";
49
50const std::string DB::MEASUREMENT_UNIT_TABLE_NAME = "comun_unida_medida";
51
52const std::string DB::INPUT_SUPPLIER_TABLE_NAME =
53    "cmproveedores_proveedorinsumo";
54
55const std::string DB::SUPPLIER_TABLE_NAME = "cmproveedores_proveedor";
56
57const std::string DB::PRODUCTION_QUANTITIES_TABLE_NAME =
58    "produccion_produccion_precios_r";
59
60const std::string DB::ACQ_PRICE_TABLE_NAME = "produccion_consumo_precios_r";
61
62const std::string DB::COUNTRY_TABLE_NAME = "comun_pais";
63
64 const std::string DB::PARISH_TABLE_NAME = "comun_parroquia";
65
66const std::string DB::TOWN_TABLE_NAME = "comun_municipio";
67
68const std::string DB::STATE_TABLE_NAME = "comun_entidad";
69
70const std::string DB::COMPANY_OCCUPANCY_TABLE_NAME =
71    "unidadecon_personal_ocupado";
72
73const std::string DB::ID = "id";
74
75const std::string DB::NAME = "nombre";
76
77const std::string DB::COMPANY_NAME = "razon_social";
78
79const std::string DB::TECHNICAL_SPECIFICATION = "esp_tec";
80
81const std::string DB::TARIFF_CODE = "codigo_aran_id";
82
83const std::string DB::MEASUREMENT_UNIT_ID = "unidad_medida_id";
84
85const std::string DB::TRADEMARK = "marca";
86
87const std::string DB::PLANT_ID = "planta_id_id";
88
89const std::string DB::CODE = "codigo";
90
91const std::string DB::PARISH_CODE = "parroquia_codigo";
92
93const std::string DB::TOWN_CODE = "municipio_codigo";
94
95const std::string DB::STATE_CODE = "entidad_codigo";
96
97const std::string DB::COMPANY_RIF = "unidad_economica_rif";
98
99const std::string DB::UE_RIF = "ue_rif";
100
101const std::string DB::RIF = "rif";
102
103const std::string DB::NATIONALITY = "nacional";
104
105const std::string DB::ACQ_PRICE = "cost_adq";
106
107const std::string DB::NAC_ACQ_PRICE = "prec_adq_nac";
108
109const std::string DB::CIIU_ID = "ciiu_id";
110
111const std::string DB::ACTIVE = "activo";
112
113const std::string DB::MAIN = "principal";
114
115const std::string DB::INPUT_ID = "insumo_id_id";
116
117const std::string DB::PRODUCT_ID = "producto_id_id";
118
119const std::string DB::SUPPLIER_ID = "proveedor_id_id";
120
121const std::string DB::PRODUCED_QUANTITY = "cant_producido";
122
123const std::string DB::PRICE = "precio_venta";
124
125const std::string DB::BOUGHT_QUANTITY = "cantidad_comprada_r";
126
127const std::string DB::QUANTITY = "cantidad";
128
129const std::string DB::ORIG_COUNTRY_ID= "pais_origen_id";
130
131const std::string DB::PROC_COUNTRY_ID = "pais_procedencia_id";
132
133const std::string DB::YEAR_R = "anho_r";
134
135const std::string DB::YEAR = "anho";
136
137const std::string DB::USED_CAPACITY = "capacidad_utilizada";
138
139const std::string DB::INSERTION_DATE = "fecha_insercion";
140
141const std::string DB::OPERATING = "operativo";
142
143const std::string DotColor::COLORS[] = {
144    "black",
145    "blue",
146    "darkolivegreen",
147    "blueviolet",
148    "brown",
149    "indigo",
150    "orangered",
151    "steelblue",
152    "seagreen",
153    "hotpink",
154    "magenta",
155    "purple",
156    "red",
157    "darkslategray",
158    "midnightblue"
159};
160
161const std::string & DotColor::operator () (const size_t & i) {
162    if (i >= DotColor::NUM_COLORS)
163        throw std::overflow_error("i is greater than num_colors");
164
165    return DotColor::COLORS[i];
166}
167
168ProductInfo::ProductInfo()
169    : plantId(-1), plantName("NULL"), usedCapacity(0), INIT_COMPANY_ATTRS,
170      productId(-1), INIT_GOOD_ATTRS {
171
172    // Empty
173}
174
175InputInfo::InputInfo()
176    : INIT_COMPANY_ATTRS, id(-1), INIT_GOOD_ATTRS {
177    // Empty
178}
179
180ProductInfo inputToProduct(const InputInfo & input) {
181    ProductInfo product;
182
183    product.name = input.name;
184    product.technicalSpecifications = input.technicalSpecifications;
185    product.tariffCode = input.tariffCode;
186    product.measurementUnit = input.measurementUnit;
187    product.trademark = input.trademark;
188    product.companyRif = input.companyRif;
189    product.companyName = input.companyName;
190    product.quantity = input.quantity;
191    product.totalQuantity = input.totalQuantity;
192    product.nationality = input.nationality;
193    product.origCountry = input.origCountry;
194    product.procCountry = input.procCountry;
195
196//    product.origCountry = getOrigCountry(product.companyRif);
197//    product.procCountry = getProcCountry(product.companyRif);
198
199    return product;
200}
201
202AlterInfo::AlterInfo()
203    : numNode(-1), value(0) {
204
205    // Empty
206}
207
208PlantLocation::PlantLocation()
209    : parish(""), town(""), state("") {
210
211    // Empty
212}
213
214std::string numtostrRec(const long long & num, const char & thousandSep) {
215
216    if (num < 1000) {
217
218        std::stringstream sstr;
219
220        sstr << num;
221
222        return sstr.str();
223    }
224
225    real aux = real(num) / 1000.0;
226
227    long long intPart = (long long) aux;
228
229    aux -= intPart;
230
231    long long extract = aux * 1000;
232
233    std::stringstream sstr;
234
235    sstr << extract;
236
237    std::string str = sstr.str();
238
239    if (extract < 100.0L) {
240        str = "0" + str;
241    }
242
243    if (extract < 10.0L) {
244        str = "0" + str;
245    }
246
247    return numtostrRec(intPart, thousandSep) + thousandSep + str;
248}
249
250std::string numtostr(const real & _num, const int & numDec,
251                     const char & thousandSep, const char & decSep) {
252
253    std::string sign = _num < 0.0L ? "-" : "";
254
255    real num = std::fabs(_num);
256
257    real numRound = std::pow(10, numDec);
258
259    num *= numRound;
260
261    num = std::round(num);
262
263    num /= numRound;
264
265    long long intPart = (long long) num;
266
267    real dec = num - intPart;
268
269    if (dec < 1e-5)
270        dec = 0;
271
272    char buffer[256];
273
274    sprintf(buffer, "%g", dec);
275
276    std::string strDec = buffer;
277
278    std::string ret = numtostrRec(intPart, thousandSep);
279
280    if (strDec.size() > 2)
281        ret += decSep +  strDec.substr(2, strDec.size() - 2);
282
283    return sign + ret;
284}
285
286void modStr(std::string & str) {
287
288    size_t pos;
289
290    while ((pos = str.find('<')) != std::string::npos)
291        str.replace(pos, 1, "&lt;");
292
293    while ((pos = str.find('>')) != std::string::npos)
294        str.replace(pos, 1, "&gt;");
295
296    for (size_t i = 0; i < str.size(); ++i) {
297
298        if (str[i] == '\"') {
299            str.replace(i, 1, "\\\"");
300            ++i;
301        }
302        else if (str[i] == '\n') {
303            str.replace(i, 1, "\\n");
304            ++i;
305        }
306    }
307}
308
309std::string currentTime()
310{
311  time_t now = time(0);
312
313  struct tm * st_now = localtime(&now);
314
315  std::stringstream sstr;
316
317  sstr << st_now->tm_mday << "/" << st_now->tm_mon + 1 << "/"
318       << st_now->tm_year + 1900 << " " << st_now->tm_hour << ":"
319       << st_now->tm_min << ":" << st_now->tm_sec;
320
321  return sstr.str();
322}
323
Note: See TracBrowser for help on using the repository browser.