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_week_prod_totals(daily, sourcetype): if daily: end_date = daily.production_date start_date = end_date - timedelta(days=WEEKDAYS - 1) sp_query = SourceProduction.objects.filter( Q(daily__production_date__gte=start_date), Q(daily__production_date__lte=end_date), sourcetype=sourcetype, ) else: sp_query = None if not sp_query: wp = {f'week_{key[:5]}': np.nan for key in source_prod_schema[0:6]} wp[f'week_{source_prod_schema[6]}'] = np.nan wp['week_total'] = np.nan return wp # only include sources and skips wp = { f'week_{key[:5]}': np.nansum([val[key] for val in sp_query.values()]) for key in source_prod_schema[0:6] } # get average of number of sources wp[f'week_{source_prod_schema[6]}'] = nan_avg_array( [val[source_prod_schema[6]] for val in sp_query.values()]) # only include sources from terrain types wp['week_total'] = np.sum(wp[f'week_{key[:5]}'] for key in source_prod_schema[0:5]) return wp
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
def calc_proj_prod_totals(self, daily, sourcetype): # filter for all days in the project up to and including the production date if daily: sp_query = SourceProduction.objects.filter( daily__production_date__lte=daily.production_date, sourcetype=sourcetype, ).order_by('daily__production_date') else: sp_query = None if not sp_query: pp = {f'proj_{key[:5]}': np.nan for key in source_prod_schema[0:6]} pp[f'proj_{source_prod_schema[6]}'] = np.nan pp['proj_total'] = np.nan return pp, {} p_series = { f'{key[:5]}_series': nan_array([val[key] for val in sp_query.values()]) for key in source_prod_schema[0:6] } p_series = self.calc_ctm_series(p_series, sourcetype) p_series[f'{source_prod_schema[6]}_series'] = np.array( [val.avg_sources for val in sp_query]) p_series['date_series'] = np.array( [val.daily.production_date for val in sp_query]) # only include sources and skips pp = { f'proj_{key[:5]}': np.nansum(p_series[f'{key[:5]}_series']) for key in source_prod_schema[0:6] } # get average of number of sources pp[f'proj_{source_prod_schema[6]}'] = nan_avg_array( p_series[f'{source_prod_schema[6]}_series']) # only include sources from terrain types pp['proj_total'] = np.sum(pp[f'proj_{key[:5]}'] for key in source_prod_schema[0:5]) return pp, p_series
def calc_month_prod_totals(daily, sourcetype): # filter for days in the month up to and including the production date if daily: sp_query = SourceProduction.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), sourcetype=sourcetype, ) else: sp_query = None if not sp_query: mp = { f'month_{key[:5]}': np.nan for key in source_prod_schema[0:6] } mp[f'month_{source_prod_schema[6]}'] = np.nan mp['month_total'] = np.nan return mp # only include sources and skips mp = { f'month_{key[:5]}': np.nansum([val[key] for val in sp_query.values()]) for key in source_prod_schema[0:6] } # get average of number of sources mp[f'month_{source_prod_schema[6]}'] = nan_avg_array( [val[source_prod_schema[6]] for val in sp_query.values()]) # for total sp only include sources from terrain type mp['month_total'] = np.sum(mp[f'month_{key[:5]}'] for key in source_prod_schema[0:5]) return mp