Permalink
Browse files

adding rankings…

adding rankings, make some formatting changes, improved calculations,
cleaned up code and added comments
  • Loading branch information...
chriscasey committed Apr 18, 2012
1 parent 6baa0ec commit 6839b43ddd9d9f27fc8324499b13bc9d43754038
@@ -0,0 +1,61 @@
+from GChartWrapper import *
+from collections import Counter
+
+def generateHdLineChart(computers):
+
+ # smallHd = Computer.objects.filter(school=school, hd_size='60').count()
+ # mediumHd = Computer.objects.filter(school=school, hd_size='128').count()
+ # largeHd = Computer.objects.filter(school=school, hd_size='250').count()
+ smallHd = 1
+ mediumHd = 1
+ largeHd = 1
+
+ hds = Counter()
+ for computer in computers:
+ hds[computer.hd_size] += 1
+
+
+ hdDataset = [smallHd, mediumHd, largeHd]
+ hdChart = Pie3D( hdDataset )
+ hdChart.label('60 GB','128 GB','250GB')
+ hdChart.color('4d89f9','c6d9fd')
+ hdChart.size(300,100)
+
+ return hdChart
+
+def generateOsPieChart(computers):
+
+ osxCount = 0
+ linuxCount = 0
+ windowsCount = 0
+ for computer in computers:
+ if computer.os == 'OSX':
+ osxCount += 1
+ elif computer.os == 'LINUX':
+ linuxCount += 1
+ elif computer.os == 'WINDOWS':
+ windowsCount +=1
+
+ osDataset = []
+ osDataLabels = []
+ if osxCount > 0:
+ osDataset.append(osxCount)
+ osDataLabels.append("OS X")
+ if linuxCount > 0:
+ osDataset.append(linuxCount)
+ osDataLabels.append("LINUX")
+
+ if windowsCount > 0:
+ osDataset.append(windowsCount)
+ osDataLabels.append("WINDOWS")
+
+ labels = "\""
+ labels += "\",\"".join(osDataLabels)
+ labels += "\""
+
+ osChart = Pie3D( osDataset )
+ osChart.label(labels)
+ osChart.color('4d89f9','c6d9fd')
+ osChart.size(300,100)
+
+ return osxCount, linuxCount, windowsCount, osChart
@@ -0,0 +1,28 @@
+
+
+def findStudentToComputerRanking(thisSchool, studentsPerComputerRatioList):
+ rank = 1
+ for school in studentsPerComputerRatioList:
+ if school[0].id == thisSchool.id:
+ return rank
+ rank += 1
+ return rank
+
+
+def findTeacherToComputerRanking(thisSchool, teachersPerComputerRatioList):
+ rank = 1
+ for school in teachersPerComputerRatioList:
+ if school[0].id == thisSchool.id:
+ return rank
+ rank += 1
+ return rank
+
+
+def findComputerCountRanking(thisSchool, computersPerSchoolCountList):
+ rank = 1
+ for school in computersPerSchoolCountList:
+ if school[0].id == thisSchool.id:
+ return rank
+ rank += 1
+ return rank
+
@@ -1,4 +1,4 @@
-from GChartWrapper import *
+
def computeDistrictRatios(schools, computers):
@@ -20,43 +20,12 @@ def computeDistrictRatios(schools, computers):
teachersPerComputerRatioList.append((school, teachersPerComputerRatio))
###sort all of the lists before returning them
- studentsPerComputerRatioList = sorted(studentsPerComputerRatioList, key=lambda ratio: ratio[1])[:5]
- computersPerSchoolCountList = sorted(computersPerSchoolCountList, key=lambda ratio: ratio[1])[:5]
- teachersPerComputerRatioList = sorted(teachersPerComputerRatioList, key=lambda ratio: ratio[1])[:5]
-
- return studentsPerComputerRatioList, teachersPerComputerRatioList, computersPerSchoolCountList
-
-
-
-def computeSchoolRatios(scomputers):
- return 1
-
+ studentsPerComputerRatioList = sorted(studentsPerComputerRatioList, key=lambda ratio: ratio[1])
+ computersPerSchoolCountList = sorted(computersPerSchoolCountList, key=lambda ratio: ratio[1])
+ teachersPerComputerRatioList = sorted(teachersPerComputerRatioList, key=lambda ratio: ratio[1])
+ return studentsPerComputerRatioList, teachersPerComputerRatioList, computersPerSchoolCountList
-def generateOsPieChart(osxCount, linuxCount, windowsCount):
-
- osDataset = []
- osDataLabels = []
- if osxCount > 0:
- osDataset.append(osxCount)
- osDataLabels.append("OS X")
- if linuxCount > 0:
- osDataset.append(linuxCount)
- osDataLabels.append("LINUX")
-
- if windowsCount > 0:
- osDataset.append(windowsCount)
- osDataLabels.append("WINDOWS")
-
- labels = "\""
- labels += "\",\"".join(osDataLabels)
- labels += "\""
- print labels
- osChart = Pie3D( osDataset )
- osChart.label(labels)
- osChart.color('4d89f9','c6d9fd')
- osChart.size(300,100)
-
- return osChart
+
@@ -10,6 +10,14 @@ body.no-user-base {
text-align: center;
}
+.center {
+ margin-left:10%;
+ margin-right:auto;
+ width:80%;
+}
+.right {
+ float: right;
+}
input.btn[type=submit] {
margin-bottom: 1px;
@@ -33,32 +41,31 @@ div.button {
float:right;
text-align: right;
}
-#stats .row {
+.stats .row {
margin-top: 30px;
}
+.computers .row {
+ margin-top: 5px;
+ margin-bottom: 20px;
+}
-#stats img.chart {
+.stats img.chart {
margin: 20px 0 20px 0;
display: block;
text-align: center;
}
-#stats .stat h4 {
+.stats .stat h4 {
border-bottom: 1px solid #F0F1F2;
margin: 0 0 10px;
padding: 0 0 5px;
text-align: center;
}
-#stats .stat .statValue {
+.stats .stat .statValue {
background: #F0F1F2;
display: block;
font-size: 60px;
line-height: 120px;
text-align: center;
}
-.center {
- margin-left:10%;
- margin-right:auto;
- width:80%;
-}
@@ -7,27 +7,28 @@
{% block content %}
-<div>
- <div class="row">
- <div class="span6">
- <h1>{{ userDistrict.full_name }}</h1>
- <h3>{{ userDistrict.city }}, {{ userDistrict.state }}</h3>
- </div>
- <div class="span6">
- <p>
- Navigate to a school:&nbsp;&nbsp;&nbsp;
- <a name="schoolNavigator" id="schoolNavigator" class="btn btn-info btn-mini" href="/schools/">Go</a>
- </p>
- <select name="schoolSelect" id="schoolSelect">
- {% for school in schools %}
- <option value="{{school.id}}" selected="selected">{{school.full_name}}</option>
- {% endfor %}
- </select>
- </div>
- </div>
-</div>
+<!-- top row -->
+<div class="row">
+ <div class="span6">
+ <h2>{{ userDistrict.full_name }}</h2>
+ <h3>{{ userDistrict.city }}, {{ userDistrict.state }}</h3>
+ </div>
+ <div class="span6">
+ <div class="right">
+ Navigate to a school:&nbsp;&nbsp;&nbsp;
+ <a name="schoolNavigator" id="schoolNavigator" class="btn btn-info btn-mini" href="/schools/">Go</a>
+ <br><br>
+ <select name="schoolSelect" id="schoolSelect" class="right">
+ {% for school in schools %}
+ <option value="{{school.id}}" selected="selected">{{school.full_name}}</option>
+ {% endfor %}
+ </select>
+ </div>
+ </div>
+ </div>
-<div id="stats">
+<!-- first row of pill boxes -->
+<div class="stats">
<div class="row">
<div class="span4 stat">
<h4 class="statTitle">Number of Schools</h4>
@@ -44,7 +45,8 @@ <h4 class="statTitle">Number of Teachers</h4>
</div>
</div>
-<div id="stats">
+<!-- second row of pill boxes -->
+<div class="stats">
<div class="row">
<div class="span4 stat c">
<h4 class="statTitle">Worst Students-per-Computer Ratios</h4>
@@ -57,7 +59,8 @@ <h4 class="statTitle">School Types</h4>
</div>
</div>
-<div id="stats">
+<!-- chart row -->
+<div class="stats">
<div class="row">
<div class="span4 stat">
<h4 class="statTitle">Worst Students-per-Computer Ratios</h4>
@@ -86,6 +89,7 @@ <h4 class="statTitle">Worst Teacher-per-Computer Ratios</h4>
</div>
</div>
+<!-- js -->
<script type="text/javascript">
$(document).ready( function(){
Oops, something went wrong.

0 comments on commit 6839b43

Please sign in to comment.