Skip to content

Commit

Permalink
format NaN to zero
Browse files Browse the repository at this point in the history
format NaN value of ptime column to zero, and fix sum of dataframe
  • Loading branch information
amsbr committed Sep 11, 2019
1 parent b82f6e8 commit 5269183
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions octoprint_stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,25 @@ def calcKwh(self, x, total):

return calc

def formatNum(self, x):
try:
if x == "NaN":
return 0
else:
return float(x)
except Exception:
return 0

def filterEvent(self, event, group, filterp = 'current_year'):
search = Query()

search_data = (search.event_type == event)
event_data = self.statDB.getData(self.statDB.query(search_data, 'events'))
event_df = pd.DataFrame(event_data)

if (event == "PRINT_DONE") or (event == "PRINT_CANCELLED") or (event == "PRINT_FAILED"):
event_df['ptime'] = event_df['ptime'].apply(self.formatNum)

if(event_data != []):
event_df["event_y"] = event_df["event_time"].apply(self.parseYear)
event_df["event_ym"] = event_df["event_time"].apply(self.parseYearMonth)
Expand Down

0 comments on commit 5269183

Please sign in to comment.