# Path: salmon/metrics/models.py
# class Source(models.Model):
# class Metric(models.Model):
#     class Meta:
# class MetricGroup(Metric):
#     class Meta:
#     def __unicode__(self):
#     def get_absolute_url(self):
#     def __init__(self, *args, **kwargs):
#     def _reset_changes(self):
#     def whisper_filename(self):
#     def add_latest_to_archive(self):
#     def get_or_create_archive(self):
#     def load_archive(self, from_date, to_date=None):
#     def in_alert_state(self):
#     def get_value_display(self):
#     def time_between_updates(self):
#     def do_transform(self):
#     def do_counter_conversion(self):
#     def check_alarm(self):
#     def save(self, *args, **kwargs):
#     OPERATOR_CHOICES = (
#         ('lt', 'value < alert'),
#         ('le', 'value <= alert'),
#         ('eq', 'value == alert'),
#         ('ne', 'value != alert'),
#         ('ge', 'value >= alert'),
#         ('gt', 'value > alert'),
#     )
#     DISPLAY_CHOICES = (
#         ('float', 'Number'),
#         ('boolean', 'True/False'),
#         ('byte', 'Bytes'),
#         ('percentage', 'Percentage'),
#         ('second', 'Seconds'),
#     )


from django.contrib import admin
from . import models
    list_display = ('name', 'display_as', 'is_counter', 'transform',
                    'alert_operator', 'alert_value')


    def get_queryset(self, request):
        """Shows one entry per distinct metric name"""
        queryset = super(MetricGroupAdmin, self).get_queryset(request)
        # poor-man's DISTINCT ON for Sqlite3
        qs_values = queryset.values('id', 'name')
        # 2.7+ only :(
        # = {metric['name']: metric['id'] for metric in qs_values}
        distinct_names = {}
        for metric in qs_values:
            distinct_names[metric['name']] = metric['id']
        queryset = self.model.objects.filter(id__in=distinct_names.values())
        return queryset

    def save_model(self, request, obj, form, change):
        """Updates all metrics with the same name"""
        like_metrics = self.model.objects.filter(name=obj.name)
        # 2.7+ only :(
        # = {key: form.cleaned_data[key] for key in form.changed_data}
        updates = {}
        for key in form.changed_data:
            updates[key] = form.cleaned_data[key]
        like_metrics.update(**updates)



admin.site.register(models.Metric, MetricAdmin)

# Path: salmon/metrics/models.py
# class Source(models.Model):
# class Metric(models.Model):
#     class Meta:
# class MetricGroup(Metric):
#     class Meta:
#     def __unicode__(self):
#     def get_absolute_url(self):
#     def __init__(self, *args, **kwargs):
#     def _reset_changes(self):
#     def whisper_filename(self):
#     def add_latest_to_archive(self):
#     def get_or_create_archive(self):
#     def load_archive(self, from_date, to_date=None):
#     def in_alert_state(self):
#     def get_value_display(self):
#     def time_between_updates(self):
#     def do_transform(self):
#     def do_counter_conversion(self):
#     def check_alarm(self):
#     def save(self, *args, **kwargs):
#     OPERATOR_CHOICES = (
#         ('lt', 'value < alert'),
#         ('le', 'value <= alert'),
#         ('eq', 'value == alert'),
#         ('ne', 'value != alert'),
#         ('ge', 'value >= alert'),
#         ('gt', 'value > alert'),
#     )
#     DISPLAY_CHOICES = (
#         ('float', 'Number'),
#         ('boolean', 'True/False'),
#         ('byte', 'Bytes'),
#         ('percentage', 'Percentage'),
#         ('second', 'Seconds'),
#     )


# Path: salmon/metrics/admin.py
from django.contrib import admin
from . import models

    list_display = ('name', 'display_as', 'is_counter', 'transform',
                    'alert_operator', 'alert_value')


    def get_queryset(self, request):
        """Shows one entry per distinct metric name"""
        queryset = super(MetricGroupAdmin, self).get_queryset(request)
        # poor-man's DISTINCT ON for Sqlite3
        qs_values = queryset.values('id', 'name')
        # 2.7+ only :(
        # = {metric['name']: metric['id'] for metric in qs_values}
        distinct_names = {}
        for metric in qs_values:
            distinct_names[metric['name']] = metric['id']
        queryset = self.model.objects.filter(id__in=distinct_names.values())
        return queryset

    def save_model(self, request, obj, form, change):
        """Updates all metrics with the same name"""
        like_metrics = self.model.objects.filter(name=obj.name)
        # 2.7+ only :(
        # = {key: form.cleaned_data[key] for key in form.changed_data}
        updates = {}
        for key in form.changed_data:
            updates[key] = form.cleaned_data[key]
        like_metrics.update(**updates)



admin.site.register(models.Metric, MetricAdmin)

admin.site.register(models.MetricGroup, MetricGroupAdmin)