petterreinholdtsen / battery-stats

Log battery charge (battery-stats-collector), show gnuplot graphs (battery-graph)
GNU General Public License v2.0
27 stars 13 forks source link

handle polyfit exceptions #25

Closed anarcat closed 8 months ago

anarcat commented 7 years ago

in some weird cases (e.g. my battery changed, actually), the polyfit function will freak out and give a ValueError exception:

Traceback (most recent call last):
  File "./src/battery-stats-graph", line 199, in <module>
    death = guess_expiry(data[full], data['timestamp'], zero)
  File "./src/battery-stats-graph", line 170, in guess_expiry
    fit = np.polyfit(data[full], data['timestamp'], 1)
  File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 581, in polyfit
    c, resids, rank, s = lstsq(lhs, rhs, rcond)
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 1867, in lstsq
    0, work, lwork, iwork, 0)
ValueError: On entry to DLASCL parameter number 4 had an illegal value

we shouldn't completely crash in those cases: if we fail to find a fit or the data is too much garbage, just output a warning and attempt to generate the graph anyways

anarcat commented 6 years ago

ping? any update here?

anarcat commented 1 year ago

ping?