Sample CSV File can be viewed here
What I have: My python code does the checking for work duration based on the Current Values.
import csv
from datetime import date,time,datetime
import pandas as pd
import matplotlib.pyplot as plt
def print_output(df):
worktime = len(df.loc[df['AC_Input_Current'] >= 4.9])
noworktime = len(df) - worktime
print ('Daily record: \n')
print ('Start: ', df.index.min(), ' - ', 'End:', df.index.max())
print ('%.2f' %(worktime/60),'[in Mins]',' or ','%.2f' %(worktime/3600),'[Hrs]',' of work')
print ('%.2f' %(noworktime/60),'[in Mins]',' or ','%.2f' %(noworktime/3600),'[Hrs]',' of no work done')
print ('Total duration recorded: ','%.2f' %((noworktime + worktime)/60),'[Mins]',' or ','%.2f' %((noworktime + worktime)/3600),'[Hrs]\n')
dateparse = lambda x: pd.datetime.strptime(x, '%d/%m/%Y %H:%M:%S')
Data = pd.read_csv('MainD2.csv', parse_dates=['Time_Stamp'], date_parser = dateparse, index_col='Time_Stamp')
Data.resample('D').apply(lambda x: print_output(x))
The results are below after running the codes: The result I have for the duration in mins is what I want to adjust a little but I'm not sure how.
For example: the first result from below starts from 2017-06-21 01:09:21
to 2017-06-21 23:15:04
What I want to get but do not know how to:
- For e.g. based on the first result; Instead of getting the 1 result from the whole timeline of the day from 01:09:21
to 23:15:04
, I need to get the results from 08:00:00
to 12:30:00
,12:31:00
to 13:12:00
,13:12:01
to 18:30:00
,19:30:00
to 23:59:59
- If there is no values from 00:00:00
to 01:09:20
, ignore them and continue getting results based on the time that is wanted ( above statement ).
Start: 2017-06-21 01:09:21 - End: 2017-06-21 23:15:04
43.75 [in Mins] or 0.73 [Hrs] of work
161.63 [in Mins] or 2.69 [Hrs] of no work done
Total duration recorded: 205.38 [Mins] or 3.42 [Hrs]
Start: 2017-06-22 00:38:54 - End: 2017-06-22 05:47:29
30.25 [in Mins] or 0.50 [Hrs] of work
271.40 [in Mins] or 4.52 [Hrs] of no work done
Total duration recorded: 301.65 [Mins] or 5.03 [Hrs]
Start: 2017-06-23 00:39:50 - End: 2017-06-23 23:10:15
44.23 [in Mins] or 0.74 [Hrs] of work
263.35 [in Mins] or 4.39 [Hrs] of no work done
Total duration recorded: 307.58 [Mins] or 5.13 [Hrs]
Start: 2017-06-24 00:38:10 - End: 2017-06-24 13:33:49
77.83 [in Mins] or 1.30 [Hrs] of work
120.00 [in Mins] or 2.00 [Hrs] of no work done
Total duration recorded: 197.83 [Mins] or 3.30 [Hrs]
Start: 2017-06-25 09:54:25 - End: 2017-06-25 20:16:05
75.62 [in Mins] or 1.26 [Hrs] of work
131.28 [in Mins] or 2.19 [Hrs] of no work done
Total duration recorded: 206.90 [Mins] or 3.45 [Hrs]
Start: 2017-06-26 00:51:32 - End: 2017-06-26 01:05:55
9.18 [in Mins] or 0.15 [Hrs] of work
4.92 [in Mins] or 0.08 [Hrs] of no work done
Total duration recorded: 14.10 [Mins] or 0.23 [Hrs]