Changeset 3083


Ignore:
Timestamp:
01/12/17 12:01:53 (7 years ago)
Author:
labetoulle
Message:

Overall update (typos, get_project_list.py, ...)

Location:
TOOLS/ConsoGENCI/trunk
Files:
1 added
7 edited

Legend:

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

    r2783 r3083  
    6868 
    6969  if not filelist: 
    70     print("No files found, exit") 
     70    print("No input files found, exit") 
    7171    exit(1) 
    7272 
  • TOOLS/ConsoGENCI/trunk/bin/libconso.py

    r2783 r3083  
    1111 
    1212# this must come first 
    13 from __future__ import print_function, unicode_literals, division 
     13# from __future__ import print_function, unicode_literals, division 
     14from __future__ import print_function, division 
    1415 
    1516# standard library imports 
     
    2526# Application library imports 
    2627 
     28######################################################################## 
     29 
     30# .. Constants and variables .. 
     31# ============================= 
     32cm2in = 1. / 2.54 
     33 
    2734 
    2835######################################################################## 
     
    3441    return 
    3542 
    36   # .. Copy pdf file to dods server .. 
     43  # .. Convert pdf to temporary png .. 
    3744  # ================================== 
     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  # ---------------- 
    3863  command = [ 
    3964    "scp", 
     
    4671  ] 
    4772  print(command) 
    48   try : 
     73  try: 
    4974    subprocess.call(command) 
    50   except Exception as rc : 
     75  except Exception as rc: 
    5176    print("Error in scp for {}:\n{}".format(command, rc)) 
    5277 
    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  # ---------------- 
    6680  command = [ 
    6781    "scp", 
     
    7589 
    7690  print(command) 
    77   try : 
     91  try: 
    7892    subprocess.call(command) 
    79   except Exception as rc : 
     93  except Exception as rc: 
    8094    print("Error in scp for {}:\n{}".format(command, rc)) 
    8195 
     
    121135    if DIR[option] and not os.path.isdir(DIR[option]): 
    122136      print("mkdir {}".format(DIR[option])) 
    123       try : 
     137      try: 
    124138        os.makedirs(DIR[option]) 
    125       except Exception as rc : 
     139      except Exception as rc: 
    126140        print("Could not create {}:\n{}".format(DIR[option], rc)) 
    127141 
     
    234248 
    235249######################################################################## 
    236 def plot_save(img_out, title): 
    237   """ 
    238   """ 
     250def plot_save(img_out, title, png=False): 
     251  """ 
     252  """ 
     253  import matplotlib.pyplot as plt 
    239254  from matplotlib.backends.backend_pdf import PdfPages 
    240255 
     
    244259  if not os.path.isdir(dirname): 
    245260    print("mkdir {}".format(dirname)) 
    246     try : 
     261    try: 
    247262      os.makedirs(dirname) 
    248     except Exception as rc : 
     263    except Exception as rc: 
    249264      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    ) 
    250276 
    251277  with PdfPages(img_out) as pdf: 
     
    270296class AllocItem(object): 
    271297 
    272   #--------------------------------------------------------------------- 
     298  # -------------------------------------------------------------------- 
    273299  def __init__( 
    274300    self, 
     
    293319    self.daily_conso = self.alloc / self.days 
    294320 
    295   #--------------------------------------------------------------------- 
     321  # -------------------------------------------------------------------- 
    296322  def __repr__(self): 
    297323    return "{} ({:%Y%m%d}/{:%Y%m%d}): {}".format( 
     
    306332class Project(object): 
    307333 
    308   #--------------------------------------------------------------------- 
     334  # -------------------------------------------------------------------- 
    309335  def __init__(self, project_name, center): 
    310336    self.project = project_name 
     
    312338    self.alloc_items = [] 
    313339 
    314   #--------------------------------------------------------------------- 
     340  # -------------------------------------------------------------------- 
    315341  def __repr__(self): 
    316342    return "{}/{}: {}".format( 
     
    320346    ) 
    321347 
    322   #--------------------------------------------------------------------- 
     348  # -------------------------------------------------------------------- 
    323349  def add_alloc( 
    324350    self, 
     
    362388    self.nb_alloc = len(self.alloc_items) 
    363389 
    364   #--------------------------------------------------------------------- 
     390  # -------------------------------------------------------------------- 
    365391  def get_theo_eq(self, dates): 
    366392 
     
    399425      y0 = yf 
    400426 
    401   #--------------------------------------------------------------------- 
     427  # -------------------------------------------------------------------- 
    402428  def fill_data(self, row): 
    403429    # self.id = row["id"] 
     
    414440######################################################################## 
    415441class SizeUnit(object): 
    416   #--------------------------------------------------------------------- 
     442  # -------------------------------------------------------------------- 
    417443  def __init__(self, size, unit): 
    418444    self.size = size 
    419445    self.unit = unit 
    420446 
    421   #--------------------------------------------------------------------- 
     447  # -------------------------------------------------------------------- 
    422448  def __repr__(self): 
    423449    return "{:6.2f}{}o".format(self.size, self.unit) 
    424450 
    425   #--------------------------------------------------------------------- 
     451  # -------------------------------------------------------------------- 
    426452  def convert_size(self, unit_out): 
    427453    """ 
  • TOOLS/ConsoGENCI/trunk/bin/libconso_cpt.py

    r2783 r3083  
    1919 
    2020# This must come first 
    21 from __future__ import print_function, unicode_literals, division 
     21# from __future__ import print_function, unicode_literals, division 
     22from __future__ import print_function, division 
    2223 
    2324# Standard library imports 
  • TOOLS/ConsoGENCI/trunk/bin/libconso_db.py

    r2783 r3083  
    1919 
    2020# This must come first 
    21 from __future__ import print_function, unicode_literals, division 
     21# from __future__ import print_function, unicode_literals, division 
     22from __future__ import print_function, division 
    2223 
    2324# Standard library imports 
     
    3536  ) 
    3637 
    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  ) 
    3943 
    4044  # Get a connection, if a connect cannot be made an exception will be 
    4145  # raised here 
    42   try : 
     46  try: 
    4347    conn = psycopg2.connect(conn_string) 
    4448  except Exception as rc: 
  • TOOLS/ConsoGENCI/trunk/bin/plot_bilan.py

    r2783 r3083  
    1010# ==================================================================== # 
    1111 
     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 
    1220# this must come first 
    1321from __future__ import print_function, unicode_literals, division 
     22# from __future__ import print_function, division 
    1423 
    1524# standard library imports 
     
    2635######################################################################## 
    2736class PlotData(object): 
    28   #--------------------------------------------------------------------- 
     37  # -------------------------------------------------------------------- 
    2938  def __init__(self, date_min, date_max): 
    3039    self.date_min = date_min 
     
    3746######################################################################## 
    3847class DataDict(dict): 
    39   #--------------------------------------------------------------------- 
     48  # -------------------------------------------------------------------- 
    4049  def __init__(self): 
    4150    self = {} 
    4251 
    43   #--------------------------------------------------------------------- 
     52  # -------------------------------------------------------------------- 
    4453  def init_range(self, date_beg, date_end, inc=1): 
    4554    """ 
     
    5564      self.add_item(date) 
    5665 
    57   #--------------------------------------------------------------------- 
     66  # -------------------------------------------------------------------- 
    5867  def fill_data(self, projet): 
    5968    """ 
     
    7180    ) 
    7281 
     82    if args.subproject: 
     83      subp_condition = "sub_project = \'{}\'".format(args.subproject) 
     84    else: 
     85      subp_condition = "sub_project IS NULL" 
     86 
    7387    table_name = "conso.tbl_consumption" 
    7488    request = ( 
     
    7690      "FROM " + table_name + " " 
    7791      "WHERE login IS NULL " 
     92      # "  AND sub_project IS NULL " 
     93      "  AND " + subp_condition + " " 
    7894      "  AND " + id_condition + " " 
    7995      "ORDER BY date" 
     
    8399    if args.verbose: 
    84100      print("Access table \"{}\"".format(table_name)) 
    85       print(request) 
    86101    cdb.select_db(cursor, request) 
    87102 
     
    96111        self[date.date()].fill() 
    97112 
    98   #--------------------------------------------------------------------- 
     113  # -------------------------------------------------------------------- 
    99114  def add_item(self, date, conso=np.nan, 
    100115               real_use=np.nan, theo_use=np.nan, 
     
    111126    ) 
    112127 
    113   #--------------------------------------------------------------------- 
     128  # -------------------------------------------------------------------- 
    114129  def get_items_in_range(self, date_beg, date_end, inc=1): 
    115130    """ 
     
    122137    return items[::inc] 
    123138 
    124   #--------------------------------------------------------------------- 
     139  # -------------------------------------------------------------------- 
    125140  def get_items_in_full_range(self, inc=1): 
    126141    """ 
     
    132147    return items[::inc] 
    133148 
    134   #--------------------------------------------------------------------- 
     149  # -------------------------------------------------------------------- 
    135150  def get_items(self, inc=1): 
    136151    """ 
     
    144159 
    145160class Conso(object): 
    146   #--------------------------------------------------------------------- 
     161  # -------------------------------------------------------------------- 
    147162  def __init__(self, date, conso=np.nan, 
    148163               real_use=np.nan, theo_use=np.nan, 
    149164               run_mean=np.nan, pen_mean=np.nan, 
    150165               run_std=np.nan, pen_std=np.nan): 
    151     self.date     = date 
    152     self.conso    = conso 
    153     self.real_use = real_use 
    154     self.theo_use = theo_use 
    155     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([]) 
    156171    self.poly_delay = np.poly1d([]) 
    157     self.run_mean = run_mean 
    158     self.pen_mean = pen_mean 
    159     self.run_std  = run_std 
    160     self.pen_std  = pen_std 
    161     self.filled   = False 
    162  
    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  # -------------------------------------------------------------------- 
    164179  def __repr__(self): 
    165180    return "{:.2f} ({:.2%})".format(self.conso, self.real_use) 
    166181 
    167   #--------------------------------------------------------------------- 
     182  # -------------------------------------------------------------------- 
    168183  def isfilled(self): 
    169184    return self.filled 
    170185 
    171   #--------------------------------------------------------------------- 
     186  # -------------------------------------------------------------------- 
    172187  def fill(self): 
    173188    self.filled = True 
     
    177192def plot_init(): 
    178193  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)) 
    180196  ax_theo = ax_conso.twinx() 
    181197 
     
    329345    if d.weekday() == 0: 
    330346      ax_conso.axvline( 
    331         x=x, color="black", alpha=0.5, 
     347        x=x, color="gray", alpha=0.5, 
    332348        linewidth=0.5, linestyle=":" 
    333349      ) 
     
    393409  parser.add_argument("project", action="store", 
    394410                      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") 
    397423 
    398424  parser.add_argument("-v", "--verbose", action="store_true", 
     
    400426  parser.add_argument("-f", "--full", action="store_true", 
    401427                      help="plot the whole period") 
     428  parser.add_argument("--png", action="store_true", 
     429                      help="pgn output in addition to pdf") 
    402430  parser.add_argument("-i", "--increment", action="store", 
    403431                      type=int, default=1, dest="inc", 
     
    448476  config_file = os.path.join( 
    449477    "card", 
    450     "config_{}_{}.ini".format(args.center, args.project) 
     478    "config_{}_{}.ini".format(args.centre, args.project) 
    451479  ) 
    452480 
     
    461489  #                     [OUT["PARAM"], OUT["UTHEO"], OUT["BILAN"]]) 
    462490 
    463   img_name = "{}_{}_{}".format( 
     491  img_name = "{}_{}_{}_{}_{}".format( 
    464492    os.path.splitext( 
    465493      os.path.basename(__file__) 
    466494    )[0].replace("plot_", ""), 
     495    args.centre, 
    467496    args.project, 
    468     args.center, 
     497    args.subproject if args.subproject else args.project, 
     498    args.node.replace("/", ""), 
    469499  ) 
    470500 
     
    509539    "FROM " + table_name + " " 
    510540    "WHERE project = '" + args.project + "' " 
     541    "AND node_type = '" + args.node + "' " 
     542    "AND is_active = TRUE " 
    511543    "ORDER BY start_date" 
    512544    ";" 
     
    518550  # print(cursor.description) 
    519551 
    520   projet = Project(args.project, args.center) 
     552  projet = Project(args.project, args.centre) 
    521553  for row in cursor: 
    522554    if (bilan_plot.date_min >= row["start_date"].date() and 
     
    572604  projet.get_theo_eq(dates) 
    573605 
    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  ) 
    576610  consos = [] 
    577611  consos.append(cumul[0]) 
     
    595629    theo_uses.append(100. * poly_theo(dates.index(date))) 
    596630    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 
    598637  theo_uses = np.array(theo_uses, dtype=float) 
    599638  delay_uses = np.array(delay_uses, dtype=float) 
     
    632671  # ... Tweak figure ... 
    633672  # -------------------- 
    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() 
    636677  ) 
    637678  faitle = "(le {:%d/%m/%Y})".format( 
     
    649690  if args.range: 
    650691    img_out = os.path.join( 
    651       DIR["PLOT"], args.center, args.project, 
     692      DIR["PLOT"], args.centre, args.project, 
    652693      "{}_{:%Y%m%d}_{:%Y%m%d}.pdf".format(img_name, *args.range) 
    653694    ) 
    654695  else: 
    655696    img_out = os.path.join( 
    656       DIR["PLOT"], args.center, args.project, 
     697      DIR["PLOT"], args.centre, args.project, 
    657698      "{}_{:%Y%m%d}.pdf".format(img_name, today) 
    658699    ) 
    659700  if args.verbose: 
    660701    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) 
    663711 
    664712  # ... Publish figure on dods ... 
  • TOOLS/ConsoGENCI/trunk/card/config_center_project.ini.init

    r2775 r3083  
    11[projet] 
    2 name: project_name 
     2name = project_name 
    33 
    44[directories] 
    5 ROOT_DIR: /path/to/ConsoGENCI 
    6 DATA: %(ROOT_DIR)s/data 
    7 PLOT: %(ROOT_DIR)s/plot 
     5ROOT_DIR = /path/to/ConsoGENCI 
     6DATA = %(ROOT_DIR)s/data 
     7PLOT = %(ROOT_DIR)s/plot 
    88DODS 
    99 
    1010[dods] 
    11 DIR: /path/to/dods/ConsoGENCI 
    12 USER: user 
    13 SERVER: host 
     11DIR = /path/to/dods/ConsoGENCI 
     12USER = user 
     13SERVER = host 
  • TOOLS/ConsoGENCI/trunk/launch_conso.sh

    r2783 r3083  
    1313# ====================================================================== 
    1414 
     15date 
     16whereami=$( hostname -s ) 
     17 
    1518# set -vx 
    16  
    17 whereami=$( hostname -s ) 
    1819 
    1920# .. System dependant steps .. 
     
    5152BIN_DIR=${ROOT_DIR}/bin 
    5253 
    53 declare -A proj_center=(["gencimp6"]="tgcc" ["rgzi"]="idris") 
     54declare -A proj_center=(["gencmip6"]="tgcc" ["rgzi"]="idris") 
    5455 
    5556for projet in "${!proj_center[@]}" 
Note: See TracChangeset for help on using the changeset viewer.