def _calcula_factura(self):
<EOL>self._dict_repr = None<EOL>self._str_repr = None<EOL>self._html_repr = None<EOL>self._html_repr_completa = None<EOL>cod_tarifa = DATOS_TIPO_PEAJE[self._tipo_peaje][<NUM_LIT:1>]<EOL>year = self._t0.year<EOL>year_f = self._tf.year<EOL>self._num_dias_factura = (self._tf - self._t0).days  <EOL>if year_f > year:<EOL><INDENT>ts_limit = pd.Timestamp('<STR_LIT>'.format(year))<EOL>days_1 = (ts_limit - self._t0).days<EOL>days_2 = (self._tf - ts_limit).days<EOL>n_days_y1 = (pd.Timestamp('<STR_LIT>'.format(year + <NUM_LIT:1>)) - pd.Timestamp('<STR_LIT>'.format(year))).days<EOL>n_days_y2 = (pd.Timestamp('<STR_LIT>'.format(year_f + <NUM_LIT:1>)) - pd.Timestamp('<STR_LIT>'.format(year_f))).days<EOL>self._periodos_fact = ((days_1, n_days_y1, year), (days_2, n_days_y2, year_f))<EOL><DEDENT>else:<EOL><INDENT>n_days_y = (pd.Timestamp('<STR_LIT>'.format(year + <NUM_LIT:1>)) - pd.Timestamp('<STR_LIT>'.format(year))).days<EOL>self._periodos_fact = ((self._num_dias_factura, n_days_y, year),)<EOL><DEDENT>if self._pvpc_data is None:<EOL><INDENT>pvpc_data = PVPC(update=True, verbose=False)<EOL>self._pvpc_data = pvpc_calc_tcu_cp_feu_d(pvpc_data.data['<STR_LIT:data>'], verbose=False, convert_kwh=True)<EOL><DEDENT>cols_tarifa = list(filter(lambda x: cod_tarifa in x, self._pvpc_data.columns))<EOL>pvpc_t_ini, pvpc_t_fin = self._t0 + pd.Timedelta('<STR_LIT>'), self._tf + pd.Timedelta('<STR_LIT>')<EOL>self._pvpc_horario = self._pvpc_data[cols_tarifa].loc[pvpc_t_ini:pvpc_t_fin].iloc[:-<NUM_LIT:1>]<EOL>self._termino_fijo, self._termino_fijo_total = [], <NUM_LIT:0><EOL>for (days_fac, days_year, year) in self._periodos_fact:<EOL><INDENT>coef_potencia = MARGEN_COMERCIALIZACIÓN_EUR_KW_AÑO_MCF + TERM_POT_PEAJE_ACCESO_EUR_KW_AÑO_TPA[year]<EOL>coste = self._potencia_contratada * days_fac * coef_potencia / days_year<EOL>self._termino_fijo.append((coste, coef_potencia))<EOL>self._termino_fijo_total += coste<EOL><DEDENT>self._termino_fijo_total = self._round(self._termino_fijo_total)<EOL>if self._consumo is not None:<EOL><INDENT>son_totales, consumo_calc = self._consumo_numerico()<EOL>if son_totales:<EOL><INDENT>c_coef = '<STR_LIT>'.format(cod_tarifa)<EOL>hay_discr, perfs_interv = self._asigna_periodos_discr_horaria(self._pvpc_horario[c_coef])<EOL>if not hay_discr:<EOL><INDENT>self._consumo_horario = (perfs_interv * consumo_calc[<NUM_LIT:0>] / perfs_interv.sum()).rename(COL_CONSUMO)<EOL><DEDENT>else:<EOL><INDENT>consumos_horarios_periodos = []<EOL>for i, cons_periodo_i in enumerate(consumo_calc):<EOL><INDENT>c = '<STR_LIT>'.format(i + <NUM_LIT:1>)<EOL>idx = perfs_interv[perfs_interv[c]].index<EOL>consumos_horarios_periodos.append(perfs_interv.loc[idx, c_coef] * cons_periodo_i<EOL>/ perfs_interv.loc[idx, c_coef].sum())<EOL><DEDENT>self._consumo_horario = pd.Series(pd.concat(consumos_horarios_periodos)<EOL>).rename(COL_CONSUMO).sort_index()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._consumo_horario = self._check_hourly_data(consumo_calc)<EOL>t0, tf = self._consumo_horario.index[<NUM_LIT:0>], self._consumo_horario.index[-<NUM_LIT:1>]<EOL>self._pvpc_horario = self._pvpc_horario.loc[t0:tf]<EOL><DEDENT>col_tcu = '<STR_LIT>'.format(cod_tarifa)<EOL>if len(self._periodos_fact) > <NUM_LIT:1>:<EOL><INDENT>ts_limit = pd.Timestamp('<STR_LIT>'.format(self._tf.year)).tz_localize(self._consumo_horario.index.tz)<EOL>consumo_1 = self._consumo_horario.loc[:ts_limit].iloc[:-<NUM_LIT:1>]<EOL>consumo_2 = self._consumo_horario.loc[ts_limit:]<EOL>pvpc_1 = self._pvpc_horario.loc[:ts_limit].iloc[:-<NUM_LIT:1>]<EOL>pvpc_2 = self._pvpc_horario.loc[ts_limit:]<EOL>tea_y1, tcu_y1, cons_tot_y1 = list(zip(*self._coste_tea_tcu(consumo_1, pvpc_1[col_tcu], self._t0.year)))<EOL>tea_y2, tcu_y2, cons_tot_y2 = list(zip(*self._coste_tea_tcu(consumo_2, pvpc_2[col_tcu], self._tf.year)))<EOL>self._coste_peaje_acceso_tea = (tea_y1, tea_y2)<EOL>self._coste_ponderado_energia_tcu = (tcu_y1, tcu_y2)<EOL>self._consumos_totales_por_periodo = (cons_tot_y1, cons_tot_y2)<EOL>coste_variable_tot = sum([sum(x) for x in self._coste_peaje_acceso_tea])<EOL>coste_variable_tot += sum([sum(x) for x in self._coste_ponderado_energia_tcu])<EOL><DEDENT>else:<EOL><INDENT>tea, tcu, cons_tot = list(zip(*self._coste_tea_tcu(self._consumo_horario, self._pvpc_horario[col_tcu],<EOL>self._t0.year)))<EOL>self._coste_peaje_acceso_tea = tea<EOL>self._coste_ponderado_energia_tcu = tcu<EOL>self._consumos_totales_por_periodo = cons_tot<EOL>coste_variable_tot = self._round_sum(self._coste_peaje_acceso_tea)<EOL>coste_variable_tot += self._round_sum(self._coste_ponderado_energia_tcu)<EOL><DEDENT>self._consumo = self._consumo_horario<EOL><DEDENT>else:<EOL><INDENT>self._coste_peaje_acceso_tea = (<NUM_LIT:0.>,)<EOL>self._coste_ponderado_energia_tcu = (<NUM_LIT:0.>,)<EOL>self._consumos_totales_por_periodo = (<NUM_LIT:0.>,)<EOL>coste_variable_tot = <NUM_LIT:0.><EOL><DEDENT>self._termino_variable_total = self._round(coste_variable_tot)<EOL>subt_fijo_var = self._termino_fijo_total + self._termino_variable_total<EOL>self._descuento_bono_social = <NUM_LIT:0.><EOL>if self._con_bono_social:<EOL><INDENT>self._descuento_bono_social = self._round(-<NUM_LIT> * self._round(subt_fijo_var))<EOL>subt_fijo_var += self._descuento_bono_social<EOL><DEDENT>self._termino_impuesto_electrico = self._round(self._impuesto_electrico_general * subt_fijo_var)<EOL>subt_fijo_var += self._termino_impuesto_electrico<EOL>if self.alquiler_euros is not None:<EOL><INDENT>self._termino_equipo_medida = self._round(self.alquiler_euros)<EOL><DEDENT>else:<EOL><INDENT>frac_año = sum([nd / dy for nd, dy, _ in self._periodos_fact])<EOL>self._termino_equipo_medida = self._round(frac_año * self.alquiler_euros_año)<EOL><DEDENT>self._calcula_iva_y_total()<EOL>
Método para regenerar el cálculo de la factura eléctrica.