def calc_combined_production(self, day, times_total, prod_total_by_type): days = get_period_days(day) prod_total = {} for ptotal in prod_total_by_type.values(): prod_total = sum_keys(prod_total, ptotal) for period in ['day', 'week', 'month', 'proj']: # calculate weighted sum of tcf and ctm tcf = 0 ctm = 0 for ptotal in prod_total_by_type.values(): tcf += ptotal[f'{period}_tcf'] * ptotal[f'{period}_total'] ctm += ptotal[f'{period}_ctm'] * ptotal[f'{period}_total'] prod_total[f'{period}_tcf'] = (tcf / prod_total[f'{period}_total'] if prod_total[f'{period}_total'] > 0 else np.nan) prod_total[f'{period}_ctm'] = (round(ctm / prod_total[f'{period}_total']) if prod_total[f'{period}_total'] > 0 else np.nan) prod_total[f'{period}_appctm'] = calc_ratio( prod_total[f'{period}_total'], prod_total[f'{period}_ctm']) prod_total[f'{period}_avg'] = int(prod_total[f'{period}_total'] / days[period]) prod_total[f'{period}_rate'] = self.calc_rate( day, CTM_METHOD, prod_total[f'{period}_appctm'], times_total[f'{period}_total_time'], times_total[f'{period}_standby']) prod_total[f'{period}_perc_skips'] = calc_ratio( prod_total[f'{period}_skips'], prod_total[f'{period}_total']) return prod_total
def month_receiver_total(daily, receivertype): if daily: rcvr_query = ReceiverProduction.objects.filter( Q(daily__production_date__year=daily.production_date.year) & Q(daily__production_date__month=daily.production_date.month) & Q(daily__production_date__day__lte=daily.production_date.day), receivertype=receivertype, ) else: rcvr_query = None if not rcvr_query: m_rcvr = {f'month_{key}': 0 for key in receiver_prod_schema} return m_rcvr m_rcvr = { f'month_{key}': sum(nan_array([val[key] for val in rcvr_query.values()])) for key in receiver_prod_schema[0:7] } m_rcvr['month_qc_field'] = nan_avg_array( [val['qc_field'] for val in rcvr_query.values()]) m_rcvr['month_qc_teams'] = nan_avg_array( [val['qc_teams'] for val in rcvr_query.values()]) m_rcvr['month_fc_teams'] = nan_avg_array( [val['fc_teams'] for val in rcvr_query.values()]) m_rcvr['month_bc_teams'] = nan_avg_array( [val['bc_teams'] for val in rcvr_query.values()]) m_rcvr['month_perc_node_skips'] = calc_ratio( m_rcvr['month_node_skips'], daily.project.planned_receivers) return m_rcvr
def week_receiver_total(daily, receivertype): if daily: end_date = daily.production_date start_date = end_date - timedelta(days=WEEKDAYS - 1) rcvr_query = ReceiverProduction.objects.filter( Q(daily__production_date__gte=start_date), Q(daily__production_date__lte=end_date), receivertype=receivertype, ) else: rcvr_query = None if not rcvr_query: w_rcvr = {f'week_{key}': 0 for key in receiver_prod_schema} return w_rcvr w_rcvr = { f'week_{key}': sum(nan_array([val[key] for val in rcvr_query.values()])) for key in receiver_prod_schema[0:7] } w_rcvr['week_qc_field'] = nan_avg_array( [val['qc_field'] for val in rcvr_query.values()]) w_rcvr['week_qc_teams'] = nan_avg_array( [val['qc_teams'] for val in rcvr_query.values()]) w_rcvr['week_fc_teams'] = nan_avg_array( [val['fc_teams'] for val in rcvr_query.values()]) w_rcvr['week_bc_teams'] = nan_avg_array( [val['bc_teams'] for val in rcvr_query.values()]) w_rcvr['week_perc_node_skips'] = calc_ratio( w_rcvr['week_node_skips'], daily.project.planned_receivers) return w_rcvr
def calc_ctm_series(self, p_series, sourcetype): terrain_series = list( zip(*[ val for key, val in p_series.items() if key != 'skips_series' ])) p_series['tcf_series'] = [] p_series['total_sp_series'] = [] p_series['ctm_series'] = [] p_series['appctm_series'] = [] p_series['rate_series'] = [] for terrain_sp in terrain_series: sp_total = np.nansum(terrain_sp) p_series['total_sp_series'].append(sp_total) if sp_total > 0: p_series['tcf_series'].append( terrain_sp[0] / sp_total * TCF_table['sp_t1'] + terrain_sp[1] / sp_total * TCF_table['sp_t2'] + terrain_sp[2] / sp_total * TCF_table['sp_t3'] + terrain_sp[3] / sp_total * TCF_table['sp_t4'] + terrain_sp[4] / sp_total * TCF_table['sp_t5']) else: p_series['tcf_series'].append(np.nan) for tcf, total in zip(p_series['tcf_series'], p_series['total_sp_series']): ctm = self.calc_ctm(sourcetype, tcf) appctm = calc_ratio(total, ctm) p_series['ctm_series'].append(ctm) p_series['appctm_series'].append(appctm) p_series['rate_series'].append(np.nan) return p_series
def calc_period_totals(self, day, stype, times_total, prod_total): days = get_period_days(day) for period in ['day', 'week', 'month', 'proj']: prod_total[f'{period}_tcf'] = self.calc_tcf(period, prod_total) prod_total[f'{period}_ctm'] = self.calc_ctm( stype, prod_total[f'{period}_tcf']) * days[period] prod_total[f'{period}_appctm'] = calc_ratio( prod_total[f'{period}_total'], prod_total[f'{period}_ctm']) prod_total[f'{period}_avg'] = int(prod_total[f'{period}_total'] / days[period]) prod_total[f'{period}_rate'] = self.calc_rate( day, CTM_METHOD, prod_total[f'{period}_appctm'], times_total[f'{period}_total_time'], times_total[f'{period}_standby']) prod_total[f'{period}_perc_skips'] = calc_ratio( prod_total[f'{period}_skips'], prod_total[f'{period}_total']) return prod_total
def calc_combined_series(self, day, times_total, prod_series_by_type): prod_series = {} for pseries in prod_series_by_type.values(): prod_series = sum_keys(prod_series, pseries) ps_length = len(prod_series['total_sp_series']) ctm_series = np.zeros(ps_length) tcf_series = np.zeros(ps_length) totals = np.array(prod_series['total_sp_series']) for pseries in prod_series_by_type.values(): ctm = np.array(pseries['ctm_series']) app = np.array(pseries['total_sp_series']) tcf = np.array(pseries['tcf_series']) weights = np.array( [v1 / v2 if v2 > 0 else 0 for v1, v2 in zip(app, totals)]) ctm_series = ctm_series + ctm * weights tcf_series = tcf_series + tcf * weights prod_series['ctm_series'] = ctm_series prod_series['tcf_series'] = tcf_series prod_series['appctm_series'] = np.array([ calc_ratio(v1, v2) if v2 > 0 else np.nan for v1, v2 in zip(totals, ctm_series) ]) rate_series = [] for appctm, total_time, standby in zip( prod_series['appctm_series'], self.time_series['total_time_series'], self.time_series['standby_series']): rate_series.append( self.calc_rate(day, CTM_METHOD, appctm, total_time, standby)) prod_series['rate_series'] = np.array(rate_series) return prod_series
def day_receiver_total(daily, receivertype): if daily: try: rcvr = ReceiverProduction.objects.get( daily=daily, receivertype=receivertype, ) except ReceiverProduction.DoesNotExist: d_rcvr = {f'day_{key}': 0 for key in receiver_prod_schema} return d_rcvr else: d_rcvr = {f'day_{key}': 0 for key in receiver_prod_schema} return d_rcvr d_rcvr = { f'day_{key}': np.nan_to_num(getattr(rcvr, key)) for key in receiver_prod_schema } d_rcvr['day_perc_node_skips'] = calc_ratio( d_rcvr['day_node_skips'], daily.project.planned_receivers) return d_rcvr
def project_receiver_total(daily, receivertype): if daily: rcvr_query = ReceiverProduction.objects.filter( daily__production_date__lte=daily.production_date, receivertype=receivertype, ).order_by('daily__production_date') else: rcvr_query = None if not rcvr_query: p_rcvr = {f'proj_{key}': 0 for key in receiver_prod_schema} return p_rcvr, {} rcvr_series = { f'{key}_series': [val[key] for val in rcvr_query.values()] for key in receiver_prod_schema } p_rcvr = { f'proj_{key}': sum(nan_array([val[key] for val in rcvr_query.values()])) for key in receiver_prod_schema[0:7] } p_rcvr['proj_qc_field'] = nan_avg_array( [val['qc_field'] for val in rcvr_query.values()]) p_rcvr['proj_qc_teams'] = nan_avg_array( [val['qc_teams'] for val in rcvr_query.values()]) p_rcvr['proj_fc_teams'] = nan_avg_array( [val['fc_teams'] for val in rcvr_query.values()]) p_rcvr['proj_bc_teams'] = nan_avg_array( [val['bc_teams'] for val in rcvr_query.values()]) p_rcvr['proj_perc_node_skips'] = calc_ratio( p_rcvr['proj_node_skips'], daily.project.planned_receivers) return p_rcvr, rcvr_series