Skip to content

Commit

Permalink
Merge pull request #127 from gisce/imp_ajustos_balancejats
Browse files Browse the repository at this point in the history
Calcular ajustos balancejats en periodes agrupats
  • Loading branch information
eberloso authored May 14, 2020
2 parents 790c09d + d342f54 commit a81f1c8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
30 changes: 29 additions & 1 deletion gestionatr/input/messages/F1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,25 @@ def get_consum_facturat(self, tipus, periode):

def get_lectures_amb_ajust_autoconsum(self, tipus='S', ajust_balancejat=True, motiu_ajust="98"):
return self.get_lectures_amb_ajust_quadrat_amb_consum(tipus=tipus, ajust_balancejat=ajust_balancejat, motiu_ajust=motiu_ajust)


def periodes_facturats_agrupats(self, nperiodes_lectures, tipus='A'):
if tipus not in ['A', 'S']:
return None

res = {}
if tipus == 'A' and self.energia_activa:
for activa in self.energia_activa.terminos_energia_activa:
for periode_activa in activa.periodos:
if periode_activa.nombre not in res:
res[periode_activa.nombre] = True

else: # if tipus == 'S':
for concepte in self.conceptos_repercutibles:
if concepte.concepto_repercutible[0] == '7' and concepte.concepto_repercutible not in res:
res[concepte.concepto_repercutible] = True

return len(res.keys()) != nperiodes_lectures

def get_lectures_amb_ajust_quadrat_amb_consum(self, tipus='S', ajust_balancejat=True, motiu_ajust="98"):
lectures_per_periode = {}
for comptador in self.get_comptadors():
Expand All @@ -1232,6 +1250,16 @@ def get_lectures_amb_ajust_quadrat_amb_consum(self, tipus='S', ajust_balancejat=
lectures_per_periode[periode] = []
lectures_per_periode[periode].append(lectura)

nperiodes = len([l for l in lectures_per_periode.keys() if l])
if self.periodes_facturats_agrupats(nperiodes, tipus=tipus) and ajust_balancejat:
for periode in lectures_per_periode.keys():
if not periode:
continue
periode_agrupat = "P{0}".format(int(periode[1:]) + nperiodes/2)
if lectures_per_periode.get(periode_agrupat):
lectures_per_periode[periode].extend(lectures_per_periode.get(periode_agrupat))
del lectures_per_periode[periode_agrupat]

res = {}
for periode, lectures in lectures_per_periode.iteritems():
if ajust_balancejat:
Expand Down
32 changes: 21 additions & 11 deletions gestionatr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,25 @@ def repartir_consums_entre_lectures(consums, lectures_xml):
res[l] = consums[i]
i += 1
elif len(consums) == 1:
consum = consums[0]
import math
parte_decimal, parte_entera = math.modf(consum)
part_igual = int(parte_entera) / len(lectures_xml)
residu = (int(parte_entera) % len(lectures_xml)) + parte_decimal

l = None
for l in lectures_xml:
res[l] = part_igual
if l:
res[l] += residu
periodes = list(set([l.periode for l in lectures_xml]))
if len(periodes) > 1:
consum_acumulat = 0
for l in lectures_xml:
res[l] = l.consumo_calculado
if l != lectures_xml[0]:
consum_acumulat += l.consumo_calculado
if res:
res[lectures_xml[0]] = consums[0] - consum_acumulat
else:
consum = consums[0]
import math
parte_decimal, parte_entera = math.modf(consum)
part_igual = int(parte_entera) / len(lectures_xml)
residu = (int(parte_entera) % len(lectures_xml)) + parte_decimal

l = None
for l in lectures_xml:
res[l] = part_igual
if l:
res[l] += residu
return res

0 comments on commit a81f1c8

Please sign in to comment.