Add debugging in gcal renderer.
[kiosk.git] / weather_renderer.py
index 4a5663cfb612469b3890a2cb0a5be68b6a639a1d..23c5a201e6e44f254c39c112a2d6c59451231ba5 100644 (file)
@@ -246,6 +246,7 @@ function makePrecipChart(name, xValues, yValues) {
                 days_seen.add(formatted_date)
             total = len(days_seen)
 
+            first_day = True
             days_seen = set()
             for n, date in enumerate(sorted(highs.keys())):
                 if n % 3 == 0:
@@ -264,6 +265,10 @@ function makePrecipChart(name, xValues, yValues) {
                     aggregate = r + s
                     aggregate_precip += aggregate
                     precip[date].append(aggregate)
+                if first_day:
+                    while len(precip[date]) < 8:
+                        precip[date].insert(0, 0)
+                        first_day = False
 
                 day = datetime.fromtimestamp(ts[date])
                 formatted_date = day.strftime("%a %e %b")
@@ -275,26 +280,34 @@ function makePrecipChart(name, xValues, yValues) {
                 )
 
                 # Date
-                f.write(
-                    "  <tr><td colspan=3 height=50><b><center><font size=6>"
-                    + formatted_date
-                    + "</font></center></b></td></tr>\n"
-                )
+                f.write(f'''
+<tr>
+  <td colspan=3 height=50>
+    <center>
+      <font size=7><b>{formatted_date}</b></font>
+    </center>
+  </td>
+</tr>''')
 
                 # Conditions icon
-                f.write(
-                    '  <tr><td colspan=3 height=100><center><img src="/kiosk/images/weather/%s" height=125></center></td></tr>\n'
-                    % self.pick_icon(conditions[date], rain[date], snow[date])
-                )
+                icon = self.pick_icon(conditions[date], rain[date], snow[date])
+                f.write(f'''
+<tr>
+  <td colspan=3 height=100>
+    <center>
+      <img src="/kiosk/images/weather/{icon}" height=145>
+    </center>
+  </td>
+</tr>''')
 
-                # Low temp
+                # Low temp -- left
                 color = "#000099"
                 if lows[date] <= 32.5:
                     color = "#009999"
                 f.write(f'''
 <tr>
   <td width=33% align=left>
-    <font color="{color}">
+    <font color="{color}" size=6>
       <b>{int(lows[date])}&deg;F&nbsp;&nbsp;</b>
     </font>
   </td>
@@ -306,8 +319,8 @@ function makePrecipChart(name, xValues, yValues) {
                     f.write(f'''
   <td width=33%>
     <center>
-      <font style="background-color:#dfdfff; color:#003355">
-        <b>{aggregate_precip:3.1f}"</b>
+      <font style="background-color:#dfdfff; color:#003355" size=6>
+        <b>{aggregate_precip:3.1f}&#8221;</b>
       </font>
     </center>
   </td>
@@ -321,14 +334,17 @@ function makePrecipChart(name, xValues, yValues) {
                     color = "#AA0000"
                 f.write(f'''
   <td align=right>
-    <font color="{color}">
+    <font color="{color}" size=6>
       <b>&nbsp;&nbsp;{int(highs[date])}&deg;F</b>
     </font>
   </td>
-</tr>
+</tr>''')
+
+                # Precip graph
+                f.write(f'''
 <tr>
   <td colspan=3 style="vertical-align:top;">
-    <canvas id="myChart{n}" style="width:100%;max-width:300px"></canvas>
+    <canvas id="myChart{n}" style="width:100%;max-width:400px;height:180px;"></canvas>
   </td>
 </tr>
 <script>