Skip to content

Commit

Permalink
Muevo funciones de normalizacion de indicadores a archivo propio, y l…
Browse files Browse the repository at this point in the history
…as migro
  • Loading branch information
pepeciavirella committed Nov 4, 2019
1 parent 6eed0c7 commit ae4ebba
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 213 deletions.
@@ -0,0 +1,22 @@
from __future__ import unicode_literals

from django.db import migrations

from monitoreo.apps.dashboard.normalization_utils import normalize_node_indicator_values, \
normalize_network_indicator_values, normalize_federator_indicator_values


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0055_auto_20191030_1544'),
]

operations = [
migrations.RunPython(normalize_node_indicator_values,
migrations.RunPython.noop),
migrations.RunPython(normalize_network_indicator_values,
migrations.RunPython.noop),
migrations.RunPython(normalize_federator_indicator_values,
migrations.RunPython.noop),
]
41 changes: 41 additions & 0 deletions monitoreo/apps/dashboard/normalization_utils.py
@@ -0,0 +1,41 @@
from __future__ import unicode_literals

import json
import logging

from pydatajson.helpers import fields_to_uppercase

LOGGER = logging.getLogger(__name__)


def normalize_values(apps, model):
queryset = model.objects.filter(indicador_tipo__nombre__in=[
'distribuciones_formatos_cant', 'datasets_frecuencia_cant'])

for indicator in queryset:
try:
value = json.loads(indicator.indicador_valor)
if isinstance(value, dict):
normalized_value = fields_to_uppercase(value)
if normalized_value != value:
# No quiero hacer un save si los valores no cambian
indicator.indicador_valor = json.dumps(normalized_value)
indicator.save()
except json.JSONDecodeError:
msg = f'error parseando el indicador:{indicator.pk}'
LOGGER.warning(msg)


def normalize_node_indicator_values(apps, _schema_editor):
indicador = apps.get_model('dashboard', 'Indicador')
normalize_values(apps, indicador)


def normalize_network_indicator_values(apps, _schema_editor):
indicador_red = apps.get_model('dashboard', 'IndicadorRed')
normalize_values(apps, indicador_red)


def normalize_federator_indicator_values(apps, _schema_editor):
indicador_federador = apps.get_model('dashboard', 'IndicadorFederador')
normalize_values(apps, indicador_federador)

0 comments on commit ae4ebba

Please sign in to comment.