def initialize_model(tsid, target_date): """make instances of model classes""" start_time = time.time() tdate = target_date.strftime('%Y-%m-%d') # with futures.ThreadPoolExecutor(8) as executor: # res = [executor.submit(fn, tsid, tdate=tdate) for fn in [make_sections, # make_dgu_groups, # make_bids, # make_stations, # make_areas, # make_impex_areas, # make_nodes, # make_loads, # make_consumers, # make_dpgs, # make_dgus, # make_wsumgen, # make_gus, # make_lines, # make_price_zones, # make_settings]] # # list(res) make_sections(tsid, tdate=tdate) make_dgu_groups(tsid, tdate=tdate) make_bids(tsid, tdate=tdate) make_stations(tsid, tdate=tdate) make_areas(tsid, tdate=tdate) make_impex_areas(tsid, tdate=tdate) make_nodes(tsid, tdate=tdate) make_loads(tsid, tdate=tdate) make_consumers(tsid, tdate=tdate) make_dpgs(tsid, tdate=tdate) make_dgus(tsid, tdate=tdate) make_wsumgen(tsid, tdate=tdate) make_gus(tsid, tdate=tdate) make_lines(tsid, tdate=tdate) make_price_zones(tsid, tdate=tdate) make_settings(tsid, tdate=tdate) make_peak_so(tsid, target_date, tdate=tdate) print(time.time() - start_time)
# tup = tuple(map(lambda x, y: Decimal(x) - Decimal(y), n, o)) # if sum(map(abs, tup)) > 1e-3: # print(tup + n) # print('%i;%i;%f;%i;%i;%f;' % (tup + n), file=f) # else: # print('%i;%i;%f;' % tup, file=f) # ORM.recreate_all() # sections = make_sections(tsid, tdate) dgu_groups = make_dgu_groups(tsid, tdate) bids = make_bids(tsid, tdate) stations = make_stations(tsid, tdate) areas = make_areas(tsid, tdate) impex_areas = make_impex_areas(tsid, tdate) nodes = make_nodes(tsid, tdate) loads = make_loads(tsid, tdate) consumers = make_consumers(tsid, tdate) dpgs = make_dpgs(tsid, tdate) dgus = make_dgus(tsid, tdate)
import mat4py from utils import DB from decimal import * from operator import itemgetter getcontext().prec = 28 getcontext().rounding = ROUND_HALF_UP def f(x): return Decimal(x).quantize(Decimal('0.0000001')).quantize( Decimal('0.000001')) con = DB.OracleConnection() dates = con.exec_script('''select trade_session_id, target_date--, note from tsdb2.trade_Session where trunc(target_date) = to_date('10102016', 'ddmmyyyy') and is_main = 1 order by target_date''') for tsid, tdate in dates: ns = stations.make_stations(tsid, tdate.date()) print(len(ns)) for station in ns: if not station.category is None and station.category != 1: print(station.code, station.type, station.category) gaes = ns[198495] print(gaes.code, gaes.type, gaes.category)