<br><br><div class="gmail_quote">On Fri, Jun 1, 2012 at 9:12 AM, Adam <span dir="ltr">&lt;<a href="mailto:amgaweda@gmail.com" target="_blank">amgaweda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m working on a class that handles multiple rooms that generate a large amount of data. Currently my class model looks something like this (more apologies for any indentation errors):<br>
Class Model:<br>
    rooms= {}<br>
    for z in range(num_of_zones):<br>
        for i in range(24):<br>
            tmp[i] = { VAR:0, SD:0, AVG:0, READINGS:[] }<br>
            tmp[i][&#39;updated&#39;] = datetime.utcnow()<br>
                for j in OT_RANGE:<br>
                    tmp[i][j] = { VAR:0, SD:0, AVG:0, READINGS:[] }<br>
        rooms[z] = tmp<br>
<br>
In case that gets complicated, I&#39;m looking to store readings based off the current hour and current outside temperature. The Model class has other variables and functions that it uses to compare and manipulate the data as it comes in.<br>

<br>
My question is in regards to the storing all this data in a dictionary, which makes it easy to reference self.rooms[z][12][85][AVG]; however is this better/worse or the same as creating a &#39;Room&#39; class to store the data? Since a &#39;Room&#39; only contains a large amount of data, but doesn&#39;t contain any functions, which form of storing the data is considered &#39;better&#39;?<br>

<br>
Thank you,<br>
Adam<br>
______________________________<u></u>_________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/tutor</a><br>
</blockquote></div><br><div>If you have functions (or in this case methods) which will be used on a certain &#39;objects&#39; data structure, a class representation of the data is the natural fit. Otherwise, you will need to pass the dictionary around to various functions and this will be seriously confusing.</div>
<div><br></div><div>However, you probably should consider how to represent that data within a class body, that is, it is extremely confusing to access data such as self.rooms[z][12][85][AVG].</div><div><br></div><div>Instead, you should break down what the data structure into like-things and how they are related, for example, you might consider something like this:</div>
<div><br></div><div>class Weather(object):</div><div>    def __init__(self, temp, precipitation, humidity, bara_pres):</div><div>        self. temp = temp</div><div>        self. temp = precipitation</div><div>        self. temp = humidity</div>
<div>        self. temp = bara_pres</div><div>    def my_func(self, *args,**kwargs):</div><div>        pass #do stuff here<br></div><div><br></div><div>However, if you need to either further define the datapoints of if you want the datapoints to be able to &quot;do things&quot; then you could do something like this:</div>
<div><br></div><div>class Temperature(object):</div><div><div>    def __init__(self, temp):</div><div>        self. temp = temp</div></div><div>        self.other_stuff_about_temp = stuff</div><div><br></div><div><div>    def my_temp_func(self, *args,**kwargs):</div>
<div>        pass #do stuff here</div></div><div><br></div><div><br></div><div><div>class Weather(object):</div><div>    def __init__(self, temp, precipitation, humidity, bara_pres):</div><div>        self. temp = 
Temperature(temp)</div><div>        self.precipitation = precipitation</div><div>        self.humidity = humidity</div><div>        self.bara_pres = bara_pres</div><div>    def my_func(self, *args,**kwargs):</div><div>        pass #do stuff here</div>
</div><div><br></div><div>from here you could either put your instantiated objects into a list and do math on the elements thereof, or you could put them into another class object like this:</div><div><br></div><div>class WeatherOverTime(object):</div>
<div><div>    def __init__(self, my_list):</div><div>        self.my_list =  my_list</div></div><div><br></div><div>    def avg(self, attr): #attr is the attribute you want to take an average of, so humidity, temp, whatever.</div>
<div>        temp_list = map(lambda x: getattr(x, attr), my_list)</div><div>        return sum(temp_list) / count(temp_list)</div><div>        </div><div><br></div>