Changeset 2751
- Timestamp:
- 02/24/16 17:11:19 (9 years ago)
- Location:
- TOOLS/ConsoGENCI/trunk/bin
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/ConsoGENCI/trunk/bin/init_alloc_tbl.py
r2713 r2751 19 19 20 20 21 ######################################## 21 ####################################################################### 22 22 if __name__ == "__main__": 23 23 24 24 project_list = [ 25 25 { 26 "name": "gen cmip6",26 "name": "gen0826", 27 27 "centre": "tgcc", 28 28 "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", 33 51 }, 34 52 { … … 36 54 "centre": "tgcc", 37 55 "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", 39 66 "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", 42 87 }, 43 88 { … … 47 92 "node": "standard", 48 93 "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", 51 105 }, 52 106 ] … … 99 153 100 154 cdb.commit_db(conn) 155 156 cdb.close_db(conn) -
TOOLS/ConsoGENCI/trunk/bin/init_conso_tbl.py
r2713 r2751 1 1 #!/usr/bin/env python 2 2 # -*- 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 11 3 12 4 # This must come first … … 18 10 # import datetime as dt 19 11 from argparse import ArgumentParser 12 import pprint 20 13 21 14 # Application library imports 22 import libconsodb as cdb 15 import libconso_db as cdb 16 import libconso_cpt as ccpt 17 18 pp = pprint.PrettyPrinter(indent=2) 23 19 24 20 25 ######################################## 21 ####################################################################### 26 22 def get_arguments(): 27 23 parser = ArgumentParser() … … 53 49 54 50 55 ######################################## 51 ####################################################################### 56 52 if __name__ == "__main__": 57 53 … … 64 60 print(args) 65 61 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__))) 67 65 DATA_DIR = os.path.join(ROOT_DIR, "data") 68 69 66 SUBMIT_DIR = os.getcwd() 70 67 71 # project = "rgzi" 72 # centre = "idris" 68 if args.verbose: 69 print("SUBMIT_DIR:", SUBMIT_DIR) 70 print("DATA_DIR:", DATA_DIR) 73 71 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) 75 75 76 # Connection info 76 # .. Connection to database .. 77 # ============================ 78 if args.verbose: 79 print("Connection to database") 77 80 db_host = "134.157.170.104" 78 81 # db_port = "5432" … … 80 83 db_user = "prodiguer_db_user" 81 84 # 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 files94 # 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 = item106 if login not in conso_per_login:107 conso_per_login[login] = set()108 conso_per_login[login].add((date, conso, ))109 110 85 conn, cursor = cdb.connect_db(db_host, db_name, db_user) 111 86 112 # Extract allocation id from table 87 # .. Extract allocation id from table .. 88 # ====================================== 113 89 table_name = "conso.tbl_allocation" 114 90 request = ( 115 "SELECT id " 91 # "SELECT id " 92 "SELECT * " 116 93 "FROM " + table_name + " " 117 94 "WHERE project = '" + args.project + "'" 118 95 " 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" 119 99 ";" 120 100 ) 121 101 122 102 cdb.select_db(cursor, request) 123 if cursor.rowcount != 1: 124 print(cursor.fetchall()) 125 exit() 103 # print(cursor.rowcount) 104 # print(cursor.fetchall()) 126 105 127 (allocation_id, ) = cursor.fetchone() 106 allocs = [] 107 for row in cursor: 108 allocs.append(ccpt.AllocRow(row)) 128 109 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 ) 130 117 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) 133 130 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 # --------------------------------- 134 136 lines_req = [ 135 137 ( … … 140 142 "{create})" 141 143 ) .format( 142 alloc=alloc ation_id,143 date= date,144 total_hrs= conso if not math.isnan(conso) else "'NaN'",145 login="'"+ login+"'" iflogin != "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", 146 148 create="CURRENT_TIMESTAMP", 147 ) for (date, conso) in conso_list149 ) for item in consos 148 150 ] 149 151 152 # print(lines_req) 153 154 # exit() 155 156 # ... Create full request ... 157 # --------------------------- 150 158 table_name = "conso.tbl_consumption" 151 159 request = ( … … 160 168 ) 161 169 request = request + ", ".join(lines_req) 162 print(request)163 170 171 # ... Execute request ... 172 # ----------------------- 173 if args.verbose: 174 print("Execute request for alloc_id = {}".format(alloc_id)) 164 175 cdb.insert_db(cursor, request) 165 176 177 # ... Commit inserts ... 178 # ---------------------- 166 179 if not args.dryrun: 180 if args.verbose: 181 print("Commit inserts") 167 182 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 13 13 import subprocess 14 14 import datetime as dt 15 import numpy as np15 # import numpy as np 16 16 import ConfigParser as cp 17 17
Note: See TracChangeset
for help on using the changeset viewer.