Changeset 2783 for TOOLS


Ignore:
Timestamp:
03/21/16 15:55:15 (8 years ago)
Author:
labetoulle
Message:
  • Run everything (DB inserts + plots) from single bash script
  • Change exit codes (unsigned in bash, so no negative values...) :
    • 0: everything was ok;
    • 1: nothing done, 'cause nothing to do => ok;
    • >= 2: error.
  • DB access now needs password
  • plot_bilan: added date of production and plotted range to image
  • Cleaning (useless comments, ...)
Location:
TOOLS/ConsoGENCI/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/ConsoGENCI/trunk/bin/init_alloc_tbl.py

    r2776 r2783  
    4545      "machine": "curie", 
    4646      "node": "thin/standard", 
    47       "alloc": 15000000, 
     47      "alloc": 10000000, 
    4848      "start": "2015-07-01 00:00:00", 
    4949      "end": "2015-12-31 23:59:59", 
     
    117117    db_data.db_host, 
    118118    db_data.db_name, 
    119     db_data.db_user 
     119    db_data.db_user, 
     120    db_data.db_pwd, 
    120121  ) 
    121122 
     
    160161 
    161162  cdb.close_db(conn) 
     163 
     164  exit(0) 
  • TOOLS/ConsoGENCI/trunk/bin/init_conso_tbl.py

    r2776 r2783  
    7777    db_data.db_host, 
    7878    db_data.db_name, 
    79     db_data.db_user 
     79    db_data.db_user, 
     80    db_data.db_pwd, 
    8081  ) 
    8182 
     
    175176    print("Close connection") 
    176177  cdb.close_db(conn) 
     178 
     179  exit(0) 
  • TOOLS/ConsoGENCI/trunk/bin/insert_conso_tbl.py

    r2776 r2783  
    6969  if not filelist: 
    7070    print("No files found, exit") 
    71     exit(0) 
     71    exit(1) 
    7272 
    7373  if args.verbose: 
     
    8383    db_data.db_host, 
    8484    db_data.db_name, 
    85     db_data.db_user 
     85    db_data.db_user, 
     86    db_data.db_pwd, 
    8687  ) 
    8788 
     
    211212    print("Close connection") 
    212213  cdb.close_db(conn) 
     214 
     215  exit(0) 
  • TOOLS/ConsoGENCI/trunk/bin/libconso.py

    r2776 r2783  
    3838  command = [ 
    3939    "scp", 
    40     "-v", 
    4140    img_out, 
    4241    "{}@{}:{}".format( 
     
    6766  command = [ 
    6867    "scp", 
    69     "-v", 
    7068    img_png, 
    7169    "{}@{}:{}".format( 
     
    104102  for section in ("projet", "directories"): 
    105103    if not config.has_section(section): 
    106       print("Missing section {} in {}, we stop".format(section, filename)) 
    107       exit(1) 
     104      print( 
     105        "Missing section {} in {}, we stop".format(section, filename) 
     106      ) 
     107      exit(9) 
    108108 
    109109  # ... Project name ... 
     
    183183  """ 
    184184  return dt.datetime.strptime(string, fmt) 
    185  
    186  
    187 # ######################################################################## 
    188 # def date_to_string(dtdate, fmt="%Y-%m-%d"): 
    189 #   """ 
    190 #   """ 
    191 #   return dt.datetime.strftime(dtdate, fmt) 
    192185 
    193186 
     
    235228    for f_in, f_out in zip(file_list, res): 
    236229      print("=> {}: {}".format(f_in, f_out)) 
    237     exit(1) 
     230    exit(9) 
    238231 
    239232  return res 
     
    264257    d["Title"]   = title 
    265258    d["Author"]  = os.path.basename(__file__) 
    266     # d["Subject"] = "Time spent over specific commands during create_ts \ 
    267     #                 jobs at IDRIS and four configurations at TGCC" 
     259 
     260    # d["Subject"] = ( 
     261    #   "Time spent over specific commands during create_ts " 
     262    #   "jobs at IDRIS and four configurations at TGCC" 
     263    # ) 
    268264    # d["Keywords"] = "bench create_ts TGCC IDRIS ncrcat" 
    269265    # d["CreationDate"] = dt.datetime(2009, 11, 13) 
  • TOOLS/ConsoGENCI/trunk/bin/libconso_cpt.py

    r2776 r2783  
    146146  else: 
    147147    print("Unknown center {}".format(center)) 
    148     exit() 
     148    exit(9) 
    149149 
    150150 
  • TOOLS/ConsoGENCI/trunk/bin/libconso_db.py

    r2775 r2783  
    2929 
    3030####################################################################### 
    31 def connect_db(db_host, db_name, db_user): 
     31def connect_db(db_host, db_name, db_user, db_pwd): 
    3232 
    33   conn_string = "host={} dbname={} user={}".format( 
    34     db_host, db_name, db_user 
     33  conn_string = "host={} dbname={} user={} password={}".format( 
     34    db_host, db_name, db_user, db_pwd 
    3535  ) 
    3636 
     
    4444  except Exception as rc: 
    4545    print("Problem with DB connect:\n{}".format(rc)) 
    46     exit(1) 
     46    exit(9) 
    4747 
    4848  # conn.cursor will return a cursor object, you can use this cursor 
     
    6363  except Exception as rc: 
    6464    print("Problem with select:\n{}".format(rc)) 
    65     exit(1) 
     65    exit(9) 
    6666 
    6767  # # retrieve the records from the database 
     
    8585  except Exception as rc: 
    8686    print("Problem with insert:\n{}".format(rc)) 
    87     exit(1) 
     87    exit(9) 
    8888 
    8989 
     
    9898  except Exception as rc: 
    9999    print("Problem with commit:\n{}".format(rc)) 
    100     exit(1) 
     100    exit(9) 
    101101 
    102102 
     
    110110  except Exception as rc: 
    111111    print("Problem with close:\n{}".format(rc)) 
    112     exit(1) 
     112    exit(9) 
    113113 
    114114 
  • TOOLS/ConsoGENCI/trunk/bin/plot_bilan.py

    r2776 r2783  
    116116    """ 
    117117    items = (item for item in self.itervalues() 
    118                    if item.date.date() >= date_beg and 
    119                       item.date.date() <= date_end) 
     118                   if item.date >= date_beg and 
     119                      item.date <= date_end) 
    120120    items = sorted(items, key=lambda item: item.date) 
    121121 
     
    228228  fig, ax_conso, ax_theo, 
    229229  xcoord, dates, max_real_use, 
    230   title, faitle, projet 
     230  title, faitle, projet, bilan_plot 
    231231): 
    232232  """ 
    233233  """ 
    234   # from matplotlib.ticker import AutoMinorLocator 
     234  from matplotlib.ticker import AutoMinorLocator 
    235235 
    236236  # ... Config axes ... 
     
    279279  ax_conso.plot( 
    280280    x_list, y_list, 
    281     color="blue", alpha=line_alpha, 
     281    linewidth=0.5, 
     282    color="blue", 
     283    alpha=line_alpha, 
    282284    label=line_label, 
    283285  ) 
     
    312314  ) 
    313315 
    314   # minor_locator = AutoMinorLocator() 
    315   # ax.yaxis.set_minor_locator(minor_locator) 
     316  minor_locator = AutoMinorLocator() 
     317  ax_conso.yaxis.set_minor_locator(minor_locator) 
     318  minor_locator = AutoMinorLocator() 
     319  ax_theo.yaxis.set_minor_locator(minor_locator) 
    316320 
    317321  ax_conso.set_yticks(conso_yticks) 
    318  
    319322  ax_theo.set_yticks(theo_yticks) 
    320323 
     
    324327 
    325328  for x, d in zip(xcoord, dates): 
    326     # if d.weekday() == 0 and d.hour == 0: 
    327329    if d.weekday() == 0: 
    328330      ax_conso.axvline( 
     
    359361    "Allocation(s):\n" + 
    360362    "\n".join([ 
    361       "{:%d/%m/%Y}-{:%d/%m/%Y} : {:8,.0f}h".format( 
     363      "{:%d/%m/%Y}-{:%d/%m/%Y} : {:10,.0f}h".format( 
    362364        item.start_date, item.end_date, item.alloc 
    363365      ) for item in projet.alloc_items 
     
    370372  ) 
    371373 
     374  range_label = "{:%d/%m/%Y} - {:%d/%m/%Y}".format( 
     375    bilan_plot.date_min, 
     376    bilan_plot.date_max, 
     377  ) 
    372378  plt.figtext( 
    373     x=0.5, y=0.93, s=faitle, 
     379    x=0.5, y=0.93, s=range_label, 
    374380    ha="center", va="bottom", fontsize="large" 
     381  ) 
     382 
     383  faitle_label = "fait le {:%d/%m/%Y}".format(bilan_plot.faitle) 
     384  plt.figtext( 
     385    x=0.02, y=0.98, s=faitle_label, 
     386    ha="left", va="top", fontsize="x-small" 
    375387  ) 
    376388 
     
    441453  if not os.path.isfile(config_file): 
    442454    print("File {} missing ".format(config_file)) 
    443     exit(1) 
     455    exit(9) 
    444456 
    445457  (DIR, DODS) = parse_config(config_file) 
     
    457469  ) 
    458470 
    459   # if args.verbose: 
    460   #   print("Save plot as >{}<".format(img_name)) 
    461  
    462471  conn, cursor = cdb.connect_db( 
    463472    db_data.db_host, 
    464473    db_data.db_name, 
    465     db_data.db_user 
    466   ) 
    467  
    468   # today = os.path.basename(file_param).strip(OUT["PARAM"]) 
    469   # today = dt.date.strftime(dt.date.today(), "%Y%m%d") 
     474    db_data.db_user, 
     475    db_data.db_pwd, 
     476  ) 
     477 
    470478  today = dt.date.today() 
    471479 
     
    474482    print(fmt_str.format("args", args)) 
    475483    print(fmt_str.format("today", today)) 
    476   #   print(fmt_str.format("file_param", file_param)) 
    477   #   print(fmt_str.format("file_utheo", file_utheo)) 
    478   #   print(fmt_str.format("file_data", file_data)) 
    479484    print(fmt_str.format("img_name", img_name)) 
    480485    print("") 
     
    495500    ) 
    496501  bilan_plot = PlotData(date_min, date_max) 
    497  
    498   # print(bilan_plot.__dict__) 
    499   # exit() 
     502  bilan_plot.faitle = today 
    500503 
    501504  # .. Get project info .. 
    502505  # ====================== 
    503   # projet = Project(project_name) 
    504   # projet.fill_data(file_param) 
    505   # projet.get_date_init(file_utheo) 
    506  
    507506  table_name = "conso.tbl_allocation" 
    508507  request = ( 
     
    517516  # print(cursor.rowcount) 
    518517  # print(cursor.fetchall()) 
     518  # print(cursor.description) 
    519519 
    520520  projet = Project(args.project, args.center) 
    521   # print(cursor.description) 
    522521  for row in cursor: 
    523     # if row["start_date"].year == today.year: 
    524522    if (bilan_plot.date_min >= row["start_date"].date() and 
    525523        bilan_plot.date_min <= row["end_date"].date()) or \ 
     
    587585 
    588586  theo_uses = [] 
    589   for date in dates: 
     587  real_uses2 = [] 
     588  for idx, date in enumerate(dates): 
    590589    for item in projet.alloc_items: 
    591590      if date >= item.start_date.date() and \ 
    592591         date <= item.end_date.date(): 
    593592        poly_theo  = item.theo_eq 
     593        alloc_val = item.alloc 
    594594        break 
    595595    theo_uses.append(100. * poly_theo(dates.index(date))) 
     596    real_uses2.append((100 * cumul[idx]) / alloc_val) 
    596597  delay_uses = delay * [0., ] + theo_uses[:-delay] 
    597598  theo_uses = np.array(theo_uses, dtype=float) 
     
    631632  # ... Tweak figure ... 
    632633  # -------------------- 
    633   # title = "Consommation {}\n({:%d/%m/%Y} - {:%d/%m/%Y})".format( 
    634   #   projet.project.upper(), 
    635   #   projet.start_date, 
    636   #   projet.end_date 
    637   # ) 
    638   # title = "Consommation {}\n(le {:%d/%m/%Y})".format( 
    639   #   projet.project.upper(), 
    640   #   today, 
    641   # ) 
    642634  title = "Consommation {})".format( 
    643635    projet.project.upper(), 
     
    650642    fig, ax_conso, ax_theo, 
    651643    xcoord, dates, real_uses[dates.index(last_filled_date)], 
    652     title, faitle, projet 
     644    title, faitle, projet, bilan_plot 
    653645  ) 
    654646 
    655647  # ... Save figure ... 
    656648  # ------------------- 
    657   img_out = os.path.join( 
    658     DIR["PLOT"], args.center, args.project, 
    659     "{}_{:%Y%m%d}.pdf".format(img_name, today) 
    660   ) 
     649  if args.range: 
     650    img_out = os.path.join( 
     651      DIR["PLOT"], args.center, args.project, 
     652      "{}_{:%Y%m%d}_{:%Y%m%d}.pdf".format(img_name, *args.range) 
     653    ) 
     654  else: 
     655    img_out = os.path.join( 
     656      DIR["PLOT"], args.center, args.project, 
     657      "{}_{:%Y%m%d}.pdf".format(img_name, today) 
     658    ) 
    661659  if args.verbose: 
    662660    print("Save image as {}".format(img_out)) 
     
    674672  #   plt.show() 
    675673 
    676   # exit(0) 
     674  exit(0) 
Note: See TracChangeset for help on using the changeset viewer.