Fixed issue #16

replace/626be97e54acaf83e7d63522929f477c22a6fc81
Meng Li 2019-12-03 10:46:03 -05:00
parent fd753d87c1
commit dbe2e236a9
1 changed files with 5 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import plotly.graph_objects as go
def getBatteryConsumptionRatesBarChart(battery_data, pid): def getBatteryConsumptionRatesBarChart(battery_data, pid):
plot = go.Figure(go.Bar( plot = go.Figure(go.Bar(
x=battery_data["battery_daily_avgconsumptionrate"], x=battery_data["battery_daily_avgconsumptionrate"],
y=battery_data["local_date"].apply(lambda x: x.replace("-","/")).tolist(), y=battery_data["local_date"].apply(lambda x: x.strftime("%Y/%m/%d")).tolist(),
orientation='h')) orientation='h'))
plot.update_layout(title="Daily battery consumption rates bar chart for " + pid, plot.update_layout(title="Daily battery consumption rates bar chart for " + pid,
xaxis_title="battery drains % per hour", xaxis_title="battery drains % per hour",
@ -15,12 +15,14 @@ def getBatteryConsumptionRatesBarChart(battery_data, pid):
battery_data = pd.read_csv(snakemake.input[0]) battery_data = pd.read_csv(snakemake.input[0], parse_dates=["local_date"])
pid = snakemake.params["pid"] pid = snakemake.params["pid"]
if battery_data.empty: if battery_data.empty:
empty_html = open(snakemake.output[0], "w") empty_html = open(snakemake.output[0], "w")
empty_html.write("There is no battery data for " + pid) empty_html.write("There is no battery data for " + pid)
empty_html.close() empty_html.close()
else: else:
battery_data.set_index(["local_date"], inplace=True)
battery_data = battery_data.resample("1D").asfreq().fillna(0).reset_index()
plot = getBatteryConsumptionRatesBarChart(battery_data, pid) plot = getBatteryConsumptionRatesBarChart(battery_data, pid)
pio.write_html(plot, file=snakemake.output[0], auto_open=False) pio.write_html(plot, file=snakemake.output[0], auto_open=False)