def view_edu(add_logotype=False): try: conn = MySQLConnection(**config_eduwork) cursor = conn.cursor() header = lambda: [d[0] for d in cursor.description] if add_logotype: cursor.execute('SELECT * FROM `edu`') print( data2rst([ header(), *[[ *row[:-1], row[-1][:10] + b'...' if row[-1] is not None else None ] for row in cursor] ], center_cells=True)) else: cursor.execute( 'SELECT `id_edu`, `short_title`, `nolong_title`, `title` FROM `edu`' ) print( data2rst([header(), *[list(row) for row in cursor]], center_cells=True)) except Error as err: print(err) finally: cursor.close() conn.close()
def schema_as_table(self, table_format='rst'): ''' Method to export schema as tabular table - converts list of lists into ASCII table Args: table_format (str) ['rst','md'] ''' # init table table = [] # set headers table.append(['Parameter','Type','Description']) # loop through schema properties and add props = self.schema['properties'] for k,v in props.items(): table.append([ "``%s``" % k, self._table_format_type(v['type']), self._table_format_desc(v['description']) ]) # sort by property name table.sort(key=lambda x: x[0]) # return as table based on table_format if table_format == 'rst': return dashtable.data2rst(table, use_headers=True) elif table_format == 'md': return dashtable.data2md(table, use_headers=True) elif table_format == 'html': return None
def display_re_switchover_summary(self, host, task_status, data): if self.re_switch_details: self._display.display( '########## Table: RE Switchover Summary ####################') if self.playbook_filename in RE_SWITCHOVER_PLAYBOOKS: table_rows = [] table_rows.append([ 'Device', 'Master RE-Before Switch', 'Master RE-After Switch', 'Switchover Status', 'Comments' ]) for host, details in self.re_switch_details.items(): table_row = [host, '', '', '', ''] for key, val in self.re_switch_details[host].items(): if key == 'master_re_before_switchover': table_row[1] = val if val else '' elif key == 'master_re_after_switchover': table_row[2] = val if val else '' elif key == 'comments': for comment in val: table_row[4] = '{0}\n- {1}'.format(table_row[4] + '- ' + comment) if table_row[1].strip().lower() == table_row[2].strip().lower( ) and table_row[1] != '' and table_row[2] != '': table_row[3] = 'Fail' elif table_row[1].strip().lower() != table_row[2].strip( ).lower() and table_row[1] != '' and table_row[2] != '': table_row[3] = 'Success' else: table_row[3] = 'Fail' table_rows.append(table_row) self._display.display(data2rst(table_rows, use_headers=True))
def calculate_publish(self, *args, **kwargs): result = self.calculate(*args, **kwargs) rv = result['rv'] header_1 = ['Повторюваність, %'] header_2 = [] row_1 = [] row_2 = [] rv_keys = ('Пн', 'ПнСх', 'Сх', 'ПдСх', 'Пд', 'ПдЗ', 'З', 'ПнЗ') for i in range(3): for key in rv_keys: if i == 0: header_1.insert(1, '') header_2.append(key) elif i == 1: row_1.append(str(rv[key][0])) elif i == 2: row_2.append(str(rv[key][1])) header_1[-1] = 'Штиль, %' header_2.append('') row_1.append(str(result['clam'])) row_2.append('') table = [header_1, header_2, row_1, row_2] spans = [([0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7]), ([0, 8], [1, 8]), ([2, 8], [3, 8])] return data2rst(table, spans=spans, use_headers=False)
def report(url): print("{}URL REPORT LOADED".format(notations._run)) print("{}Building Query".format(notations.star)) param["resource"] = url try: print("{}Checking URL Connection".format(notations._run)) r = requests.get(api["report"], params=param) print("{}Fetching the response".format(notations.star)) data = dict(r.json()) print("{}Formatting the response to human readable format".format( notations.star)) table = [] for x, y in data.items(): x = x.replace("_", " ") x = x.title() if x == "Scans": continue elif x == "total": x = "Total Scans" table.append([x, y]) print("{}Scan result for {}".format(notations.info, url)) print(data2rst(table, use_headers=False)) x = input("{}Do you want scan result of anti viruses [y/N] ".format( notations.ques)).lower() if x == "y": globals.showScanResult(data['scans']) except requests.ConnectionError: print("{}Can't connect to internet".format(notations._err)) exit(1) pass except requests.HTTPError: print("{}Invalid URL".format(notations._err)) exit(1) pass
def scan(url): print("{}URL SCAN LOADED".format(notations._run)) print("{}Building Query".format(notations.star)) param["url"] = url try: print("{}Checking URL Connection".format(notations.star)) r = requests.post(api["scan"], params=param) print("{}Fetching the response".format(notations.star)) data = r.json() table = [] for x, y in data.items(): x = x.replace("_", " ") x = x.title() if not x == "Response Code": table.append([x, y]) if data["response_code"] == -1: raise requests.HTTPError print("{}Scan result for {}".format(notations.star, url)) print(data2rst(table, use_headers=False)) x = input("{}Do you want to retrieve scan report [y/N]".format( notations.ques)).lower() if x == "y": report(url) except requests.ConnectionError: print("{}Can't connect to internet".format(notations._err)) exit(1) pass except requests.HTTPError: print("{}Invalid URL".format(notations._err)) exit(1) pass
def print_table_12_2(label, array_, fmt=None): print( data2rst([[label, '', '', '', '', '', '', '', '', '', '', ''], [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII' ], list(array_) if fmt is None else [('{0:%s}' % fmt).format(v) for v in array_]], spans=[[[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11]]], center_cells=True))
def log_gathered_fact_table(self, loghost, logfile): if self._playbook_filename in ('PLAY BOOK NAMES HAVING DIFFRENT FORMAT TO LOG'): pass # LOGIC FOR DISPLAYING FACTS IN DIFFERENT FORMAT FOR SOME PLAYBOOKS else: for host, facts in sorted(self.host_facts.items()): if host == loghost: table_rows = [] spans = [] table_rows.append(['Device', 'Model', 'RE', 'Mastership State', 'Software Version', 'Switch Style', 'Comments']) row_num = 0 logfile.write('\n########## Table: Device Info ####################\n') if self.host_facts.get(host, {}).get('passed'): device_model = facts.get('model', ERROR_UNABLE_2_GET) switch_style = facts.get('switch_style', ERROR_UNABLE_2_GET) #try: #self._display.display(str(self.host_facts.get(host, {}.get('master_re')))) #self._display.display(str(host)) master_re = self.host_facts.get(host, {}).get('master_re').upper() #except: # master_re = None #self._display.display(str(self.host_facts)) if not self.host_facts.get(host, {}).get('has_2re'): row_num += 1 mastership_state = self.host_facts.get(host, {}).get(master_re, {}).get('mastership_state', ERROR_UNABLE_2_GET) soft_ver = self.host_facts.get(host, {}).get(master_re, {}).get('soft_ver', ERROR_UNABLE_2_GET) table_rows.append([host, device_model, master_re, mastership_state, soft_ver, switch_style, 'Single RE device']) else: host_span = [] model_span = [] switch_style_span = [] comments_span = [] for re in (RE0, RE1): row_num += 1 host_span.append([row_num, 0]) model_span.append([row_num, 1]) switch_style_span.append([row_num, 5]) comments_span.append([row_num, 6]) mastership_state = self.host_facts.get(host, {}).get(re, {}).get('mastership_state', ERROR_UNABLE_2_GET) soft_ver = self.host_facts.get(host, {}).get(re, {}).get('soft_ver', ERROR_UNABLE_2_GET) if re == RE0: table_rows.append([host ,device_model, re, mastership_state, soft_ver, switch_style, '']) else: table_rows.append(['', '', re, mastership_state, soft_ver, '', '']) spans.extend([host_span, model_span, switch_style_span, comments_span]) else: #self._display.display(str(self.host_facts)) row_num += 1 err_msg = self.host_facts.get(host, {}).get('err_msg') if not err_msg: err_msg = 'Unable to get the details' table_rows.append([host, '', '', '', '', '', err_msg]) logfile.write(str(data2rst(table_rows, spans=spans, use_headers=True)))
def view(self): libs.banner.banner() # printing the banner print("<--=[Viewing All]=-->\n") data = self.execute() # execute and getting data rows = len(data) - 1 if rows > 0: # checks if table has any data or not print(colorama.Fore.LIGHTGREEN_EX + "[*] Success - Total ", rows, "row(s) fetched\n\n" + colorama.Style.RESET_ALL) print(dashtable.data2rst(data, center_cells=True, use_headers=True)) else: print(colorama.Fore.LIGHTBLUE_EX + "[*] Info - No Entry Found" + colorama.Style.RESET_ALL) pass
def print_table_13(label, array_, row_start=1, fmt=None): print( data2rst([[label, '', '', '', '', '', '', '', '', '', '', '', ''], [ '№ вар.', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII' ], *[[ i, *(v if fmt is None else [('{0:%s}' % fmt).format(x) for x in v]) ] for i, v in enumerate(array_, start=row_start)]], spans=[[[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12]]], center_cells=True))
def view_group(): try: conn = MySQLConnection(**config_eduwork) cursor = conn.cursor() header = lambda: [d[0] for d in cursor.description] cursor.execute('SELECT * FROM `group`') print( data2rst([header(), *[list(row) for row in cursor]], center_cells=True)) except Error as err: print(err) finally: cursor.close() conn.close()
def view(self): libs.banner.banner() print("<--=[Viewing for {}]=-->\n\n".format(self.roll_number)) data = self.execute() # getiing data from sql if len(data) > 1: # checking if roll number exists or not print(dashtable.data2rst(data, center_cells=True)) print(colorama.Fore.LIGHTGREEN_EX + "\n[!] Success - Successfully executed") pass else: print(colorama.Fore.LIGHTRED_EX + "\n[x] Error - Roll number {} doesn't exists".format( self.roll_number)) pass pass
def view_account_temp(is_full=False): try: conn = MySQLConnection(**config_eduwork_temp) cursor = conn.cursor() if is_full: query = 'SELECT * FROM `account_temp`' else: query = 'SELECT `email`, `ip`, `mac`, `get_datetime` FROM account_temp' cursor.execute(query) print( data2rst( [[d[0] for d in cursor.description], *[list(row) for row in cursor]], center_cells=True)) except Error as err: print(err) finally: cursor.close() conn.close()
def v2_playbook_on_stats(self, stats): if self.fail_summary: self._display.display('########## Table: Play Failure Summary ####################') #table_fail_summary = Texttable() table_rows = [] spans = [] host_span = [] row = 0 table_rows.append(['Device', 'Failed Tasks', 'Message(If Any)']) for host, tasks_and_messages in self.fail_summary.items(): host_in_table = False total_rows = len(tasks_and_messages) host_span = [] for task, message in tasks_and_messages: row += 1 host_span.append([row, 0]) if not host_in_table: table_rows.append([host, task, message]) host_in_table = True else: table_rows.append(['', task, message]) spans.extend([host_span]) self._display.display(data2rst(table_rows, spans=spans, use_headers=True))
def pytest_sessionfinish(session, exitstatus): print('=' * 35, 'DL report', '=' * 35) print(f"session exitstatus is {exitstatus}") if exitstatus != 0: return print(session.results) parsed_results = [] params_variety = dict() table_params = set() static_params = dict() for el in session.results: options = dict() for string in el.split('|'): key, value = string.split('=') options[key] = value if key not in params_variety: params_variety[key] = [value] elif value not in params_variety[key]: params_variety[key].append(value) table_params.add(key) parsed_results.append((options, session.results[el])) assert (len(table_params) != 0) for el in parsed_results: for option in el[0]: if option not in table_params: static_params[option] = el[0][option] print(params_variety) table_name = static_params['model_name'] headers = ['criterion'] spans = [] cord = 1 for i, el in enumerate( sorted(params_variety['metric_name']) + ['time', 'memory']): # inference time, max memory headers.append(el) curr_span = [[0, cord]] cord += 1 for j in range(len(params_variety['batch_size']) - 1): headers.append('') curr_span.append([0, cord]) cord += 1 spans.append(curr_span) subheaders = ['batch_size'] for i in range((len(headers) - 1) // len(params_variety['batch_size'])): for el in params_variety['batch_size']: subheaders.append(el) cells = dict() order = ['criterion_func'] + ['batch_size'] for el in parsed_results: mystr = [] for param in order: mystr.append(el[0][param]) mystr = '|'.join(mystr) if mystr in cells: logging.warning("Doubled results. Something went wrong") else: cells[mystr] = el[1] cells_structure = [] columns = sorted(params_variety['metric_name']) + ['time', 'memory'] for crit in sorted(params_variety['criterion_func']): row = [crit] for col in columns: for bs in sorted(params_variety['batch_size']): results = cells[f'{crit}|{bs}'] if col not in results: row.append("-") else: row.append(f"{results[col]:6.4f}") cells_structure.append(row) print(table_name) print( dashtable.data2rst([headers, subheaders] + cells_structure, spans=spans))
def __show_table(self): table = self.__new_table() spans = copy.deepcopy(self.__spans) print(data2rst(table, spans))
def calculate_publish(self, *args, **kwargs): result = self.calculate(*args, **kwargs) A = result['A'] header_1 = [ 'Середня місячна температура повітря / середня добова \ амплітуда\nтемператури, ⁰С', '', '', '', '', '', '', '', '', '', '', '', 'Температура повітря, ⁰С', '', '', '', '', '', '', 'Період із середньою добовою\nтемпературою повітря', '', '', '', '', '' ] header_2 = [ 'С.р.', 'холодного періоду', '', '', '', 'теплого\nперіоду', '', '≤ 8 ⁰С', '', '≤ 10 ⁰С', '', '≤ 21 ⁰С', '' ] header_3 = [ '', '', '', '', '', '', '', '', '', '', '', '', '', 'найхолод-\nніша доба\nзабезпече-\nністю', '', "найхолод-\nніша\nп'ятиденка\nзабезпече-\nністю", '', 't_д\n0,95', 't_х5\n0,99', 'Z,\nдіб', 't_с,\n⁰С', 'Z,\nдіб', 't_с,\n⁰С', 'Z,\nдіб', 't_с,\n⁰С' ] header_4 = [ '', '', '', '', '', '', '', '', '', '', '', '', '', '0,98', '0,92', '0,98', '0,92', '', '', '', '', '', '', '', '' ] row_1 = [] row_2 = [] A_keys = ('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII') for i in range(6): k = 0 for key in A_keys: if i == 2: header_2.insert(k, key) k += 1 elif i == 4: row_1.append(str(A[key][0])) elif i == 5: row_2.append(str(A[key][1])) row_1 += [ str(result['t_s_y']), str(result['t_max_e'][0.98]), str(result['t_max_e'][0.92]), str(result['t_h5'][0.98]), str(result['t_h5'][0.92]), str(result['t_max_e_tpr_0.95']), str(result['t_h5_tpr_0.99']) ] row_2 += ['', '', '', '', '', '', ''] pd = result['period_t_s_e'] for t_data in ('≤ 8 ⁰С', '≤ 10 ⁰С', '≥ 21 ⁰С'): row_1.append(str(pd[t_data]['Z'])) row_1.append(str(pd[t_data]['t_s'])) row_2 += ['', ''] table = [header_1, header_2, header_3, header_4, row_1, row_2] spans = [([0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11]), ([0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18]), ([0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24]), ([1, 12], [2, 12], [3, 12]), ([1, 13], [1, 14], [1, 15], [1, 16]), ([1, 17], [1, 18]), ([1, 19], [1, 20]), ([1, 21], [1, 22]), ([1, 23], [1, 24]), ([2, 13], [2, 14]), ([2, 15], [2, 16]), ([2, 17], [3, 17]), ([2, 18], [3, 18]), ([2, 19], [3, 19]), ([2, 20], [3, 20]), ([2, 21], [3, 21]), ([2, 22], [3, 22]), ([2, 23], [3, 23]), ([2, 24], [3, 24]), ([1, 10], [2, 10], [3, 10]), ([1, 11], [2, 11], [3, 11])] for c in range(10): spans.append(([1, c], [2, c], [3, c])) for k in range(12, 25): spans.append(([4, k], [5, k])) return data2rst(table, spans=spans, use_headers=False)
def table_texts(self, name, question_headers, total_score=None, question_grades=None): if question_grades and total_score is None: total_score = sum( [e for r in question_grades for e in (r[0] if r else [20])]) score_perc_question = total_score / len(question_headers) tables = [] overall = [[f'{name}', '', 'Info/Result', '']] overall_spans = [[[0, 0], [0, 1]], [[0, 2], [0, 3]]] for i, (q_result, q_header) in enumerate( zip(self.question_results, question_headers)): recalculated_points = question_grades[i][ 0] if question_grades and question_grades[i] else None has_sourced = q_result.compilation_error == '' table = [[f'Q{i+1}', '', 'Info/Result', '']] spans = [[[0, 0], [0, 1]], [[0, 2], [0, 3]]] if has_sourced: for q_i, (test, (p, e)) in enumerate( zip(q_header.normalized_tests(), q_result.points)): score_perc = recalculated_points[q_i] if recalculated_points else \ score_perc_question / len(q_result.points) spans.append([[q_i + 1, 0], [q_i + 1, 1]]) if e == '': # True or False, without source error table.append([f'{test}({score_perc:.2f})', '', p, '']) spans.append([[q_i + 1, 2], [q_i + 1, 3]]) else: table.append( [f'{test}({score_perc:.2f})', '', 'Error', e]) else: table.append( ['Source Error', '', q_result.compilation_error, '']) spans.append([[1, 0], [1, 1]]) spans.append([[1, 2], [1, 3]]) table.append([ f'Total({sum(recalculated_points) if recalculated_points else score_perc_question:.2f})', '', q_result.total_point, '' ]) spans.append([[len(table) - 1, 0], [len(table) - 1, 1]]) spans.append([[len(table) - 1, 2], [len(table) - 1, 3]]) overall.append([ f'Q{i+1}({sum(recalculated_points) if recalculated_points else score_perc_question:.2f})', '', q_result.total_point, '' ]) overall_spans.append([[len(overall) - 1, 0], [len(overall) - 1, 1]]) overall_spans.append([[len(overall) - 1, 2], [len(overall) - 1, 3]]) tables.append( data2rst(table, spans=spans, center_headers=True, center_cells=True, use_headers=True)) if len(question_headers) > 1: overall.append([ f'Total({total_score:.2f})', '', sum([q_r.total_point for q_r in self.question_results]), '' ]) overall_spans.append([[len(overall) - 1, 0], [len(overall) - 1, 1]]) overall_spans.append([[len(overall) - 1, 2], [len(overall) - 1, 3]]) tables.append( data2rst(overall, spans=overall_spans, center_headers=True, center_cells=True, use_headers=True)) return tables
def run(): repos = get_repo_names() branches = get_reference_branches() # Get all statuses and list of unique topics statuses = {} topics = [] for repo in repos: statuses[repo] = {} for branch in branches: status = get_topics_merge_status(repo, branch) statuses[repo][branch] = status for state in ['merged', 'notmerged']: for topic in status[state]: topics.append(topic) topics = list(set(topics)) logging.debug(f'data:\n{pprint.pformat(statuses)}') logging.debug(f'topics:\n{pprint.pformat(topics)}') # Colored output settings repo_colors = [ colored.fg(0) + colored.bg(7), colored.fg(0) + colored.bg('cyan'), colored.fg(0) + colored.bg(208), colored.fg(15) + colored.bg(63), colored.fg(7) + colored.bg(21), colored.fg(0) + colored.bg(229), colored.fg(0) + colored.bg(221), colored.fg(0) + colored.bg(214), colored.fg(0) + colored.bg(208), ] yes_color = colored.stylize(' Yes ', colored.fg('green')) no_color = colored.stylize(' No ', colored.fg('red')) # Create data rows for output # Row format is: # CONTROL HIERA LEGACY # 0 1 2 3 4 5 6 # topic prod test prod test prod test br_max_len = 4 br_hdrs = [b[:br_max_len].upper() for b in branches] hdr_row_2 = ['TOPIC'] [hdr_row_2.extend(br_hdrs) for r in repos] #rows = [] rows = [hdr_row_2] max_topic_len = 0 for topic in sorted(topics): rownum = len(rows) if len(topic) > max_topic_len: max_topic_len = len(topic) row = [topic] for repo in repos: for branch in branches: colnum = len(row) val = '-' if topic in statuses[repo][branch]['merged']: #val = yes val = 'Yes' elif topic in statuses[repo][branch]['notmerged']: #val = no val = 'No' row.append(val) rows.append(row) # Make repo header row pad_len = 2 #cell padding size sep_len = 2 #column separator size sep = ' ' * sep_len hdr_row_1 = [''] for i, r in enumerate(repos): hdr_row_1.append(r.upper()) for b in branches[1:]: hdr_row_1.append('') rows.insert(0, hdr_row_1) table_params = { 'use_headers': True, 'center_cells': False, 'center_headers': True, } # colspans are directly related to number of branches and number of repos num_branches = len(branches) if num_branches > 1: spanlist = [] for repo_iter in range(len(repos)): cells = [] for br_iter in range(1, num_branches + 1): colnum = repo_iter * num_branches + br_iter cells.append([0, colnum]) spanlist.append(cells) table_params['spans'] = spanlist table_params['spans'] = spanlist text_table = dashtable.data2rst(rows, **table_params) # Attempt to replace plain strings with colorized versions text_table = text_table.replace(' Yes ', yes_color) text_table = text_table.replace(' No ', no_color) for i, r in enumerate(repos): R = r.upper() pattern = f'\|( +{R} +)\|' match = re.search(pattern, text_table) if match: old = match.group(1) new = colored.stylize(old, repo_colors[i]) text_table = text_table.replace(old, new) # Remove column markers text_table = text_table.replace('|', ' ') # Unindent everything lines = text_table.splitlines() lines = [l[2:] for l in lines] # Save last line to use as header demark demark_line = lines.pop() demark_line = demark_line.replace('+', ' ') # Remove non-content lines lines = [l for l in lines if ' ' in l] # Add in demark line lines.insert(2, demark_line) print('\n'.join(lines))
def calculate(t_z_h5, q_0, V_bud, N, t_gv, a_gv, fi, f_z, vartheta, S_0, F_r, eta_0, UL, a, b, c_pa, tip_tp, P_tp, epsilon_tp, epsilon_el, P_el, t_co_1, t_co_2, eta_K, Q_n_r, c_gaz, c_el, q_gru, d, l_0, data_t_n_s=None, data_t_hv=None, data_t_gru=None, fname_climate=None, target_graph=TargetGraph.show, show_own_frame=True, figure_embedded=None): ''' СО: @param: t_z_h5 (float) - температура холодної п'ятиденки із забезпеченням 0,92; @param: q_0 (float) - питома потужність тепловитрат, Вт/(м^3*град.С); @param: V_bud (float) - об'єм будинку по зовнішніх обмірах, м^3. СГВ: @param: N (int) - кількість мешканців у будинку; @param: t_gv (int) - температура гарячої води, град.С; @param: a_gv (int) - добова витрата гарячої води на 1 особу, л/добу. Геліоколектор: @param: fi (float) - географічна широта, град. пн. ш.; @param: f_z (float) - ступінь заміщення тепловитрат СГВ; @param: vartheta (float) - параметр; @param: S_0 (float) - площа одного геліоколектору, м^2; @param: F_r (float); @param: eta_0 (float) - оптичний ККД; @param: UL (float) - коефіцієнт тепловитрат, Вт/(м^2*К); @param: a (float); @param: b (float); @param: c_pa (float) - питома теплоємність, кДж/(кг*К). Теплова помпа: @param: tip_tp (str) - тип теплової помпи; @param: P_tp (float) - потужність, кВт; @param: epsilon_tp (float) - тепловий к.к.д.; @param: epsilon_el (float) - електричний к.к.д.; @param: P_el (float) - потужність електрична, кВт; @param: t_co_1 (int) - температура нагрітої води для СО підлоги, град.С; @param: t_co_2 (int) - температура охолодженої води для СО підлоги, град.С; @param: eta_K (float) - к.к.д згоряння палива; @param: Q_n_r (float) - нижча теплота згоряння палива, кДж/м^3; @param: c_gaz (float) - вартість 1 м^3 газу, грн/м^3; @param: c_el (float) - Вартість 1 кВт*год, грн/(кВт*год). Ґрунт і контур СО підлоги: @param: q_gru (float) - питома тепловіддача ґрунту, Вт/м^2; @param: d (int) - внутрішній діаметр поліетиленової труби, мм; @param: l_0 (float) - питома довжина тепловідбору, м/м^2. @param: data_t_n_s (dict) - середньомісячна температура зовн. пов; @param: data_t_hv (dict) - температура холодної води по місяцях, град.С; @param: data_t_gru (dict) - т-ра ґрунту, град.С; @param: fname_climate (str) - шлях до кліматичних даних програми. ''' print('Розрахунок виконується о: {}.'.format( datetime.strftime(datetime.now(), '%d.%m.%Y %H:%M:%S'))) print(' Вихідні дані: '.center(80, '=')) if not fname_climate: fname_climate = r'C:\Users\ichet\Dropbox\myDocs\St\antStepClimaData.txt' mis = np.arange(1, 13) data_dni_mis = { 1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 } # СО: if not data_t_n_s: # Середньомісячна температура зовн. пов. data_t_n_s = { 1: -6.1, 2: -5.6, 3: -0.7, 4: 7.2, 5: 14.3, 6: 17.6, 7: 18.8, 8: 17.7, 9: 13.7, 10: 7.2, 11: 1.0, 12: -3.7 } # СГВ: if not data_t_hv: # Температура холодної води по місяцях, град.С. data_t_hv = { 1: 5, 2: 4, 3: 3, 4: 4, 5: 6, 6: 10, 7: 16, 8: 17, 9: 14, 10: 11, 11: 8, 12: 6 } # Ґрунт і контур СО підлоги: if not data_t_gru: # Т-ра ґрунту, град.С. data_t_gru = { 1: 9.5, 2: 7.6, 3: 6.6, 4: 6.6, 5: 7.4, 6: 8.3, 7: 10.4, 8: 11.9, 9: 12.8, 10: 13.2, 11: 12.7, 12: 11.4 } dni_mis = np.array(list( data_dni_mis.values())) # Дні місяця протягом року. t_n_s = np.array(list(data_t_n_s.values())) # Середньомісячні температури. t_hv = np.array(list(data_t_hv.values())) # Температура холодної води. t_gru = np.array(list(data_t_gru.values())) # Температура ґрунту. print('Шлях до файлу з джерелом кліматичних даних: "{}".'.format( fname_climate)) print('**** СО: ****') print("Середня температура найхолоднішої п'ятиденки, t_z_h5 = {} град.С.". format(t_z_h5)) print('Середні температури зовнішнього повітря, t_n_s, град.С:') print_table_12_2('t_n_s, град.С', t_n_s) #print('Середня температура внутрішнього повітря в будинку, t_v_s = {} град.С.' # .format(t_v_s)) print( 'Питома потужність тепловитрат, q_0 = {} Вт/(м^3*град.С).'.format(q_0)) print("Об'єм будинку по зовнішніх обмірах, V_bud = {} м^3.".format(V_bud)) print('**** СГВ: ****') print('Кількість мешканців у будинку, N = {}.'.format(N)) print('Температура холодної води по місяцях, t_hv, град.С:') print_table_12_2('t_hv, град.С', t_hv) print('Температура гарячої води, t_gv = {} град.С.'.format(t_gv)) print('Добова витрата гарячої води на 1 особу, a_gv = {} л/добу.'.format( a_gv)) print('**** Геліоколектор: ****') print('Географічна широта, fi = {} пн. ш.'.format(fi)) print('Ступінь заміщення тепловитрат СГВ, f_z = {}.'.format(f_z)) print('Параметр, vartheta = {}.'.format(vartheta)) print('Площа 1-го геліоколектору, S_0 = {} м^2.'.format(S_0)) print('F_r = {}.'.format(F_r)) print('Оптичний к.к.д., eta_0 = {}.'.format(eta_0)) print('UL = {}'.format(UL)) print('a = {}, b = {}.'.format(a, b)) print('c_pa = {}.'.format(c_pa)) print('**** Теплова помпа (ТП): ****') print('Тип: ', tip_tp) print('Теплова потужність, P_tp = {} кВт.'.format(P_tp)) print('Тепловий к.к.д, epsilon_tp = {}.'.format(epsilon_tp)) print('Електричний к.к.д., epsilon_el = {}.'.format(epsilon_el)) print('Електрична потужність, P_el = {} кВт.'.format(P_el)) print('Т-ра нагрітої води для СО підлоги, t_co_1 = {} град.С.'.format( t_co_1)) print('Т-ра охолодженої води для СО підлоги, t_co_2 = {} град.С.'.format( t_co_2)) print('К.к.д. згоряння палива, eta_K = {}.'.format(eta_K)) print('Нижча теплота згоряння палива, Q_n_r = {} кДж/м^3.'.format(Q_n_r)) print('Вартість 1 м^3 газу, c_газ = {} грн/м^3.'.format(c_gaz)) print('Вартість 1 кВт*год, c_el = {} грн/(кВт*год).'.format(c_el)) print('**** Ґрунт і контур СО підлоги: ****') print('Температура ґрунту по місяцях, t_gru, град.С:') print_table_12_2('t_gru, град.С', t_gru) print('Питома тепловіддача ґрунту, q_gru = {} Вт/м^2.'.format(q_gru)) print('Внутрішній діаметр, d = {} мм.'.format(d)) print('Питома довжина тепловідбору, l_0 = {} м/м^2.'.format(l_0)) c_pv = 4.19 # Питома теплоємність води, КДж/(кг*К). ro_v = 1000 # Густина води за нормальних умов, кг/м^3. print( data2rst([[ 'Місяць', 'К-сть\nднів', 't_n_s,\nград.С', 't_hv,\nград.С', 't_gru,\nград.С' ], *[[i[0], *i[1:]] for i in zip(mis, dni_mis, t_n_s, t_hv, t_gru)]], center_cells=True)) print(' Розрахунок теплового навантаження системи опалення: '.center( 80, '=')) P_op_max = round(q_0 * V_bud * (18 - t_z_h5)) print('Максимальна потужність системи опалення, P_op_max = {} Вт.'.format( P_op_max)) # Алгоритм для функціонування системи опалення в опалювальний період: # for j=1:1:12, k(j)=1; if j<4 | j>10, l(j)=1; elseif j==4 | j==10 # l(j)=1/2;k(j)=2; else, l(j)=0; end, end # Qop_d=round(3.6*24*q0*Vbud*(18-tns).*l.*k) # Qop_mis=round(Qop_d./k.*dniMis) print('Середньодобове теплове навантаження системи опалення, Q_op_d, кДж:') Q_op_d = np.around(3.6 * 24 * q_0 * V_bud * (18 - t_n_s)) print_table_12_2('Q_op_d, кДж', Q_op_d) print('Середньомісячне теплове навантаження, Q_op_mis, кДж:') Q_op_mis = Q_op_d * dni_mis print_table_12_2('Q_op_mis, кДж', Q_op_mis) Q_op_r = Q_op_d.dot(dni_mis) print('Річне теплове навантаження на систему опалення, Q_op_r = {} кДж.'. format(Q_op_r)) print( ' Розрахунок теплового навантаження системи гарячого водопостачання: '. center(80, '=')) print( 'Кількість мешканців у будинку N = {} чол.,\nТемпература гарячої води ' 't_gv = {} град.С.'.format(N, t_gv)) print( 'Норма витрати гарячої води на одну особу a = {} л/добу.'.format(a_gv)) print('Помісячне середньодобове теплове навантаження системи гарячого ' 'водопостачання (СГВ), Q_gv_d, кДж:') Q_gv_d = np.around(1.2 * a_gv / 1000 * c_pv * ro_v * (t_gv - t_hv) * N) print_table_12_2('Q_gv_d, кДж', Q_gv_d) print( 'Середньомісячне значення потужності системи гарячого водопостачання, ' 'P_gv_mis, кВт:') P_gv_mis = Q_gv_d / (3600 * 24) print_table_12_2('P_gv_mis, кВт', P_gv_mis, fmt=FLOAT_DEC_4) t_hv_min = t_hv.min() n = t_hv.argmin() print( 'Потужність резервного водонагрівача для n = {} міс. із t_hv_min = {} град.С, ' 'P_rez_mis_max, кВт:'.format(n + 1, t_hv_min)) P_rez_mis_max = 24 / 6 * P_gv_mis[..., n] print('P_rez_mis_max = {0:.4f} кВт.'.format(P_rez_mis_max)) print('Місячне навантаження СГВ, Q_gv_mis, кДж:') Q_gv_mis = np.around(Q_gv_d * dni_mis) print_table_12_2('Q_gv_mis, кДж', Q_gv_mis) Q_gv_r = Q_gv_d.dot(dni_mis) print('Річне теплове навантаження на СГВ, Q_gv_r = {} кДж.'.format(Q_gv_r)) del t_hv_min print(' Розрахунок сумарного теплового навантаження: '.center(80, '=')) print('Помісячне теплове навантаження системи теплопостачання (СТП), ' 'Q_tm_mis, кДж:') Q_tm_mis = Q_op_mis + Q_gv_mis print_table_12_2('Q_tm_mis, кДж', Q_tm_mis) Q_tm_r = Q_tm_mis.sum() print('Річне теплове навантаження, Q_tm_r = {} кДж.'.format(Q_tm_r)) print('Помісячна теплова потужність навантаження СТП, P_tm_mis, кВт:') P_tm_mis = Q_tm_mis / (24 * dni_mis * 3600) print_table_12_2('P_tm_mis, кВт', P_tm_mis, fmt=FLOAT_DEC_4) P_tm_max = P_op_max / 1000 + P_gv_mis[n] print('Максимальна потужність теплового навантаження СТП у ' "найхолоднішу п'ятиденку, P_tm_max = {0:.4f} кВт.".format(P_tm_max)) del n print(80 * '=') print( 'Таблиця розрахунку теплових навантажень гібридної системи теплопостачання:' ) P_rez_mis_max = np.repeat(P_rez_mis_max, 12) M = np.c_[t_n_s, t_hv, Q_op_d / 1000, Q_op_mis / 1000, Q_gv_d / 1000, Q_gv_mis / 1000, Q_tm_mis / 1000, np.around(P_gv_mis, 3), np.around(P_rez_mis_max, 3), np.around(P_tm_mis, 3)].transpose() L = np.zeros(11) L[4] = Q_op_r / 1000 L[6] = Q_gv_r / 1000 L[7] = Q_tm_r / 1000 table_labels = ('t_n_s,\nград.С', 't_hv,\nград.С', 'Q_op_d,\nМДж', 'Q_op_mis,\nМДж', 'Q_gv_d,\nМДж', 'Q_gv_mis,\nМДж', 'Q_tm_mis,\nМДж', 'P_gv_mis,\nкВт', 'P_rez_mis_max,\nкВт', 'P_tm_mis,\nкВт') spans = [([0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13]), ([0, 0], [1, 0]), ([0, 1], [1, 1]), ([0, 14], [1, 14])] print( data2rst( [[ '№', 'Назва\nвеличини', 'Місяці', '', '', '', '', '', '', '', '', '', '', '', '' ], [ '', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X', 'XI', 'XII', '' ], *[[ i + 1, label, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9], item[10], item[11], l ] for i, (label, item, l) in enumerate(zip(table_labels, M, L))]], spans=spans, center_cells=True)) print( ' Розрахунок сонячної енергії, яка надходить на горизонтальну поверхню ' .center(80, '=')) print('Порядковий номер дня в році станом на 15 число кожного місяця m:') m = 15 + np.append([0], dni_mis[:-1]).cumsum() print_table_12_2('m', m) print('Сонячне схилення, яке дорівнює географічній широті місцевості, над ' 'якою в полудень m-го дня Сонце перебуває в зеніті, delta, град:') delta = 23.45 * np.sin(np.radians((284 + m) / 365 * 360)) print_table_12_2('delta, град', delta.transpose(), fmt=FLOAT_DEC_4) print( 'Середнє значення сонячного схилення за період: день, місяць, сезон, рік, ' '(delta_A + delta_B) / 2 = delta_S, град:') # deltaA - на 15 березня, deltaB - на 15 жовтня, геліосистема функціонує з # 1 березня до 31 жовтня - 8 місяців. delta_A = delta[2] delta_B = delta[9] delta_S = (delta_A + delta_B) / 2 print('delta_S = {0:.4f} град'.format(delta_S)) beta = fi - delta_S print( 'Оптимальний кут нахилу геліоколктора до горизонту, beta = {0:.4f} град.' .format(beta)) print( 'Азимутальний кут заходу Сонця для горизонтальної площини -A_h, град:') A_h = -(np.degrees( np.arccos(-np.tan(np.radians(fi)) * np.tan(np.radians(delta))))) print_table_12_2('-Ah, град', A_h.transpose(), fmt=FLOAT_DEC_4) print( 'Азимутальний кут заходу Сонця для випадку, нахиленої площини під кутом ' 'beta до горизонту поверхні ГК -Ab, град:') A_b = -(np.degrees( np.arccos(-np.tan(np.radians(fi - beta)) * np.tan(np.radians(delta))))) print_table_12_2('-Ab, град', A_b.transpose(), fmt=FLOAT_DEC_4) n = (np.abs(A_b) > np.abs(A_h)) A_b[n] = A_h[n] print_table_12_2('-Ab, град', A_b.transpose(), fmt=FLOAT_DEC_4) print( 'Допоміжний коефіцієнт R_b перерахунку надходження лише прямої радіації ' 'із значення для горизонтальної поверхні на значення для нахиленої ' 'поверхні під кутом beta до горизонту і ораєнтованої в південному ' 'напрямку R_b:') val_R_b = ((np.cos(np.radians(fi - beta)) * np.cos( np.radians(delta)) * np.sin(np.radians(A_b)) + np.radians( A_b * np.sin(np.radians(fi - beta)) * np.sin(np.radians(delta)))) / (np.cos(np.radians(fi)) * np.cos(np.radians(delta)) * np.sin(np.radians(A_h)) + np.radians( A_h * np.sin(np.radians(fi)) * np.sin(np.radians(delta))))) print_table_12_2('R_b, град', val_R_b.transpose(), fmt=FLOAT_DEC_4) print( ' Розрахунок кількості радіації, яка надходить на похилий геліоколектор (ГК): ' .center(80, '=')) print( 'Коефіцієнт перерахунку, R, надходження сумарної сонячної радіації із ' 'значенням для горизонтальної поверхні на значення для похилої поверхні:' ) print('Завантаження даних із файлу "{}" ...'.format(fname_climate)) data_climate = np.loadtxt(fname_climate)[..., 1:] print( 'Нижче подана таблиця середньомісячних значень [H_0, r, H_th, H_dh],\nде ' 'H_0 - позаатмосферна радіація, МДж/м^2,\nr - альбедо,\nH_th - середньодобова ' 'повна радіація, МДж/м^2,\nH_dh - розсіяна радіація, МДж/м^2.') H_th_s = 0 H_dh_s = 0 # Середні значення повної та розсіяної радіації за місяць. for i in range(3, 12, 2): H_th_s += 6 * data_climate[..., i - 1] / 30 H_dh_s += 6 * data_climate[..., i] / 30 data_15 = np.hstack( (data_climate[..., (0, 1)], H_th_s[..., np.newaxis], H_dh_s[..., np.newaxis])) print( data2rst([[ 'Місяць', 'H_0,\nМДж/м^2', 'r', 'H_th,\nМДж/м^2', 'H_dh,\nМДж/м^2' ], *[[i, *v] for i, v in enumerate(data_15, start=1)]], center_cells=True)) H_0 = data_15[..., 0] r = data_15[..., 1] H_th = data_15[..., 2] H_dh = data_15[..., 3] R = (1 - H_dh / H_th) * val_R_b + H_dh / H_th * (1 + np.cos(np.radians(beta)))/2 + \ r * (1 - np.cos(np.radians(beta))) / 2 print_table_12_2('R', R, fmt=FLOAT_DEC_4) print( 'Середньоденне за місяць надходження сонячної радіації на 1 м^2 похилої ' 'поверхні, H_b_d, МДж/м^2:') H_b_d = R * H_th print_table_12_2('H_b_d, МДж/м^2', H_b_d, fmt=FLOAT_DEC_4) print('Помісячне та річне надходження сонячної радіації на 1 м^2 похилої ' 'поверхні ГК, H_b_mis, МДж/м^2, та H_b_r, МДж/м^2:') H_b_mis = dni_mis * H_b_d print_table_12_2('H_b_mis, МДж/м^2', H_b_mis, fmt=FLOAT_DEC_4) H_b_r = H_b_mis.sum() print('H_b_r = {0:.4f} МДж/м^2'.format(H_b_r)) I_b_d = H_b_d / (3600 * 24) * 10**6 I_0 = H_0 / (3600 * 24) * 10**6 print( data2rst([[ 'Місяць', 'H_th,\nМДж/м^2', 'H_dh,\nМДж/м^2', 'm', 'delta,\nград', 'A_h,\nград', 'A_b,\nград', 'r', 'R_b', 'R', 'H_b_d,\nМДж/м^2', 'H_b_mis,\nМДж/м^2', 'H_0,\nВт/м^2', 'H,\nВт/м^2' ], *[[ i[0], '{0:.4f}'.format(i[1]), '{0:.4f}'.format(i[2]), i[3], '{0:.4f}'.format(i[4]), '{0:.4f}'.format(i[5]), '{0:.4f}'.format( i[6]), '{0:.4f}'.format(i[7]), '{0:.4f}'.format(i[8]), '{0:.4f}'.format(i[9]), '{0:.4f}'.format(i[10]), '{0:.4f}'.format( i[11]), '{0:.4f}'.format(i[12]), '{0:.4f}'.format(i[13]) ] for i in zip(mis, H_th, H_dh, m, delta, A_h, A_b, r, val_R_b, R, H_b_d, H_b_mis, I_0, I_b_d)]], center_cells=True)) del m, n, H_th_s, H_dh_s print(' Найближчий метод розрахунку площі геліоколекторів (ГК): '.center( 80, '=')) H_b_c = H_b_mis[2:10].sum() print( 'Сумарне надходження сонячної радіації на похилу поверхню ГК за сезонний ' 'період - 8 місяців, H_b_c = {0:.4f} МДж/м^2'.format(H_b_c)) Q_gv_c_MJ = Q_gv_mis[2:10].sum() / 1000 print('Сумарне сезонне теплове навантаження СГВ, Q_gv_c = {0:.4f} МДж.'. format(Q_gv_c_MJ)) S = vartheta * Q_gv_c_MJ / H_b_c print( 'Сумарна площа геліоколекторів, S = {0:.4f} м^2, при ступені заміщення ' 'тепловитрат СГВ, f = {1}, та параметру vartheta = {2}:'.format( S, f_z, vartheta)) k = int(round(S / S_0)) print( 'Кількість стандартних геліоколекторів, k = {}, площею S_0 = {} м^2:'. format(k, S_0)) S_k = k * S_0 vartheta = H_b_c / Q_gv_c_MJ * S_k print( 'Реальна площа, S_k = {0:.4f} м^2, та коефіцієнт vartheta = {1:.4f}.'. format(S_k, vartheta)) print(' Розрахунок теплопродуктивності сонячних установок: '.center( 80, '=')) print('Середньомісячні коефіцієнти ясності, k_j, на 15 число:') k_j = H_th / H_0 print_table_12_2('k_j', ('{0:.4f}'.format(v) for v in k_j)) print('Середньомісячне значення параметру, P:') P = (t_hv - t_n_s) / k_j print_table_12_2('P', P, fmt=FLOAT_DEC_4) print('Значення оптичних к.к.д., eta, та витрати антифризу, G_gk, кг/год, ' 'із c_pa = {} кДж/(кг*град.С) по місяцях:'.format(c_pa)) eta = F_r * eta_0 - F_r * UL * (t_hv + t_gv - 2 * t_n_s) / (2 * I_b_d) print_table_12_2('eta', eta, fmt=FLOAT_DEC_4) G_gk = 3.6 * I_b_d * S_k * eta / (3.16 * (t_gv - t_hv)) print_table_12_2('G_gk, кг/год', G_gk, fmt=FLOAT_DEC_4) print('К.к.д. для найтеплішого місяця:') t_n_s_max = t_n_s.max() n = t_n_s.argmax() I_b_d_tm = I_b_d[n] eta = smp.S('F_r*eta_0-F_r*UL*(t_hv+t_gv-2*t_n_s)/(2*I_b_d)') eta_1 = eta.subs({ 'F_r': F_r, 'eta_0': eta_0, 'UL': UL, 't_gv': t_gv, 't_hv': t_hv[n], 't_n_s': t_n_s_max, 'I_b_d': I_b_d_tm }) eta_rzr = eta_1 print( 'Оптичний к.к.д., eta_0 = {3:.4f}, для найтеплішого місяця n = {0} із ' 't_n_s_max = {1:.1f} град.С та I_b_d = {2:.4f} Вт/м^2:'.format( n + 1, t_n_s_max, I_b_d_tm, eta_1)) # К.к.д. для найсяянішого місяця I_b_d_max = I_b_d.max() n_2 = I_b_d.argmax() t_n_s_I_m = t_n_s[n_2] if I_b_d_max >= .95 * 1000: print('К.к.д. для найсяянішого місяця:') eta_2 = eta.subs({ 'F_r': F_r, 'eta_0': eta_0, 'UL': UL, 't_gv': t_gv, 't_hv': t_hv[n_2], 't_n_s': t_n_s_I_m, 'I_b_d': I_b_d_max }) print( 'Оптичний к.к.д. eta_0 = {3:.4f} для місяця n_2 = {0} із ' 'I_b_d_max = {1:.4f} Вт/м^2 ~ 1000 Вт/м^2 із t_n_s_I_m = {2:.1f} град.С' .format(n_2 + 1, I_b_d_max, t_n_s_I_m, eta_2)) if eta_2 > eta_1: eta_rzr = eta_2 n = n_2 del n_2 G_gk = 3.6 * I_b_d_tm * S_k * eta_rzr / (c_pa * (t_gv - t_hv[n])) print('Мінімально необхідна продуктивність циркуляційної помпи для ' 'незамерзаючого теплоносія, G = {0:.4f} кг/год.'.format(G_gk)) print( 'Прийнятно колектор із подвійним заскленням і селективно-поглинаючою ' 'поверхнею із коефіцієнтами:\nоптичний к.к.д. eta_0 = {0:.4f}, a = {1:.4f}, ' 'b = {2:.7f}:'.format(eta_0, a, b)) print('Ефективність роботи ГК в реальних умовах експлуатації - питома ' 'теплопродуктивність - середньоденне (протягом місяця) виробництво ' 'теплової енергії 1 м^2 його сприймаючої поверхні, q_gk_d, МДж/м^2:') q_gk_d = eta_0 * H_b_d * (1 - a * P + b * P**2) print_table_12_2('q_gk_d, МДж/м^2', q_gk_d, fmt=FLOAT_DEC_4) V_a = 0.05 * S_k print("Об'єм теплоакумулятора, V_a = {0:.4f} м^3.".format(V_a)) del k, n print(' Аналіз помісячних балансів енергії: '.center(80, '=')) print('Помісячне виробництво тепла сонячною СГВ, H_gk_mis, МДж, загальною ' 'площею, S_k:') H_gk_mis = S_k * q_gk_d * dni_mis print_table_12_2('H_gk_mis, МДж', H_gk_mis, fmt=FLOAT_DEC_4) Q_gv_mis_MJ = Q_gv_mis / 1000 print_table_12_2('Q_gv_mis, МДж', Q_gv_mis_MJ, fmt=FLOAT_DEC_4) Q_gv_mis_MJ = np.r_[Q_gv_mis_MJ[0], Q_gv_mis_MJ] H_gk_mis = np.r_[H_gk_mis[0], H_gk_mis] #Q_gv_mis_MJ = np.r_[Q_gv_mis_MJ, Q_gv_mis_MJ[11]] #H_gk_mis = np.r_[H_gk_mis, H_gk_mis[11]] if target_graph != TargetGraph.no_showsave: from matplotlib import pyplot as plt, rcParams, ticker view_graph_params = get_show_own_frame_params(show_own_frame) rcParams['axes.formatter.use_locale'] = True rcParams.update({ 'font.family': 'serif', 'mathtext.fontset': 'dejavuserif', 'font.size': view_graph_params['font_size'], 'axes.titlesize': view_graph_params['ax_titlesize'] }) DIRECT_PATH = r'C:\Users\ichet\Dropbox\myDocs\St\data_antTetploMonitorDyblanu' if target_graph != TargetGraph.show: try: shutil.rmtree(DIRECT_PATH) except FileNotFoundError: pass os.mkdir(DIRECT_PATH) grid_color = '#ABB2B9' ax_pos = view_graph_params['ax_pos'] print(' Графік теплового навантаження СГВ протягом року: '.center( 80, '=')) #f_kw = 3.6 * np.r_[dni_mis, dni_mis[11]] # Перерахунок МДж/міс у кВт*год/добу. #f_kw_1 = 3.6 * dni_mis # Те ж саме. fig_title = 'Баланс теплової енергії протягом року' if figure_embedded: fig = figure_embedded fig.own_window_title = fig_title else: fig = plt.figure(**get_figure_data()) fig.canvas.set_window_title(fig_title) ax = fig.add_subplot(111) line_1, = ax.step(np.r_[mis, 13], 1 / 3.6 * Q_gv_mis_MJ, c='b', linestyle='-', lw=2) ax.annotate(r'1', xy=((mis[10] + mis[11]) / 2, 1 / 3.6 * Q_gv_mis_MJ[11]), xycoords='data', xytext=((mis[11] + 12) / 2, 1 / 3.6 * Q_gv_mis_MJ[10]), textcoords='data', va='top', ha='left', arrowprops=dict(arrowstyle='-')) # Графік виробітку ГК теплової енергії напротязі року. line_2, = ax.step(np.r_[mis, 13], 1 / 3.6 * H_gk_mis, c='r', linestyle='--', lw=2) ax.annotate(r'2', xy=((mis[10] + mis[11]) / 2, 1 / 3.6 * H_gk_mis[11]), xycoords='data', xytext=((mis[11] + 12) / 2, 1 / 3.6 * H_gk_mis[10] * 3 / 4), textcoords='data', va='top', ha='left', arrowprops=dict(arrowstyle='-')) #Q_son_r = np.array([ 22.2222, 60.5556, 131.9444, 230., 367.2222, 508.3333, 644.4444, #767.2222, 846.9444, 898.3333, 920.5556, 936.1111]) # Графік місячних значень сонячної радіації на горизонтальну поверхню. H_b_mis_GRAF = 1 / 3.6 * np.r_[H_b_mis[0], H_b_mis] * S_k line_3, = ax.step(np.r_[mis, 13], H_b_mis_GRAF, c='orange', linestyle='-.', lw=2) ax.annotate(r'3', xy=((mis[10] + mis[11]) / 2, H_b_mis_GRAF[11]), xycoords='data', xytext=((mis[11] + 12) / 2, H_b_mis_GRAF[10] * 3 / 4), textcoords='data', va='top', ha='left', arrowprops=dict(arrowstyle='-')) # Для фотофальків. Q_fotowalk = .15 * 1 / 3.6 * np.r_[H_b_mis[0], H_b_mis] * S_k line_4, = ax.step(np.r_[mis, 13], Q_fotowalk, color='g', linestyle=':', lw=2) ax.annotate(r'4', xy=((mis[10] + mis[11]) / 2, Q_fotowalk[11]), xycoords='data', xytext=((mis[11] + 12) / 2, Q_fotowalk[10] * 4 / 3), textcoords='data', va='top', ha='left', arrowprops=dict(arrowstyle='-')) y_locator_base = 100 y_max = np.ceil( np.max( np.max([ line.get_ydata() for line in (line_1, line_2, line_3, line_4) ]))) y_max_k, y_max_delta = divmod(y_max, y_locator_base) if y_max_delta: y_max = y_locator_base * (y_max_k + 1) ax.set_ylim(0, y_max) # Тепловтрати. ax_2 = ax.twinx() ax_2.set_ylabel(r'$\mathrm{Q_{втр}, кВт\cdot год}$', y=1.025, ha='right', va='bottom', rotation=0) #, color='r') #ax2.tick_params('y', colors='r') Q_tw = 1 / 3600 * np.r_[Q_op_mis[0], Q_op_mis] Q_tw[5:10] = 0 line_5, = ax_2.plot(np.r_[mis, 13], Q_tw, color='#800000', linestyle=(0, (3, 1, 1, 1, 1, 1)), lw=2, drawstyle='steps') ax_2.annotate(r'5', xy=((mis[10] + mis[11]) / 2, Q_tw[11]), xycoords='data', xytext=((mis[9] + mis[10]) / 2, .9 * Q_tw[12]), textcoords='data', va='top', ha='left', arrowprops=dict(arrowstyle='-')) locator_y_2 = ticker.MultipleLocator(base=500) ax_2.yaxis.set_major_locator(locator_y_2) y_locator_base_2 = 500 y_max_2 = np.ceil(max(Q_tw)) y_max_k, y_max_delta = divmod(y_max_2, y_locator_base_2) if y_max_delta: y_max = y_locator_base_2 * (y_max_k + 1) ax_2.set_ylim(0, y_max_2) ax.set_title( r'Помісячний виробіток теплової енергії СГК і теплове ' 'навантаження СГВ', y=view_graph_params['ax_title_y']) ax.set_xlabel('Місяці', x=1, ha="right") ax.set_ylabel(r'$\mathrm{Q_{i}, кВт\cdot год}$', y=1.025, ha=view_graph_params['ax_ha'], va='bottom', rotation=0) ax.set_xlim(mis[0], mis[-1] + 1) ax.set_xticks(np.r_[mis, 13]) ax.spines['top'].set_color(grid_color) ax.spines['right'].set_color(grid_color) ax.grid(color=grid_color) ax.legend(loc=3, ncol=5, mode='expand', bbox_to_anchor=(.05, 1.08, .9, .102), handles=[line_1, line_2, line_3, line_4, line_5], labels=[ r'$\mathrm{Q_{гв\,міс.}}$', r'$\mathrm{Q_{гк.\,міс.}}$', r'$\mathrm{Q_{с.р.\,міс.}}$', r'$\mathrm{Q_{foto_k.\,міс.}}$', r'$\mathrm{Q_{втр.\,міс.}}$' ]) ax.set_position(ax_pos) ax_2.set_position(ax_pos) fig.tight_layout() print('Визначення різниць, dH_mis, МДж:') H_gk_mis = H_gk_mis[:-1] Q_gv_mis_MJ = Q_gv_mis_MJ[:-1] dH_mis = H_gk_mis - Q_gv_mis_MJ print_table_12_2('dH_mis, МДж', dH_mis, fmt=FLOAT_DEC_4) print( data2rst([[ 'Місяць', 'k_j', 'P', 'q_gk_d,\nМДж/м^2', 'H_gk_mis,\nМДж', 'dH_mis,\nМДж' ], *[[ i[0], '{0:.4f}'.format(i[1]), '{0:.4f}'.format( i[2]), '{0:.4f}'.format(i[3]), '{0:.4f}'.format(i[4]), '{0:.4f}'.format(i[5]) ] for i in zip(mis, k_j, P, q_gk_d, H_gk_mis, dH_mis)]], center_cells=True)) # Зафарбовування надлишку теплової енергії протягом року. #fig = plt.gcf() #ax = fig.axes[0] #jdH_mis = dH_mis[i] / f_kw_1; jH_gk_mis = H_gk_mis[i] / f_kw_1 #jQ_tm_mis_MJ = val_Q_tm_mis_MJ[i] / f_kw_1 n = (dH_mis >= 0) mis_1 = np.vstack((mis[n], (mis[n] + 1))) mis_1 = mis_1.ravel(order='F') mis_2 = mis_1[::-1] H = np.vstack((1 / 3.6 * H_gk_mis[n], 1 / 3.6 * H_gk_mis[n])) H = H.ravel(order='F') Q = np.vstack((1 / 3.6 * Q_gv_mis_MJ[n], 1 / 3.6 * Q_gv_mis_MJ[n])) Q = Q.ravel(order='F') Q_2 = Q[::-1] ax.fill(np.hstack((mis_1 - 1, mis_2 - 1)), np.hstack((H, Q_2)), color=(1, .7, .9)) if target_graph in (TargetGraph.save, TargetGraph.show_and_save): plt.savefig(os.path.join(DIRECT_PATH, 'graf.png'), format='png') del n, mis_1, mis_2, H, Q, Q_2 print(' Розрахунок параметрів теплової помпи: '.format(80, '=')) P_tp_0 = 1.2 * P_tm_max print('Номінальна потужність теплової помпи (ТП), P_tp_0 = {0:.4f} кВт.'. format(P_tp_0)) print( 'Із каталогу вибрана ТП {} із P_тп = {} кВт, к.к.д. epsilon_тп = {}, ' 'P_el = {} кВт при t_gru = {} град.С, яка забезпечує вихідну температуру ' 't_co_1 = {} град.С.'.format(tip_tp, P_tp, epsilon_tp, P_el, t_gru[0], t_co_1)) print( 'Середньоденна, tau_D, год, та середньомісячна, tau_mis, год, тривалість ' 'роботи ТП:') tau_D = 24 * P_tm_mis / P_tp tau_mis = tau_D * dni_mis print_table_12_2('tau_D,\nгод', tau_D, FLOAT_DEC_4) print_table_12_2('tau_mis,\nгод', tau_mis, FLOAT_DEC_4) print('Теплопомпова установка працює з 1 жовтня по 30 квітня - 7 місяців.') print('Помісячна, W_el_mis, кВт*год, витрата ' 'електроенергії для приводу ТП:') W_el_mis = tau_mis * P_el print_table_12_2('W_el_mis, кВт*год', W_el_mis, FLOAT_DEC_4) W_el_r = W_el_mis[0:4].sum() + W_el_mis[9:12].sum() print( 'Річна витрата електроенергії для приводу ТП, W_el_r = {0:.4f} кВт*год' .format(W_el_r)) dt_co = t_co_1 - t_co_2 print( 'Перепад температур підлгового опалення (СО), dt_co = {} град.'.format( dt_co)) G_tp = 3600 * P_tm_max / (c_pv * dt_co) print('Витрата теплоносія в СО для підбору циркуляційної помпи, ' 'G_tp = {0:.4f} кг/год.'.format(G_tp)) P_gru = (P_tm_max - P_el) / epsilon_el print('Необхідна потужність тепловідбору ґрунту, P_гр. = {0:.4f} кВт, при ' 'електричному к.к.д, epsilon_el = {1}.'.format(P_gru, epsilon_el)) S_gru = 1000 * P_gru / q_gru print('Площа ґрунту, S_гр. = {0:.4f}'.format(S_gru)) l = S_gru * l_0 print('Довжина поліетиленової труби d = {0} мм через питому довжину ' 'тепловідбору, l_0 = {1} м/м^2, - l = {2:.2f} м.'.format(d, l_0, l)) del d, l_0 print(' Аналіз ефективності гібридної системи та висновки: '.format( 80, '=')) V_gaz_r = Q_tm_r / (eta_K * Q_n_r) print("Річний об'єм зекономленого газу, V_gaz_r = {0:.4f} м^3, при " 'к.к.д., eta_K = {1}, і Q_n_r = {2} кДж/м^3.'.format( V_gaz_r, eta_K, Q_n_r)) B_gaz = V_gaz_r * c_gaz B_el = W_el_r * c_el print( 'Вартість еквівалентної кількості природнього газу, B_газ = {0:.2f} грн, ' 'та електроенергії, B_ел = {1:.2f} грн, при c_газ = {2} грн/м^3 та ' 'c_ел = {3} грн/(кВт*год).'.format(B_gaz, B_el, c_gaz, c_el)) print(' Розрахунок завершено! '.center(80, '=')) if target_graph in (TargetGraph.show, TargetGraph.show_and_save): plt.show()
def print_table_2(label, array_, row_start=1, fmt=None): print( data2rst([['№ вар.', label], *[[i, v if fmt is None else ('{0:%s}' % fmt).format(v)] for i, v in enumerate(array_, start=row_start)]], center_cells=True))
held_karp_thread.wait() random_insertion_thread.wait() mst_approx_thread.wait() # Get solutions [held_karp_sol, held_karp_time] = held_karp_thread.get() print("Held-Karp solution:", held_karp_sol) [random_insertion_sol, random_insertion_time] = random_insertion_thread.get() print("Constructive heuristic solution:", random_insertion_sol) [mst_approx_sol, mst_approx_time] = mst_approx_thread.get() print("2-approx solution:", mst_approx_sol) # Fill table with results table[index + 2][1] = held_karp_sol table[index + 2][2] = round(held_karp_time, 3) table[index + 2][3] = \ str(round(((held_karp_sol - optimal_solutions[index]) / optimal_solutions[index] * 100), 3)) + "%" table[index + 2][4] = random_insertion_sol table[index + 2][5] = round(random_insertion_time, 3) table[index + 2][6] = \ str(round(((random_insertion_sol - optimal_solutions[index]) / optimal_solutions[index] * 100), 3)) + "%" table[index + 2][7] = mst_approx_sol table[index + 2][8] = round(mst_approx_time, 3) table[index + 2][9] = \ str(round(((mst_approx_sol - optimal_solutions[index]) / optimal_solutions[index] * 100), 3)) + "%" print("--------------------------------") print(dashtable.data2rst(table, spans, use_headers=True, center_cells=True, center_headers=True))
Eq_dQ_osn = smp.Eq( dQ_osn, q_st * (1 / R_st - 1 / R_st_1) + q_v * (1 / R_v - 1 / R_v_1) + q_p * (1 / R_p - 1 / R_p_1) + q_g * (1 / R_g - 1 / R_g_1) + q_d * (1 / R_d - 1 / R_d_1)) print('Зміна максимальних основних тепловтрат будинку, dQ_osn, Вт, залежно ' 'від коефіцієнтів тепловтрат захищень, K, Вт/(м^2*град.С), визначаються ' 'за формулою:') print(Eq_dQ_osn) print('Введені максимальні витрати тепла захищеннями будинку ' 'при K = 1 Вт/(м^2*град.С), q, м^2*град.С:') print( data2rst( [['Огородження', 'Позначення', 'q, м^2*град.С'], ['Зовнішні стіни', q_st, val_q_st], ['Вікна', q_v, val_q_v], ['Підвальне перекриття', q_p, val_q_p], ['Горищне перекриття', q_g, val_q_g], ['Вхідні двері', q_d, val_q_d]], center_cells=True)) print( 'Введені нормативні опори теплопередачі захищень будинку, R, (м^2*град.С)/Вт:' ) print( data2rst( [['Огородження', 'Позначення', 'R, (м^2*град.С)/Вт'], ['Зовнішні стіни', R_st, val_R_st], ['Вікна', R_v, val_R_v], ['Підвальне перекриття', R_p, val_R_p], ['Горищне перекриття', R_g, val_R_g], ['Вхідні двері', R_d, val_R_d]], center_cells=True)) # Основні максимальні тепловтрати будинку. val_R_st_1 = smp.oo