Agile_Data_Code
Agile_Data_Code copied to clipboard
ch08/web/index.py
For some weird reason, I'm not able to get thru in the web page to click and show the page with the chart showing the probabilities. Am getting error IndexError: Out of bound when the function self.smoothed[idx] is being evaluated. I'm dumping the screen of WSGI when it happen along with the variable and line of suspect. Please advise. Thanks.
I got throuh the same error.
I guess It is the smooth rendering function which render a 15-long array, instead of a 24-one. We sohuld check somewhere that if there is no value we put a default one on the array.
self.raw_data = [ [{u'total': 1L, u'sent_hour': u'06'}, {u'total': 1L, u'sent_hour': u'08'}, {u'total': 1L, u'sent_hour': u'09'}, {u'total': 8L, u'sent_hour': u'10'}, {u'total': 6L, u'sent_hour': u'11'}, {u'total': 4L, u'sent_hour': u'13'}, {u'total': 6L, u'sent_hour': u'14'}, {u'total': 1L, u'sent_hour': u'15'}, {u'total': 6L, u'sent_hour': u'16'}, {u'total': 6L, u'sent_hour': u'17'}, {u'total': 2L, u'sent_hour': u'19'}, {u'total': 10L, u'sent_hour': u'20'}, {u'total': 1L, u'sent_hour': u'21'}, {u'total': 2L, u'sent_hour': u'22'}, {u'total': 1L, u'sent_hour': u'23'}] ]
self.data = [ [ 1 1 1 8 6 4 6 1 6 6 2 10 1 2 1] ]
x = [ 1 1 1 8 6 4 6 1 6 6 2 10 1 2 1]
s = [-2 -4 -6 1 1 1 1 8 6 4 6 1 6 6 2 10 1 2 1 1 0 1 -8]
w = [ 0.08 0.54 1. 0.54 0.08]
y = [-2.07142857 -3.67857143 -3.4375 -0.86607143 0.75 1.25
2.86607143 5.4375 5.82142857 5. 4.3125 3.69642857
4.65178571 5. 5. 5.47321429 3.44642857 1.76785714
1.20535714 0.79464286 0.23214286 -1.44642857 -3.33035714]
self.smoothed = [ 0.75 1.25 2.86607143 5.4375 5.82142857 5. 4.3125
3.69642857 4.65178571 5. 5. 5.47321429 3.44642857
1.76785714 1.20535714]
hours = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23']
idx = 0
val = 00
idx = 1
val = 01
idx = 2
val = 02
idx = 3
val = 03
idx = 4
val = 04
idx = 5
val = 05
idx = 6
val = 06
idx = 7
val = 07
idx = 8
val = 08
idx = 9
val = 09
idx = 10
val = 10
idx = 11
val = 11
idx = 12
val = 12
idx = 13
val = 13
idx = 14
val = 14
idx = 15
val = 15
127.0.0.1 - - [07/Nov/2014 22:35:02] "GET /email/CAGHwgF7fnbysJQp9q+L6pRwNALHT- [email protected] HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Users/romainjouin/Documents/pcm/venv/lib/python2.7/site-packages/flask/app. py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/romainjouin/Documents/pcm/venv/lib/python2.7/site-packages/flask/app. py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/romainjouin/Documents/pcm/venv/lib/python2.7/site-packages/flask/app. py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/romainjouin/Documents/pcm/venv/lib/python2.7/site-packages/flask/app. py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/romainjouin/Documents/pcm/venv/lib/python2.7/site-packages/flask/app. py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/romainjouin/Documents/pcm/venv/lib/python2.7/site-packages/flask/app. py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/romainjouin/Documents/pcm/Agile_Data_code/ch08/web/index.py", line 37, in email
smoothed_dist = get_smoothed_sent_dist(email['from']['address'])
File "/Users/romainjouin/Documents/pcm/Agile_Data_code/ch08/web/index.py", line 29, in get_smoothed_sent_dist
smoothed_dist = smitty.to_objects()
File "/Users/romainjouin/Documents/pcm/Agile_Data_code/ch08/web/smoother.py", line 41, in to_objects
objects.append({"sent_hour": val, "total": round(self.smoothed[idx], 0)})
IndexError: index 15 is out of bounds for axis 0 with size 15
changing the to_array function made the trick : we begin with a 24 zero-valuated numpy array, and we put the founds totals in the correct hours :
def to_array(self, in_data, data_key):
data_array = np.zeros(24)
for datum in in_data:
total = datum[data_key]
sent_hour = int(datum["sent_hour"])
data_array[sent_hour] = total
return data_array