def reload_list(self): model = self.enh_model index_FS = self.get_header_index(HEADER_FS) index_GEAR = self.get_header_index(HEADER_GEAR) index_COST = self.get_header_index(HEADER_COST) index_CUMULATIVE_COST = self.get_header_index(HEADER_CUMULATIVE_COST) index_PROBABILITY = self.get_header_index(HEADER_PROBABILITY) index_CUMULATIVE_PROBABILITY = self.get_header_index(HEADER_CUMULATIVE_PROBABILITY) #exchange_dict = dict_box_list([x for x in model.fs_exchange if x.active], lambda x: x.effective_fs_level() - 1) exchange_dict: Dict[int, FailStackItemExchange] = {x.effective_fs_level()-1: x for x in model.fs_exchange if x.active} with SpeedUpTable(self): with QBlockSig(self): clear_table(self) fs_items = model.primary_fs_gear fs_cost = model.primary_fs_cost cum_fs_cost = model.primary_cum_fs_cost cum_fs_probs = model.cum_fs_probs fs_probs = model.fs_probs for i, this_gear in enumerate(fs_items): rc = self.rowCount() self.insertRow(rc) self.setRowHeight(rc, 32) twi = QTableWidgetItem(str(i+1)) self.setItem(rc, index_FS, twi) if this_gear is None: twi = QTableWidgetItem('Free!') self.setItem(rc, index_GEAR, twi) else: two = GearWidget(this_gear, model, edit_able=False, display_full_name=True) two.add_to_table(self, rc, col=index_GEAR) twi = monnies_twi_factory(fs_cost[i]) self.setItem(rc, index_COST, twi) twi = monnies_twi_factory(cum_fs_cost[i]) self.setItem(rc, index_CUMULATIVE_COST, twi) twi = QTableWidgetItem(STR_PERCENT_FORMAT.format(fs_probs[i])) self.setItem(rc, index_PROBABILITY, twi) twi = QTableWidgetItem(STR_PERCENT_FORMAT.format(cum_fs_probs[i])) self.setItem(rc, index_CUMULATIVE_PROBABILITY, twi) if i in exchange_dict: item = exchange_dict[i] widget = make_material_list_widget([(x.item_id, x.amount) for x in item.exchange_items.values()], show_names=True, item_store=model.item_store()) self.removeCellWidget(rc, index_GEAR) self.setCellWidget(rc, index_GEAR, widget) self.resizeColumnsToContents()
def reload_list(self): settings = self.enh_model.settings try: enhance_me = settings[self.prop_in_list] r_enhance_me = settings[self.prop_out_list] except KeyError as e: raise SettingsException('Key missing for enhancement gear', e) with SpeedUpTable(self): for gear in enhance_me: with QBlockSig(self): self.table_add_gear(gear) for gear in r_enhance_me: with QBlockSig(self): self.table_add_gear(gear, check_state=Qt.Unchecked) self.setSortingEnabled(True) return enhance_me, r_enhance_me
def reload_list(self): model = self.enh_model settings = model.settings clear_table(self) try: fail_stackers = settings[self.prop_in_list] r_fail_stackers = settings[self.prop_out_list] except KeyError as e: raise SettingsException( 'Fail-stacking material is missing from the settings file', e) with SpeedUpTable(self): for gear in fail_stackers: with QBlockSig(self): self.table_FS_add_gear(gear) for gear in r_fail_stackers: with QBlockSig(self): self.table_FS_add_gear(gear, check_state=Qt.Unchecked) self.setSortingEnabled(True)
def cmdEquipCost_clicked(self): model = self.enh_model frmMain = self.frmMain send_fs_signal = model.fs_needs_update #if len(self.invalidated_gear) == 0: # return This is handled in model.calc_equip_costs try: model.calc_equip_costs(gear=self.invalidated_gear) self.invalidated_gear = set() except ValueError as f: print(fmt_traceback(f.__traceback__)) frmMain.sig_show_message.emit(frmMain.WARNING, str(f)) return except Invalid_FS_Parameters as e: frmMain.sig_show_message.emit(frmMain.WARNING, str(e)) return if send_fs_signal: # This updates the UI to the fail stack list being updated from model.calc_equip_costs self.sig_fs_list_updated.emit() idx_NAME = self.get_header_index(HEADER_NAME) idx_CRONSTONE = self.get_header_index(HEADER_CRONSTONE) idx_FS = self.get_header_index(HEADER_FS) idx_COST = self.get_header_index(HEADER_COST) idx_MAT_COST = self.get_header_index(HEADER_MAT_COST) idx_NUM_FAILS = self.get_header_index(HEADER_NUM_FAILS) idx_PROBABILITY = self.get_header_index(HEADER_PROBABILITY) idx_USES_MEMFRAGS = self.get_header_index(HEADER_USES_MEMFRAGS) def populate_row(this_head, this_gear: Gear, eh_idx): cost_vec_l = this_gear.cost_vec[eh_idx] restore_cost_vec_min = this_gear.restore_cost_vec_min[eh_idx] idx_ = numpy.argmin(this_gear.cost_vec[eh_idx]) gw: GearWidget = self.itemWidget(this_head, idx_NAME) gw.update_data() uses_crons = eh_idx in this_gear.cron_use if uses_crons: if gw.trinket is None: gw.set_trinket(pix[STR_PIC_CRON]) else: if gw.trinket is not None: gw.set_trinket(None) this_head.setText(idx_CRONSTONE, str(uses_crons)) this_head.setText(idx_FS, str(idx_)) this_head.setText(idx_COST, MONNIES_FORMAT.format(round(cost_vec_l[idx_]))) this_head.setText( idx_MAT_COST, MONNIES_FORMAT.format(round(restore_cost_vec_min))) this_fail_map = numpy.array(this_gear.gear_type.map)[eh_idx] if uses_crons: avg_num_fails = (1 / this_gear.gear_type.map[eh_idx][idx_]) else: avg_num_fails = this_gear.gear_type.p_num_atmpt_map[eh_idx][ idx_] - 1 this_head.setText(idx_NUM_FAILS, STR_TWO_DEC_FORMAT.format(avg_num_fails)) this_head.setText(idx_PROBABILITY, STR_PERCENT_FORMAT.format(this_fail_map[idx_])) if hasattr(this_gear, 'using_memfrags'): this_head.setText(idx_USES_MEMFRAGS, str(this_gear.using_memfrags)) with QBlockSig(self): with SpeedUpTable(self): for i in range(0, self.topLevelItemCount()): this_head = self.topLevelItem(i) gear_widget = self.itemWidget(this_head, idx_NAME) this_gear: Gear = gear_widget.gear eh_idx = this_gear.get_enhance_lvl_idx() populate_row(this_head, this_gear, eh_idx) for j in range(0, this_head.childCount()): this_child = this_head.child(j) child_gear_widget = self.itemWidget( this_child, idx_NAME) child_gear = child_gear_widget.gear eh_idx = child_gear.get_enhance_lvl_idx() populate_row(this_child, this_gear, eh_idx)
def table_FS_add_gear(self, this_gear: Gear, check_state=Qt.Checked): frmMain = self.frmMain model = self.enh_model rc = self.rowCount() idx_HEADER_NAME = self.get_header_index(HEADER_NAME) idx_HEADER_GEAR_TYPE = self.get_header_index(HEADER_GEAR_TYPE) idx_HEADER_TARGET = self.get_header_index(HEADER_TARGET) with SpeedUpTable(self, blk_sig=True): self.insertRow(rc) with QBlockSig(self): # If the rows are not initialized then the context menus will bug out for i in range(0, self.columnCount()): twi = QTableWidgetItem('') self.setItem(rc, i, twi) twi_gt = QTableWidgetItem( ) # Hidden behind the combo box displays number (for sorting?) twi_lvl = QTableWidgetItem( ) # Hidden behind the combo box displays number (for sorting?) f_two = GearWidget(this_gear, model, default_icon=pix.get_icon(STR_LENS_PATH), check_state=check_state, edit_able=True) f_two.sig_error.connect(self.frmMain.sig_show_message) f_two.context_menu = QMenu( f_two ) # Don't want upgrade / downgrade options on this type of gear self.make_menu(f_two.context_menu) f_two.create_Cmbs(self) cmb_gt = f_two.cmbType cmb_enh = f_two.cmbLevel cmb_gt.currentTextChanged.connect( lambda x: set_cell_color_compare(twi_gt, x)) cmb_enh.currentTextChanged.connect(lambda x: set_cell_lvl_compare( twi_lvl, x, this_gear.gear_type)) f_two.add_to_table(self, rc, col=idx_HEADER_NAME) self.setCellWidget(rc, idx_HEADER_GEAR_TYPE, cmb_gt) self.setCellWidget(rc, idx_HEADER_TARGET, cmb_enh) self.setItem(rc, idx_HEADER_GEAR_TYPE, twi_gt) self.setItem(rc, idx_HEADER_TARGET, twi_lvl) set_cell_lvl_compare(twi_lvl, cmb_enh.currentText(), this_gear.gear_type) set_cell_color_compare(twi_gt, cmb_gt.currentText()) f_two.chkInclude.stateChanged.connect( lambda x: self.gw_check_state_changed(f_two, x)) self.clearSelection() self.selectRow(rc) with QBlockSig(self): self.cellWidget( rc, idx_HEADER_GEAR_TYPE).currentTextChanged.connect( frmMain.invalidate_fs_list) self.cellWidget(rc, idx_HEADER_TARGET).currentTextChanged.connect( frmMain.invalidate_fs_list) self.set_item_data(rc) self.resizeColumnToContents(idx_HEADER_NAME) f_two.sig_gear_changed.connect(self.fs_gear_sig_gear_changed)
def cmdCalc_clicked(self): model = self.enh_model frmMain = self.frmMain send_fs_signal = model.fs_needs_update or model.fs_secondary_needs_update if send_fs_signal: model.calcFS() #if len(self.invalidated_gear) == 0: # return This is handled in model.calc_equip_costs try: model.calc_equip_cost_u(self.invalidated_gear, model.cum_fs_cost) self.invalidated_gear = set() except ValueError as f: print(fmt_traceback(f.__traceback__)) frmMain.sig_show_message.emit(frmMain.WARNING, str(f)) return except Invalid_FS_Parameters as e: frmMain.sig_show_message.emit(frmMain.WARNING, str(e)) return if send_fs_signal: # This updates the UI to the fail stack list being updated from model.calc_equip_costs self.sig_fs_list_updated.emit() idx_NAME = self.get_header_index(HEADER_NAME) idx_TARGET = self.get_header_index(HEADER_TARGET) idx_CRONSTONE = self.get_header_index(HEADER_CRONSTONE) idx_FS = self.get_header_index(HEADER_FS) idx_COST = self.get_header_index(HEADER_COST) idx_SELL_OUT = self.get_header_index(HEADER_SELL_OUT) idx_MARGIN = self.get_header_index(HEADER_MARGIN) model = self.enh_model settings = model.settings tax = settings[settings.P_MARKET_TAX] item_store = settings[settings.P_ITEM_STORE] with SpeedUpTable(self): for i in range(0, self.topLevelItemCount()): this_head = self.topLevelItem(i) this_head.takeChildren() gear_widget: GearWidget = self.itemWidget(this_head, idx_NAME) this_gear: Gear = gear_widget.gear manager = GearManager(this_gear) manager.calculate_margins() if gear_widget.cmbLevel.currentIndex() == 0: try: start, stop = manager.find_best_margin() lvl_txt = this_gear.gear_type.idx_lvl_map[start] margin = manager.get_margin(start, stop) except GearNotProfitableException: margin = 0 pure_margin_stop = manager.find_margin_idx_for_pure() pure_margin = manager.get_margin(-1, pure_margin_stop) if pure_margin < margin: start = -1 stop = pure_margin_stop margin = pure_margin lvl_txt = gear_widget.cmbLevel.itemText(1) if margin >= 0: this_head.setText(idx_SELL_OUT, 'Not profitable') continue gear_widget.cmbLevel.setItemText( 0, 'Auto({})'.format(lvl_txt)) else: start = gear_widget.cmbLevel.get_level() stop = manager.find_best_margin_for_start(start) margin = manager.get_margin(start, stop) eh_idx = start + 1 fs = numpy.argmin(this_gear.cost_vec[stop]) this_gear.set_enhance_lvl( this_gear.gear_type.idx_lvl_map[eh_idx]) uses_crons = eh_idx in this_gear.cron_use if uses_crons: if gear_widget.trinket is None: gear_widget.set_trinket(pix[STR_PIC_CRON]) else: if gear_widget.trinket is not None: gear_widget.set_trinket(None) gear_widget.set_pixmap(enhance_overlay=True) self.add_children(this_head, start, stop, manager) this_head.setText(idx_SELL_OUT, str(this_gear.gear_type.idx_lvl_map[stop])) this_head.setText(idx_MARGIN, MONNIES_FORMAT.format(margin)) this_head.setText(idx_FS, str(fs))
def cmdFSRefresh_clicked(self, fsl: FailStackList): model: Enhance_model = self.enh_model settings = model.settings with SpeedUpTable(self): with QBlockSig(self): clear_table(self) if not fsl.validate(): return clear_table(self) try: if model.fs_needs_update: model.calcFS() else: model.calc_fs_secondary() except Invalid_FS_Parameters as e: self.frmMain.show_warning_msg(str(e)) return if not fsl.has_ran(): fsl.set_primary_data(model.primary_fs_gear, model.primary_fs_cost, model.primary_cum_fs_cost) fsl.evaluate_map() index_FS = self.get_header_index(HEADER_FS) index_GEAR = self.get_header_index(HEADER_GEAR) index_COST = self.get_header_index(HEADER_COST) index_CUMULATIVE_COST = self.get_header_index(HEADER_CUMULATIVE_COST) index_PROBABILITY = self.get_header_index(HEADER_PROBABILITY) index_CUMULATIVE_PROBABILITY = self.get_header_index( HEADER_CUMULATIVE_PROBABILITY) with SpeedUpTable(self): fs_items = fsl.gear_list fs_cost = fsl.fs_cost cum_fs_cost = fsl.fs_cum_cost this_gear = fsl.secondary_gear bti_m_o = this_gear.gear_type.bt_start - 1 prv_num = fsl.starting_pos for i, num in enumerate(fsl.secondary_map): fsg = this_gear.gear_type.get_fs_gain(bti_m_o + i) for j in range(0, num): rc = self.rowCount() self.insertRow(rc) self.setItem(rc, index_FS, QTableWidgetItem(str(prv_num))) two = GearWidget(fs_items[prv_num], model, edit_able=False, display_full_name=True) two.add_to_table(self, rc, col=index_GEAR) this_cost = numpy.sum(fs_cost[prv_num:prv_num + fsg]) twi = monnies_twi_factory(this_cost) self.setItem(rc, index_COST, twi) this_cum_cost = cum_fs_cost[min( len(cum_fs_cost) - 1, prv_num + fsg)] twi = monnies_twi_factory(this_cum_cost) self.setItem(rc, index_CUMULATIVE_COST, twi) prv_num += fsg if prv_num > settings[settings.P_NUM_FS]: return