def print_energy_structure(self): """ Prints energy structure, month and hour schedule of when every period is active, to terminal """ pprint.pprint(self.tariff) if not self.energy_period_list: # if list is empty it is not printed pass else: print(" ") print("Tiered Energy Usage Charge Structure") for period in self.energy_period_list: print(" ") period.tostring() for tier in period.tier_list: tier.tostring() print(" ") self.energyweekdayschedule = self.tariff["items"][0]["energyweekdayschedule"] self.energyweekendschedule = self.tariff["items"][0]["energyweekendschedule"] for year in self.energyweekdayschedule: count = 0 for month in year: year[count] = month + 1 count += 1 print(year) print('=----------------------------------------------------------------------=') for year in self.energyweekendschedule: count = 0 for month in year: year[count] = month + 1 count += 1 print(year)
def get_basic_info(): print('\nActual period: {}, day: {}'.format(Prd.get_actual_period_name(), Prd.get_period_day_number())) print('Total expenses: {}/{} ({}%)'.format( Trc.get_total(), ctg.get_total_of_limits(), get_percentage(Trc.get_total(), ctg.get_total_of_limits()))) print('Incomes: {}\n'.format(Pmt.get_total()))
def rates(self, dates): """ Assigns rates to each energy period in date_list before list is formatted """ temp_list = [] for p in self.energy_period_list: p.get_highest_rate() temp_list.append(p.highest_rate) for period in dates: period.append(temp_list[period[3] - 1])
def statistics(): if Prd.is_period_active(): print('Actual period: {}, day: {}'.format(Prd.get_actual_period_name(), Prd.get_period_day_number())) print('Available categories: {}'.format([*ctg.get_categories_names()])) print(stat.get_total_info()) print(stat.get_total_savings()) stat.get_average_expanses_by_day() stat.print_biggest_expanse() for category in ctg.get_categories_names(): print('-{}:'.format(category)) stat.get_total_by_category(category) stat.print_biggest_expanse_by_category(category) stat.get_average_by_category(category) stat.get_average_by_category_per_day(category) else: print('There is no active period!') back_to_main_menu()
def print_index(self, index): """ Establishes all periods and tiers of the tariff using period and tier objects Args: index (Int): user input for which tariff they choose """ i = index label = self.data["items"][i - 1]["label"] params = { 'version': 5, 'api_key': 'AHNGCVlcEKTgH6fgr1bXiSnneVb00masZcjSgp3I', 'format': 'json', 'getpage': label, 'detail': 'full' } r = requests.get(url=self.URL, params=params) self.tariff = r.json() if "energyratestructure" in self.tariff["items"][0]: # print(self.tariff["items"][0]["energyratestructure"]) self.energyratestructure = self.tariff["items"][0][ "energyratestructure"] pcount = 1 # period count tcount = 1 # tier count for p in self.energyratestructure: self.energy_period_list.append(period.Period(pcount)) for i in p: if "max" in i: self.max = i["max"] if "rate" in i: self.rate = i["rate"] if "unit" in i: self.unit = i["unit"] if "adjustment" in i: self.adj = i["adjustment"] if "sell" in i: self.sell = i["sell"] self.energy_period_list[pcount - 1].add( et.Tier(tcount, self.max, self.rate, self.unit, self.adj, self.sell)) tcount += 1 self.reset() tcount = 1 pcount += 1
def update_limits(): if Prd.is_period_active() is False: print(*ctg.get_categories_list()) answer = input('Which category limit would you like to update? ') if answer in ctg.get_categories_names(): ctg.update_category_limit(answer) elif answer.lower() == 'q': main_menu() else: print('There is no such category!') return update_limits() else: print('Categories cannot be modified when period is active!') back_to_main_menu()
def map(self): import User User.init_db() import Campus Campus.init() import Class Class.init() import ClassRoom ClassRoom.init() import Course Course.init() import Cursus Cursus.init() import Event Event.init() import Period Period.init() import Planning Planning.init() import Settings Settings.init() import University University.init()
def add_remove_category(): if Prd.is_period_active() is False: print(*ctg.get_categories_names()) answer = input('Would you like to [a]add or [r]remove category? ') if answer.lower() == 'a': ctg.add_category() print(*ctg.get_categories_names()) elif answer.lower() == 'r': ctg.remove_category() print(*ctg.get_categories_names()) elif answer.lower() == 'q': main_menu() else: print('There is no such option. Please choose proper one!') return add_remove_category() else: print('Categories cannot be modified when period is active!') back_to_main_menu()
def history(): if Prd.is_period_active(): answer = input( 'Would you like to show [f]full history, [s]sort descending or [g]group by categories? ' ) if answer.lower() == 'f': stat.show_history() elif answer.lower() == 's': stat.show_history_sorted_descending() elif answer.lower() == 'g': stat.show_history_group_by_categories() elif answer.lower() == 'q': main_menu() else: print('There is no such option. Please choose proper one!') return history() else: print('There is no active period!') back_to_main_menu()
def add_income(): if Prd.is_period_active(): answer = input('Would you like to [a]add or [r]remove income? ') if answer.lower() == 'a': Pmt.add_payment(uti.get_payment(), uti.get_description()) print('Income added successfully!') elif answer.lower() == 'r': payment_id = input('Insert income &id: ') if payment_id in Pmt.get_payment_id_list(): Pmt.remove_payment(payment_id) print('Income removed successfully!') else: print('There is no income with such &id!') return add_income() elif answer.lower() == 'q': main_menu() else: print('There is no such option. Please choose proper one!') return add_transaction() else: print('There is no active period!') back_to_main_menu()
def add_transaction(): if Prd.is_period_active(): answer = input('Would you like to [a]add or [r]remove transaction? ') if answer.lower() == 'a': Trc.add_transaction(uti.get_expanse(), uti.get_description(), uti.get_category()) print('Transaction added successfully!') elif answer.lower() == 'r': transaction_id = input('Insert transaction &id: ') if transaction_id in Trc.get_transactions_id_list(): Trc.remove_transaction(transaction_id) print('Transaction removed successfully!') else: print('There is no transaction with such &id!') return add_transaction() elif answer.lower() == 'q': main_menu() else: print('There is no such option. Please choose proper one!') return add_transaction() else: print('There is no active period!') back_to_main_menu()
def manage_periods(): print('Actual period: {}'.format(Prd.get_actual_period_name())) answer = input( 'Would you like to [l]list, [s]start, [c]close or [r]remove periods? ') if answer.lower() == 's': if Prd.is_period_active() is False: Prd.start_period() else: print('There is already active period!') elif answer.lower() == 'c': if Prd.is_period_active(): Prd.close_period() else: print('There is no active period to close!') elif answer.lower() == 'q': main_menu() elif answer.lower() == 'l': if len(Prd.get_periods_list()) > 0: print(Prd.get_periods_names()) else: print('There are no periods to list!') elif answer.lower() == 'r': print(*Prd.get_periods_names()) period_name = input('Insert period name to remove: ') if period_name in Prd.get_periods_names(): Prd.remove_period_from_history(period_name) else: print('There is no period with such name!') return manage_periods() else: print('There is no such option. Please choose proper one!') return manage_periods() back_to_main_menu()
periods = {} added = [] root = TrieNode('*', Course(0,'*')) # itera sobre as linhas do csv for cod, nome, ano, periodo, vinculados, matriculados, ingressantes, diplomados, evadidos in zip(data["CodCurso"], data["NomeCurso"], data["Ano"], data["Periodo"], data["Vinculados"], data["Matriculados"], data["Ingressantes"], data["Diplomados"], data["Evadidos"]): date = str(ano) + "/" + str(periodo) # se ainda não registrou o curso if cod not in courses.keys(): courses[cod] = Course(cod, nome.upper()) # se ainda não registrou a data if date not in periods.keys(): periods[date] = Period(ano, periodo) # Duplica os dados para as duas visualizações periods[date].addData(cod, vinculados, matriculados, ingressantes, diplomados, evadidos) courses[cod].addData(date, vinculados, matriculados, ingressantes, diplomados, evadidos) # só adiciona uma vez na árvore if cod not in added: add_node(root, courses[cod]) added.append(cod) # Salva os cursos num arquivo binário pickle with open('courses.p', 'wb') as f: pickle.dump(courses,f)
def get_average_by_category_per_day(category): if Prd.get_period_day_number() > 0: print(' Average expanses in category per day is {}'.format( round( Trc.get_total_by_category(category) / Prd.get_period_day_number(), 2)))
def get_average_expanses_by_day(): if Prd.get_period_day_number() > 0: print('Average expanses per day is {}'.format( round(Trc.get_total() / Prd.get_period_day_number(), 2)))