Changeset 2776 for TOOLS/ConsoGENCI/trunk/bin
- Timestamp:
- 03/15/16 10:59:31 (8 years ago)
- Location:
- TOOLS/ConsoGENCI/trunk/bin
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/ConsoGENCI/trunk/bin/init_alloc_tbl.py
r2775 r2776 21 21 22 22 # standard library imports 23 # from pprint import pprint24 23 25 24 # Application library imports … … 115 114 ] 116 115 117 # Connection info118 # db_host = "134.157.170.104"119 # # db_port = "5432"120 # db_name = "prodiguer"121 # db_user = "prodiguer_db_user"122 # # db_pwd = "secret"123 124 116 conn, cursor = cdb.connect_db( 125 117 db_data.db_host, -
TOOLS/ConsoGENCI/trunk/bin/init_conso_tbl.py
r2775 r2776 16 16 import os 17 17 import math 18 # import datetime as dt19 18 from argparse import ArgumentParser 20 19 import pprint … … 42 41 parser.add_argument("-r", "--range", action="store", nargs=2, 43 42 help="date range: ssaammjj ssaammjj") 44 45 # parser.add_argument("-f", "--full", action="store_true",46 # help="plot the whole period")47 # parser.add_argument("-i", "--increment", action="store",48 # type=int, default=1, dest="inc",49 # help="sampling increment")50 # parser.add_argument("-m", "--max", action="store_true",51 # help="plot with y_max = allocation")52 # parser.add_argument("-s", "--show", action="store_true",53 # help="interactive mode")54 # parser.add_argument("-d", "--dods", action="store_true",55 # help="copy output on dods")56 43 57 44 return parser.parse_args() … … 87 74 if args.verbose: 88 75 print("Connection to database") 89 # db_host = "134.157.170.104"90 # # db_port = "5432"91 # db_name = "prodiguer"92 # db_user = "prodiguer_db_user"93 # # db_pwd = "secret"94 76 conn, cursor = cdb.connect_db( 95 77 db_data.db_host, … … 102 84 table_name = "conso.tbl_allocation" 103 85 request = ( 104 # "SELECT id "105 86 "SELECT * " 106 87 "FROM " + table_name + " " 107 88 "WHERE project = '" + args.project + "'" 108 89 " AND centre = '" + args.center + "'" 109 # " AND start_date < '" + dt.datetime.strftime(date, "%Y-%m-%d") + "'"110 # " AND end_date > '" + dt.datetime.strftime(date, "%Y-%m-%d") + "'"111 90 "ORDER BY start_date" 112 91 ";" … … 163 142 ] 164 143 165 # print(lines_req)166 167 # exit()168 169 144 # ... Create full request ... 170 145 # --------------------------- -
TOOLS/ConsoGENCI/trunk/bin/insert_conso_tbl.py
r2775 r2776 16 16 import os 17 17 import math 18 # import datetime as dt19 18 from argparse import ArgumentParser 20 19 import shutil … … 43 42 parser.add_argument("-r", "--range", action="store", nargs=2, 44 43 help="date range: ssaammjj ssaammjj") 45 46 # parser.add_argument("-f", "--full", action="store_true",47 # help="plot the whole period")48 # parser.add_argument("-i", "--increment", action="store",49 # type=int, default=1, dest="inc",50 # help="sampling increment")51 # parser.add_argument("-m", "--max", action="store_true",52 # help="plot with y_max = allocation")53 # parser.add_argument("-s", "--show", action="store_true",54 # help="interactive mode")55 # parser.add_argument("-d", "--dods", action="store_true",56 # help="copy output on dods")57 58 44 return parser.parse_args() 59 45 … … 94 80 if args.verbose: 95 81 print("Connection to database") 96 # db_host = "134.157.170.104"97 # # db_port = "5432"98 # db_name = "prodiguer"99 # db_user = "prodiguer_db_user"100 # # db_pwd = "secret"101 82 conn, cursor = cdb.connect_db( 102 83 db_data.db_host, … … 109 90 table_name = "conso.tbl_allocation" 110 91 request = ( 111 # "SELECT id "112 92 "SELECT * " 113 93 "FROM " + table_name + " " 114 94 "WHERE project = '" + args.project + "'" 115 95 " AND centre = '" + args.center + "'" 116 # " AND start_date < '" + dt.datetime.strftime(date, "%Y-%m-%d") + "'"117 # " AND end_date > '" + dt.datetime.strftime(date, "%Y-%m-%d") + "'"118 96 "ORDER BY start_date" 119 97 ";" … … 128 106 allocs.append(ccpt.AllocRow(row)) 129 107 130 # .. Build dictionary fromfiles ..131 # =================== ==============108 # .. Process files .. 109 # =================== 132 110 for filename in filelist: 111 112 fileout = os.path.join(dirout, os.path.basename(filename)) 113 if os.path.isfile(fileout): 114 print( 115 "file {} already processed, remove file".format( 116 os.path.basename(filename) 117 ) 118 ) 119 if not args.dryrun: 120 try: 121 os.remove(filename) 122 except Exception as rc: 123 print("Could not move {}:\n{}".format(filename, rc)) 124 break 125 126 # .. Build dictionary from files .. 127 # ================================= 133 128 conso_per_alloc = {} 134 129 -
TOOLS/ConsoGENCI/trunk/bin/libconso.py
r2775 r2776 18 18 import os.path 19 19 import glob 20 import shutil21 20 import subprocess 22 21 import datetime as dt … … 39 38 command = [ 40 39 "scp", 40 "-v", 41 41 img_out, 42 42 "{}@{}:{}".format( … … 46 46 ) 47 47 ] 48 print(command) 48 49 try : 49 50 subprocess.call(command) … … 56 57 command = ["convert", "-density", "200", img_out, img_png] 57 58 59 print(command) 58 60 try : 59 61 subprocess.call(command) 60 62 except Exception as rc : 61 print("Error in convert for {}:\n{}".format( fileout, rc))63 print("Error in convert for {}:\n{}".format(img_out, rc)) 62 64 63 65 # .. Copy png file to dods server .. … … 65 67 command = [ 66 68 "scp", 69 "-v", 67 70 img_png, 68 71 "{}@{}:{}".format( … … 72 75 ) 73 76 ] 77 78 print(command) 74 79 try : 75 80 subprocess.call(command) … … 79 84 # .. Delete temporary png file .. 80 85 # =============================== 81 82 return 83 84 basefile = os.path.basename(filein) 85 86 fileout = os.path.join(DIR["DODS"], basefile) 87 filepng = os.path.join(DIR["DODS"], "img", basefile.split(".")[0] + ".png") 88 89 #Â Copy file 90 shutil.copy(filein, fileout) 91 92 # Convert it to png for web page 93 command = ["convert", "-density", "200", fileout, filepng] 94 95 try : 96 subprocess.call(command) 97 except Exception as rc : 98 print("Error in convert for {}:\n{}".format(fileout, rc)) 86 try: 87 os.remove(img_png) 88 except Exception as rc: 89 print("Could not remove {}:\n{}".format(img_png, rc)) 99 90 100 91 return … … 120 111 section = "projet" 121 112 option = "name" 122 project_name = config.get(section, option)113 # project_name = config.get(section, option) 123 114 124 115 # ... Common directories ... … … 179 170 try: 180 171 res = dt.datetime.strptime(ssaammjj, fmt) 181 except Exception as rc:172 except Exception: 182 173 pass 183 174 else: 184 break 175 break 185 176 186 177 return res.date() … … 304 295 self.days = delta.days + 1 305 296 306 self.daily_conso = self.alloc / self.days 297 self.daily_conso = self.alloc / self.days 307 298 308 299 #--------------------------------------------------------------------- … … 369 360 ) 370 361 371 372 362 self.days = sum( 373 363 [item.days for item in self.alloc_items] … … 379 369 def get_theo_eq(self, dates): 380 370 381 x0 = 0371 # x0 = 0 382 372 y0 = 0. 383 373 … … 385 375 yi = y0 386 376 yf = y0 + item.alloc / self.alloc 387 377 388 378 if item.start_date.date() in dates: 389 379 xi = dates.index(item.start_date.date()) … … 410 400 item.yi = yi 411 401 item.yf = yf 412 402 413 403 y0 = yf 414 404 -
TOOLS/ConsoGENCI/trunk/bin/libconso_cpt.py
r2775 r2776 24 24 import os 25 25 import glob 26 # import psycopg227 # import psycopg2.extras28 26 import pprint 29 27 -
TOOLS/ConsoGENCI/trunk/bin/plot_bilan.py
r2775 r2776 15 15 # standard library imports 16 16 from argparse import ArgumentParser 17 # import os18 # import pprint19 17 import datetime as dt 20 from dateutil.relativedelta import relativedelta21 18 import numpy as np 22 19 23 20 # Application library imports 24 21 from libconso import * 25 import libconso db as cdb22 import libconso_db as cdb 26 23 import db_data 27 24 … … 226 223 ) 227 224 225 228 226 ######################################################################## 229 227 def plot_config( 230 228 fig, ax_conso, ax_theo, 231 229 xcoord, dates, max_real_use, 232 title, projet230 title, faitle, projet 233 231 ): 234 232 """ 235 233 """ 236 from matplotlib.ticker import AutoMinorLocator234 # from matplotlib.ticker import AutoMinorLocator 237 235 238 236 # ... Config axes ... … … 293 291 ) 294 292 295 296 293 # 3) Ticks labels 297 294 (date_beg, date_end) = (dates[0], dates[-1]) … … 362 359 "Allocation(s):\n" + 363 360 "\n".join([ 364 "{:%d -%m-%Y}-{:%d-%m-%Y} : {:8,.0f}h".format(361 "{:%d/%m/%Y}-{:%d/%m/%Y} : {:8,.0f}h".format( 365 362 item.start_date, item.end_date, item.alloc 366 363 ) for item in projet.alloc_items … … 368 365 ) 369 366 plt.figtext( 370 x=0.92, y=0.93, s=alloc_label ,367 x=0.92, y=0.93, s=alloc_label.replace(",", " "), 371 368 backgroundcolor="linen", 372 369 ha="right", va="bottom", fontsize="x-small" 370 ) 371 372 plt.figtext( 373 x=0.5, y=0.93, s=faitle, 374 ha="center", va="bottom", fontsize="large" 373 375 ) 374 376 … … 592 594 break 593 595 theo_uses.append(100. * poly_theo(dates.index(date))) 594 delay_uses = delay * [0., ] + theo_uses[:-delay]596 delay_uses = delay * [0., ] + theo_uses[:-delay] 595 597 theo_uses = np.array(theo_uses, dtype=float) 596 598 delay_uses = np.array(delay_uses, dtype=float) 597 599 598 599 run_mean = np.array([item.run_mean for item in selected_items], 600 dtype=float) 601 pen_mean = np.array([item.pen_mean for item in selected_items], 602 dtype=float) 603 run_std = np.array([item.run_std for item in selected_items], 604 dtype=float) 605 pen_std = np.array([item.pen_std for item in selected_items], 606 dtype=float) 600 run_mean = np.array( 601 [item.run_mean for item in selected_items], 602 dtype=float 603 ) 604 pen_mean = np.array( 605 [item.pen_mean for item in selected_items], 606 dtype=float 607 ) 608 run_std = np.array( 609 [item.run_std for item in selected_items], 610 dtype=float 611 ) 612 pen_std = np.array( 613 [item.pen_std for item in selected_items], 614 dtype=float 615 ) 607 616 608 617 # .. Plot stuff .. … … 627 636 # projet.end_date 628 637 # ) 629 title = "Consommation {}\n(le {:%d/%m/%Y})".format( 638 # title = "Consommation {}\n(le {:%d/%m/%Y})".format( 639 # projet.project.upper(), 640 # today, 641 # ) 642 title = "Consommation {})".format( 630 643 projet.project.upper(), 644 ) 645 faitle = "(le {:%d/%m/%Y})".format( 631 646 today, 632 647 ) … … 635 650 fig, ax_conso, ax_theo, 636 651 xcoord, dates, real_uses[dates.index(last_filled_date)], 637 title, projet 638 ) 639 640 652 title, faitle, projet 653 ) 641 654 642 655 # ... Save figure ... … … 662 675 663 676 # exit(0) 664
Note: See TracChangeset
for help on using the changeset viewer.