<commit_before># mqttseed application command
from django.core.management.base import BaseCommand
from django.conf import settings
from django.utils.six import BytesIO

from rest_framework.parsers import JSONParser
from rest_framework.renderers import JSONRenderer

from mqtt.publish import PublishClient

from django.contrib.auth.models import User

from login.models import Profile
    
from ambulance.models import Ambulance

from hospital.models import Hospital, HospitalEquipment

class Client(PublishClient):

    # The callback for when the client receives a CONNACK
    # response from the server.
    def on_connect(self, client, userdata, flags, rc):

        # is connected?
        if not super().on_connect(client, userdata, flags, rc):
            return False

        # initialize pubset
        self.pubset = set()
        self.can_disconnect = False

        # Seed hospitals
        self.seed_hospital_data(client)
        self.seed_hospital_equipment_data(client)
        self.seed_hospital_metadata(client)

        # Seed ambulances
        self.seed_ambulance_data(client)

        # Seed profiles
        self.seed_profile_data(client)
        
        # Seed calls
        # self.seed_calls(client)

        # Good to disconnect
        self.can_disconnect = True
        
    def publish(self, topic, message, *vargs, **kwargs):

        # increment pubcount then publish
        result = self.client.publish(topic, message, *vargs, **kwargs)
        self.pubset.add(result.mid)

        # echo if verbosity > 0
        if self.verbosity > 1:
            self.stdout.write("   {}: {}".format(topic, message))
        elif self.verbosity > 0:
            self.stdout.write("   {}".format(topic))

    def seed_settings(self, client):
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding settings"))

        # seeding settings
        self.publish_settings()
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding hospital metadata"))
            
    def seed_profile_data(self, client):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding profile data"))

        # seeding profiles
        for obj in Profile.objects.all():
            self.publish_profile(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding profile data"))
            
    def seed_ambulance_data(self, client):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding ambulance data"))

        # seeding ambulances
        for obj in Ambulance.objects.all():
            self.publish_ambulance(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding ambulance data"))

    def seed_hospital_data(self, client):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding hospital data"))

        # seeding hospital 
        for obj in Hospital.objects.all():
            self.publish_hospital(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding hospital data"))

            
    def seed_hospital_equipment_data(self, client):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding hospital equipment data"))

        # seeding hospital 
        for obj in HospitalEquipment.objects.all():
            self.publish_hospital_equipment(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding hospital equipment data"))

            
    def seed_hospital_metadata(self, client):
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding hospital metadata"))

        # seeding hospital metadata
        for hospital in Hospital.objects.all():<commit_msg>Settings api and mqtt view<commit_after># mqttseed application command
from django.core.management.base import BaseCommand
from django.conf import settings
from django.utils.six import BytesIO

from rest_framework.parsers import JSONParser
from rest_framework.renderers import JSONRenderer

from mqtt.publish import PublishClient

from django.contrib.auth.models import User

from login.models import Profile
    
from ambulance.models import Ambulance

from hospital.models import Hospital, HospitalEquipment

class Client(PublishClient):

    # The callback for when the client receives a CONNACK
    # response from the server.
    def on_connect(self, client, userdata, flags, rc):

        # is connected?
        if not super().on_connect(client, userdata, flags, rc):
            return False

        # initialize pubset
        self.pubset = set()
        self.can_disconnect = False

        # Seed settings
        self.seed_settings()
        
        # Seed hospitals
        self.seed_hospital_data()
        self.seed_hospital_equipment_data()
        self.seed_hospital_metadata()

        # Seed ambulances
        self.seed_ambulance_data()

        # Seed profiles
        self.seed_profile_data()
        
        # Seed calls
        # self.seed_calls()

        # Good to disconnect
        self.can_disconnect = True
        
    def publish(self, topic, message, *vargs, **kwargs):

        # increment pubcount then publish
        result = self.client.publish(topic, message, *vargs, **kwargs)
        self.pubset.add(result.mid)

        # echo if verbosity > 0
        if self.verbosity > 1:
            self.stdout.write("   {}: {}".format(topic, message))
        elif self.verbosity > 0:
            self.stdout.write("   {}".format(topic))

    def seed_settings(self):
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding settings"))

        # seeding settings
        self.publish_settings()
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding hospital metadata"))
            
    def seed_profile_data(self):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding profile data"))

        # seeding profiles
        for obj in Profile.objects.all():
            self.publish_profile(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding profile data"))
            
    def seed_ambulance_data(self):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding ambulance data"))

        # seeding ambulances
        for obj in Ambulance.objects.all():
            self.publish_ambulance(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding ambulance data"))

    def seed_hospital_data(self):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding hospital data"))

        # seeding hospital 
        for obj in Hospital.objects.all():
            self.publish_hospital(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding hospital data"))

            
    def seed_hospital_equipment_data(self):

        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding hospital equipment data"))

        # seeding hospital 
        for obj in HospitalEquipment.objects.all():
            self.publish_hospital_equipment(obj)
            
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS("<< Done seeding hospital equipment data"))

            
    def seed_hospital_metadata(self):
        if self.verbosity > 0:
            self.stdout.write(self.style.SUCCESS(">> Seeding hospital metadata"))

        # seeding hospital metadata
        for hospital in Hospital.objects.all():
{'fraction_non_alphanumeric': 0.0937381882323296, 'fraction_numerical': 0.0035277812775607914, 'mean_word_length': 2.228141520943473, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6875685', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2107, 'n_words': 542}