Changeset 3083 for TOOLS/ConsoGENCI
- Timestamp:
- 01/12/17 12:01:53 (6 years ago)
- Location:
- TOOLS/ConsoGENCI/trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/ConsoGENCI/trunk/bin/insert_conso_tbl.py
r2783 r3083 68 68 69 69 if not filelist: 70 print("No files found, exit")70 print("No input files found, exit") 71 71 exit(1) 72 72 -
TOOLS/ConsoGENCI/trunk/bin/libconso.py
r2783 r3083 11 11 12 12 # this must come first 13 from __future__ import print_function, unicode_literals, division 13 # from __future__ import print_function, unicode_literals, division 14 from __future__ import print_function, division 14 15 15 16 # standard library imports … … 25 26 # Application library imports 26 27 28 ######################################################################## 29 30 # .. Constants and variables .. 31 # ============================= 32 cm2in = 1. / 2.54 33 27 34 28 35 ######################################################################## … … 34 41 return 35 42 36 # .. Co py pdf file to dods server..43 # .. Convert pdf to temporary png .. 37 44 # ================================== 45 import matplotlib.pyplot as plt 46 47 img_png = img_out.replace(".pdf", "_tmp.png") 48 dpi = 200. 49 50 plt.savefig( 51 img_png, 52 dpi=dpi, 53 format="png", 54 # transparent=True, 55 # bbox_inches="tight", 56 # pad_inches=0.2 * cm2in, 57 ) 58 59 # .. Copy files to dods server .. 60 # =============================== 61 # ... pdf file ... 62 # ---------------- 38 63 command = [ 39 64 "scp", … … 46 71 ] 47 72 print(command) 48 try 73 try: 49 74 subprocess.call(command) 50 except Exception as rc 75 except Exception as rc: 51 76 print("Error in scp for {}:\n{}".format(command, rc)) 52 77 53 # .. Convert pdf to temporary png .. 54 # ================================== 55 img_png = img_out.replace(".pdf", ".png") 56 command = ["convert", "-density", "200", img_out, img_png] 57 58 print(command) 59 try : 60 subprocess.call(command) 61 except Exception as rc : 62 print("Error in convert for {}:\n{}".format(img_out, rc)) 63 64 # .. Copy png file to dods server .. 65 # ================================== 78 # ... png file ... 79 # ---------------- 66 80 command = [ 67 81 "scp", … … 75 89 76 90 print(command) 77 try 91 try: 78 92 subprocess.call(command) 79 except Exception as rc 93 except Exception as rc: 80 94 print("Error in scp for {}:\n{}".format(command, rc)) 81 95 … … 121 135 if DIR[option] and not os.path.isdir(DIR[option]): 122 136 print("mkdir {}".format(DIR[option])) 123 try 137 try: 124 138 os.makedirs(DIR[option]) 125 except Exception as rc 139 except Exception as rc: 126 140 print("Could not create {}:\n{}".format(DIR[option], rc)) 127 141 … … 234 248 235 249 ######################################################################## 236 def plot_save(img_out, title): 237 """ 238 """ 250 def plot_save(img_out, title, png=False): 251 """ 252 """ 253 import matplotlib.pyplot as plt 239 254 from matplotlib.backends.backend_pdf import PdfPages 240 255 … … 244 259 if not os.path.isdir(dirname): 245 260 print("mkdir {}".format(dirname)) 246 try 261 try: 247 262 os.makedirs(dirname) 248 except Exception as rc 263 except Exception as rc: 249 264 print("Could not create {}:\n{}".format(dirname, rc)) 265 266 if png: 267 img_png = img_out.replace(".pdf", ".png") 268 plt.savefig( 269 img_png, 270 dpi=dpi, 271 format="png", 272 # transparent=True, 273 # bbox_inches="tight", 274 # pad_inches=0.2 * cm2in, 275 ) 250 276 251 277 with PdfPages(img_out) as pdf: … … 270 296 class AllocItem(object): 271 297 272 # ---------------------------------------------------------------------298 # -------------------------------------------------------------------- 273 299 def __init__( 274 300 self, … … 293 319 self.daily_conso = self.alloc / self.days 294 320 295 # ---------------------------------------------------------------------321 # -------------------------------------------------------------------- 296 322 def __repr__(self): 297 323 return "{} ({:%Y%m%d}/{:%Y%m%d}): {}".format( … … 306 332 class Project(object): 307 333 308 # ---------------------------------------------------------------------334 # -------------------------------------------------------------------- 309 335 def __init__(self, project_name, center): 310 336 self.project = project_name … … 312 338 self.alloc_items = [] 313 339 314 # ---------------------------------------------------------------------340 # -------------------------------------------------------------------- 315 341 def __repr__(self): 316 342 return "{}/{}: {}".format( … … 320 346 ) 321 347 322 # ---------------------------------------------------------------------348 # -------------------------------------------------------------------- 323 349 def add_alloc( 324 350 self, … … 362 388 self.nb_alloc = len(self.alloc_items) 363 389 364 # ---------------------------------------------------------------------390 # -------------------------------------------------------------------- 365 391 def get_theo_eq(self, dates): 366 392 … … 399 425 y0 = yf 400 426 401 # ---------------------------------------------------------------------427 # -------------------------------------------------------------------- 402 428 def fill_data(self, row): 403 429 # self.id = row["id"] … … 414 440 ######################################################################## 415 441 class SizeUnit(object): 416 # ---------------------------------------------------------------------442 # -------------------------------------------------------------------- 417 443 def __init__(self, size, unit): 418 444 self.size = size 419 445 self.unit = unit 420 446 421 # ---------------------------------------------------------------------447 # -------------------------------------------------------------------- 422 448 def __repr__(self): 423 449 return "{:6.2f}{}o".format(self.size, self.unit) 424 450 425 # ---------------------------------------------------------------------451 # -------------------------------------------------------------------- 426 452 def convert_size(self, unit_out): 427 453 """ -
TOOLS/ConsoGENCI/trunk/bin/libconso_cpt.py
r2783 r3083 19 19 20 20 # This must come first 21 from __future__ import print_function, unicode_literals, division 21 # from __future__ import print_function, unicode_literals, division 22 from __future__ import print_function, division 22 23 23 24 # Standard library imports -
TOOLS/ConsoGENCI/trunk/bin/libconso_db.py
r2783 r3083 19 19 20 20 # This must come first 21 from __future__ import print_function, unicode_literals, division 21 # from __future__ import print_function, unicode_literals, division 22 from __future__ import print_function, division 22 23 23 24 # Standard library imports … … 35 36 ) 36 37 37 # # Print the connection string we will use to connect 38 # print("Connecting to database\n -> {}".format(conn_string)) 38 # Print the connection string we will use to connect 39 print("Connecting to database\n -> {}".format( 40 conn_string.replace(db_pwd, "*****") 41 ) 42 ) 39 43 40 44 # Get a connection, if a connect cannot be made an exception will be 41 45 # raised here 42 try 46 try: 43 47 conn = psycopg2.connect(conn_string) 44 48 except Exception as rc: -
TOOLS/ConsoGENCI/trunk/bin/plot_bilan.py
r2783 r3083 10 10 # ==================================================================== # 11 11 12 # ==================================================================== # 13 # ssh readonly@prodiguer-test-db.ipsl.upmc.fr # 14 # psql -U prodiguer_db_user prodiguer # 15 # # 16 # ssh readonly@prodiguer-test-db.ipsl.upmc.fr -L 5432:localhost:5432 # 17 # psql -h prodiguer-test-db.ipsl.upmc.fr -U prodiguer_db_user prodiguer 18 # ==================================================================== # 19 12 20 # this must come first 13 21 from __future__ import print_function, unicode_literals, division 22 # from __future__ import print_function, division 14 23 15 24 # standard library imports … … 26 35 ######################################################################## 27 36 class PlotData(object): 28 # ---------------------------------------------------------------------37 # -------------------------------------------------------------------- 29 38 def __init__(self, date_min, date_max): 30 39 self.date_min = date_min … … 37 46 ######################################################################## 38 47 class DataDict(dict): 39 # ---------------------------------------------------------------------48 # -------------------------------------------------------------------- 40 49 def __init__(self): 41 50 self = {} 42 51 43 # ---------------------------------------------------------------------52 # -------------------------------------------------------------------- 44 53 def init_range(self, date_beg, date_end, inc=1): 45 54 """ … … 55 64 self.add_item(date) 56 65 57 # ---------------------------------------------------------------------66 # -------------------------------------------------------------------- 58 67 def fill_data(self, projet): 59 68 """ … … 71 80 ) 72 81 82 if args.subproject: 83 subp_condition = "sub_project = \'{}\'".format(args.subproject) 84 else: 85 subp_condition = "sub_project IS NULL" 86 73 87 table_name = "conso.tbl_consumption" 74 88 request = ( … … 76 90 "FROM " + table_name + " " 77 91 "WHERE login IS NULL " 92 # " AND sub_project IS NULL " 93 " AND " + subp_condition + " " 78 94 " AND " + id_condition + " " 79 95 "ORDER BY date" … … 83 99 if args.verbose: 84 100 print("Access table \"{}\"".format(table_name)) 85 print(request)86 101 cdb.select_db(cursor, request) 87 102 … … 96 111 self[date.date()].fill() 97 112 98 # ---------------------------------------------------------------------113 # -------------------------------------------------------------------- 99 114 def add_item(self, date, conso=np.nan, 100 115 real_use=np.nan, theo_use=np.nan, … … 111 126 ) 112 127 113 # ---------------------------------------------------------------------128 # -------------------------------------------------------------------- 114 129 def get_items_in_range(self, date_beg, date_end, inc=1): 115 130 """ … … 122 137 return items[::inc] 123 138 124 # ---------------------------------------------------------------------139 # -------------------------------------------------------------------- 125 140 def get_items_in_full_range(self, inc=1): 126 141 """ … … 132 147 return items[::inc] 133 148 134 # ---------------------------------------------------------------------149 # -------------------------------------------------------------------- 135 150 def get_items(self, inc=1): 136 151 """ … … 144 159 145 160 class Conso(object): 146 # ---------------------------------------------------------------------161 # -------------------------------------------------------------------- 147 162 def __init__(self, date, conso=np.nan, 148 163 real_use=np.nan, theo_use=np.nan, 149 164 run_mean=np.nan, pen_mean=np.nan, 150 165 run_std=np.nan, pen_std=np.nan): 151 self.date = date152 self.conso = conso153 self.real_use = real_use154 self.theo_use = theo_use155 self.poly_theo = np.poly1d([])166 self.date = date 167 self.conso = conso 168 self.real_use = real_use 169 self.theo_use = theo_use 170 self.poly_theo = np.poly1d([]) 156 171 self.poly_delay = np.poly1d([]) 157 self.run_mean = run_mean158 self.pen_mean = pen_mean159 self.run_std = run_std160 self.pen_std = pen_std161 self.filled = False162 163 # ---------------------------------------------------------------------172 self.run_mean = run_mean 173 self.pen_mean = pen_mean 174 self.run_std = run_std 175 self.pen_std = pen_std 176 self.filled = False 177 178 # -------------------------------------------------------------------- 164 179 def __repr__(self): 165 180 return "{:.2f} ({:.2%})".format(self.conso, self.real_use) 166 181 167 # ---------------------------------------------------------------------182 # -------------------------------------------------------------------- 168 183 def isfilled(self): 169 184 return self.filled 170 185 171 # ---------------------------------------------------------------------186 # -------------------------------------------------------------------- 172 187 def fill(self): 173 188 self.filled = True … … 177 192 def plot_init(): 178 193 paper_size = np.array([29.7, 21.0]) 179 fig, ax_conso = plt.subplots(figsize=(paper_size/2.54)) 194 fig, ax_conso = plt.subplots(figsize=(paper_size * cm2in)) 195 # fig, ax_conso = plt.subplots(figsize=(paper_size/2.54)) 180 196 ax_theo = ax_conso.twinx() 181 197 … … 329 345 if d.weekday() == 0: 330 346 ax_conso.axvline( 331 x=x, color=" black", alpha=0.5,347 x=x, color="gray", alpha=0.5, 332 348 linewidth=0.5, linestyle=":" 333 349 ) … … 393 409 parser.add_argument("project", action="store", 394 410 help="Project name") 395 parser.add_argument("center", action="store", 396 help="Center name (idris/tgcc)") 411 parser.add_argument("centre", action="store", 412 choices=["idris", "tgcc"], 413 help="Centre name") 414 parser.add_argument( 415 "node", action="store", default="thin/standard", 416 choices=["thin/standard", "standard", "fat/large", "hybrid"], 417 help="Node type" 418 ) 419 420 parser.add_argument("--subproject", action="store", 421 type=str, default=None, 422 help="Sub-project") 397 423 398 424 parser.add_argument("-v", "--verbose", action="store_true", … … 400 426 parser.add_argument("-f", "--full", action="store_true", 401 427 help="plot the whole period") 428 parser.add_argument("--png", action="store_true", 429 help="pgn output in addition to pdf") 402 430 parser.add_argument("-i", "--increment", action="store", 403 431 type=int, default=1, dest="inc", … … 448 476 config_file = os.path.join( 449 477 "card", 450 "config_{}_{}.ini".format(args.cent er, args.project)478 "config_{}_{}.ini".format(args.centre, args.project) 451 479 ) 452 480 … … 461 489 # [OUT["PARAM"], OUT["UTHEO"], OUT["BILAN"]]) 462 490 463 img_name = "{}_{}_{} ".format(491 img_name = "{}_{}_{}_{}_{}".format( 464 492 os.path.splitext( 465 493 os.path.basename(__file__) 466 494 )[0].replace("plot_", ""), 495 args.centre, 467 496 args.project, 468 args.center, 497 args.subproject if args.subproject else args.project, 498 args.node.replace("/", ""), 469 499 ) 470 500 … … 509 539 "FROM " + table_name + " " 510 540 "WHERE project = '" + args.project + "' " 541 "AND node_type = '" + args.node + "' " 542 "AND is_active = TRUE " 511 543 "ORDER BY start_date" 512 544 ";" … … 518 550 # print(cursor.description) 519 551 520 projet = Project(args.project, args.cent er)552 projet = Project(args.project, args.centre) 521 553 for row in cursor: 522 554 if (bilan_plot.date_min >= row["start_date"].date() and … … 572 604 projet.get_theo_eq(dates) 573 605 574 cumul = np.array([item.conso for item in selected_items], 575 dtype=float) 606 cumul = np.array( 607 [item.conso for item in selected_items], 608 dtype=float 609 ) 576 610 consos = [] 577 611 consos.append(cumul[0]) … … 595 629 theo_uses.append(100. * poly_theo(dates.index(date))) 596 630 real_uses2.append((100 * cumul[idx]) / alloc_val) 597 delay_uses = delay * [0., ] + theo_uses[:-delay] 631 632 if nb_items > delay: 633 delay_uses = delay * [0., ] + theo_uses[:-delay] 634 else: 635 delay_uses = nb_items * [0., ] 636 598 637 theo_uses = np.array(theo_uses, dtype=float) 599 638 delay_uses = np.array(delay_uses, dtype=float) … … 632 671 # ... Tweak figure ... 633 672 # -------------------- 634 title = "Consommation {})".format( 635 projet.project.upper(), 673 proj_title = args.subproject if args.subproject else projet.project 674 title = "Consommation {}".format( 675 # projet.project.upper(), 676 proj_title.upper() 636 677 ) 637 678 faitle = "(le {:%d/%m/%Y})".format( … … 649 690 if args.range: 650 691 img_out = os.path.join( 651 DIR["PLOT"], args.cent er, args.project,692 DIR["PLOT"], args.centre, args.project, 652 693 "{}_{:%Y%m%d}_{:%Y%m%d}.pdf".format(img_name, *args.range) 653 694 ) 654 695 else: 655 696 img_out = os.path.join( 656 DIR["PLOT"], args.cent er, args.project,697 DIR["PLOT"], args.centre, args.project, 657 698 "{}_{:%Y%m%d}.pdf".format(img_name, today) 658 699 ) 659 700 if args.verbose: 660 701 print("Save image as {}".format(img_out)) 661 662 plot_save(img_out, title) 702 if args.png: 703 print("Produce png") 704 705 title = "Consommation {} ({}) au {:%Y%m%d}".format( 706 args.project.upper(), 707 args.centre.upper(), 708 today 709 ) 710 plot_save(img_out, title, png=args.png) 663 711 664 712 # ... Publish figure on dods ... -
TOOLS/ConsoGENCI/trunk/card/config_center_project.ini.init
r2775 r3083 1 1 [projet] 2 name :project_name2 name = project_name 3 3 4 4 [directories] 5 ROOT_DIR :/path/to/ConsoGENCI6 DATA :%(ROOT_DIR)s/data7 PLOT :%(ROOT_DIR)s/plot5 ROOT_DIR = /path/to/ConsoGENCI 6 DATA = %(ROOT_DIR)s/data 7 PLOT = %(ROOT_DIR)s/plot 8 8 DODS 9 9 10 10 [dods] 11 DIR :/path/to/dods/ConsoGENCI12 USER :user13 SERVER :host11 DIR = /path/to/dods/ConsoGENCI 12 USER = user 13 SERVER = host -
TOOLS/ConsoGENCI/trunk/launch_conso.sh
r2783 r3083 13 13 # ====================================================================== 14 14 15 date 16 whereami=$( hostname -s ) 17 15 18 # set -vx 16 17 whereami=$( hostname -s )18 19 19 20 # .. System dependant steps .. … … 51 52 BIN_DIR=${ROOT_DIR}/bin 52 53 53 declare -A proj_center=(["genc imp6"]="tgcc" ["rgzi"]="idris")54 declare -A proj_center=(["gencmip6"]="tgcc" ["rgzi"]="idris") 54 55 55 56 for projet in "${!proj_center[@]}"
Note: See TracChangeset
for help on using the changeset viewer.