def make_wsumgen(tsid): """create Wsumgen instances""" con = DB.OracleConnection() Wsumgen.clear() for new_row in con.script_cursor(ws, tsid=DB.Partition(tsid)): Wsumgen(new_row)
def make_impex_areas(tsid): """create ImpexArea instances""" con = DB.OracleConnection() ImpexArea.clear() for new_row in con.script_cursor(ias, tsid=DB.Partition(tsid)): ImpexArea(new_row)
def make_settings(tsid): """create Settings instances""" con = DB.OracleConnection() Setting.clear() for new_row in con.script_cursor(ss, tsid=DB.Partition(tsid)): Setting(new_row)
def make_dpgs(tsid): """create Dpg instances""" con = DB.OracleConnection() Dpg.clear() DpgSupply.clear() DpgImpex.clear() DpgDemand.clear() DpgDemandFSK.clear() DpgDemandSystem.clear() DpgDemandLoad.clear() for new_row in con.script_cursor(cs, tsid=DB.Partition(tsid)): if new_row.is_fsk: DpgDemandFSK(new_row) elif new_row.is_system: DpgDemandSystem(new_row) else: DpgDemandLoad(new_row) for new_row in con.script_cursor(dds, tsid=DB.Partition(tsid)): Dpg.by_id[new_row.dpg_id].add_disqualified_data(new_row) for new_row in con.script_cursor(gs, tsid=DB.Partition(tsid)): DpgSupply(new_row) for new_row in con.script_cursor(imp_s, tsid=DB.Partition(tsid)): DpgImpex(new_row)
def make_stations(tsid): """create Station instances""" con = DB.OracleConnection() Station.clear() for new_row in con.script_cursor(ss, tsid=DB.Partition(tsid)): Station(new_row)
def make_price_zones(tsid): """create PriceZone instances""" con = DB.OracleConnection() PriceZone.clear() for new_row in con.script_cursor(pzs, tsid=DB.Partition(tsid)): price_zone = PriceZone(new_row) for hour in range(HOURCOUNT): price_zone.add_price_zone_hour_data(hour)
def make_consumers(tsid): """create Consumer instances""" con = DB.OracleConnection() Consumer.clear() for new_row in con.script_cursor(rc, tsid=DB.Partition(tsid)): consumer = Consumer[new_row.consumer_code] if not consumer: consumer = Consumer(new_row) consumer.add_consumer_hour_data(new_row)
def make_areas(tsid): """create Area instances""" con = DB.OracleConnection() Area.clear() for new_row in con.script_cursor(ra, tsid=DB.Partition(tsid)): area = Area[new_row.area] if not area: area = Area(new_row) area.add_area_hour_data(new_row)
def make_nodes(tsid): """create Node instances""" con = DB.OracleConnection() Node.clear() for new_row in con.script_cursor(ns, tsid=DB.Partition(tsid)): node = Node[new_row.node_code] if not node: node = Node(new_row) node.add_node_hour_data(new_row)
def make_loads(tsid): """create Load instances""" con = DB.OracleConnection() Load.clear() for new_row in con.script_cursor(rl, tsid=DB.Partition(tsid)): load = Load[new_row.consumer_code] if not load: load = Load(new_row) load.add_load_hour_data(new_row)
def make_lines(tsid): """create Line instances""" con = DB.OracleConnection() Line.clear() for new_row in con.script_cursor(ls, tsid=DB.Partition(tsid)): node_from_code = new_row.node_from node_to_code = new_row.node_to line_par_num = new_row.n_par line = Line.by_key[node_from_code, node_to_code, line_par_num] if not line: line = Line(new_row) line.add_line_hour_data(new_row)
def make_peak_so(tsid, tdate): """create Settings instances""" con = DB.OracleConnection() PeakSO.clear() done = False for new_row in con.script_cursor(pss, tsid=DB.Partition(tsid), tdate=tdate): PeakSO(new_row) done = True if not done: for new_row in con.script_cursor(pbs): PeakSO(new_row)
def make_dgu_groups(tsid): """create DguGroup instances""" con = DB.OracleConnection() DguGroup.clear() for new_row in con.script_cursor(rgs, tsid=DB.Partition(tsid)): dgu_group = DguGroup[new_row.group_code] if not dgu_group: dgu_group = DguGroup(new_row) dgu_group.add_dgu(new_row) for new_row in con.script_cursor(prs, tsid=DB.Partition(tsid)): dgu_group = DguGroup[new_row.group_code] if dgu_group: dgu_group.add_reserve_data(new_row)
def make_gus(tsid): """create Gu instances""" con = DB.OracleConnection() Gu.clear() for new_row in con.script_cursor(gs, tsid=DB.Partition(tsid)): Gu(new_row) for new_row in con.script_cursor(ns, tsid=DB.Partition(tsid)): gu_code = new_row.gu_code if not Gu.by_code[gu_code]: Gu.from_nblock(new_row) print('WARNING!! added Gu %i not from RIO!' % gu_code) unit_hd = GuHourData(new_row) for unit in Gu.by_code[gu_code]: unit.add_gu_hour_data(new_row, unit_hd)
def make_sections(tsid): """create Section instances""" con = DB.OracleConnection() Section.clear() for new_row in con.script_cursor(ss, tsid=DB.Partition(tsid)): section_code = new_row.code section = Section[section_code] if not section: section = Section(new_row) section.add_section_hour_data(new_row) for new_row in con.script_cursor(lgs, tsid=DB.Partition(tsid)): section_code = new_row.section_code section = Section[section_code] if section: section.add_section_hour_line_data(new_row)
def make_dgus(tsid): """create Dgu instances""" con = DB.OracleConnection() Dgu.clear() for new_row in con.script_cursor(dgs, tsid=DB.Partition(tsid)): Dgu(new_row) for new_row in con.script_cursor(rgs, tsid=DB.Partition(tsid)): dgu = Dgu.by_code[new_row.rge_code] if dgu: dgu.add_dgu_hour_data(new_row) for new_row in con.script_cursor(glhs, tsid=DB.Partition(tsid)): dgu = Dgu.by_code[new_row.rge_code] if dgu: dgu.set_last_hour(new_row)
async def result_func(*args): if not source_1 and not source_2: _source_1, _source_2 = task['sources'] elif not source_1: (_source_1,), _source_2 = task['sources'], source_2 elif not source_2: _source_1, (_source_2,) = source_1, task['sources'] elif task['sources']: raise ValueError('wrong number of connections for check {}'.format(check['_id'])) else: _source_1, _source_2 = source_1, source_2 fwd = [] for source in _source_1, _source_2: con = DB.OracleConnection(source['class_name'], source['connection_string']) fwd += con, source.get('ops', {}) return target_func(*args, *fwd)
def make_bids(tsid): """create Bid instances""" con = DB.OracleConnection() Bid.clear() for new_row in con.script_cursor(bis, tsid=DB.Partition(tsid)): Bid(new_row) for new_row in con.script_cursor(bhs, tsid=DB.Partition(tsid)): bid = Bid[new_row.dpg_id] if bid: bid.add_hour_data(new_row) for new_row in con.script_cursor(bps, tsid=DB.Partition(tsid)): bid = Bid[new_row.dpg_id] if bid: bid.add_intervals_data(new_row)
def csv_comparator(data, script, filename, *join_clause, **kwargs): """comparator function""" data_o = DB.OracleConnection().script_cursor(script, **kwargs) print('filling %s' % filename) if data: first_row = data[0] else: raise Exception('empty data!') frmt = '' for datum in first_row: if isinstance(datum, int): frmt += '%i;' elif isinstance(datum, (float, Decimal)): frmt += '%f;' else: raise Exception('wrong type %r' % first_row) with open(filename, 'w', encoding='utf-8') as _file: spoiled = False for i, (new_row, old_row) in enumerate(zip_join(data, data_o, *join_clause)): try: tup = tuple( Decimal(x) - Decimal(y) for x, y in zip(new_row, old_row)) except TypeError: display(new_row) display(old_row) raise if sum(abs(i) for i in tup) > 1e-3: _file.write(frmt * 3 % (tup + new_row + old_row) + '\n') if not spoiled: display('------- check spoiled! -------') spoiled = True else: _file.write(frmt % tup + '\n') update_progress((i + 1) / len(data))
def fill_db(tdate): """insert data into DB""" start_time = time.time() con = DB.OracleConnection() send_bids_to_db(con, tdate) send_dpgs_to_db(con, tdate) send_stations_to_db(con, tdate) send_consumers_to_db(con) send_loads_to_db(con) send_areas_to_db(con) send_nodes_to_db(con) send_lines_to_db(con) send_dgus_to_db(con, tdate) send_dpgs_to_kc_dpg_node(con) send_dpgs_to_kg_dpg_rge(con) send_dpgs_to_node_bid_pair(con) if tdate.year < 2017: with con.cursor() as curs: curs.execute(''' UPDATE trader set oes = 3 where region_code in (35, 67) ''') curs.execute(''' DELETE from region where region_code in (35, 67) ''') curs.executemany(''' INSERT into region (region_code, region_name, sort_order) values (:1, :2, :3) ''', [(35, 'Республика Крым', 31), (67, 'Город Севастополь', 56)]) con.commit() print(time.time() - start_time)
bid_utils.arch_table('CONSUMER_INFO', null, null); bid_utils.arch_table('CSV', null, null); bid_utils.arch_table('DICS', null, null); bid_utils.arch_table('DISTR', null, null); bid_utils.arch_table('DISTR1', null, null); bid_utils.arch_table('EVR', null, null); bid_utils.arch_table('EVR_SRC', null, null); bid_utils.arch_table('FirstPoint', null, null); bid_utils.arch_table('GGTPS_DISTR', null, null); bid_utils.arch_table('HELP_IMPEX', null, null); bid_utils.arch_table('IASUKUT', null, null); bid_utils.arch_table('IMP_PR_REDUCE', null, null); bid_utils.arch_table('LIMITS', null, null); bid_utils.arch_table('MGP', null, null); bid_utils.arch_table('PNT', null, null); bid_utils.arch_table('RC_DISTR', null, null); bid_utils.arch_table('RD', null, null); bid_utils.arch_table('RD2', null, null); bid_utils.arch_table('REPORT', null, null); bid_utils.arch_table('RIO_2', null, null); bid_utils.arch_table('RIO__TRADER_SPEC_DATE', null, null); bid_utils.arch_table('TRADER', null, null); bid_utils.arch_table('VSVGO', null, null); end; ''') if __name__ == '__main__': for tdate, scenario_num in scenarios: main(tdate, scenario_num, DB.OracleConnection(), add_note)
from eq_db.classes import loads 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('21102016', 'ddmmyyyy') and is_main = 1 order by target_date''') for tsid, tdate in dates: ns = loads.make_loads(tsid, tdate.date()) print(len(ns)) for load in ns: for node_code, n in load.nodes.items(): if len(n['hour_data']) != 24: print(load.consumer_code, node_code, len(n['hour_data'])) print(ns[1255].consumer_code, 100748,
filename = 'sipr{}{:02}_{}_{}'.format( scenario, sipr_calc % sipr_calc_length, future_date.strftime('%Y%m%d'), template) file_path = os.path.join(r'C:\python\calc_factory\reports', filename) generate_report(main_con, script, template, worksheet, start, file_path, kwargs) reports_path = os.path.join(S.REPORTS_PATH, \ 'sipr{}{:02}'.format(scenario, sipr_calc % sipr_calc_length)) if not os.path.isdir(reports_path): os.mkdir(reports_path) shutil.copy(file_path, os.path.join(reports_path, filename)) if __name__ == '__main__': with DB.OracleConnection().cursor() as cursor: cursor.execute(''' begin UPDATE loader_out_tab set for_main_eq = 0 where code = 'run CONVERTOUT1'; commit; end; ''') try: for (target_date, sipr), scen in product(CALCS, SCENARIOS): main(target_date, sipr + sipr_calc_length * scen, DB.OracleConnection(), scen) except Exception: raise
from utils import DB tbl_script = """ SELECT table_name, status from all_tables where owner = 'FACTS' and table_name = 'LOADBIDS_DPGG_DATE' """ col_script = """ SELECT column_name, data_type from all_tab_columns where table_name = :tab_name """ con = DB.OracleConnection('facts/facts@ts_black') # Заполнение таблиц FACTS из файлов-INSERT'ов # # def read2(f): # for line in f: # try: # line2 = next(f) # except StopIteration: # line2 = '' # # yield '%s %s' % (line , line2.replace(';', '')) # # with con as curs: # # for table_name, stts in con.exec_script(tbl_script):