<commit_before>package status

import (
	"errors"
	"log"

	"github.com/byuoitav/configuration-database-microservice/accessors"
)

const VOLUME_DSP = "STATUS_VolumeDSP"
const STATUS_VOLUME_DSP = "STATUS_VolumeDSP"

type VolumeDSP struct{}

func (p *VolumeDSP) GetDevices(room accessors.Room) ([]accessors.Device, error) {

	return room.Devices, nil
}

func (p *VolumeDSP) GenerateCommands(devices []accessors.Device) ([]StatusCommand, error) {

	var audioDevices, mics, dsp []accessors.Device

	for _, device := range devices {

		log.Printf("Considering device: %s", device.GetFullName())

		if device.HasRole("Microphone") {

			log.Printf("Appending %s to mic array...", device.Name)
			mics = append(mics, device)
		} else if device.HasRole("DSP") {

			log.Printf("Appending %s to DSP array...", device.Name)
			dsp = append(dsp, device)
		} else if device.HasRole("AudioOut") {

			log.Printf("Appending %s to audio devices array...", device.Name)
			audioDevices = append(audioDevices, device)
		} else {
			continue
		}
	}

	commands, err := generateStandardStatusCommand(audioDevices, VOLUME_DSP, VolumeDefaultCommandName)
	if err != nil {
		errorMessage := "Could not generate " + STATUS_VOLUME_DSP + "commands for audio devices: " + err.Error()
		log.Printf(errorMessage)
		return []StatusCommand{}, errors.New(errorMessage)
	}

	micCommands, err := generateMicStatusCommands(mics, VOLUME_DSP, STATUS_VOLUME_DSP)
	if err != nil {
		errorMessage := "Could not generate " + STATUS_VOLUME_DSP + "commands for microphones: " + err.Error()
		log.Printf(errorMessage)
		return []StatusCommand{}, errors.New(errorMessage)
	}

	commands = append(commands, micCommands...)

	dspCommands, err := generateDSPStatusCommands(dsp, VOLUME_DSP, STATUS_VOLUME_DSP)
	if err != nil {
		errorMessage := "Could not generate " + STATUS_VOLUME_DSP + "commands for DSP: " + err.Error()
		log.Printf(errorMessage)
		return []StatusCommand{}, errors.New(errorMessage)
	}

	commands = append(commands, dspCommands...)

	return commands, nil
}

func (p *VolumeDSP) EvaluateResponse(label string, value interface{}, source accessors.Device, destination DestinationDevice) (string, interface{}, error) {

	if destination.Device.HasRole("Microphone") {
		log.Printf("Evaluating response pertaining to microphone: %s", destination.Device.Name)
	}
	return label, value, nil
}
<commit_msg>It's not the Jedi way<commit_after>package status

import (
	"errors"
	"log"

	"github.com/byuoitav/configuration-database-microservice/accessors"
)

const VOLUME_DSP = "STATUS_VolumeDSP"
const STATUS_VOLUME_DSP = "STATUS_VolumeDSP"

type VolumeDSP struct{}

func (p *VolumeDSP) GetDevices(room accessors.Room) ([]accessors.Device, error) {

	return room.Devices, nil
}

func (p *VolumeDSP) GenerateCommands(devices []accessors.Device) ([]StatusCommand, error) {

	var audioDevices, mics, dsp []accessors.Device

	for _, device := range devices {

		log.Printf("Considering device: %s", device.GetFullName())

		if device.HasRole("Microphone") {

			log.Printf("Appending %s to mic array...", device.Name)
			mics = append(mics, device)
		} else if device.HasRole("DSP") {

			log.Printf("Appending %s to DSP array...", device.Name)
			dsp = append(dsp, device)
		} else if device.HasRole("AudioOut") {

			log.Printf("Appending %s to audio devices array...", device.Name)
			audioDevices = append(audioDevices, device)
		} else {
			continue
		}
	}

	commands, err := generateStandardStatusCommand(audioDevices, VOLUME_DSP, VolumeDefaultCommandName)
	if err != nil {
		errorMessage := "Could not generate " + STATUS_VOLUME_DSP + "commands for audio devices: " + err.Error()
		log.Printf(errorMessage)
		return []StatusCommand{}, errors.New(errorMessage)
	}

	micCommands, err := generateMicStatusCommands(mics, VOLUME_DSP, STATUS_VOLUME_DSP)
	if err != nil {
		errorMessage := "Could not generate " + STATUS_VOLUME_DSP + "commands for microphones: " + err.Error()
		log.Printf(errorMessage)
		return []StatusCommand{}, errors.New(errorMessage)
	}

	commands = append(commands, micCommands...)

	dspCommands, err := generateDSPStatusCommands(dsp, VOLUME_DSP, STATUS_VOLUME_DSP)
	if err != nil {
		errorMessage := "Could not generate " + STATUS_VOLUME_DSP + "commands for DSP: " + err.Error()
		log.Printf(errorMessage)
		return []StatusCommand{}, errors.New(errorMessage)
	}

	commands = append(commands, dspCommands...)

	return commands, nil
}

func (p *VolumeDSP) EvaluateResponse(label string, value interface{}, source accessors.Device, destination DestinationDevice) (string, interface{}, error) {

	const SCALE_FACTOR = 3
	const MINIMUM = 45
	if destination.Device.HasRole("Microphone") {

		intValue, ok := value.(int)
		if ok {

			return label, (intValue - MINIMUM) * SCALE_FACTOR, nil

		}
	}
	return label, value, nil
}

{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.0006253908692933083, 'mean_word_length': 4.887116564417178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1418023', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1612, 'n_words': 380}