<commit_before>package commandevaluators

import (
	"fmt"
	"log"

	"github.com/byuoitav/av-api/base"
	"github.com/byuoitav/av-api/dbo"

	ei "github.com/byuoitav/event-router-microservice/eventinfrastructure"
)

type SetVolumeDSP struct{}

func (p *SetVolumeDSP) Evaluate(room base.PublicRoom) ([]base.ActionStructure, error) {

	log.Printf("Evaluating commands in a DSP context...")

	var actions []base.ActionStructure

	eventInfo := ei.EventInfo{
		Type:         ei.CORESTATE,
		EventCause:   ei.USERINPUT,
		EventInfoKey: "volume",
	}

	if room.Volume != nil {

		log.Printf("General volume request detected.")
		actions, err := EvaluateGeneral(eventInfo, room)
		if err != nil {
			return actions, err
		}
	}

	if len(room.AudioDevices) != 0 {

		log.Printf("Device-specific request detected.")
		specializedActions, err := EvaluateSpecific(eventInfo, room)
		if err != nil {
			return specializedActions, err
		}

		actions = append(actions, specializedActions...)

	}

	return actions, nil
}

func (p *SetVolumeDSP) Validate(action base.ActionStructure) (err error) {
	return
}

func (p *SetVolumeDSP) GetIncompatibleCommands() (incompatibleActions []string) {
	return []string{}
}

func EvaluateGeneral(eventInfo ei.EventInfo, room base.PublicRoom) ([]base.ActionStructure, error) {

	log.Printf("Builing action structrures for entire room...")

	var actions []base.ActionStructure
	devices, err := dbo.GetDevicesByBuildingAndRoomAndRole(room.Building, room.Room, "AudioOut")
	if err != nil {
		return []base.ActionStructure{}, err
	}
<commit_msg>done with set volume dsp<commit_after>package commandevaluators

import (
	"errors"
	"fmt"
	"log"
	"strconv"

	"github.com/byuoitav/av-api/base"
	"github.com/byuoitav/av-api/dbo"

	ei "github.com/byuoitav/event-router-microservice/eventinfrastructure"
)

type SetVolumeDSP struct{}

func (p *SetVolumeDSP) Evaluate(room base.PublicRoom) ([]base.ActionStructure, error) {

	log.Printf("Evaluating commands in a DSP context...")

	var actions []base.ActionStructure

	eventInfo := ei.EventInfo{
		Type:         ei.CORESTATE,
		EventCause:   ei.USERINPUT,
		EventInfoKey: "volume",
	}

	if room.Volume != nil {

		log.Printf("General volume request detected.")
		actions, err := EvaluateGeneral(eventInfo, room)
		if err != nil {
			return actions, err
		}
	}

	if len(room.AudioDevices) != 0 {

		log.Printf("Device-specific request detected.")
		specializedActions, err := EvaluateSpecific(eventInfo, room)
		if err != nil {
			return specializedActions, err
		}

		actions = append(actions, specializedActions...)

	}

	log.Printf("%v actions generated.", len(actions))
	log.Printf("Evaluation complete.")

	return actions, nil
}

func (p *SetVolumeDSP) Validate(action base.ActionStructure) (err error) {
	maximum := 100
	minimum := 0

	level, err := strconv.Atoi(action.Parameters["level"])
	if err != nil {
		return err
	}

	if level > maximum || level < minimum {
		log.Printf("ERROR. %v is an invalid volume level for %s", action.Parameters["level"], action.Device.Name)
		return errors.New(action.Action + " is an invalid command for " + action.Device.Name)
	}

	return
}

func (p *SetVolumeDSP) GetIncompatibleCommands() (incompatibleActions []string) {
	return nil
}

func EvaluateGeneral(eventInfo ei.EventInfo, room base.PublicRoom) ([]base.ActionStructure, error) {

	log.Printf("Builing action structrures for entire room...")

	var actions []base.ActionStructure
	devices, err := dbo.GetDevicesByBuildingAndRoomAndRole(room.Building, room.Room, "AudioOut")
	if err != nil {
		return []base.ActionStructure{}, err
	}

{'fraction_non_alphanumeric': 0.12950041864359477, 'fraction_numerical': 0.0016745743790120011, 'mean_word_length': 4.430303030303031, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '7372769', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1169, 'n_words': 284}