def get_month_days_in_db(self): """return the days of the current stored month in the pattern of [28, .., 1, 2, 3, .., 27]""" l = map(lambda item: item[0], misc.sort_dict_keys_numerically(self.metadata.tables)) if len(l) > 27: l = l[27:] + l[:27] return l
def gen_worker_data(self): for worker_id, name in misc.sort_dict_keys_numerically(self.worker_dict): # 第一轮for,收集数据,以便计算废品绩效 lh_sum, waste_sum = 0, 0 # 各种求和 for labor_hour, labor_hour_aux, waste, _ in self.db_operator.iterate_worker(worker_id): lh_sum += labor_hour + labor_hour_aux waste_sum += waste if worker_id not in self.attendance_dict: if config.SKIP_NOT_FOUND_ATTENDANCE: continue else: attendance = 0 attended = 0 else: attendance = self.attendance_dict[worker_id][0] attended = self.attendance_dict[worker_id][1] self.worker_data[worker_id] = WorkerData(lh_sum, waste_sum, attended, attendance, self.performance_dict[worker_id]), name # 计算废品分 lowest_ratio = min(map(lambda (item, _): item.ratio_waste, self.worker_data.values())) for worker_data in map(lambda (item, _): item, self.worker_data.values()): worker_data.score_waste = max(0, worker_data.score_waste - (worker_data.ratio_waste - lowest_ratio) * 100) worker_data.process()
def get_id_name_pairs_with_row_number(self, sheet_index): """get id-name pairs with row number so that XLWriter can write data into the right position data structure: (id: unicode, (name: unicode, row: int))""" _sheet = self.workbook.sheet_by_index(sheet_index) return misc.sort_dict_keys_numerically( {id: (name, row + 1) for row, (id, name) in enumerate(zip(_sheet.col_values(0), _sheet.col_values(1))) if id.isdigit() and name})
def get_id_name_pairs(self, sheet_index): """get (id, name) pairs from specified sheet index data structure: (id: unicode, name: unicode)""" _sheet = self.workbook.sheet_by_index(sheet_index) return misc.sort_dict_keys_numerically( {id: name for id, name in zip(_sheet.col_values(0), _sheet.col_values(1)) if id.isdigit() and name})
def get_work_performance(self, sheet_index): """get performance of workers from specified sheet index data structure: (id: unicode, performance: int)""" _sheet = self.workbook.sheet_by_index(sheet_index) d = {} _ = lambda x: int(x) if isinstance(x, basestring) and x.isdigit() else 0 for id, performance in zip(_sheet.col_values(0), _sheet.col_values(11)): if isinstance(id, basestring) and id.isdigit(): d[unicode(int(id))] = int(performance) if performance else 0 return misc.sort_dict_keys_numerically(d)
def gen_worker_rows(self): self.gen_worker_data() def _gen_row(id, name, _cont): return AbstractDataProvider.each_row.format( id=id.encode('utf-8'), name=name.encode('utf-8'), details='\n'.join(_cont) ) make_nullable = lambda x: x if x else ' ' for worker_id, (worker_data, name) in misc.sort_dict_keys_numerically(self.worker_data): if worker_id not in self.worker_dict_show: continue _cont = [] for item in worker_data.get_performances(): _cont.append(super(PerformanceDataProvider, self).day_cont % make_nullable(item)) yield _gen_row(worker_id, name, _cont)
def get_attended_days_count_pairs(self): """get attendance data from the attendance sheet, which is specified by `config.attendance_sheet_index' data structure: (id: unicode, (attendance: int, attended: int))""" id_name_dict = misc.invert_dict(dict(self.get_id_name_pairs(0))) _sheet = self.workbook.sheet_by_index(config.attendance_sheet_index) d = {} _ = lambda x: int(x) if not isinstance(x, basestring) else 0 for name, attendance, attended in zip(_sheet.col_values(2), _sheet.col_values(3), _sheet.col_values(9)): if isinstance(name, basestring): if name in id_name_dict: d[id_name_dict[name]] = _(attendance), _(attended) return misc.sort_dict_keys_numerically(d)
def write_all_data(self): worker_data = dict(self.perf_data_provider.gen_worker_data()) for worker_id, (_, worker_row) in misc.sort_dict_keys_numerically(self.worker_dict_x): self.write_data_per_worker(worker_row, worker_data[worker_id][0]) super(PerformanceXLWriter, self).write_all_data()
def write_all_data(self): for worker_id, (_, worker_row) in misc.sort_dict_keys_numerically(self.worker_dict_x): self.write_data_per_worker(worker_id, worker_row) super(LaborHourDataXLWriter, self).write_all_data()