Commit 44cfd9a3 by Rosa Delima Mendrofa

first commit

parents
"""
ASGI config for DjangoAPI project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoAPI.settings')
application = get_asgi_application()
"""
Django settings for DjangoAPI project.
Generated by 'django-admin startproject' using Django 3.0.3.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3xjo2(8qq_2k!zyix2*eccw5$lgs9tmsl(mol&z292p33_6_y0'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'MyAPI',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'DjangoAPI.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'DjangoAPI.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
)
}
"""DjangoAPI URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from MyAPI import views
urlpatterns = [
path('', views.home),
]
"""
WSGI config for DjangoAPI project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoAPI.settings')
application = get_wsgi_application()
from django.contrib import admin
from . models import approvals
# Register your models here.
admin.site.register(approvals)
from django.apps import AppConfig
class MyapiConfig(AppConfig):
name = 'MyAPI'
from django.forms import ModelForm
from . models import approvals
class MyForm(ModelForm):
class Meta:
model=approvals
fields = '__all__'
#exclude = 'firstname'
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Form Pengajuan Pinjaman</title>
<!-- Bootstrap core CSS -->
<link href="../../static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom fonts for this template -->
<link href="../../static/assets/vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
<link href="../../static/assets/vendor/simple-line-icons/css/simple-line-icons.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- Custom styles for this template -->
<link href="../../static/assets/css/landing-page.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-light bg-light static-top">
<div class="container">
<a class="navbar-brand" href="home.html/">Klasifikasi Peminjaman</a>
</div>
</nav>
<form class="text-center border border-light p-5" method="POST" action="/index2">
<p class="h4 mb-4">Masukkan Data Peminjam</p>
<div class="form-group row">
<label for="input1" class="col-sm-2 col-form-label">Annual Income</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input1" placeholder="Annual Inc">
</div>
</div>
<div class="form-group row">
<label for="input2" class="col-sm-2 col-form-label">Application Type</label>
<div class='col-sm-10'>
<select class="form-control" id="input2">
<option disabled>Kategori</option>
<option>Individu</option>
<option>Join</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="input3" class="col-sm-2 col-form-label">DTI</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input3" placeholder="dti">
</div>
</div>
<div class="form-group row">
<label for="input4" class="col-sm-2 col-form-label">Jangka Pinjaman</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input4" placeholder="jangka pinjaman">
</div>
</div>
<div class="form-group row">
<label for="input5" class="col-sm-2 col-form-label">Employee Length</label>
<div class='col-sm-10'>
<select class="form-control" id="input5">
<option disabled>Kategori</option>
<option>New Employee</option>
<option>Old Employee</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="input6" class="col-sm-2 col-form-label">Home Ownership</label>
<div class='col-sm-10'>
<select class="form-control" id="input6">
<option disabled>Kategori</option>
<option>Mortgage</option>
<option>Own</option>
<option>Rent</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="input7" class="col-sm-2 col-form-label">Installment</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input7" placeholder="installment">
</div>
</div>
<div class="form-group row">
<label for="input8" class="col-sm-2 col-form-label">Int Rate</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input8" placeholder="int rate">
</div>
</div>
<div class="form-group row">
<label for="input9" class="col-sm-2 col-form-label">Last Payment Amount</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input9" placeholder="last payment amount">
</div>
</div>
<div class="form-group row">
<label for="input10" class="col-sm-2 col-form-label">Loan Amount</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input10" placeholder="loan amount">
</div>
</div>
<div class="form-group row">
<label for="input11" class="col-sm-2 col-form-label">Purpose</label>
<div class='col-sm-10'>
<select class="form-control" id="input11">
<option disabled>Kategori</option>
<option>Debt Consolidation</option>
<option>Business</option>
<option>Asset</option>
<option>Medical</option>
<option>Other</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="input12" class="col-sm-2 col-form-label">Term</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input12" placeholder="term">
</div>
</div>
<div class="form-group row">
<label for="input13" class="col-sm-2 col-form-label">Year Issue Day</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input13" placeholder="year issue day">
</div>
</div>
<div class="form-group row">
<label for="input14" class="col-sm-2 col-form-label">Month Issue Day</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input14" placeholder="month issue day">
</div>
</div>
<div class="form-group row">
<label for="input15" class="col-sm-2 col-form-label">Day Of Issue Day</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input15" placeholder="day of issue day">
</div>
</div>
<div class="form-group row">
<label for="input16" class="col-sm-2 col-form-label">Loan Frequency</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input16" placeholder="loan frequency">
</div>
</div>
<div class="form-group row">
<label for="input17" class="col-sm-2 col-form-label">Loan Status</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input17" placeholder="loan status">
</div>
</div>
<div class="form-group row">
<label for="input18" class="col-sm-2 col-form-label">Predicted</label>
<div class='col-sm-10'>
<input type="text" class="form-control" id="input18" placeholder="predicted">
</div>
</div>
<button class="btn btn-info btn-lg" type="submit">Klasifikasikan</button>
</form>
<!-- Masthead -->
<!--
<header class="masthead text-white text-center">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-xl-9 mx-auto">
<h1 class="mb-5">Silahkan pilih jenis Buku Lagu yang Anda inginkan:</h1>
<div class="row">
<div class="col-12 col-md-4">
<a href="/index" class="btn btn-block btn-lg btn-primary">Buku Nyanyian HKBP</a>
</div>
<div class="col-12 col-md-4">
<a href="/index2" class="btn btn-block btn-lg btn-primary">Nyanyian Pujian</a>
</div>
<div class="col-12 col-md-4">
<a href="/index3" class="btn btn-block btn-lg btn-primary">Kidung Jemaat</a>
</div>
</div>
</div>
</div>
</div>
</div>
</header>-->
<!-- Icons Grid -->
<!-- <section class="features-icons bg-light text-center">
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3">
<div class="features-icons-icon d-flex">
<i class="icon-screen-desktop m-auto text-primary"></i>
</div>
<h3>Fully Responsive</h3>
<p class="lead mb-0">This theme will look great on any device, no matter the size!</p>
</div>
</div>
<div class="col-lg-4">
<div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3">
<div class="features-icons-icon d-flex">
<i class="icon-layers m-auto text-primary"></i>
</div>
<h3>Bootstrap 4 Ready</h3>
<p class="lead mb-0">Featuring the latest build of the new Bootstrap 4 framework!</p>
</div>
</div>
<div class="col-lg-4">
<div class="features-icons-item mx-auto mb-0 mb-lg-3">
<div class="features-icons-icon d-flex">
<i class="icon-check m-auto text-primary"></i>
</div>
<h3>Easy to Use</h3>
<p class="lead mb-0">Ready to use with your own content, or customize the source files!</p>
</div>
</div>
</div>
</div>
</section>
<!-- Image Showcases -->
<!-- <section class="showcase">
<div class="container-fluid p-0">
<div class="row no-gutters">
<div class="col-lg-6 order-lg-2 text-white showcase-img" style="background-image: url('img/bg-showcase-1.jpg');"></div>
<div class="col-lg-6 order-lg-1 my-auto showcase-text">
<h2>Fully Responsive Design</h2>
<p class="lead mb-0">When you use a theme created by Start Bootstrap, you know that the theme will look great on any device, whether it's a phone, tablet, or desktop the page will behave responsively!</p>
</div>
</div>
<div class="row no-gutters">
<div class="col-lg-6 text-white showcase-img" style="background-image: url('img/bg-showcase-2.jpg');"></div>
<div class="col-lg-6 my-auto showcase-text">
<h2>Updated For Bootstrap 4</h2>
<p class="lead mb-0">Newly improved, and full of great utility classes, Bootstrap 4 is leading the way in mobile responsive web development! All of the themes on Start Bootstrap are now using Bootstrap 4!</p>
</div>
</div>
<div class="row no-gutters">
<div class="col-lg-6 order-lg-2 text-white showcase-img" style="background-image: url('img/bg-showcase-3.jpg');"></div>
<div class="col-lg-6 order-lg-1 my-auto showcase-text">
<h2>Easy to Use &amp; Customize</h2>
<p class="lead mb-0">Landing Page is just HTML and CSS with a splash of SCSS for users who demand some deeper customization options. Out of the box, just add your content and images, and your new landing page will be ready to go!</p>
</div>
</div>
</div>
</section> -->
<!-- Testimonials -->
<!-- <section class="testimonials text-center bg-light">
<div class="container">
<h2 class="mb-5">What people are saying...</h2>
<div class="row">
<div class="col-lg-4">
<div class="testimonial-item mx-auto mb-5 mb-lg-0">
<img class="img-fluid rounded-circle mb-3" src="img/testimonials-1.jpg" alt="">
<h5>Margaret E.</h5>
<p class="font-weight-light mb-0">"This is fantastic! Thanks so much guys!"</p>
</div>
</div>
<div class="col-lg-4">
<div class="testimonial-item mx-auto mb-5 mb-lg-0">
<img class="img-fluid rounded-circle mb-3" src="img/testimonials-2.jpg" alt="">
<h5>Fred S.</h5>
<p class="font-weight-light mb-0">"Bootstrap is amazing. I've been using it to create lots of super nice landing pages."</p>
</div>
</div>
<div class="col-lg-4">
<div class="testimonial-item mx-auto mb-5 mb-lg-0">
<img class="img-fluid rounded-circle mb-3" src="img/testimonials-3.jpg" alt="">
<h5>Sarah W.</h5>
<p class="font-weight-light mb-0">"Thanks so much for making these free resources available to us!"</p>
</div>
</div>
</div>
</div>
</section> -->
<!-- Call to Action -->
<!-- <section class="call-to-action text-white text-center">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-xl-9 mx-auto">
<h2 class="mb-4">Ready to get started? Sign up now!</h2>
</div>
<div class="col-md-10 col-lg-8 col-xl-7 mx-auto">
<form>
<div class="form-row">
<div class="col-12 col-md-9 mb-2 mb-md-0">
<input type="email" class="form-control form-control-lg" placeholder="Enter your email...">
</div>
<div class="col-12 col-md-3">
<button type="submit" class="btn btn-block btn-lg btn-primary">Sign up!</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section> -->
<!-- Footer -->
<!-- <footer class="footer bg-light">
<div class="container">
<div class="row">
<div class="col-lg-6 h-100 text-center text-lg-left my-auto">
<ul class="list-inline mb-2">
<li class="list-inline-item">
<a href="#">About</a>
</li>
<li class="list-inline-item">&sdot;</li>
<li class="list-inline-item">
<a href="#">Contact</a>
</li>
<li class="list-inline-item">&sdot;</li>
<li class="list-inline-item">
<a href="#">Terms of Use</a>
</li>
<li class="list-inline-item">&sdot;</li>
<li class="list-inline-item">
<a href="#">Privacy Policy</a>
</li>
</ul>
<p class="text-muted small mb-4 mb-lg-0">&copy; Your Website 2019. All Rights Reserved.</p>
</div>
<div class="col-lg-6 h-100 text-center text-lg-right my-auto">
<ul class="list-inline mb-0">
<li class="list-inline-item mr-3">
<a href="#">
<i class="fab fa-facebook fa-2x fa-fw"></i>
</a>
</li>
<li class="list-inline-item mr-3">
<a href="#">
<i class="fab fa-twitter-square fa-2x fa-fw"></i>
</a>
</li>
<li class="list-inline-item">
<a href="#">
<i class="fab fa-instagram fa-2x fa-fw"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
</footer> -->
<!-- Bootstrap core JavaScript -->
<script src="../../static/assets/vendor/jquery/jquery.min.js"></script>
<script src="../../static/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
from django.db import models
# Create your models here.
class approvals(models.Model):
ApplicationType= (
('Individu', 'Individu'),
('Join', 'Join')
)
EmploymentLength = (
('Old Employee', 'Old Employee'),
('New Employee', 'New Employee')
)
HomeOwnership = (
('MORTGAGE', 'MORTGAGE'),
('OWN', 'OWN'),
('RENT', 'RENT'),
('ANY', 'ANY'),
('OTHER', 'OTHER'),
('NONE', 'NONE')
)
PURPOSE = (
('debt_consolidation', 'debt_consolidation'),
('business', 'business'),
('asset', 'asset'),
('educational', 'educational'),
('medical', 'medical'),
('wedding', 'wedding'),
('vacation', 'vacation'),
('moving', 'moving'),
('other', 'other')
)
TERM = (
('60 months', '60 months'),
('36 months', '36 months')
)
firstname=models.CharField(max_length=15)
lastname=models.CharField(max_length=15)
annual_inc=models.IntegerField(default=0)
application_type=models.CharField(max_length=15, choices=ApplicationType)
dti=models.IntegerField(default=0)
emp_length=models.CharField(max_length=24, choices=EmploymentLength)
home_ownership=models.CharField(max_length=15, choices=HomeOwnership)
installment=models.IntegerField(default=0)
int_rate=models.IntegerField(default=0)
last_pymnt_amnt=models.IntegerField(default=0)
loan_amnt=models.IntegerField(default=0)
purpose=models.CharField(max_length=24, choices=PURPOSE)
term=models.CharField(max_length=24, choices=TERM)
loan_difference=models.IntegerField(default=0)
issue_d=models.DateField()
loan_freq=models.IntegerField(default=0)
def __str__(self):
return '{}'.format(self.lastname, self.firstname)
from rest_framework import serializers
from . models import approvals
class approvalsSerializers(serializers.ModelSerializer):
class Meta:
model=approvals
fields='__all__'
from django.test import TestCase
# Create your tests here.
from django.urls import path, include
from . import views
from rest_framework import routers
router = routers.DefaultRouter()
router.register('MyAPI', views.ApprovalsView)
urlpatterns = [
path('', views.home),
#path('form/', views.myform, name='myform'),
#path('api/', include(router.urls)),
#path('status/', views.approvereject),
]
from django.shortcuts import render
from . forms import MyForm
from rest_framework import viewsets
from rest_framework.decorators import api_view
from django.core import serializers
from rest_framework.response import Response
from rest_framework import status
from django.http import JsonResponse
from rest_framework.parsers import JSONParser
from . models import approvals
from . serializers import approvalsSerializers
import pickle
from sklearn.externals import joblib
import json
import numpy as np
from sklearn import preprocessing
import pandas as pd
def home(request):
return render(request, 'apps/home.html')
class ApprovalsView(viewsets.ModelViewSet):
queryset = approvals.objects.all()
serializer_class = approvalsSerializers
def myform(request):
if request.method=="POST":
form = MyForm(request.POST)
if form.is_valid():
myform = form.save(commit=False)
else:
form = MyForm()
@api_view(["POST"])
def approvereject(request):
try:
mdl=joblib.load("/Users/R. D. Mendrofa/DjangoAPI/MyAPI/loan_model.pkl")
mydata=pd.read_excel('/Users/R. D. Mendrofa/DjangoAPI/bankloan.csv')
mydata=request.data
unit=np.array(list(mydata.values()))
unit=unit.reshape(1,-1)
scalers=joblib.load("/Users/R. D. Mendrofa/DjangoAPI/MyAPIscalers.pkl")
X=scalers.transform(unit)
y_pred=mdl .predict(X)
y_pred=(y_pred>0.58)
newdf=pd.DataFrame(y_pred, columns=['loan_status'])
newdf=newdf.replace({True:'Approved', False:'Rejected'})
return JsonResponse('Your Status is {}'.format(newdf), safe=False)
except ValueError as e:
return Response(e.args[0], status.HTTP_400_BAD_REQUEST)
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DjangoAPI.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment