From ae2e7eb3d7bd702534471dfacf657e33abea8c43 Mon Sep 17 00:00:00 2001
From: Pradyumna Kaushik <pkaushi1@binghamton.edu>
Date: Sat, 28 Jan 2017 21:09:43 -0500
Subject: [PATCH] Added function to determine the watts value to consider for
 each task, depending on weather -classMapWatts was enabled and also weather
 the workload contained a map of power-class to the watts requirement.

---
 schedulers/helpers.go | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/schedulers/helpers.go b/schedulers/helpers.go
index 6d90c6c..1891808 100644
--- a/schedulers/helpers.go
+++ b/schedulers/helpers.go
@@ -3,6 +3,9 @@ package schedulers
 import (
 	"fmt"
 	"log"
+	"bitbucket.org/sunybingcloud/electron/def"
+	mesos "github.com/mesos/mesos-go/mesosproto"
+	"bitbucket.org/sunybingcloud/electron/utilities/offerUtils"
 )
 
 func coLocated(tasks map[string]bool) {
@@ -13,3 +16,22 @@ func coLocated(tasks map[string]bool) {
 
 	fmt.Println("---------------------")
 }
+
+/*
+ Determine the watts value to consider for each task.
+
+ This value could either be task.Watts or task.ClassToWatts[<power class>]
+ If task.ClassToWatts is not present, then return task.Watts (this would be for workloads which don't have classMapWatts)
+*/
+func wattsToConsider(task def.Task, classMapWatts bool, offer *mesos.Offer) float64 {
+	if classMapWatts {
+		// checking if ClassToWatts was present in the workload.
+		if task.ClassToWatts != nil {
+			return task.ClassToWatts[offerUtils.PowerClass(offer)]
+		} else {
+			return task.Watts
+		}
+	} else {
+		return task.Watts
+	}
+}