Changeset 2776 for TOOLS


Ignore:
Timestamp:
03/15/16 10:59:31 (8 years ago)
Author:
labetoulle
Message:

typos and cleaning

Location:
TOOLS/ConsoGENCI/trunk/bin
Files:
6 edited

Legend:

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

    r2775 r2776  
    2121 
    2222# standard library imports 
    23 # from pprint import pprint 
    2423 
    2524# Application library imports 
     
    115114  ] 
    116115 
    117   # Connection info 
    118   # 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  
    124116  conn, cursor = cdb.connect_db( 
    125117    db_data.db_host, 
  • TOOLS/ConsoGENCI/trunk/bin/init_conso_tbl.py

    r2775 r2776  
    1616import os 
    1717import math 
    18 # import datetime as dt 
    1918from argparse import ArgumentParser 
    2019import pprint 
     
    4241  parser.add_argument("-r", "--range", action="store", nargs=2, 
    4342                      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") 
    5643 
    5744  return parser.parse_args() 
     
    8774  if args.verbose: 
    8875    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" 
    9476  conn, cursor = cdb.connect_db( 
    9577    db_data.db_host, 
     
    10284  table_name = "conso.tbl_allocation" 
    10385  request = ( 
    104     # "SELECT id " 
    10586    "SELECT * " 
    10687    "FROM " + table_name + " " 
    10788    "WHERE project = '" + args.project + "'" 
    10889    "  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") + "'" 
    11190    "ORDER BY start_date" 
    11291    ";" 
     
    163142    ] 
    164143 
    165     # print(lines_req) 
    166  
    167     # exit() 
    168  
    169144    # ... Create full request ... 
    170145    # --------------------------- 
  • TOOLS/ConsoGENCI/trunk/bin/insert_conso_tbl.py

    r2775 r2776  
    1616import os 
    1717import math 
    18 # import datetime as dt 
    1918from argparse import ArgumentParser 
    2019import shutil 
     
    4342  parser.add_argument("-r", "--range", action="store", nargs=2, 
    4443                      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  
    5844  return parser.parse_args() 
    5945 
     
    9480  if args.verbose: 
    9581    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" 
    10182  conn, cursor = cdb.connect_db( 
    10283    db_data.db_host, 
     
    10990  table_name = "conso.tbl_allocation" 
    11091  request = ( 
    111     # "SELECT id " 
    11292    "SELECT * " 
    11393    "FROM " + table_name + " " 
    11494    "WHERE project = '" + args.project + "'" 
    11595    "  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") + "'" 
    11896    "ORDER BY start_date" 
    11997    ";" 
     
    128106    allocs.append(ccpt.AllocRow(row)) 
    129107 
    130   # .. Build dictionary from files .. 
    131   # ================================= 
     108  # .. Process files .. 
     109  # =================== 
    132110  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    # ================================= 
    133128    conso_per_alloc = {} 
    134129 
  • TOOLS/ConsoGENCI/trunk/bin/libconso.py

    r2775 r2776  
    1818import os.path 
    1919import glob 
    20 import shutil 
    2120import subprocess 
    2221import datetime as dt 
     
    3938  command = [ 
    4039    "scp", 
     40    "-v", 
    4141    img_out, 
    4242    "{}@{}:{}".format( 
     
    4646    ) 
    4747  ] 
     48  print(command) 
    4849  try : 
    4950    subprocess.call(command) 
     
    5657  command = ["convert", "-density", "200", img_out, img_png] 
    5758 
     59  print(command) 
    5860  try : 
    5961    subprocess.call(command) 
    6062  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)) 
    6264 
    6365  # .. Copy png file to dods server .. 
     
    6567  command = [ 
    6668    "scp", 
     69    "-v", 
    6770    img_png, 
    6871    "{}@{}:{}".format( 
     
    7275    ) 
    7376  ] 
     77 
     78  print(command) 
    7479  try : 
    7580    subprocess.call(command) 
     
    7984  # .. Delete temporary png file .. 
    8085  # =============================== 
    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)) 
    9990 
    10091  return 
     
    120111  section = "projet" 
    121112  option  = "name" 
    122   project_name = config.get(section, option) 
     113  # project_name = config.get(section, option) 
    123114 
    124115  # ... Common directories ... 
     
    179170    try: 
    180171      res = dt.datetime.strptime(ssaammjj, fmt) 
    181     except Exception as rc: 
     172    except Exception: 
    182173      pass 
    183174    else: 
    184       break  
     175      break 
    185176 
    186177  return res.date() 
     
    304295    self.days = delta.days + 1 
    305296 
    306     self.daily_conso = self.alloc / self.days  
     297    self.daily_conso = self.alloc / self.days 
    307298 
    308299  #--------------------------------------------------------------------- 
     
    369360    ) 
    370361 
    371  
    372362    self.days = sum( 
    373363      [item.days for item in self.alloc_items] 
     
    379369  def get_theo_eq(self, dates): 
    380370 
    381     x0 = 0 
     371    # x0 = 0 
    382372    y0 = 0. 
    383373 
     
    385375      yi = y0 
    386376      yf = y0 + item.alloc / self.alloc 
    387        
     377 
    388378      if item.start_date.date() in dates: 
    389379        xi = dates.index(item.start_date.date()) 
     
    410400        item.yi = yi 
    411401        item.yf = yf 
    412        
     402 
    413403      y0 = yf 
    414404 
  • TOOLS/ConsoGENCI/trunk/bin/libconso_cpt.py

    r2775 r2776  
    2424import os 
    2525import glob 
    26 # import psycopg2 
    27 # import psycopg2.extras 
    2826import pprint 
    2927 
  • TOOLS/ConsoGENCI/trunk/bin/plot_bilan.py

    r2775 r2776  
    1515# standard library imports 
    1616from argparse import ArgumentParser 
    17 # import os 
    18 # import pprint 
    1917import datetime as dt 
    20 from dateutil.relativedelta import relativedelta 
    2118import numpy as np 
    2219 
    2320# Application library imports 
    2421from libconso import * 
    25 import libconsodb as cdb 
     22import libconso_db as cdb 
    2623import db_data 
    2724 
     
    226223  ) 
    227224 
     225 
    228226######################################################################## 
    229227def plot_config( 
    230228  fig, ax_conso, ax_theo, 
    231229  xcoord, dates, max_real_use, 
    232   title, projet 
     230  title, faitle, projet 
    233231): 
    234232  """ 
    235233  """ 
    236   from matplotlib.ticker import AutoMinorLocator 
     234  # from matplotlib.ticker import AutoMinorLocator 
    237235 
    238236  # ... Config axes ... 
     
    293291  ) 
    294292 
    295    
    296293  # 3) Ticks labels 
    297294  (date_beg, date_end) = (dates[0], dates[-1]) 
     
    362359    "Allocation(s):\n" + 
    363360    "\n".join([ 
    364       "{:%d-%m-%Y}-{:%d-%m-%Y} : {:8,.0f}h".format( 
     361      "{:%d/%m/%Y}-{:%d/%m/%Y} : {:8,.0f}h".format( 
    365362        item.start_date, item.end_date, item.alloc 
    366363      ) for item in projet.alloc_items 
     
    368365  ) 
    369366  plt.figtext( 
    370     x=0.92, y=0.93, s=alloc_label, 
     367    x=0.92, y=0.93, s=alloc_label.replace(",", " "), 
    371368    backgroundcolor="linen", 
    372369    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" 
    373375  ) 
    374376 
     
    592594        break 
    593595    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] 
    595597  theo_uses = np.array(theo_uses, dtype=float) 
    596598  delay_uses = np.array(delay_uses, dtype=float) 
    597599 
    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  ) 
    607616 
    608617  # .. Plot stuff .. 
     
    627636  #   projet.end_date 
    628637  # ) 
    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( 
    630643    projet.project.upper(), 
     644  ) 
     645  faitle = "(le {:%d/%m/%Y})".format( 
    631646    today, 
    632647  ) 
     
    635650    fig, ax_conso, ax_theo, 
    636651    xcoord, dates, real_uses[dates.index(last_filled_date)], 
    637     title, projet 
    638   ) 
    639  
    640    
     652    title, faitle, projet 
     653  ) 
    641654 
    642655  # ... Save figure ... 
     
    662675 
    663676  # exit(0) 
    664  
Note: See TracChangeset for help on using the changeset viewer.