def predict(): form = OutputForm() from_d = request.form['from']; cname = form.clientName.data lename = form.Legal.data; #attribute_value = request.form['attribute_value']; df = model_call(str(cname),str(lename)) model = pickle.load(open('model.pkl', 'rb')) lastdate_=give_last_date(cname, lename) pred=model.forecast(6) start = from_d show_predict=np.array(df[str(datetime.datetime.strptime(str(lastdate_),'%Y%m%d').date())]) show_predict=np.append(show_predict, pred) fig = go.Figure() fig.add_trace(go.Scatter(x = df[start:].index, y=df[start:], mode='lines', name='Recorded')) fig.add_trace(go.Scatter(x=give_dates(lastdate_), y=show_predict, mode='lines', name='Predicted',line=dict(width=4, dash='dot'))) slope = pred[-1] - df[-1] final_verdict='' if slope>0: final_verdict="Beneficial to work with this client" else : final_verdict="Not beneficial to work with this client" fig.update_layout(title_text=final_verdict) fig.update_yaxes(title_text="Paid Amount") fig.update_xaxes(title_text='Dates') pio.write_html(fig, file='templates/predict.html', auto_open=False) return render_template('predict.html')
def predict(): form = OutputForm() from_d = request.form['from'] cname = form.clientName.data lename = form.Legal.data #attribute_value = request.form['attribute_value']; plot_pred(cname, lename, from_d) return render_template('predict.html')
def home(): form = OutputForm() return render_template('index.html', form=form)
def create_edit_output(request, output_id=None): if request.method == 'POST': if output_id != None: output = OutputSubstance.objects.get(id=output_id) form = OutputForm(request.POST, instance=output) if form.is_valid(): form.save() messages.success(request, "Output updated") admin = User.objects.get(username=ADMIN_USERNAME) addMessage = InternalMessage( sender=admin, title=request.user.first_name + ' made some changes to ' + form.cleaned_data['name'] + '...', body=request.user.first_name + ' made changes to ' + form.cleaned_data['name'] + '\n\nYou should probably take a look...') addMessage.save() addMessage.recipient.add(admin) addMessage.save() else: messages.add_message(request, settings.DISALLOWED_MESSAGE, "Hold on, somethings not right there...") return render(request, 'create_edit_output.html', { 'form': form, 'output': output }) return HttpResponseRedirect('/data/output/all') else: form = OutputForm(request.POST) if form.is_valid(): new_output = form.save() messages.success(request, "Output added") admin = User.objects.get(username=ADMIN_USERNAME) addMessage = InternalMessage( sender=admin, title=request.user.first_name + ' added an Output', body=request.user.first_name + ' added an Output called ' + form.cleaned_data['name'] + '\n\nYou should look at it and add the emission factor and SimaPro ID...' ) addMessage.save() addMessage.recipient.add(admin) addMessage.save() else: messages.add_message(request, settings.DISALLOWED_MESSAGE, "Hold on, somethings not right there...") return render(request, 'create_edit_output.html', {'form': form}) return HttpResponseRedirect('/data/output/all/') else: args = {} args.update(csrf(request)) if output_id is None: form = OutputForm() else: output_instance = OutputSubstance.objects.get(id=output_id) args['output'] = output_instance form = OutputForm(instance=output_instance) args['form'] = form try: args['dismissMessage'] = Content.objects.get( name='InputsOutputsMessage') except: pass return render(request, 'create_edit_output.html', args)
def home(): form = OutputForm() return render_template('index.html', listofatt=listofatt, allClients=allClients, allLegalEntities=allLegalEntities, form = form)