Skip to content

Commit

Permalink
Date Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs997 committed Sep 8, 2023
1 parent 32989fb commit 1566d52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
35 changes: 27 additions & 8 deletions webdesign/polls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ def index(request):

csvtime=datetime.utcnow()
csvname='API URL'
datamindate=input_ts.index.min()
datamaxdate=input_ts.index.max()
context= {'csvname': csvname}
context.update({'csvtype': csvtype} )
context.update({'csvtime': csvtime} )
context.update( {'csvdata':input_ts.reset_index().to_dict('records')})
context.update({'datamindate': input_ts.index.min()} )
context.update({'datamaxdate': input_ts.index.max()} )

context.update({'datamindate': datamindate} )
context.update({'datamaxdate': datamaxdate} )
headers=[]
for col in input_ts.reset_index().columns:
headers.append({'column': col})
Expand Down Expand Up @@ -110,9 +111,15 @@ def index(request):
context.update({'csvtype': csvtype} )
context.update({'csvtime': csvtime} )
context.update( {'csvdata':input_ts.reset_index().to_dict('records')})
context.update({'datamindate': input_ts.index.min()} )
context.update({'datamaxdate': input_ts.index.max()} )

if 'Multitime' in csvtype:
datamindate=input_ts.index.min()
datamaxdate=input_ts.index.max()
elif 'Singletime' in csvtype:
datamindate=input_ts['date'].min()
datamaxdate=input_ts['date'].max()

context.update({'datamindate': datamindate} )
context.update({'datamaxdate': datamaxdate} )
headers=[]
for col in input_ts.reset_index().columns:
headers.append({'column': col})
Expand All @@ -131,13 +138,17 @@ def index(request):
if not input_ts.empty:
formdata = {}
# formdata['csvfrequency'] = freq

methods=request.POST.getlist('datapreprocess')
smoothing_window = request.POST.get('smoothingwindow')
cat_method=request.POST.getlist('categorizetype')
num_bins = request.POST.get('binsize')
win_size = request.POST.get('trendsize')
fill_method=request.POST.getlist('fillmethod')
datamindate=request.POST.getlist('min_date')
datamaxdate=request.POST.getlist('max_date')

datamindate = datetime.strptime(datamindate[0], '%Y-%m-%d')
datamaxdate = datetime.strptime(datamaxdate[0], '%Y-%m-%d')

if(not smoothing_window):
smoothing_window = 7
Expand Down Expand Up @@ -178,6 +189,7 @@ def index(request):
headers=[]
if(csvtype=='Singletime'):
workflow_type='single'
input_ts = input_ts.loc[(input_ts['date'] >= datamindate ) & (input_ts['date'] <= datamaxdate)]
input_df = input_ts
name, cat_ts, df ,formdata = single_ts_workflow(input_df,request, fill_method, formdata, methods, freq, cat_method, workflow_type, smoothing_window, win_size, num_bins, custom_range)

Expand Down Expand Up @@ -208,6 +220,11 @@ def index(request):
elif(csvtype=='Multitime'):
workflow_type='multi-signal'
cat_df = pd.DataFrame()
if input_ts[datamindate:datamaxdate].empty:
input_ts=input_ts[datamaxdate:datamindate]
else:
input_ts=input_ts[datamindate:datamaxdate]

for column in input_ts.columns:
signal_ts = input_ts[[column]]
signal_ts.columns = ['value']
Expand Down Expand Up @@ -250,7 +267,9 @@ def index(request):
fig = px.line(input_ts.reset_index(), x='date', y=input_ts.columns.to_list())
graph_plotly = plot(fig, output_type="div")
# context.update( {'graph_plotly':graph_plotly})


context.update({'datamindate': datamindate} )
context.update({'datamaxdate': datamaxdate} )
context.update( {'formdata': json.dumps(formdata)} )

else:
Expand Down
4 changes: 2 additions & 2 deletions webdesign/templates/includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ <h4>PEpiTA</h4>
<label>Date Filter:</label>
<ul>
<li style="list-style-type: none;"> <label for="min_date">Min Date:</label>
<input type="date" id="min_date" name="min_date" value="" style="font-size:13px;width:57%;height:20px">
<input type="date" id="min_date" name="min_date" value="{{datamindate|date:'Y-m-d'}}" style="font-size:13.5px;width:55%;height:20px">
</li>
<li style="list-style-type: none;">
<label for="max_date">Max Date:</label>
<input type="date" id="max_date" name="max_date" value="" style="font-size:13px;width:57%;height:20px">
<input type="date" id="max_date" name="max_date" value="{{datamaxdate|date:'Y-m-d'}}" style="font-size:13.5px;width:55%;height:20px">

</li>
</ul>
Expand Down

0 comments on commit 1566d52

Please sign in to comment.