Changeset 2751


Ignore:
Timestamp:
02/24/16 17:11:19 (8 years ago)
Author:
labetoulle
Message:

Homogenization of cpt files parsing, including multi-node projects on Curie

Location:
TOOLS/ConsoGENCI/trunk/bin
Files:
2 added
3 edited

Legend:

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

    r2713 r2751  
    1919 
    2020 
    21 ######################################## 
     21####################################################################### 
    2222if __name__ == "__main__": 
    2323 
    2424  project_list = [ 
    2525    { 
    26       "name": "gencmip6", 
     26      "name": "gen0826", 
    2727      "centre": "tgcc", 
    2828      "machine": "curie", 
    29       "node": "thin", 
    30       "alloc": 5000000, 
    31       "start": "20150101", 
    32       "end": "20150630", 
     29      "node": "fat/large", 
     30      "alloc": 114000, 
     31      "start": "2015-01-01 00:00:00", 
     32      "end": "2015-12-31 23:59:59", 
     33    }, 
     34    { 
     35      "name": "gen0826", 
     36      "centre": "tgcc", 
     37      "machine": "curie", 
     38      "node": "hybrid", 
     39      "alloc": 25000, 
     40      "start": "2015-01-01 00:00:00", 
     41      "end": "2015-12-31 23:59:59", 
     42    }, 
     43    { 
     44      "name": "gen0826", 
     45      "centre": "tgcc", 
     46      "machine": "curie", 
     47      "node": "thin/standard", 
     48      "alloc": 114000, 
     49      "start": "2015-01-01 00:00:00", 
     50      "end": "2015-12-31 23:59:59", 
    3351    }, 
    3452    { 
     
    3654      "centre": "tgcc", 
    3755      "machine": "curie", 
    38       "node": "thin", 
     56      "node": "thin/standard", 
     57      "alloc": 5000000, 
     58      "start": "2015-01-01 00:00:00", 
     59      "end": "2015-06-30 23:59:59", 
     60    }, 
     61    { 
     62      "name": "gencmip6", 
     63      "centre": "tgcc", 
     64      "machine": "curie", 
     65      "node": "thin/standard", 
    3966      "alloc": 15000000, 
    40       "start": "20150701", 
    41       "end": "20151231", 
     67      "start": "2015-07-01 00:00:00", 
     68      "end": "2015-12-31 23:59:59", 
     69    }, 
     70    { 
     71      "name": "gencmip6", 
     72      "centre": "tgcc", 
     73      "machine": "curie", 
     74      "node": "thin/standard", 
     75      "alloc": 25000000, 
     76      "start": "2016-01-01 00:00:00", 
     77      "end": "2016-06-30 23:59:59", 
     78    }, 
     79    { 
     80      "name": "gencmip6", 
     81      "centre": "tgcc", 
     82      "machine": "curie", 
     83      "node": "thin/standard", 
     84      "alloc": 50000000, 
     85      "start": "2016-07-01 00:00:00", 
     86      "end": "2016-12-31 23:59:59", 
    4287    }, 
    4388    { 
     
    4792      "node": "standard", 
    4893      "alloc": 2000000, 
    49       "start": "20150101", 
    50       "end": "20151231", 
     94      "start": "2015-01-01 00:00:00", 
     95      "end": "2015-12-31 23:59:59", 
     96    }, 
     97    { 
     98      "name": "rgzi", 
     99      "centre": "idris", 
     100      "machine": "ada", 
     101      "node": "standard", 
     102      "alloc": 4000000, 
     103      "start": "2016-01-01 00:00:00", 
     104      "end": "2016-12-31 23:59:59", 
    51105    }, 
    52106  ] 
     
    99153 
    100154  cdb.commit_db(conn) 
     155 
     156  cdb.close_db(conn) 
  • TOOLS/ConsoGENCI/trunk/bin/init_conso_tbl.py

    r2713 r2751  
    11#!/usr/bin/env python 
    22# -*- coding: utf-8 -*- 
    3  
    4 # ==================================================================== # 
    5 # ssh readonly@prodiguer-test-db.ipsl.upmc.fr                          # 
    6 # psql -U prodiguer_db_user prodiguer                                  # 
    7 #                                                                      # 
    8 # ssh readonly@prodiguer-test-db.ipsl.upmc.fr -L 5432:localhost:5432   # 
    9 # ==================================================================== # 
    10  
    113 
    124# This must come first 
     
    1810# import datetime as dt 
    1911from argparse import ArgumentParser 
     12import pprint 
    2013 
    2114# Application library imports 
    22 import libconsodb as cdb 
     15import libconso_db as cdb 
     16import libconso_cpt as ccpt 
     17 
     18pp = pprint.PrettyPrinter(indent=2) 
    2319 
    2420 
    25 ######################################## 
     21####################################################################### 
    2622def get_arguments(): 
    2723  parser = ArgumentParser() 
     
    5349 
    5450 
    55 ######################################## 
     51####################################################################### 
    5652if __name__ == "__main__": 
    5753 
     
    6460    print(args) 
    6561 
    66   ROOT_DIR = "/home_local/slipsl/ConsoGENCMIP6/init_db" 
     62  # ... Files and directories ... 
     63  # ----------------------------- 
     64  ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
    6765  DATA_DIR = os.path.join(ROOT_DIR, "data") 
    68  
    6966  SUBMIT_DIR = os.getcwd() 
    7067 
    71   # project = "rgzi" 
    72   # centre = "idris" 
     68  if args.verbose: 
     69    print("SUBMIT_DIR:", SUBMIT_DIR) 
     70    print("DATA_DIR:", DATA_DIR) 
    7371 
    74   conso_per_login = {} 
     72  pattern = ccpt.cpt_pattern(args.center, args.project) 
     73  dirin = os.path.join(DATA_DIR, args.center, args.project) 
     74  filelist = ccpt.find_input_files(dirin, pattern, args.range) 
    7575 
    76   # Connection info 
     76  # .. Connection to database .. 
     77  # ============================ 
     78  if args.verbose: 
     79    print("Connection to database") 
    7780  db_host = "134.157.170.104" 
    7881  # db_port = "5432" 
     
    8083  db_user = "prodiguer_db_user" 
    8184  # db_pwd = "secret" 
    82  
    83   if args.center == "idris": 
    84     pattern = "compta_*.dat" 
    85   elif args.center == "tgcc": 
    86     pattern = "ccc_myproject.dat_*" 
    87   else: 
    88     print("Unknown center {}".format(args.center)) 
    89     exit() 
    90  
    91   filelist = cdb.find_input_files(DATA_DIR, pattern, args.range) 
    92  
    93   # Build dictionary from files 
    94   # for filename in cdb.find_idris_files(DATA_DIR): 
    95   for filename in filelist: 
    96     print(filename) 
    97     # jour, heure, alloc, consos = \ 
    98     date, alloc, consos = \ 
    99           cdb.parse_input_cpt(filename, args.project, args.center) 
    100           # cdb.parse_idris_cpt(filename, args.project) 
    101  
    102     # date = dt.datetime.strptime("{} {}".format(jour, heure), "%d/%m/%Y %H:%M") 
    103  
    104     for item in consos: 
    105       login, conso = item 
    106       if login not in conso_per_login: 
    107         conso_per_login[login] = set() 
    108       conso_per_login[login].add((date, conso, )) 
    109  
    11085  conn, cursor = cdb.connect_db(db_host, db_name, db_user) 
    11186 
    112   # Extract allocation id from table 
     87  # .. Extract allocation id from table .. 
     88  # ====================================== 
    11389  table_name = "conso.tbl_allocation" 
    11490  request = ( 
    115     "SELECT id " 
     91    # "SELECT id " 
     92    "SELECT * " 
    11693    "FROM " + table_name + " " 
    11794    "WHERE project = '" + args.project + "'" 
    11895    "  AND centre = '" + args.center + "'" 
     96    # "  AND start_date < '" + dt.datetime.strftime(date, "%Y-%m-%d") + "'" 
     97    # "  AND end_date > '" + dt.datetime.strftime(date, "%Y-%m-%d") + "'" 
     98    "ORDER BY start_date" 
    11999    ";" 
    120100  ) 
    121101 
    122102  cdb.select_db(cursor, request) 
    123   if cursor.rowcount != 1: 
    124     print(cursor.fetchall()) 
    125     exit() 
     103  # print(cursor.rowcount) 
     104  # print(cursor.fetchall()) 
    126105 
    127   (allocation_id, ) = cursor.fetchone() 
     106  allocs = [] 
     107  for row in cursor: 
     108    allocs.append(ccpt.AllocRow(row)) 
    128109 
    129   for login, conso_list in conso_per_login.iteritems(): 
     110  # .. Build dictionary from files .. 
     111  # ================================= 
     112  conso_per_alloc = {} 
     113  for filename in filelist: 
     114    date, blocs = ccpt.parse_input_cpt( 
     115      filename, args.project, args.center, mode_conso=True 
     116    ) 
    130117 
    131     # test = "'"+login+"'" if login != "total" else "NULL" 
    132     # print(test) 
     118    for bloc in blocs: 
     119      if not bloc.alloc_id: 
     120        bloc.alloc_id = ccpt.get_project_id(bloc, allocs) 
     121        if not bloc.alloc_id: 
     122          print("no alloc id found, skip bloc") 
     123          print(bloc.machine, bloc.node, bloc.cpt_date) 
     124          pp.pprint(allocs) 
     125          continue 
     126      if bloc.alloc_id not in conso_per_alloc: 
     127        conso_per_alloc[bloc.alloc_id] = set() 
     128      for conso in bloc.consos: 
     129        conso_per_alloc[bloc.alloc_id].add(conso) 
    133130 
     131  # .. Insert data in table, one alloc_id at a time .. 
     132  # ================================================== 
     133  for alloc_id, consos in conso_per_alloc.iteritems(): 
     134    # ... Create request sub string ... 
     135    # --------------------------------- 
    134136    lines_req = [ 
    135137      ( 
     
    140142        "{create})" 
    141143      ) .format( 
    142         alloc=allocation_id, 
    143         date=date, 
    144         total_hrs=conso if not math.isnan(conso) else "'NaN'", 
    145         login="'"+login+"'" if login != "total" else "NULL", 
     144        alloc=alloc_id, 
     145        date=item.date, 
     146        total_hrs=item.conso if not math.isnan(item.conso) else "'NaN'", 
     147        login="'"+item.login+"'" if item.login != "total" else "NULL", 
    146148        create="CURRENT_TIMESTAMP", 
    147       ) for (date, conso) in conso_list 
     149      ) for item in consos 
    148150    ] 
    149151 
     152    # print(lines_req) 
     153 
     154    # exit() 
     155 
     156    # ... Create full request ... 
     157    # --------------------------- 
    150158    table_name = "conso.tbl_consumption" 
    151159    request = ( 
     
    160168    ) 
    161169    request = request + ", ".join(lines_req) 
    162     print(request) 
    163170 
     171    # ... Execute request ... 
     172    # ----------------------- 
     173    if args.verbose: 
     174      print("Execute request for alloc_id = {}".format(alloc_id)) 
    164175    cdb.insert_db(cursor, request) 
    165176 
     177    # ... Commit inserts ... 
     178    # ---------------------- 
    166179    if not args.dryrun: 
     180      if args.verbose: 
     181        print("Commit inserts") 
    167182      cdb.commit_db(conn) 
     183 
     184  # .. Close connection to database .. 
     185  # ================================== 
     186  if args.verbose: 
     187    print("Close connection") 
     188  cdb.close_db(conn) 
  • TOOLS/ConsoGENCI/trunk/bin/libconso.py

    r2713 r2751  
    1313import subprocess 
    1414import datetime as dt 
    15 import numpy as np 
     15# import numpy as np 
    1616import ConfigParser as cp 
    1717 
Note: See TracChangeset for help on using the changeset viewer.