jbrusey / cogent-house

Cogent House is a system for sensing temperature, humidity, CO2, Air Quality, VOC, hot water consumption, and electricity consumption within the home. It has been developed by the [http://cogentcomputing.org Cogent Computing Applied Research Centre] at Coventry University. Cogent House is developed using TinyOS and Python.
4 stars 2 forks source link

export fails for electricity data #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. go to export page
2. select house and date range; ask for electricity data

What is the expected output? What do you see instead?
expect it to download csv

instead see error:

Internal Server Error

The server encountered an unexpected internal server error

(generated by waitress)

From log:

2014-03-07 16:02:54,107 ERROR [waitress][Dummy-3] Exception when serving /export
Traceback (most recent call last):
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/waitress/channel.py", line 332, in service
    task.service()
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/waitress/task.py", line 173, in service
    self.execute()
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/waitress/task.py", line 388, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/paste/deploy/config.py", line 291, in __call__
    return self.app(environ, start_response)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid/router.py", line 187, in __call__
    response = self.handle_request(request)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid/tweens.py", line 20, in excview_tween
    response = handler(request)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid_tm/__init__.py", line 82, in tm_tween
    reraise(*exc_info)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid_tm/__init__.py", line 63, in tm_tween
    response = handler(request)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid/router.py", line 164, in handle_request
    response = view_callable(context, request)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid/config/views.py", line 227, in _secured_view
    return view(context, request)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid/config/views.py", line 333, in rendered_view
    result = view(context, request)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pyramid/config/views.py", line 471, in _requestonly_view
    response = view(request)
  File "/home/dang/viewer-repo/salford/cogentviewer/views/export.py", line 158, in exportdata
    interpolate = interpolate,
  File "/home/dang/viewer-repo/salford/cogentviewer/views/export.py", line 253, in processExport
    df = calculateCurrent(df,aggregate)
  File "/home/dang/viewer-repo/salford/cogentviewer/views/export.py", line 442, in calculateCurrent
    elec["kWh"]  = elec.apply(currentFunc,axis=1)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pandas/core/frame.py", line 4416, in apply
    return self._apply_standard(f, axis)
  File "/home/dang/viewer-repo/salford-env/lib/python2.6/site-packages/pandas/core/frame.py", line 4491, in _apply_standard
    raise e
ZeroDivisionError: ('float division', u'occurred at index 19740')

From a brief look at the code, it looks like it is code meant for the Optismart 
sensor (which gives pulse output in terms of kWh) but is being used for 
CurrentCost data, which is in terms of watts and the delta is meaningless.

Original issue reported on code.google.com by james.br...@gmail.com on 9 Mar 2014 at 2:21

GoogleCodeExporter commented 9 years ago
Scratch my last comment. 

Line 475 of export.py says 
  return hours / kW

however we actually want "kWh" which means kW * hours. 

Presumably at some point for this house there was a five minute period with 
zero electricity use.

Original comment by james.br...@gmail.com on 9 Mar 2014 at 10:22

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Changed code to multiply kW * Hours
This should fix the export issue.

Original comment by DjGoldsm...@googlemail.com on 12 Mar 2014 at 3:23

GoogleCodeExporter commented 9 years ago
end user reports that they are getting a value of 6.5kWh for a 5 minute period. 
Possibly the calculation is still incorrect?

Original comment by james.br...@gmail.com on 12 Mar 2014 at 4:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
21/11/2013 09:55, house name 69 L road, Node: ('Node 49221: Utility Room Power 
(kWh)', u'mean')

Original comment by james.br...@gmail.com on 12 Mar 2014 at 4:27

GoogleCodeExporter commented 9 years ago

I think that the electricity data is still in kW. I loked at the data and found 
an example fairly early on, i'm sure there's more, a reading of 6.5 kWh 
recorded in a 5 minute period. In order to 6.5 kwh used in 5 minutes, the 
electricity needs to be used at a rate of 78kW. This is impossibly high for a 
domestic house, the domestic grid dosen't go this high.

The particular reading is at 21/11/2013 09:55, house name 69 longford road, 
Node: ('Node 49221: Utility Room Power (kWh)', u'mean')

Looking at the data, it looks like it’s displaying in kW (although the column 
is labelled kWh); that’s ok, I’m familiar with working in both kW and kWh. 
If the node is producing kW, let’s work in kW; changing to kWh can be done 
but it’s easy to get it wrong. Depending on the format of the data, it’s 
not a case of simply multiplying by ‘hours’. I’m happy with it remaining 
as kW. 

Original comment by B.i.robe...@salford.ac.uk on 12 Mar 2014 at 4:40

GoogleCodeExporter commented 9 years ago
a quick test on the original data proves that this is now working correctly 
(0.0856 kWh for 21/11/13 9:57 at 69L)

Original comment by james.br...@gmail.com on 28 Mar 2014 at 9:35

GoogleCodeExporter commented 9 years ago

Original comment by james.br...@gmail.com on 28 Mar 2014 at 9:36