├── config
├── __init__.py
├── settings
│ ├── __init__.py
│ ├── local.py
│ ├── test.py
│ └── production.py
├── urls.py
└── wsgi.py
├── app
├── dataset
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ ├── admin.py
│ ├── apps.py
│ ├── serializers.py
│ └── urls.py
├── static
│ ├── fonts
│ │ └── .gitkeep
│ ├── sass
│ │ ├── custom_bootstrap_vars.scss
│ │ └── project.scss
│ ├── images
│ │ └── favicon.ico
│ ├── data
│ │ ├── trained_model_1.pkl
│ │ ├── trained_model_2.pkl
│ │ ├── trained_model_5.pkl
│ │ ├── german_data_w_selected_features_100_5_5.csv
│ │ ├── german_data_w_selected_features_100_5_5_synthetic.csv
│ │ ├── german_data_w_selected_features_systematic_synthetic.csv
│ │ └── german_data_sample_synthetic.csv
│ ├── lib
│ │ ├── __pycache__
│ │ │ ├── rankSVM.cpython-35.pyc
│ │ │ └── gower_distance.cpython-35.pyc
│ │ ├── prediction_interval.py
│ │ ├── rankSVM.py
│ │ ├── rankSVM2.py
│ │ └── gower_distance.py
│ ├── css
│ │ └── project.css
│ └── js
│ │ └── project.js
├── templates
│ ├── pages
│ │ ├── about.html
│ │ └── home.html
│ ├── 404.html
│ ├── 403_csrf.html
│ ├── bootstrap4
│ │ ├── layout
│ │ │ └── field_errors_block.html
│ │ └── field.html
│ ├── account
│ │ ├── base.html
│ │ ├── account_inactive.html
│ │ ├── password_reset_from_key_done.html
│ │ ├── signup_closed.html
│ │ ├── verification_sent.html
│ │ ├── password_set.html
│ │ ├── password_reset_done.html
│ │ ├── password_change.html
│ │ ├── logout.html
│ │ ├── signup.html
│ │ ├── verified_email_required.html
│ │ ├── password_reset.html
│ │ ├── password_reset_from_key.html
│ │ ├── email_confirm.html
│ │ ├── login.html
│ │ └── email.html
│ ├── 500.html
│ ├── users
│ │ ├── user_list.html
│ │ ├── user_form.html
│ │ └── user_detail.html
│ └── base.html
├── __init__.py
├── contrib
│ ├── __init__.py
│ └── sites
│ │ ├── __init__.py
│ │ └── migrations
│ │ ├── __init__.py
│ │ ├── 0002_alter_domain_unique.py
│ │ ├── 0001_initial.py
│ │ └── 0003_set_site_domain_and_name.py
└── views.py
├── src
├── .env
├── src
│ ├── config
│ │ ├── _tooltip.scss
│ │ ├── _sizes.scss
│ │ ├── _colors.scss
│ │ └── _variables.scss
│ ├── components
│ │ ├── FairnessBar
│ │ │ ├── styles.scss
│ │ │ └── index.js
│ │ ├── UtilityBar
│ │ │ ├── styles.scss
│ │ │ └── index.js
│ │ ├── UtilityView
│ │ │ ├── styles.scss
│ │ │ └── index.js
│ │ ├── RankingInspectorView
│ │ │ ├── LegendView
│ │ │ │ └── styles.scss
│ │ │ ├── OutputSpaceView
│ │ │ │ └── styles.scss
│ │ │ ├── InputSpaceView
│ │ │ │ └── styles.scss
│ │ │ ├── LocalInspectionView
│ │ │ │ └── styles.scss
│ │ │ ├── FeatureInspectionView
│ │ │ │ └── styles.scss
│ │ │ └── styles.scss
│ │ ├── Footer
│ │ │ ├── styles.scss
│ │ │ └── index.js
│ │ ├── Menubar
│ │ │ ├── styles.scss
│ │ │ └── index.js
│ │ ├── RankingsListView
│ │ │ └── styles.scss
│ │ ├── App
│ │ │ └── styles.scss
│ │ ├── RankingView
│ │ │ ├── styles.scss
│ │ │ └── wholeRankingChart.js
│ │ └── Generator
│ │ │ └── styles.scss
│ ├── translations.js
│ ├── redux
│ │ ├── modules
│ │ │ └── users.js
│ │ ├── actions.js
│ │ ├── reducers.js
│ │ └── configureStore.js
│ ├── index.js
│ ├── index.css
│ └── data
│ │ └── dim_reduction_result.json
├── public
│ ├── favicon.ico
│ ├── manifest.json
│ ├── index.html
│ └── index.css
├── .gitignore
├── config
│ ├── polyfills.js
│ ├── paths.js
│ ├── env.js
│ └── webpackDevServer.config.js
└── package.json
├── .gitattributes
├── pytest.ini
├── docs
├── __init__.py
├── deploy.rst
├── install.rst
├── index.rst
├── make.bat
├── Makefile
└── docker_ec2.rst
├── .coveragerc
├── locale
└── README.rst
├── .vscode
├── settings.json
└── launch.json
├── setup.cfg
├── yarn.lock
├── .pylintrc
├── requirements
├── production.txt
├── base.txt
└── local.txt
├── .editorconfig
├── LICENSE
├── manage.py
├── Pipfile
├── README.rst
├── README.md
└── .gitignore
/config/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/dataset/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/.env:
--------------------------------------------------------------------------------
1 | NODE_PATH=src
--------------------------------------------------------------------------------
/app/static/fonts/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/config/settings/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/src/config/_tooltip.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/app/dataset/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/static/sass/custom_bootstrap_vars.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/src/components/FairnessBar/styles.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/src/components/UtilityBar/styles.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/templates/pages/about.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
--------------------------------------------------------------------------------
/app/templates/pages/home.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
--------------------------------------------------------------------------------
/pytest.ini:
--------------------------------------------------------------------------------
1 | [pytest]
2 | DJANGO_SETTINGS_MODULE=config.settings.test
3 |
--------------------------------------------------------------------------------
/src/src/components/UtilityView/styles.scss:
--------------------------------------------------------------------------------
1 | .UtilityView {
2 | grid-area: u;
3 | }
--------------------------------------------------------------------------------
/app/dataset/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
--------------------------------------------------------------------------------
/app/dataset/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/app/dataset/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/src/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/src/public/favicon.ico
--------------------------------------------------------------------------------
/docs/__init__.py:
--------------------------------------------------------------------------------
1 | # Included so that Django's startproject comment runs against the docs directory
2 |
--------------------------------------------------------------------------------
/src/src/components/RankingInspectorView/LegendView/styles.scss:
--------------------------------------------------------------------------------
1 | .LegendView {
2 | grid-area: lg;
3 | }
--------------------------------------------------------------------------------
/app/static/images/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/app/static/images/favicon.ico
--------------------------------------------------------------------------------
/docs/deploy.rst:
--------------------------------------------------------------------------------
1 | Deploy
2 | ========
3 |
4 | This is where you describe how the project is deployed in production.
5 |
--------------------------------------------------------------------------------
/app/static/data/trained_model_1.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/app/static/data/trained_model_1.pkl
--------------------------------------------------------------------------------
/app/static/data/trained_model_2.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/app/static/data/trained_model_2.pkl
--------------------------------------------------------------------------------
/app/static/data/trained_model_5.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/app/static/data/trained_model_5.pkl
--------------------------------------------------------------------------------
/docs/install.rst:
--------------------------------------------------------------------------------
1 | Install
2 | =========
3 |
4 | This is where you write how to get a new laptop to run this project.
5 |
--------------------------------------------------------------------------------
/src/src/translations.js:
--------------------------------------------------------------------------------
1 | export const translations = {
2 | es: {
3 | "Log in": "Iniciar Sesión"
4 | }
5 | };
6 |
--------------------------------------------------------------------------------
/app/dataset/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class DatasetConfig(AppConfig):
5 | name = 'app.dataset'
6 |
--------------------------------------------------------------------------------
/.coveragerc:
--------------------------------------------------------------------------------
1 | [run]
2 | include = my_awesome_project/*
3 | omit = *migrations*, *tests*
4 | plugins =
5 | django_coverage_plugin
6 |
--------------------------------------------------------------------------------
/app/static/lib/__pycache__/rankSVM.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/app/static/lib/__pycache__/rankSVM.cpython-35.pyc
--------------------------------------------------------------------------------
/app/__init__.py:
--------------------------------------------------------------------------------
1 | __version__ = '0.1.0'
2 | __version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
3 |
--------------------------------------------------------------------------------
/locale/README.rst:
--------------------------------------------------------------------------------
1 | Translations
2 | ============
3 |
4 | Translations will be placed in this folder when running::
5 |
6 | python manage.py makemessages
7 |
--------------------------------------------------------------------------------
/app/static/lib/__pycache__/gower_distance.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ayong8/FairSight/HEAD/app/static/lib/__pycache__/gower_distance.cpython-35.pyc
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "python.pythonPath": "/Users/yong8/.local/share/virtualenvs/FairSight2-1VTXp12b/bin/python",
3 | "python.linting.pylintEnabled": false
4 | }
--------------------------------------------------------------------------------
/src/src/components/RankingInspectorView/OutputSpaceView/styles.scss:
--------------------------------------------------------------------------------
1 | .OutputSpaceView {
2 | grid-area: tr;
3 | border: 1px dashed #e4e4e4;
4 | padding: 15px;
5 | margin: 5px;
6 | overflow-y: scroll;
7 | }
--------------------------------------------------------------------------------
/app/contrib/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | To understand why this file is here, please read:
3 |
4 | http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
5 | """
6 |
--------------------------------------------------------------------------------
/app/contrib/sites/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | To understand why this file is here, please read:
3 |
4 | http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
5 | """
6 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | max-line-length = 120
3 | exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules
4 |
5 | [pycodestyle]
6 | max-line-length = 120
7 | exclude=.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules
8 |
--------------------------------------------------------------------------------
/app/contrib/sites/migrations/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | To understand why this file is here, please read:
3 |
4 | http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
5 | """
6 |
--------------------------------------------------------------------------------
/app/templates/404.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block title %}Page not found{% endblock %}
4 |
5 | {% block content %}
6 |
Page not found
7 |
8 | This is not the page you were looking for.
9 | {% endblock content %}
10 |
--------------------------------------------------------------------------------
/app/templates/403_csrf.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block title %}Forbidden (403){% endblock %}
4 |
5 | {% block content %}
6 | Forbidden (403)
7 |
8 | CSRF verification failed. Request aborted.
9 | {% endblock content %}
10 |
--------------------------------------------------------------------------------
/app/templates/bootstrap4/layout/field_errors_block.html:
--------------------------------------------------------------------------------
1 |
2 | {% if form_show_errors and field.errors %}
3 | {% for error in field.errors %}
4 | {{ error }}
5 | {% endfor %}
6 | {% endif %}
7 |
8 |
--------------------------------------------------------------------------------
/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 | redux-devtools-extension@^2.13.2:
6 | version "2.13.2"
7 | resolved "https://registry.yarnpkg.com/redux-devtools-extension/-/redux-devtools-extension-2.13.2.tgz#e0f9a8e8dfca7c17be92c7124958a3b94eb2911d"
8 |
--------------------------------------------------------------------------------
/.pylintrc:
--------------------------------------------------------------------------------
1 | [MASTER]
2 | load-plugins=pylint_common, pylint_django
3 |
4 | [FORMAT]
5 | max-line-length=120
6 |
7 | [MESSAGES CONTROL]
8 | disable=missing-docstring,invalid-name
9 |
10 | [DESIGN]
11 | max-parents=13
12 |
13 | [TYPECHECK]
14 | generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete
15 |
--------------------------------------------------------------------------------
/app/templates/account/base.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% block title %}{% block head_title %}{% endblock head_title %}{% endblock title %}
3 |
4 | {% block content %}
5 |
6 |
7 | {% block inner %}{% endblock %}
8 |
9 |
10 | {% endblock %}
11 |
--------------------------------------------------------------------------------
/app/templates/account/account_inactive.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 |
5 | {% block head_title %}{% trans "Account Inactive" %}{% endblock %}
6 |
7 | {% block inner %}
8 | {% trans "Account Inactive" %}
9 |
10 | {% trans "This account is inactive." %}
11 | {% endblock %}
12 |
13 |
--------------------------------------------------------------------------------
/app/templates/account/password_reset_from_key_done.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% block head_title %}{% trans "Change Password" %}{% endblock %}
5 |
6 | {% block inner %}
7 | {% trans "Change Password" %}
8 | {% trans 'Your password is now changed.' %}
9 | {% endblock %}
10 |
11 |
--------------------------------------------------------------------------------
/app/templates/account/signup_closed.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 |
5 | {% block head_title %}{% trans "Sign Up Closed" %}{% endblock %}
6 |
7 | {% block inner %}
8 | {% trans "Sign Up Closed" %}
9 |
10 | {% trans "We are sorry, but the sign up is currently closed." %}
11 | {% endblock %}
12 |
13 |
--------------------------------------------------------------------------------
/src/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "192x192",
8 | "type": "image/png"
9 | }
10 | ],
11 | "start_url": "./index.html",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/app/templates/500.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 |
3 | {% block title %}Server Error{% endblock %}
4 |
5 | {% block content %}
6 | Ooops!!! 500
7 |
8 | Looks like something went wrong!
9 |
10 | We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.
11 | {% endblock content %}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
--------------------------------------------------------------------------------
/src/src/redux/modules/users.js:
--------------------------------------------------------------------------------
1 | // imports
2 |
3 | // actions and action creator => actions.js
4 |
5 |
6 |
7 | // reducer
8 | const initialState = {
9 | topK: 30
10 | };
11 |
12 | function reducer(state = initialState, action) {
13 | switch (action.type) {
14 | default:
15 | return state;
16 | }
17 | }
18 |
19 | // reducer functions
20 |
21 | // exports
22 |
23 | // export reducer by default
24 |
25 | export default reducer;
26 |
--------------------------------------------------------------------------------
/app/templates/account/verification_sent.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 |
5 | {% block head_title %}{% trans "Verify Your E-mail Address" %}{% endblock %}
6 |
7 | {% block inner %}
8 | {% trans "Verify Your E-mail Address" %}
9 |
10 | {% blocktrans %}We have sent an e-mail to you for verification. Follow the link provided to finalize the signup process. Please contact us if you do not receive it within a few minutes.{% endblocktrans %}
11 |
12 | {% endblock %}
13 |
14 |
--------------------------------------------------------------------------------
/app/templates/users/user_list.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% load static i18n %}
3 | {% block title %}Members{% endblock %}
4 |
5 | {% block content %}
6 |
17 | {% endblock content %}
18 |
--------------------------------------------------------------------------------
/app/templates/users/user_form.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% load crispy_forms_tags %}
3 |
4 | {% block title %}{{ user.username }}{% endblock %}
5 |
6 | {% block content %}
7 | {{ user.username }}
8 |
17 | {% endblock %}
18 |
--------------------------------------------------------------------------------
/app/templates/account/password_set.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load crispy_forms_tags %}
5 |
6 | {% block head_title %}{% trans "Set Password" %}{% endblock %}
7 |
8 | {% block inner %}
9 | {% trans "Set Password" %}
10 |
11 |
16 | {% endblock %}
17 |
18 |
--------------------------------------------------------------------------------
/app/static/css/project.css:
--------------------------------------------------------------------------------
1 | /* These styles are generated from project.scss. */
2 |
3 | .alert-debug {
4 | color: black;
5 | background-color: white;
6 | border-color: #d6e9c6;
7 | }
8 |
9 | .alert-error {
10 | color: #b94a48;
11 | background-color: #f2dede;
12 | border-color: #eed3d7;
13 | }
14 |
15 | /* Display django-debug-toolbar.
16 | See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742
17 | and https://github.com/pydanny/cookiecutter-django/issues/317
18 | */
19 | [hidden][style="display: block;"] {
20 | display: block !important;
21 | }
22 |
--------------------------------------------------------------------------------
/app/templates/account/password_reset_done.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load account %}
5 |
6 | {% block head_title %}{% trans "Password Reset" %}{% endblock %}
7 |
8 | {% block inner %}
9 | {% trans "Password Reset" %}
10 |
11 | {% if user.is_authenticated %}
12 | {% include "account/snippets/already_logged_in.html" %}
13 | {% endif %}
14 |
15 | {% blocktrans %}We have sent you an e-mail. Please contact us if you do not receive it within a few minutes.{% endblocktrans %}
16 | {% endblock %}
17 |
18 |
--------------------------------------------------------------------------------
/app/templates/account/password_change.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load crispy_forms_tags %}
5 |
6 | {% block head_title %}{% trans "Change Password" %}{% endblock %}
7 |
8 | {% block inner %}
9 | {% trans "Change Password" %}
10 |
11 |
16 | {% endblock %}
17 |
18 |
--------------------------------------------------------------------------------
/requirements/production.txt:
--------------------------------------------------------------------------------
1 | # PRECAUTION: avoid production dependencies that aren't in development
2 |
3 | -r ./base.txt
4 |
5 | gunicorn==19.8.1 # https://github.com/benoitc/gunicorn
6 | psycopg2==2.7.4 --no-binary psycopg2 # https://github.com/psycopg/psycopg2
7 | Collectfast==0.6.2 # https://github.com/antonagestam/collectfast
8 |
9 | # Django
10 | # ------------------------------------------------------------------------------
11 | django-storages[boto3]==1.6.6 # https://github.com/jschneier/django-storages
12 | django-anymail[mailgun]==3.0 # https://github.com/anymail/django-anymail
13 |
--------------------------------------------------------------------------------
/src/src/components/Footer/styles.scss:
--------------------------------------------------------------------------------
1 | .Footer {
2 | grid-area: f;
3 |
4 | max-width: 1000px;
5 | width: 100%;
6 | margin: 0 auto;
7 | display: flex;
8 | align-items: center;
9 | justify-content: space-between;
10 | font-weight: 600;
11 | text-transform: uppercase;
12 | font-size: 12px;
13 |
14 | .column {
15 | .nav {
16 | .list {
17 | display: flex;
18 | .list-item {
19 | margin-left: 10px;
20 | color: $dark-blue;
21 | }
22 | }
23 | }
24 | .copyright {
25 | color: $dark-grey;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/views.py:
--------------------------------------------------------------------------------
1 | from django.views.generic import View
2 | from django.http import HttpResponse
3 | from django.conf import settings
4 | import os
5 |
6 |
7 | class ReactAppView(View):
8 |
9 | def get(self, request):
10 | try:
11 | with open(os.path.join(str(settings.ROOT_DIR), 'src', 'build', 'index.html')) as file:
12 | return HttpResponse(file.read())
13 | except:
14 | return HttpResponse(
15 | """
16 | index.html not found ! build your React app !!
17 | """,
18 | status=501,
19 | )
20 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. My Awesome Project documentation master file, created by
2 | sphinx-quickstart.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | Welcome to My Awesome Project's documentation!
7 | ====================================================================
8 |
9 | Contents:
10 |
11 | .. toctree::
12 | :maxdepth: 2
13 |
14 | install
15 | deploy
16 | docker_ec2
17 | tests
18 |
19 |
20 |
21 | Indices and tables
22 | ==================
23 |
24 | * :ref:`genindex`
25 | * :ref:`modindex`
26 | * :ref:`search`
27 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 |
3 | root = true
4 |
5 | [*]
6 | charset = utf-8
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.{py,rst,ini}]
12 | indent_style = space
13 | indent_size = 4
14 |
15 | [*.py]
16 | line_length=120
17 | known_first_party=my_awesome_project
18 | multi_line_output=3
19 | default_section=THIRDPARTY
20 |
21 | [*.{html,css,scss,json,yml}]
22 | indent_style = space
23 | indent_size = 2
24 |
25 | [*.md]
26 | trim_trailing_whitespace = false
27 |
28 | [Makefile]
29 | indent_style = tab
30 |
31 | [nginx.conf]
32 | indent_style = space
33 | indent_size = 2
34 |
--------------------------------------------------------------------------------
/app/contrib/sites/migrations/0002_alter_domain_unique.py:
--------------------------------------------------------------------------------
1 | import django.contrib.sites.models
2 | from django.db import migrations, models
3 |
4 |
5 | class Migration(migrations.Migration):
6 |
7 | dependencies = [
8 | ('sites', '0001_initial'),
9 | ]
10 |
11 | operations = [
12 | migrations.AlterField(
13 | model_name='site',
14 | name='domain',
15 | field=models.CharField(
16 | max_length=100, unique=True, validators=[django.contrib.sites.models._simple_domain_name_validator],
17 | verbose_name='domain name'
18 | ),
19 | ),
20 | ]
21 |
--------------------------------------------------------------------------------
/src/src/components/RankingInspectorView/InputSpaceView/styles.scss:
--------------------------------------------------------------------------------
1 | .InputSpaceView {
2 | grid-area: i;
3 | border: 1px dashed #e4e4e4;
4 | padding: 15px;
5 | margin: 5px;
6 | width: 280px;
7 | }
8 |
9 | .inputSpaceViewTitleWrapper {
10 | display: flex;
11 |
12 | .inputSpaceViewTitle {
13 | padding: 0;
14 | }
15 | }
16 |
17 | .FeatureTable {
18 | margin: 0 10px;
19 | border: 1px solid lightgray;
20 | }
21 | .FeatureTable > thead {
22 | border-bottom: 1px solid lightgray;
23 | }
24 | .IndividualPlotStatusView {
25 | display: flex;
26 | width: 100%;
27 |
28 | .selectedInstanceInfo {
29 | margin: 5px;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/templates/account/logout.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 |
5 | {% block head_title %}{% trans "Sign Out" %}{% endblock %}
6 |
7 | {% block inner %}
8 | {% trans "Sign Out" %}
9 |
10 | {% trans 'Are you sure you want to sign out?' %}
11 |
12 |
19 |
20 |
21 | {% endblock %}
22 |
23 |
--------------------------------------------------------------------------------
/src/src/config/_sizes.scss:
--------------------------------------------------------------------------------
1 | $max-page-width: 935px;
2 |
3 | /*
4 | Css-grid layout for the website structure
5 | grid-template-rows: 50px 200px 400px 250px 80px;
6 | grid-template-columns: 25% 40% 15% 20%;
7 | */
8 |
9 | $layout-first-row: 50px;
10 | $layout-second-row: 200px;
11 | $layout-third-row: 400px;
12 | $layout-fourth-row: 250px;
13 | $layout-fifth-row: 80px;
14 |
15 | $layout-first-column: 25%;
16 | $layout-second-column: 40%;
17 | $layout-third-column: 15%;
18 | $layout-fourth-column: 20%;
19 |
20 | $processView-individualFairness-width: 20%;
21 | $processView-individualFairness-height: 80%;
22 |
23 | /*
24 | Component layouts bound to css-grid layouts
25 | */
26 |
27 |
--------------------------------------------------------------------------------
/src/config/polyfills.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | if (typeof Promise === 'undefined') {
4 | // Rejection tracking prevents a common issue where React gets into an
5 | // inconsistent state due to an error, but it gets swallowed by a Promise,
6 | // and the user has no idea what causes React's erratic future behavior.
7 | require('promise/lib/rejection-tracking').enable();
8 | window.Promise = require('promise/lib/es6-extensions.js');
9 | }
10 |
11 | // fetch() polyfill for making API calls.
12 | require('whatwg-fetch');
13 |
14 | // Object.assign() is commonly used with React.
15 | // It will use the native implementation if it's present and isn't buggy.
16 | Object.assign = require('object-assign');
17 |
--------------------------------------------------------------------------------
/src/src/config/_colors.scss:
--------------------------------------------------------------------------------
1 | $bg-color: #fafafa;
2 | $dark-blue: #003569;
3 | $dark-grey: #999;
4 |
5 | $system-color: #003569;
6 | $individual-color: lightgray;
7 | $group-color1: #00fa9a; // For non-protected group
8 | $group-color2: #ff7043; // For protected group
9 | $true-color: aqua;
10 | $false-color: bisque;
11 | $topk-color: #4169e1; // royalblue
12 | $non-topk-color: gray;
13 | $topk-true-color: mediumblue;
14 | $topk-false-color: burlywood;
15 | $non-topk-true-color: deepskyblue;
16 | $non-topk-false-color: wheat;
17 | $instance-color: deepskyblue; // Same as non-topk-color
18 | $outlier-color: red;
19 | $individual-pair-color: #003569;
20 | $between-group-pair-color: SLATEBLUE;
21 | $within-group-pair-color: #c71585;
22 |
23 | $utility-color: #c2185b;
24 | $fairness-color: #003569;
--------------------------------------------------------------------------------
/app/templates/account/signup.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load crispy_forms_tags %}
5 |
6 | {% block head_title %}{% trans "Signup" %}{% endblock %}
7 |
8 | {% block inner %}
9 | {% trans "Sign Up" %}
10 |
11 | {% blocktrans %}Already have an account? Then please sign in .{% endblocktrans %}
12 |
13 |
21 |
22 | {% endblock %}
23 |
24 |
--------------------------------------------------------------------------------
/src/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import { Provider } from 'react-redux';
4 | //import I18n from 'redux-i18n';
5 | import { ConnectedRouter } from 'react-router-redux';
6 | import store, { history } from 'redux/configureStore';
7 | import App from 'components/App';
8 |
9 | import 'bootstrap/dist/css/bootstrap.css';
10 | import 'normalize.css/normalize.css';
11 | import '@blueprintjs/core/lib/css/blueprint.css';
12 | import '@blueprintjs/icons/lib/css/blueprint-icons.css';
13 | import 'antd/dist/antd.css';
14 | //import { translations } from 'translations';
15 |
16 | ReactDOM.render(
17 |
18 |
19 |
20 |
21 | ,
22 | document.getElementById('root')
23 | );
24 |
--------------------------------------------------------------------------------
/src/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | FairSight
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/src/redux/actions.js:
--------------------------------------------------------------------------------
1 | /*
2 | * 액션 타입
3 | */
4 |
5 | export const ADD_TODO = 'ADD_TODO'
6 | export const COMPLETE_TODO = 'COMPLETE_TODO'
7 | export const SET_VISIBILITY_FILTER = 'SET_VISIBILITY_FILTER'
8 | export const SET_TOP_K = 'SET_TOP_K'
9 |
10 | /*
11 | * 다른 상수
12 | */
13 |
14 | export const VisibilityFilters = {
15 | SHOW_ALL: 'SHOW_ALL',
16 | SHOW_COMPLETED: 'SHOW_COMPLETED',
17 | SHOW_ACTIVE: 'SHOW_ACTIVE'
18 | }
19 |
20 | /*
21 | * 액션 생산자
22 | */
23 | export function setTopK(topK) {
24 | return { type: SET_TOP_K, topk }
25 | }
26 |
27 | export function addTodo(text) {
28 | return { type: ADD_TODO, text }
29 | }
30 |
31 | export function completeTodo(index) {
32 | return { type: COMPLETE_TODO, index }
33 | }
34 |
35 | export function setVisibilityFilter(filter) {
36 | return { type: SET_VISIBILITY_FILTER, filter }
37 | }
--------------------------------------------------------------------------------
/src/src/components/RankingInspectorView/LocalInspectionView/styles.scss:
--------------------------------------------------------------------------------
1 | .LocalInspectionView {
2 | grid-area: ii;
3 | width: 30%;
4 |
5 | .localInspectorTitle {
6 | background-color: #00346b;
7 | color: white;
8 | }
9 |
10 | .groupInspectionTitle,
11 | .individualInspectionTitle {
12 | font-weight: 800;
13 | font-size: 1.2rem;
14 | border-bottom: 1px solid grey;
15 | margin-bottom: 5px;
16 | }
17 | /* margin: 5px 0; */
18 | // background-color: #f5f4f4;
19 |
20 | // .instanceDataTableWrapper {
21 | // display: flex;
22 | // }
23 | .IndividualStatus {
24 | height: 400px;
25 | padding-top: 5px;
26 | }
27 | .infoWrapper {
28 | margin: 10px;
29 | }
30 | .selectedRankingIntervalInfo {
31 | width: 80%;
32 | }
33 | .individualMeasures,
34 | .groupMeasures {
35 | font-weight: 600;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/static/js/project.js:
--------------------------------------------------------------------------------
1 | /* Project specific Javascript goes here. */
2 |
3 | /*
4 | Formatting hack to get around crispy-forms unfortunate hardcoding
5 | in helpers.FormHelper:
6 |
7 | if template_pack == 'bootstrap4':
8 | grid_colum_matcher = re.compile('\w*col-(xs|sm|md|lg|xl)-\d+\w*')
9 | using_grid_layout = (grid_colum_matcher.match(self.label_class) or
10 | grid_colum_matcher.match(self.field_class))
11 | if using_grid_layout:
12 | items['using_grid_layout'] = True
13 |
14 | Issues with the above approach:
15 |
16 | 1. Fragile: Assumes Bootstrap 4's API doesn't change (it does)
17 | 2. Unforgiving: Doesn't allow for any variation in template design
18 | 3. Really Unforgiving: No way to override this behavior
19 | 4. Undocumented: No mention in the documentation, or it's too hard for me to find
20 | */
21 | $('.form-group').removeClass('row');
22 |
--------------------------------------------------------------------------------
/app/templates/account/verified_email_required.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 |
5 | {% block head_title %}{% trans "Verify Your E-mail Address" %}{% endblock %}
6 |
7 | {% block inner %}
8 | {% trans "Verify Your E-mail Address" %}
9 |
10 | {% url 'account_email' as email_url %}
11 |
12 | {% blocktrans %}This part of the site requires us to verify that
13 | you are who you claim to be. For this purpose, we require that you
14 | verify ownership of your e-mail address. {% endblocktrans %}
15 |
16 | {% blocktrans %}We have sent an e-mail to you for
17 | verification. Please click on the link inside this e-mail. Please
18 | contact us if you do not receive it within a few minutes.{% endblocktrans %}
19 |
20 | {% blocktrans %}Note: you can still change your e-mail address .{% endblocktrans %}
21 |
22 |
23 | {% endblock %}
24 |
25 |
--------------------------------------------------------------------------------
/app/templates/users/user_detail.html:
--------------------------------------------------------------------------------
1 | {% extends "base.html" %}
2 | {% load static %}
3 |
4 | {% block title %}User: {{ object.username }}{% endblock %}
5 |
6 | {% block content %}
7 |
8 |
9 |
10 |
11 |
12 |
{{ object.username }}
13 | {% if object.name %}
14 |
{{ object.name }}
15 | {% endif %}
16 |
17 |
18 |
19 | {% if object == request.user %}
20 |
21 |
30 |
31 | {% endif %}
32 |
33 |
34 |
35 | {% endblock content %}
36 |
37 |
--------------------------------------------------------------------------------
/app/templates/account/password_reset.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load account %}
5 | {% load crispy_forms_tags %}
6 |
7 | {% block head_title %}{% trans "Password Reset" %}{% endblock %}
8 |
9 | {% block inner %}
10 |
11 | {% trans "Password Reset" %}
12 | {% if user.is_authenticated %}
13 | {% include "account/snippets/already_logged_in.html" %}
14 | {% endif %}
15 |
16 | {% trans "Forgotten your password? Enter your e-mail address below, and we'll send you an e-mail allowing you to reset it." %}
17 |
18 |
23 |
24 | {% blocktrans %}Please contact us if you have any trouble resetting your password.{% endblocktrans %}
25 | {% endblock %}
26 |
27 |
--------------------------------------------------------------------------------
/requirements/base.txt:
--------------------------------------------------------------------------------
1 | pytz==2018.5 # https://github.com/stub42/pytz
2 | python-slugify==1.2.5 # https://github.com/un33k/python-slugify
3 | Pillow==5.2.0 # https://github.com/python-pillow/Pillow
4 | argon2-cffi==18.1.0 # https://github.com/hynek/argon2_cffi
5 | redis>=2.10.5 # https://github.com/antirez/redis
6 |
7 | # Django
8 | # ------------------------------------------------------------------------------
9 | django==2.0.8 # pyup: < 2.1 # https://www.djangoproject.com/
10 | django-environ==0.4.5 # https://github.com/joke2k/django-environ
11 | django-model-utils==3.1.2 # https://github.com/jazzband/django-model-utils
12 | django-allauth==0.36.0 # https://github.com/pennersr/django-allauth
13 | django-crispy-forms==1.7.2 # https://github.com/django-crispy-forms/django-crispy-forms
14 | django-redis==4.9.0 # https://github.com/niwinz/django-redis
15 |
16 | # Django REST Framework
17 | djangorestframework==3.8.2 # https://github.com/encode/django-rest-framework
18 | coreapi==2.3.3 # https://github.com/core-api/python-client
19 |
--------------------------------------------------------------------------------
/src/src/config/_variables.scss:
--------------------------------------------------------------------------------
1 | @import "./_colors.scss";
2 | @import "./_sizes.scss";
3 |
4 |
5 | :export {
6 | rankingListViewWidth: $layout-first-column;
7 | rankingListViewHeight: $layout-third-row + $layout-fourth-row;
8 |
9 | systemColor: $system-color;
10 | individualColor: $individual-color;
11 | groupColor1: $group-color1;
12 | groupColor2: $group-color2;
13 | instanceColor: $instance-color;
14 | topkColor: $topk-color;
15 | nonTopkColor: $non-topk-color;
16 | trueColor: $true-color;
17 | falseColor: $false-color;
18 | topkTrueColor: $topk-true-color;
19 | topkFalseColor: $topk-false-color;
20 | nonTopkTrueColor: $non-topk-true-color;
21 | nonTopkFalseColor: $non-topk-false-color;
22 | outlierColor: $outlier-color;
23 | individualPairColor: $individual-pair-color;
24 | betweenGroupPairColor: $between-group-pair-color;
25 | withinGroupPairColor: $within-group-pair-color;
26 |
27 | utilityColor: $utility-color;
28 | fairnessColor: $fairness-color;
29 | }
--------------------------------------------------------------------------------
/app/templates/account/password_reset_from_key.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load crispy_forms_tags %}
5 | {% block head_title %}{% trans "Change Password" %}{% endblock %}
6 |
7 | {% block inner %}
8 | {% if token_fail %}{% trans "Bad Token" %}{% else %}{% trans "Change Password" %}{% endif %}
9 |
10 | {% if token_fail %}
11 | {% url 'account_reset_password' as passwd_reset_url %}
12 | {% blocktrans %}The password reset link was invalid, possibly because it has already been used. Please request a new password reset .{% endblocktrans %}
13 | {% else %}
14 | {% if form %}
15 |
20 | {% else %}
21 | {% trans 'Your password is now changed.' %}
22 | {% endif %}
23 | {% endif %}
24 | {% endblock %}
25 |
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | The MIT License (MIT)
3 | Copyright (c) 2018, Daniel Roy Greenfeld
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
11 |
--------------------------------------------------------------------------------
/app/templates/account/email_confirm.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load account %}
5 |
6 | {% block head_title %}{% trans "Confirm E-mail Address" %}{% endblock %}
7 |
8 |
9 | {% block inner %}
10 | {% trans "Confirm E-mail Address" %}
11 |
12 | {% if confirmation %}
13 |
14 | {% user_display confirmation.email_address.user as user_display %}
15 |
16 | {% blocktrans with confirmation.email_address.email as email %}Please confirm that {{ email }} is an e-mail address for user {{ user_display }}.{% endblocktrans %}
17 |
18 |
22 |
23 | {% else %}
24 |
25 | {% url 'account_email' as email_url %}
26 |
27 | {% blocktrans %}This e-mail confirmation link expired or is invalid. Please issue a new e-mail confirmation request .{% endblocktrans %}
28 |
29 | {% endif %}
30 |
31 | {% endblock %}
32 |
33 |
--------------------------------------------------------------------------------
/src/src/components/Footer/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import styles from "./styles.scss";
3 |
4 | const Footer = (props, context) => (
5 |
6 |
7 |
8 | {/*
9 | About Us
10 | Support
11 | Blog
12 | Press
13 | API
14 | Jobs
15 | Privacy
16 | Terms
17 | Directory
18 | Language
19 | */}
20 |
21 |
22 |
23 | © PICSO LAB
24 |
25 |
26 | );
27 |
28 | export default Footer;
29 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "browser-preview",
9 | "request": "attach",
10 | "name": "Browser Preview: Attach"
11 | },
12 | {
13 | "type": "browser-preview",
14 | "request": "launch",
15 | "name": "Browser Preview: Launch",
16 | "url": "http://localhost:3000"
17 | },
18 | {
19 | "name": "Django",
20 | "type": "python",
21 | "request": "launch",
22 | "program": "${workspaceFolder}/manage.py",
23 | "args": [
24 | "runserver",
25 | "--noreload",
26 | "--nothreading"
27 | ],
28 | "django": true
29 | },
30 | {
31 | "type": "chrome",
32 | "request": "launch",
33 | "name": "Launch Chrome against localhost",
34 | "url": "http://localhost:3000",
35 | "webRoot": "${workspaceFolder}/src"
36 | }
37 | ]
38 | }
--------------------------------------------------------------------------------
/src/src/redux/reducers.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from 'redux';
2 | import { SET_TOP_K } from './actions';
3 |
4 | const { SHOW_ALL } = VisibilityFilters;
5 |
6 | function topk(state = 40, action) {
7 | switch (action.type) {
8 | case SET_TOP_K:
9 | return action.topk;
10 | default:
11 | return state;
12 | }
13 | }
14 |
15 | function visibilityFilter(state = SHOW_ALL, action) {
16 | switch (action.type) {
17 | case SET_VISIBILITY_FILTER:
18 | return action.filter;
19 | default:
20 | return state;
21 | }
22 | }
23 |
24 | function todos(state = [], action) {
25 | switch (action.type) {
26 | case ADD_TODO:
27 | return [...state, {
28 | text: action.text,
29 | completed: false
30 | }];
31 | case COMPLETE_TODO:
32 | return [
33 | ...state.slice(0, action.index),
34 | Object.assign({}, state[action.index], {
35 | completed: true
36 | }),
37 | ...state.slice(action.index + 1)
38 | ];
39 | default:
40 | return state;
41 | }
42 | }
43 |
44 | const appReducer = combineReducers({
45 | topk
46 | });
47 |
48 | export default appReducer;
--------------------------------------------------------------------------------
/src/src/redux/configureStore.js:
--------------------------------------------------------------------------------
1 | import { combineReducers, createStore, applyMiddleware } from "redux";
2 | import { routerReducer, routerMiddleware } from "react-router-redux";
3 | import { composeWithDevTools } from "redux-devtools-extension";
4 | import createHistory from "history/createBrowserHistory";
5 | import thunk from "redux-thunk";
6 | import users from "redux/modules/users";
7 | //import { i18nState } from "redux-i18n";
8 |
9 | const env = process.env.NODE_ENV;
10 |
11 | const history = createHistory();
12 |
13 | const middlewares = [thunk, routerMiddleware(history)];
14 |
15 | if (env === "development") {
16 | const { logger } = require("redux-logger");
17 | middlewares.push(logger);
18 | }
19 |
20 | const reducer = combineReducers({
21 | users,
22 | routing: routerReducer
23 | });
24 |
25 | let store;
26 |
27 | if (env === "development") {
28 | store = initialState =>
29 | createStore(reducer, composeWithDevTools(applyMiddleware(...middlewares)));
30 | } else {
31 | store = initialState => createStore(reducer, applyMiddleware(...middlewares));
32 | }
33 |
34 | export { history };
35 |
36 | export default store();
37 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
7 |
8 | try:
9 | from django.core.management import execute_from_command_line
10 | except ImportError:
11 | # The above import may fail for some other reason. Ensure that the
12 | # issue is really that Django is missing to avoid masking other
13 | # exceptions on Python 2.
14 | try:
15 | import django # noqa
16 | except ImportError:
17 | raise ImportError(
18 | "Couldn't import Django. Are you sure it's installed and "
19 | "available on your PYTHONPATH environment variable? Did you "
20 | "forget to activate a virtual environment?"
21 | )
22 |
23 | raise
24 |
25 | # This allows easy placement of apps within the interior
26 | # my_awesome_project directory.
27 | current_path = os.path.dirname(os.path.abspath(__file__))
28 | sys.path.append(os.path.join(current_path, "my_awesome_project"))
29 |
30 | execute_from_command_line(sys.argv)
31 |
--------------------------------------------------------------------------------
/app/static/sass/project.scss:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | // project specific CSS goes here
6 |
7 | ////////////////////////////////
8 | //Variables//
9 | ////////////////////////////////
10 |
11 | // Alert colors
12 |
13 | $white: #fff;
14 | $mint-green: #d6e9c6;
15 | $black: #000;
16 | $pink: #f2dede;
17 | $dark-pink: #eed3d7;
18 | $red: #b94a48;
19 |
20 | ////////////////////////////////
21 | //Alerts//
22 | ////////////////////////////////
23 |
24 | // bootstrap alert CSS, translated to the django-standard levels of
25 | // debug, info, success, warning, error
26 |
27 | .alert-debug {
28 | background-color: $white;
29 | border-color: $mint-green;
30 | color: $black;
31 | }
32 |
33 | .alert-error {
34 | background-color: $pink;
35 | border-color: $dark-pink;
36 | color: $red;
37 | }
38 |
39 | ////////////////////////////////
40 | //Django Toolbar//
41 | ////////////////////////////////
42 |
43 | // Display django-debug-toolbar.
44 | // See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742
45 | // and https://github.com/pydanny/cookiecutter-django/issues/317
46 |
47 | [hidden][style="display: block;"] {
48 | display: block !important;
49 | }
50 |
--------------------------------------------------------------------------------
/src/src/components/Menubar/styles.scss:
--------------------------------------------------------------------------------
1 | .Menubar {
2 | grid-area: m;
3 |
4 | width: 100%;
5 |
6 | display: grid;
7 | grid-template-columns: 15% 6% 20% 38%;
8 | grid-template-rows: 100%;
9 | grid-template-areas: 't a r f';
10 |
11 | align-items: center;
12 |
13 | background-color: #ffffff;
14 | color: #003569;
15 |
16 | .appTitle {
17 | grid-area: t;
18 |
19 | font-size: 30px;
20 | font-weight: 800;
21 | text-transform: uppercase;
22 | align-items: center;
23 | margin-left: 10px;
24 | }
25 |
26 | .addDataset {
27 | grid-area: d;
28 | align-items: center;
29 | padding: 9px 9px;
30 |
31 | display: grid;
32 | .addDatasetTitle {
33 | justify-self: center;
34 | }
35 | }
36 | .addRanking {
37 | grid-area: a;
38 | align-items: center;
39 | justify-self: center;
40 | padding: 17px 20px;
41 | }
42 |
43 | .FilterView {
44 | grid-area: f;
45 | justify-self: end;
46 | align-self: end;
47 | padding-bottom: 5px;
48 | font-size: 1.1rem;
49 | }
50 |
51 | .ranking {
52 | grid-area: r;
53 | }
54 |
55 | .ProcessIndicator > div > div {
56 | font-size: 0.9rem;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/requirements/local.txt:
--------------------------------------------------------------------------------
1 | -r ./base.txt
2 |
3 | Werkzeug==0.14.1 # https://github.com/pallets/werkzeug
4 | ipdb==0.11 # https://github.com/gotcha/ipdb
5 | Sphinx==1.7.6 # https://github.com/sphinx-doc/sphinx
6 | psycopg2-binary==2.7.5 # https://github.com/psycopg/psycopg2
7 |
8 | # Testing
9 | # ------------------------------------------------------------------------------
10 | pytest==3.6.4 # https://github.com/pytest-dev/pytest
11 | pytest-sugar==0.9.1 # https://github.com/Frozenball/pytest-sugar
12 |
13 | # Code quality
14 | # ------------------------------------------------------------------------------
15 | flake8==3.5.0 # https://github.com/PyCQA/flake8
16 | coverage==4.5.1 # https://github.com/nedbat/coveragepy
17 |
18 | # Django
19 | # ------------------------------------------------------------------------------
20 | factory-boy==2.11.1 # https://github.com/FactoryBoy/factory_boy
21 |
22 | django-debug-toolbar==1.9.1 # https://github.com/jazzband/django-debug-toolbar
23 | django-extensions==2.1.0 # https://github.com/django-extensions/django-extensions
24 | django-coverage-plugin==1.5.0 # https://github.com/nedbat/django_coverage_plugin
25 | pytest-django==3.3.3 # https://github.com/pytest-dev/pytest-django
26 |
--------------------------------------------------------------------------------
/app/contrib/sites/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | import django.contrib.sites.models
2 | from django.contrib.sites.models import _simple_domain_name_validator
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = []
9 |
10 | operations = [
11 | migrations.CreateModel(
12 | name='Site',
13 | fields=[
14 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
15 | ('domain', models.CharField(
16 | max_length=100, verbose_name='domain name', validators=[_simple_domain_name_validator]
17 | )),
18 | ('name', models.CharField(max_length=50, verbose_name='display name')),
19 | ],
20 | options={
21 | 'ordering': ('domain',),
22 | 'db_table': 'django_site',
23 | 'verbose_name': 'site',
24 | 'verbose_name_plural': 'sites',
25 | },
26 | bases=(models.Model,),
27 | managers=[
28 | ('objects', django.contrib.sites.models.SiteManager()),
29 | ],
30 | ),
31 | ]
32 |
--------------------------------------------------------------------------------
/app/contrib/sites/migrations/0003_set_site_domain_and_name.py:
--------------------------------------------------------------------------------
1 | """
2 | To understand why this file is here, please read:
3 |
4 | http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
5 | """
6 | from django.conf import settings
7 | from django.db import migrations
8 |
9 |
10 | def update_site_forward(apps, schema_editor):
11 | """Set site domain and name."""
12 | Site = apps.get_model('sites', 'Site')
13 | Site.objects.update_or_create(
14 | id=settings.SITE_ID,
15 | defaults={
16 | 'domain': 'app.com',
17 | 'name': 'app'
18 | }
19 | )
20 |
21 |
22 | def update_site_backward(apps, schema_editor):
23 | """Revert site domain and name to default."""
24 | Site = apps.get_model('sites', 'Site')
25 | Site.objects.update_or_create(
26 | id=settings.SITE_ID,
27 | defaults={
28 | 'domain': 'example.com',
29 | 'name': 'example.com'
30 | }
31 | )
32 |
33 |
34 | class Migration(migrations.Migration):
35 |
36 | dependencies = [
37 | ('sites', '0002_alter_domain_unique'),
38 | ]
39 |
40 | operations = [
41 | migrations.RunPython(update_site_forward, update_site_backward),
42 | ]
43 |
--------------------------------------------------------------------------------
/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 | url = "https://pypi.org/simple"
3 | verify_ssl = true
4 | name = "pypi"
5 |
6 | [packages]
7 | pytz = "==2018.5"
8 | python-slugify = "==1.2.5"
9 | redis = ">=2.10.5"
10 | django-environ = "==0.4.5"
11 | django-model-utils = "==3.1.2"
12 | django-allauth = "==0.36.0"
13 | django-crispy-forms = "==1.7.2"
14 | django-redis = "==4.9.0"
15 | djangorestframework = "==3.8.2"
16 | coreapi = "==2.3.3"
17 | ipdb = "==0.11"
18 | "psycopg2-binary" = "==2.7.5"
19 | pytest = "==3.6.4"
20 | pytest-sugar = "==0.9.1"
21 | "flake8" = "==3.5.0"
22 | coverage = "==4.5.1"
23 | django-debug-toolbar = "==1.9.1"
24 | django-extensions = "==2.1.0"
25 | pytest-django = "==3.3.3"
26 | Pillow = "==5.2.0"
27 | "argon2_cffi" = "==18.1.0"
28 | Django = "==2.0.8"
29 | Werkzeug = "==0.14.1"
30 | Sphinx = "==1.7.6"
31 | factory_boy = "==2.11.1"
32 | django_coverage_plugin = "==1.5.0"
33 | setuptools = "*"
34 | django-taggit = "*"
35 | django-taggit-serializer = "*"
36 | django-rest-auth = "*"
37 | django-cors-headers = "*"
38 | djangorestframework-jwt = "*"
39 | numpy = "*"
40 | pandas = "*"
41 | scikit-learn = "*"
42 | statsmodels = "*"
43 | scipy = "*"
44 | simplejson = "*"
45 | themis-ml = "*"
46 | django-storages = "*"
47 | fairsearchcore = "*"
48 |
49 | [dev-packages]
50 |
51 | [requires]
52 | python_version = "3.7"
53 |
--------------------------------------------------------------------------------
/src/src/index.css:
--------------------------------------------------------------------------------
1 | .title {
2 | display: flex;
3 | align-items: center;
4 |
5 | height: 35px;
6 | padding: 10px;
7 | /* font-weight: 600; */
8 | /* background-color: #747373;
9 | border: 1px solid #565555; */
10 | color: white;
11 | font-size: 1.1rem;
12 | text-transform: uppercase;
13 | }
14 |
15 | .subTitle {
16 | font-size: 1.2rem;
17 | margin-bottom: 15px;
18 | height: 35px;
19 | padding: 5px;
20 | }
21 |
22 | .subTitle2 {
23 | color: #00346b;
24 | font-size: 1rem;
25 | font-weight: 500;
26 | margin-top: 10px;
27 | margin-bottom: 15px;
28 | }
29 |
30 | .featureTitle {
31 | margin: 5px 0;
32 | color: #2196f3;
33 | font-size: 1rem;
34 | text-transform: uppercase;
35 | }
36 |
37 | .instanceIdTitle {
38 | margin: 5px 0;
39 | color: #2196f3;
40 | font-size: 1rem;
41 | text-transform: uppercase;
42 | }
43 |
44 | .description {
45 | font-family: 'Titillium Web';
46 | }
47 |
48 | .step1 i {
49 | color: #b5dafe;
50 | font-size: 1.6rem;
51 | }
52 | .step2 i {
53 | color: #54aaff;
54 | font-size: 1.6rem;
55 | }
56 | .step3 i {
57 | color: #1c88f3;
58 | font-size: 1.6rem;
59 | }
60 | .step4 i {
61 | color: #0575e5;
62 | font-size: 1.6rem;
63 | }
64 | .step5 i {
65 | color: #003569;
66 | font-size: 1.6rem;
67 | }
68 |
69 | /* Loading for model running */
70 | .isModelRunning {
71 | opacity: 0.3;
72 | }
73 |
--------------------------------------------------------------------------------
/src/src/components/RankingInspectorView/FeatureInspectionView/styles.scss:
--------------------------------------------------------------------------------
1 | .FeatureInspectionView {
2 | height: 500px;
3 |
4 | .featureInspectionWrapper {
5 | font-weight: 500;
6 | }
7 |
8 | .featureInspectorOverview {
9 | display: flex;
10 | }
11 |
12 | .featureInspectorTitle {
13 | background-color: #033568;
14 | color: white;
15 | margin-bottom: 0;
16 | margin-top: 5px;
17 | }
18 |
19 | .outlierAnalysis {
20 | width: 33%;
21 | height: 250px;
22 | margin: 5px;
23 | padding: 10px;
24 | background-color: #f0f0f0;
25 | overflow-y: scroll;
26 | }
27 | .featureListForOutlier {
28 | overflow-y: scroll;
29 | }
30 | .featureForOutlierTitle {
31 | display: flex;
32 | justify-content: space-between;
33 | }
34 | .similarity {
35 | font-size: 0.9rem;
36 | }
37 | .featureInspectorOverview {
38 | display: flex;
39 | }
40 | .featureRow {
41 |
42 | }
43 | .perturbedMeasure {
44 | margin: 5px 0;
45 | color: #023d74;
46 | font-size: 0.9rem;
47 | font-weight: 600;
48 | }
49 | .ccAnalysis { // Counterfactuals and Critical Region
50 | width: 66%;
51 | height: 250px;
52 | margin: 5px;
53 | padding: 10px;
54 | background-color: #f0f0f0;
55 | overflow-y: scroll;
56 | }
57 | .featureImpactsList {
58 | width: 100%;
59 | }
60 | .ccForFeature {
61 | width: 100%;
62 | margin: 5px;
63 | padding: 10px;
64 | }
65 | }
--------------------------------------------------------------------------------
/app/templates/account/login.html:
--------------------------------------------------------------------------------
1 | {% extends "account/base.html" %}
2 |
3 | {% load i18n %}
4 | {% load account socialaccount %}
5 | {% load crispy_forms_tags %}
6 |
7 | {% block head_title %}{% trans "Sign In" %}{% endblock %}
8 |
9 | {% block inner %}
10 |
11 | {% trans "Sign In" %}
12 |
13 | {% get_providers as socialaccount_providers %}
14 |
15 | {% if socialaccount_providers %}
16 | {% blocktrans with site.name as site_name %}Please sign in with one
17 | of your existing third party accounts. Or, sign up
18 | for a {{ site_name }} account and sign in below:{% endblocktrans %}
19 |
20 |
21 |
22 |
23 | {% include "socialaccount/snippets/provider_list.html" with process="login" %}
24 |
25 |
26 |
{% trans 'or' %}
27 |
28 |
29 |
30 | {% include "socialaccount/snippets/login_extra.html" %}
31 |
32 | {% else %}
33 | {% blocktrans %}If you have not created an account yet, then please
34 | sign up first.{% endblocktrans %}
35 | {% endif %}
36 |
37 |
46 |
47 | {% endblock %}
48 |
49 |
--------------------------------------------------------------------------------
/src/src/components/Menubar/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import {
3 | Alert,
4 | FormGroup,
5 | FormText,
6 | Input,
7 | Label,
8 | Badge,
9 | Dropdown,
10 | DropdownToggle,
11 | DropdownMenu,
12 | DropdownItem
13 | } from 'reactstrap';
14 | import Slider from 'react-rangeslider';
15 | import { Button, Steps, Icon } from 'antd';
16 |
17 | import styles from './styles.scss';
18 | import index from '../../index.css';
19 |
20 | class Menubar extends Component {
21 | constructor(props) {
22 | super(props);
23 |
24 | this.toggle = this.toggle.bind(this);
25 | this.state = {
26 | dropdownOpen: false,
27 | dataset: {},
28 | ranking: {}
29 | };
30 | }
31 |
32 | shouldComponentUpdate(nextProps, nextState) {
33 | if (this.props.topk !== nextProps.topk) {
34 | return true;
35 | }
36 | if (this.props.data !== nextProps.data) {
37 | return true;
38 | }
39 |
40 | return false;
41 | }
42 |
43 | toggle() {
44 | this.setState({
45 | dropdownOpen: !this.state.dropdownOpen
46 | });
47 |
48 | //this.props.onSelectSensitiveAttr(sensitiveAttr); // Then declare it
49 | }
50 |
51 | render() {
52 | if (!this.props.data || this.props.data.length === 0) {
53 | return
;
54 | }
55 | const Step = Steps.Step;
56 | const data = this.props.data;
57 |
58 | return (
59 |
60 |
FAIRSIGHT
61 |
62 | +
63 |
64 |
65 | );
66 | }
67 | }
68 |
69 | export default Menubar;
70 |
--------------------------------------------------------------------------------
/config/urls.py:
--------------------------------------------------------------------------------
1 | from django.conf import settings
2 | from django.conf.urls import include, url
3 | from django.conf.urls.static import static
4 | from django.contrib import admin
5 | from django.views.generic import TemplateView
6 | from django.views import defaults as default_views
7 | from rest_framework_jwt.views import obtain_jwt_token
8 | from app import views
9 |
10 | urlpatterns = [
11 | # Django Admin, use {% url 'admin:index' %}
12 | url(settings.ADMIN_URL, admin.site.urls),
13 |
14 | # User management
15 | url(r'^rest-auth/', include('rest_auth.urls')),
16 | url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
17 | url(r'^dataset/', include(('app.dataset.urls', 'dataset'), namespace='dataset'))
18 | #url(r'^', views.ReactAppView.as_view()),
19 |
20 |
21 | ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
22 |
23 | if settings.DEBUG:
24 | # This allows the error pages to be debugged during development, just visit
25 | # these url in browser to see how these error pages look like.
26 | urlpatterns += [
27 | url(r'^400/$', default_views.bad_request,
28 | kwargs={'exception': Exception('Bad Request!')}),
29 | url(r'^403/$', default_views.permission_denied,
30 | kwargs={'exception': Exception('Permission Denied')}),
31 | url(r'^404/$', default_views.page_not_found,
32 | kwargs={'exception': Exception('Page not Found')}),
33 | url(r'^500/$', default_views.server_error),
34 | ]
35 | if 'debug_toolbar' in settings.INSTALLED_APPS:
36 | import debug_toolbar
37 | urlpatterns = [
38 | url(r'^__debug__/', include(debug_toolbar.urls)),
39 | ] + urlpatterns
40 |
--------------------------------------------------------------------------------
/app/static/lib/prediction_interval.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import numpy as np
3 | from sklearn import datasets, linear_model
4 | from __future__ import division
5 |
6 | class LRPI:
7 | def __init__(self, normalize=False, n_jobs=1, t_value = 2.13144955):
8 | self.normalize = normalize
9 | self.n_jobs = n_jobs
10 | self.LR = linear_model.LinearRegression(normalize=self.normalize, n_jobs= self.n_jobs)
11 | self.t_value = t_value
12 |
13 | def fit(self, X_train, y_train):
14 | self.X_train = pd.DataFrame(X_train.values)
15 | self.y_train = pd.DataFrame(y_train.values)
16 |
17 | self.LR.fit(self.X_train, self.y_train)
18 | X_train_fit = self.LR.predict(self.X_train)
19 | self.MSE = np.power(self.y_train.subtract(X_train_fit), 2).sum(axis=0) / (self.X_train.shape[0] - self.X_train.shape[1] - 1)
20 | self.X_train.loc[:, 'const_one'] = 1
21 | self.XTX_inv = np.linalg.inv(np.dot(np.transpose(self.X_train.values) , self.X_train.values))
22 |
23 | def predict(self, X_test):
24 | self.X_test = pd.DataFrame(X_test.values)
25 | self.pred = self.LR.predict(self.X_test)
26 | self.X_test.loc[: , 'const_one'] =1
27 | SE = [np.dot(np.transpose(self.X_test.values[i]) , np.dot(self.XTX_inv, self.X_test.values[i]) ) for i in range(len(self.X_test)) ]
28 | results = pd.DataFrame(self.pred , columns=['Pred'])
29 |
30 | results.loc[:,"lower"] = results['Pred'].subtract((self.t_value)* (np.sqrt(self.MSE.values + np.multiply(SE,self.MSE.values) )), axis=0)
31 | results.loc[:,"upper"] = results['Pred'].add((self.t_value)* (np.sqrt(self.MSE.values + np.multiply(SE,self.MSE.values) )), axis=0)
32 |
33 | return results
--------------------------------------------------------------------------------
/src/src/components/RankingsListView/styles.scss:
--------------------------------------------------------------------------------
1 | .RankingsListView {
2 | grid-area: l;
3 |
4 | // border: 1px solid #e3e1e1;
5 | overflow-y: scroll;
6 |
7 | .titleWrapper {
8 | display: flex;
9 | background-color: #00346b;
10 | height: 35px;
11 | margin-left: 5px;
12 |
13 | .title {
14 | }
15 | .step5 {
16 | color: #003569;
17 | font-size: 1.6rem;
18 | margin-top: 12px;
19 | margin-left: 5px;
20 | }
21 | }
22 |
23 | .spaceTitle {
24 | width: 18px;
25 | background-color: #003569;
26 | color: white;
27 | border-radius: 2px;
28 | text-align: center;
29 | }
30 | .spaceTitleUtility {
31 | width: 18px;
32 | background-color: #c91765;
33 | color: white;
34 | border-radius: 2px;
35 | text-align: center;
36 | }
37 | .spaceTitleLong {
38 | width: 40px;
39 | background-color: #003569;
40 | color: white;
41 | border-radius: 2px;
42 | text-align: center;
43 | }
44 | }
45 |
46 | .rankingList {
47 | background-color: gray;
48 | border: 1px solid darkgray;
49 | }
50 |
51 | .svgRankingList {
52 | width: 100%;
53 | height: 100%;
54 | background-color: bisque;
55 | }
56 |
57 | .rankingCondition {
58 | margin: 0 5px;
59 | font-weight: 600;
60 | color: #686868;
61 | }
62 |
63 | .addRanking {
64 | display: flex;
65 | justify-content: center;
66 |
67 | margin: 5px;
68 | font-size: 20px;
69 | font-weight: bold;
70 | color: gray;
71 | border: 1px dashed gray;
72 | }
73 |
74 | .rankingInstanceWrapper {
75 | height: 40px;
76 | margin: 5px;
77 | display: -ms-flexbox;
78 | display: flex;
79 | border-bottom: 1px solid #e6e6e6;
80 | background-color: white;
81 | padding: 10px 0;
82 | }
83 |
84 | .rankingComparisonTable {
85 | margin-left: 10px;
86 | }
87 |
--------------------------------------------------------------------------------
/config/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for app project.
3 |
4 | This module contains the WSGI application used by Django's development server
5 | and any production WSGI deployments. It should expose a module-level variable
6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7 | this application via the ``WSGI_APPLICATION`` setting.
8 |
9 | Usually you will have the standard Django WSGI application here, but it also
10 | might make sense to replace the whole Django WSGI application with a custom one
11 | that later delegates to the Django one. For example, you could introduce WSGI
12 | middleware here, or combine a Django application with an application of another
13 | framework.
14 |
15 | """
16 | import os
17 | import sys
18 |
19 | from django.core.wsgi import get_wsgi_application
20 |
21 | # This allows easy placement of apps within the interior
22 | # app directory.
23 | app_path = os.path.dirname(os.path.abspath(__file__)).replace('/config', '')
24 | sys.path.append(os.path.join(app_path, 'app'))
25 |
26 |
27 |
28 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
29 | # if running multiple sites in the same mod_wsgi process. To fix this, use
30 | # mod_wsgi daemon mode with each site in its own daemon process, or use
31 | # os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production"
32 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
33 |
34 | # This application object is used by any WSGI server configured to use this
35 | # file. This includes Django's development server, if the WSGI_APPLICATION
36 | # setting points here.
37 | application = get_wsgi_application()
38 |
39 | # Apply WSGI middleware here.
40 | # from helloworld.wsgi import HelloWorldApplication
41 | # application = HelloWorldApplication(application)
42 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | My Awesome Project
2 | ==================
3 |
4 | Behold My Awesome Project!
5 |
6 | .. image:: https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg
7 | :target: https://github.com/pydanny/cookiecutter-django/
8 | :alt: Built with Cookiecutter Django
9 |
10 |
11 | :License: MIT
12 |
13 |
14 | Settings
15 | --------
16 |
17 | Moved to settings_.
18 |
19 | .. _settings: http://cookiecutter-django.readthedocs.io/en/latest/settings.html
20 |
21 | Basic Commands
22 | --------------
23 |
24 | Setting Up Your Users
25 | ^^^^^^^^^^^^^^^^^^^^^
26 |
27 | * To create a **normal user account**, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.
28 |
29 | * To create an **superuser account**, use this command::
30 |
31 | $ python manage.py createsuperuser
32 |
33 | For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.
34 |
35 | Test coverage
36 | ^^^^^^^^^^^^^
37 |
38 | To run the tests, check your test coverage, and generate an HTML coverage report::
39 |
40 | $ coverage run -m pytest
41 | $ coverage html
42 | $ open htmlcov/index.html
43 |
44 | Running tests with py.test
45 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
46 |
47 | ::
48 |
49 | $ pytest
50 |
51 | Live reloading and Sass CSS compilation
52 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53 |
54 | Moved to `Live reloading and SASS compilation`_.
55 |
56 | .. _`Live reloading and SASS compilation`: http://cookiecutter-django.readthedocs.io/en/latest/live-reloading-and-sass-compilation.html
57 |
58 |
59 |
60 |
61 |
62 | Deployment
63 | ----------
64 |
65 | The following details how to deploy this application.
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/config/settings/local.py:
--------------------------------------------------------------------------------
1 | """
2 | Local settings
3 |
4 | - Run in Debug mode
5 |
6 | - Use mailhog for emails
7 |
8 | - Add Django Debug Toolbar
9 | - Add django-extensions as app
10 | """
11 |
12 | from .base import * # noqa
13 |
14 | # DEBUG
15 | # ------------------------------------------------------------------------------
16 | DEBUG = env.bool('DJANGO_DEBUG', default=True)
17 | TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
18 |
19 | # SECRET CONFIGURATION
20 | # ------------------------------------------------------------------------------
21 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
22 | # Note: This key only used for development and testing.
23 | SECRET_KEY = env('DJANGO_SECRET_KEY', default='.80h]pfMpBKYeMmBUKB`[YN$7q*7^y<284RUt#zq[eWJG[]k&c')
24 |
25 | # Mail settings
26 | # ------------------------------------------------------------------------------
27 |
28 | EMAIL_PORT = 1025
29 |
30 | EMAIL_HOST = 'localhost'
31 |
32 |
33 | # CACHING
34 | # ------------------------------------------------------------------------------
35 | CACHES = {
36 | 'default': {
37 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
38 | 'LOCATION': ''
39 | }
40 | }
41 |
42 | # django-debug-toolbar
43 | # ------------------------------------------------------------------------------
44 | MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ]
45 | INSTALLED_APPS += ['debug_toolbar', ]
46 |
47 | INTERNAL_IPS = ['127.0.0.1', '10.0.2.2', ]
48 |
49 | DEBUG_TOOLBAR_CONFIG = {
50 | 'DISABLE_PANELS': [
51 | 'debug_toolbar.panels.redirects.RedirectsPanel',
52 | ],
53 | 'SHOW_TEMPLATE_CONTEXT': True,
54 | }
55 |
56 | # django-extensions
57 | # ------------------------------------------------------------------------------
58 | INSTALLED_APPS += ['django_extensions', ]
59 |
60 | # TESTING
61 | # ------------------------------------------------------------------------------
62 | TEST_RUNNER = 'django.test.runner.DiscoverRunner'
63 |
64 | # Your local stuff: Below this line define 3rd party library settings
65 | # ------------------------------------------------------------------------------
66 |
--------------------------------------------------------------------------------
/config/settings/test.py:
--------------------------------------------------------------------------------
1 | '''
2 | Test settings
3 |
4 | - Used to run tests fast on the continuous integration server and locally
5 | '''
6 |
7 | from .base import * # noqa
8 |
9 |
10 | # DEBUG
11 | # ------------------------------------------------------------------------------
12 | # Turn debug off so tests run faster
13 | DEBUG = False
14 | TEMPLATES[0]['OPTIONS']['debug'] = False
15 |
16 | # SECRET CONFIGURATION
17 | # ------------------------------------------------------------------------------
18 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
19 | # Note: This key only used for development and testing.
20 | SECRET_KEY = env('DJANGO_SECRET_KEY', default='CHANGEME!!!')
21 |
22 | # Mail settings
23 | # ------------------------------------------------------------------------------
24 | EMAIL_HOST = 'localhost'
25 | EMAIL_PORT = 1025
26 |
27 | # In-memory email backend stores messages in django.core.mail.outbox
28 | # for unit testing purposes
29 | EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
30 |
31 | # CACHING
32 | # ------------------------------------------------------------------------------
33 | # Speed advantages of in-memory caching without having to run Memcached
34 | CACHES = {
35 | 'default': {
36 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
37 | 'LOCATION': ''
38 | }
39 | }
40 |
41 | # TESTING
42 | # ------------------------------------------------------------------------------
43 | TEST_RUNNER = 'django.test.runner.DiscoverRunner'
44 |
45 |
46 | # PASSWORD HASHING
47 | # ------------------------------------------------------------------------------
48 | # Use fast password hasher so tests run faster
49 | # PASSWORD_HASHERS = [
50 | # 'django.contrib.auth.hashers.MD5PasswordHasher',
51 | # ]
52 |
53 | # TEMPLATE LOADERS
54 | # ------------------------------------------------------------------------------
55 | # Keep templates in memory so tests run faster
56 | TEMPLATES[0]['OPTIONS']['loaders'] = [
57 | ['django.template.loaders.cached.Loader', [
58 | 'django.template.loaders.filesystem.Loader',
59 | 'django.template.loaders.app_directories.Loader',
60 | ], ],
61 | ]
62 |
--------------------------------------------------------------------------------
/src/config/paths.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const path = require('path');
4 | const fs = require('fs');
5 | const url = require('url');
6 |
7 | // Make sure any symlinks in the project folder are resolved:
8 | // https://github.com/facebookincubator/create-react-app/issues/637
9 | const appDirectory = fs.realpathSync(process.cwd());
10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
11 |
12 | const envPublicUrl = process.env.PUBLIC_URL;
13 |
14 | function ensureSlash(path, needsSlash) {
15 | const hasSlash = path.endsWith('/');
16 | if (hasSlash && !needsSlash) {
17 | return path.substr(path, path.length - 1);
18 | } else if (!hasSlash && needsSlash) {
19 | return `${path}/`;
20 | } else {
21 | return path;
22 | }
23 | }
24 |
25 | const getPublicUrl = appPackageJson =>
26 | envPublicUrl || require(appPackageJson).homepage;
27 |
28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer
29 | // "public path" at which the app is served.
30 | // Webpack needs to know it to put the right
79 | {% endblock %}
80 |
81 |
--------------------------------------------------------------------------------
/src/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "src",
3 | "version": "0.1.0",
4 | "private": true,
5 | "proxy": "http://localhost:8000",
6 | "dependencies": {
7 | "@blueprintjs/core": "^3.2.0",
8 | "@vx/axis": "^0.0.173",
9 | "@vx/brush": "^0.0.165",
10 | "@vx/group": "^0.0.170",
11 | "@vx/mock-data": "^0.0.165",
12 | "@vx/scale": "^0.0.165",
13 | "@vx/shape": "^0.0.171",
14 | "antd": "^3.8.2",
15 | "autoprefixer": "7.1.2",
16 | "babel-core": "6.25.0",
17 | "babel-eslint": "7.2.3",
18 | "babel-jest": "20.0.3",
19 | "babel-loader": "7.1.1",
20 | "babel-preset-react-app": "^3.0.3",
21 | "babel-runtime": "6.26.0",
22 | "bootstrap": "^4.1.3",
23 | "case-sensitive-paths-webpack-plugin": "2.1.1",
24 | "chalk": "1.1.3",
25 | "chi-squared-test": "^1.1.0",
26 | "crossfilter": "^1.3.12",
27 | "css-loader": "0.28.4",
28 | "d3": "^5.5.0",
29 | "d3-beeswarm": "^0.0.5",
30 | "d3-tip": "^0.9.1",
31 | "d3-tooltip": "^0.0.1",
32 | "dc": "^3.0.6",
33 | "dotenv": "4.0.0",
34 | "eslint": "4.4.1",
35 | "eslint-config-react-app": "^2.0.1",
36 | "eslint-loader": "1.9.0",
37 | "eslint-plugin-flowtype": "2.35.0",
38 | "eslint-plugin-import": "2.7.0",
39 | "eslint-plugin-jsx-a11y": "5.1.1",
40 | "eslint-plugin-react": "7.1.0",
41 | "extract-text-webpack-plugin": "3.0.0",
42 | "file-loader": "0.11.2",
43 | "fs-extra": "3.0.1",
44 | "history": "^4.7.2",
45 | "html-webpack-plugin": "2.29.0",
46 | "jest": "20.0.4",
47 | "lodash": "^4.17.10",
48 | "lodash.unionby": "^4.8.0",
49 | "node-sass": "^4.5.3",
50 | "object-assign": "4.1.1",
51 | "postcss-flexbugs-fixes": "3.2.0",
52 | "postcss-loader": "2.0.6",
53 | "promise": "8.0.1",
54 | "prop-types": "^15.6.2",
55 | "react": "^16.0.0",
56 | "react-d3-brush": "^1.1.0",
57 | "react-dc": "^1.0.6",
58 | "react-dev-utils": "^4.1.0",
59 | "react-dom": "^16.4.1",
60 | "react-faux-dom": "^4.2.0",
61 | "react-loading-skeleton": "^1.0.0",
62 | "react-motion": "^0.5.2",
63 | "react-rangeslider": "^2.2.0",
64 | "react-redux": "^5.0.6",
65 | "react-router-dom": "^4.2.2",
66 | "react-router-redux": "^5.0.0-alpha.8",
67 | "react-spinners": "^0.5.3",
68 | "react-svg-tooltip": "^0.0.10",
69 | "react-tracker": "^0.0.8",
70 | "reactstrap": "^6.2.0",
71 | "redux": "^3.7.2",
72 | "redux-thunk": "^2.2.0",
73 | "regression": "^2.0.1",
74 | "reset-css": "^4.0.1",
75 | "sass-loader": "^6.0.6",
76 | "style-loader": "0.18.2",
77 | "sw-precache-webpack-plugin": "0.11.4",
78 | "translations": "^2.2.1",
79 | "ttest": "^1.1.0",
80 | "url-loader": "0.5.9",
81 | "webpack": "3.5.1",
82 | "webpack-dev-server": "2.8.2",
83 | "webpack-manifest-plugin": "1.2.1",
84 | "whatwg-fetch": "2.0.3"
85 | },
86 | "scripts": {
87 | "start": "node scripts/start.js",
88 | "build": "node scripts/build.js"
89 | },
90 | "babel": {
91 | "presets": [
92 | "react-app"
93 | ]
94 | },
95 | "eslintConfig": {
96 | "extends": "react-app"
97 | },
98 | "devDependencies": {
99 | "reactotron-react-js": "^1.12.2",
100 | "reactotron-redux": "^1.12.2",
101 | "redux-devtools-extension": "^2.13.2",
102 | "redux-logger": "^3.0.6"
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/src/components/UtilityView/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import * as d3 from 'd3';
3 | import _ from 'lodash';
4 | import ReactFauxDOM from 'react-faux-dom';
5 |
6 | import styles from './styles.scss';
7 | import index from '../../index.css';
8 | import gs from '../../config/_variables.scss'; // gs (=global style)
9 |
10 | /* props: this.props.ranking
11 | => selected ranking data
12 | */
13 | class UtilityView extends Component {
14 | constructor(props) {
15 | super(props);
16 | this.svg;
17 | this.layout = {
18 | width: 500,
19 | height: 80,
20 | margin: 10,
21 | marginLeft: 15,
22 | svg: {
23 | width: 450,
24 | height: 60
25 | }
26 | };
27 | }
28 |
29 | render() {
30 | const { rankingInstance, n, topk } = this.props;
31 | let sampleData = [
32 | { topK: 10, statParity: 0, conditionalParity: 0 },
33 | { topK: 15, statParity: 0.5, conditionalParity: -0.3 },
34 | { topK: 20, statParity: -0.8, conditionalParity: 0.4 },
35 | { topK: 25, statParity: -0.6, conditionalParity: -0.7 },
36 | { topK: 30, statParity: 0, conditionalParity: 0.6 },
37 | { topK: 35, statParity: 1.2, conditionalParity: 1.1 }
38 | ],
39 | gPlot,
40 | xTopKScale,
41 | yLogScoreScale,
42 | xAxisSetting,
43 | yAxisSetting,
44 | xAxis,
45 | yAxis,
46 | statParityDots,
47 | statParityLine,
48 | statParityPath,
49 | conditionalParityDots,
50 | conditionalParityLine,
51 | conditionalParityPath;
52 |
53 | this.svg = new ReactFauxDOM.Element('svg');
54 |
55 | this.svg.setAttribute('width', this.layout.svg.width);
56 | this.svg.setAttribute('height', this.layout.svg.height);
57 | this.svg.setAttribute('0 0 100 100');
58 | this.svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
59 |
60 | gPlot = d3
61 | .select(this.svg)
62 | .append('g')
63 | .attr('transform', 'translate(' + this.layout.marginLeft + ',0)');
64 |
65 | xTopKScale = d3
66 | .scaleLinear()
67 | .domain([1, n])
68 | .range([0, this.layout.svg.width - this.layout.margin]);
69 |
70 | yLogScoreScale = d3
71 | .scaleLinear()
72 | .domain([-2, 2])
73 | .range([this.layout.svg.height - this.layout.margin, this.layout.margin]);
74 |
75 | xAxisSetting = d3
76 | .axisBottom(xTopKScale)
77 | .tickSize(0)
78 | .ticks(5);
79 | yAxisSetting = d3
80 | .axisLeft(yLogScoreScale)
81 | .tickSize(0)
82 | .ticks(5);
83 |
84 | xAxis = d3
85 | .select(this.svg)
86 | .append('g')
87 | .call(xAxisSetting)
88 | .attr('class', 'xAxis')
89 | .attr(
90 | 'transform',
91 | 'translate(' +
92 | this.layout.marginLeft +
93 | ',' +
94 | (this.layout.svg.height - this.layout.margin) +
95 | ')'
96 | );
97 |
98 | yAxis = d3
99 | .select(this.svg)
100 | .append('g')
101 | .call(yAxisSetting)
102 | .attr('class', 'yAxis')
103 | .attr('transform', 'translate(' + this.layout.marginLeft + ',0)');
104 |
105 | return (
106 |
107 |
Utility
108 | {/*
(Statistical parity, Conditional parity)
*/}
109 | {this.svg.toReact()}
110 |
111 | );
112 | }
113 | }
114 |
115 | export default UtilityView;
116 |
--------------------------------------------------------------------------------
/src/config/env.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const fs = require('fs');
4 | const path = require('path');
5 | const paths = require('./paths');
6 |
7 | // Make sure that including paths.js after env.js will read .env variables.
8 | delete require.cache[require.resolve('./paths')];
9 |
10 | const NODE_ENV = process.env.NODE_ENV;
11 | if (!NODE_ENV) {
12 | throw new Error(
13 | 'The NODE_ENV environment variable is required but was not specified.'
14 | );
15 | }
16 |
17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
18 | var dotenvFiles = [
19 | `${paths.dotenv}.${NODE_ENV}.local`,
20 | `${paths.dotenv}.${NODE_ENV}`,
21 | // Don't include `.env.local` for `test` environment
22 | // since normally you expect tests to produce the same
23 | // results for everyone
24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`,
25 | paths.dotenv,
26 | ].filter(Boolean);
27 |
28 | // Load environment variables from .env* files. Suppress warnings using silent
29 | // if this file is missing. dotenv will never modify any environment variables
30 | // that have already been set.
31 | // https://github.com/motdotla/dotenv
32 | dotenvFiles.forEach(dotenvFile => {
33 | if (fs.existsSync(dotenvFile)) {
34 | require('dotenv').config({
35 | path: dotenvFile,
36 | });
37 | }
38 | });
39 |
40 | // We support resolving modules according to `NODE_PATH`.
41 | // This lets you use absolute paths in imports inside large monorepos:
42 | // https://github.com/facebookincubator/create-react-app/issues/253.
43 | // It works similar to `NODE_PATH` in Node itself:
44 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
45 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
46 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
47 | // https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
48 | // We also resolve them to make sure all tools using them work consistently.
49 | const appDirectory = fs.realpathSync(process.cwd());
50 | process.env.NODE_PATH = (process.env.NODE_PATH || '')
51 | .split(path.delimiter)
52 | .filter(folder => folder && !path.isAbsolute(folder))
53 | .map(folder => path.resolve(appDirectory, folder))
54 | .join(path.delimiter);
55 |
56 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
57 | // injected into the application via DefinePlugin in Webpack configuration.
58 | const REACT_APP = /^REACT_APP_/i;
59 |
60 | function getClientEnvironment(publicUrl) {
61 | const raw = Object.keys(process.env)
62 | .filter(key => REACT_APP.test(key))
63 | .reduce(
64 | (env, key) => {
65 | env[key] = process.env[key];
66 | return env;
67 | },
68 | {
69 | // Useful for determining whether we’re running in production mode.
70 | // Most importantly, it switches React into the correct mode.
71 | NODE_ENV: process.env.NODE_ENV || 'development',
72 | // Useful for resolving the correct path to static assets in `public`.
73 | // For example, .
74 | // This should only be used as an escape hatch. Normally you would put
75 | // images into the `src` and `import` them in code to get their paths.
76 | PUBLIC_URL: publicUrl,
77 | }
78 | );
79 | // Stringify all values so we can feed into Webpack DefinePlugin
80 | const stringified = {
81 | 'process.env': Object.keys(raw).reduce((env, key) => {
82 | env[key] = JSON.stringify(raw[key]);
83 | return env;
84 | }, {}),
85 | };
86 |
87 | return { raw, stringified };
88 | }
89 |
90 | module.exports = getClientEnvironment;
91 |
--------------------------------------------------------------------------------
/src/src/components/App/styles.scss:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css?family=Lato:300,400,700');
2 | @import '@blueprintjs/core/lib/css/blueprint.css';
3 |
4 | body {
5 | background-color: $bg-color;
6 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
7 | Arial, sans-serif;
8 | color: $dark-blue;
9 | }
10 |
11 | .App {
12 | width: 97.5%;
13 | height: 1500px;
14 | margin: 0 auto;
15 | margin-top: 50px;
16 | margin-bottom: -10px;
17 |
18 | display: grid;
19 | row-gap: 10px;
20 | column-gap: 10px;
21 | grid-template-rows: 20px 30px 350px 400px 800px 80px;
22 | grid-template-columns: 20% 50% 28%;
23 | grid-template-areas:
24 | 'mg mg mg'
25 | 'm m m'
26 | 'g r l'
27 | 'g ri ri'
28 | 'g ri ri'
29 | 'f f f';
30 | }
31 |
32 | .marginDiv {
33 | grid-area: mg;
34 | }
35 | .Menubar {
36 | grid-area: m;
37 | }
38 | .Generator {
39 | grid-area: g;
40 | }
41 | .RankingView {
42 | grid-area: r;
43 | }
44 | .RankingsListView {
45 | grid-area: l;
46 | }
47 | .LocalInspectionView {
48 | grid-area: ii;
49 | }
50 | .Footer {
51 | grid-area: f;
52 | }
53 |
54 | .RankingInspector {
55 | grid-area: ri;
56 |
57 | display: grid;
58 | row-gap: 10px;
59 | column-gap: 10px;
60 | grid-template-rows: 250px 100px 250px 150px 350px;
61 | grid-template-columns: 20% 40% 20% 17%;
62 | grid-template-areas:
63 | 'd d d d'
64 | 'd d d d'
65 | 'd d d d';
66 | }
67 |
68 | .marginDiv1 {
69 | grid-area: mg1;
70 | }
71 | .marginDiv2 {
72 | grid-area: mg2;
73 | }
74 | .marginDiv3 {
75 | grid-area: mg3;
76 | }
77 | .marginDiv4 {
78 | grid-area: mg4;
79 | }
80 | .marginDiv5 {
81 | grid-area: mg5;
82 | }
83 | .marginDiv6 {
84 | grid-area: mg6;
85 | }
86 | .marginDiv7 {
87 | grid-area: mg7;
88 | }
89 | .marginDiv8 {
90 | grid-area: mg8;
91 | }
92 | .marginDiv9 {
93 | grid-area: mg9;
94 | }
95 | .marginDiv10 {
96 | grid-area: mg10;
97 | }
98 | .marginDiv10 {
99 | grid-area: mg11;
100 | }
101 | .marginDiv10 {
102 | grid-area: mg12;
103 | }
104 |
105 | .DatasetView,
106 | .InputSpaceView,
107 | .IndividualFairnessView,
108 | .GroupFairnessView,
109 | .RankingView,
110 | .UtilityView {
111 | margin: 10px;
112 | background-color: white;
113 | border-left: 1px solid lightgray;
114 | border-bottom: 1px solid lightgray;
115 | }
116 |
117 | .rankingInspectorTitle {
118 | grid-area: rt;
119 | }
120 | .InputSpaceView {
121 | grid-area: i;
122 | }
123 | // .LegendView { grid-area: lg; }
124 | // .CorrelationView { grid-area: cr; }
125 | .OutputSpaceView {
126 | grid-area: tr;
127 | }
128 | .LocalInspectionView {
129 | grid-area: ii;
130 | }
131 | .RankingInspectorView {
132 | grid-area: d;
133 | }
134 | // .GroupFairnessView { grid-area: gf; }
135 | .UtilityView {
136 | grid-area: u;
137 | }
138 |
139 | .margin {
140 | grid-column: 1 / 5;
141 | grid-row: 1 / 2;
142 | display: flex;
143 | align-items: flex-end;
144 | }
145 |
146 | // UI Components
147 | .step2 {
148 | color: #54aaff;
149 | font-size: 1.6rem;
150 | margin-top: 8px;
151 | margin-left: 5px;
152 | }
153 | .step3 {
154 | color: #1c88f3;
155 | font-size: 1.6rem;
156 | margin-top: 8px;
157 | margin-left: 5px;
158 | }
159 |
160 | .loadingScreen {
161 | width: 100%;
162 | height: 1500px;
163 | padding-top: 100px;
164 | text-align: center;
165 | background-color: #003569;
166 |
167 | .loadingLogo {
168 | color: white;
169 | font-size: 45px;
170 | font-weight: 800;
171 | text-transform: uppercase;
172 | }
173 |
174 | .loadingMessage {
175 | color: white;
176 | font-size: 20px;
177 | font-weight: 500;
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/src/src/components/RankingView/styles.scss:
--------------------------------------------------------------------------------
1 | .RankingView {
2 | grid-area: r;
3 | width: 99%;
4 | background-color: white;
5 | border-bottom: 1px solid lightgray;
6 |
7 | display: grid;
8 | row-gap: 10px;
9 | column-gap: 10px;
10 | grid-template-columns: 40% 30% 30%;
11 | grid-template-rows: 10% 10% 30% 20% 20%;
12 | grid-template-areas:
13 | 'crt crt crt'
14 | 'rvt ft ft'
15 | 'wrst tf if'
16 | 'wrp wrp wrp'
17 | 'rbw rbw rbw';
18 |
19 | .currentRankingTitle {
20 | grid-area: crt;
21 | height: 35px;
22 | border-bottom: 1.5px solid lightgray;
23 | padding-bottom: 10px;
24 | background-color: #003569;
25 | color: white;
26 | }
27 |
28 | .placeholder {
29 | grid-area: ph;
30 | }
31 |
32 | .rankingViewTitle {
33 | grid-area: rvt;
34 | }
35 |
36 | .filterTitle {
37 | grid-area: ft;
38 | margin-top: 5px;
39 | // border-bottom: 1px solid #d7d7d7;
40 | }
41 |
42 | .wholeRankingPlotWrapper {
43 | grid-area: wrp;
44 | }
45 |
46 | .wholeRankingPlot {
47 | width: 90%;
48 | }
49 |
50 | .wholeRankingSummaryStat {
51 | grid-area: wrst;
52 | display: grid;
53 | grid-template-rows: 20% 40% 40%;
54 | grid-template-columns: 20% 40% 40%;
55 | grid-template-areas:
56 | 'p ut ft'
57 | 'bt bu bf'
58 | 'wt wu wf';
59 | justify-content: space-around;
60 | }
61 |
62 | .placeholder {
63 | grid-area: p;
64 | }
65 | .utilityTitle {
66 | grid-area: ut;
67 | }
68 | .fairnessTitle {
69 | grid-area: ft;
70 | }
71 | .betweenTitle {
72 | grid-area: bt;
73 | }
74 | .withinTitle {
75 | grid-area: wt;
76 | }
77 |
78 | .btnUtility {
79 | grid-area: bu;
80 | }
81 | .btnFairness {
82 | grid-area: bf;
83 | }
84 | .wtnUtility {
85 | grid-area: wu;
86 | }
87 | .wtnFairness {
88 | grid-area: wf;
89 | }
90 |
91 | .filterTitle {
92 | grid-area: wrst;
93 | margin-top: 0;
94 | // border-bottom: 1px solid #d9d9d9;
95 | }
96 |
97 | .betweenTitle,
98 | .withinTitle {
99 | align-self: center;
100 | justify-self: end;
101 | padding: 15px;
102 | }
103 |
104 | .topkSummaryStat {
105 | grid-area: tss;
106 | display: flex;
107 | }
108 |
109 | .utilityWrapper,
110 | .inputGroupFairnessWrapper,
111 | .mappingGroupFairnessWrapper,
112 | .outputGroupFairnessWrapper,
113 | .individualFairnessWrapper {
114 | width: 40%;
115 | }
116 |
117 | .utility,
118 | .groupFairness,
119 | .inputGroupFairness,
120 | .mappingGroupFairness,
121 | .outputGroupFairness,
122 | .individualFairness {
123 | font-size: 2rem;
124 | margin-bottom: 10px;
125 | }
126 |
127 | .withinUtility,
128 | .withinFairness {
129 | font-size: 1.3rem;
130 | }
131 |
132 | .topkFilterView {
133 | grid-area: tf;
134 |
135 | .topkInputWrapper {
136 | display: flex;
137 | justify-content: space-between;
138 | padding: 0 5px;
139 | }
140 | .topkInputWrapper > .ant-slider-track {
141 | background-color: blue !important;
142 | }
143 | .topkSlider {
144 | }
145 | }
146 |
147 | .intervalFilterView {
148 | grid-area: if;
149 |
150 | .intervalInputWrapper {
151 | display: flex;
152 | justify-content: space-between;
153 | padding: 0 5px;
154 | }
155 |
156 | .intervalSlider {
157 | alignt-self: center;
158 | }
159 | }
160 |
161 | .runButtonWrapper {
162 | grid-area: rbw;
163 | display: grid;
164 | -ms-flex-pack: right;
165 | justify-content: right;
166 | -ms-flex-align: center;
167 | align-items: center;
168 | padding: 0 10px;
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/app/static/data/german_data_w_selected_features_100_5_5.csv:
--------------------------------------------------------------------------------
1 | idx,credit_risk,sex,account_check_status,duration_in_month,credit_history,credit_amount,present_employment_since,marriage,age_in_years,housing,foreign_worker,job
2 | 1,0,0,0,6,4,1169,4,0,67,1,0,2
3 | 2,1,1,1,48,2,5951,2,1,22,1,0,2
4 | 3,0,0,3,12,4,2096,3,0,49,1,0,1
5 | 4,0,0,0,42,2,7882,3,0,45,2,0,2
6 | 5,1,0,0,24,3,4870,2,0,53,2,0,2
7 | 6,0,0,3,36,2,9055,2,0,35,2,0,1
8 | 7,0,0,3,24,2,2835,4,0,53,1,0,2
9 | 8,0,0,1,36,2,6948,2,0,35,0,0,3
10 | 9,0,0,3,12,2,3059,3,2,61,1,0,1
11 | 10,1,0,1,30,4,5234,0,3,28,1,0,3
12 | 11,1,1,1,12,2,1295,1,1,25,0,0,2
13 | 12,1,1,0,48,2,4308,1,1,24,0,0,2
14 | 13,0,1,1,12,2,1567,2,1,22,1,0,2
15 | 14,1,0,0,24,4,1199,4,0,60,1,0,1
16 | 15,0,1,0,15,2,1403,2,1,28,0,0,2
17 | 16,1,1,0,24,2,1282,2,1,32,1,0,1
18 | 17,0,0,3,24,4,2424,4,0,53,1,0,2
19 | 18,0,0,0,30,0,8072,1,0,25,1,0,2
20 | 19,1,1,1,24,2,12579,4,1,44,2,0,3
21 | 20,0,0,3,24,2,3430,4,0,31,1,0,2
22 | 21,0,0,3,9,4,2134,2,0,48,1,0,2
23 | 22,0,0,0,6,2,2647,2,0,44,0,0,2
24 | 23,0,0,0,10,4,2241,1,0,48,0,1,1
25 | 24,0,0,1,12,4,1804,1,0,44,1,0,2
26 | 25,0,0,3,10,4,2069,2,3,26,1,1,2
27 | 26,0,0,0,6,2,1374,2,0,36,1,0,1
28 | 27,0,0,3,6,0,426,4,3,39,1,0,1
29 | 28,0,1,2,12,1,409,2,1,42,0,0,2
30 | 29,0,0,1,7,2,2415,2,0,34,1,0,2
31 | 30,1,0,0,60,3,6836,4,0,63,1,0,2
32 | 31,0,0,1,18,2,1913,1,3,36,1,0,2
33 | 32,0,0,0,24,2,4020,2,0,27,1,0,2
34 | 33,0,0,1,18,2,5866,2,0,30,1,0,2
35 | 34,0,0,3,12,4,1264,4,0,57,0,0,1
36 | 35,0,1,2,12,2,1474,1,1,33,1,0,3
37 | 36,1,0,1,45,4,4746,1,0,25,1,0,1
38 | 37,0,0,3,48,4,6110,2,0,31,2,0,2
39 | 38,1,0,2,18,2,2100,2,0,37,1,0,2
40 | 39,0,0,2,10,2,1225,2,0,37,1,0,2
41 | 40,0,0,1,9,2,458,2,0,24,1,0,2
42 | 41,0,0,3,30,2,2333,4,0,30,1,0,3
43 | 42,0,0,1,12,2,1158,2,2,26,1,0,2
44 | 45,1,1,0,48,4,6143,4,1,58,2,0,1
45 | 46,0,1,3,11,4,1393,1,1,35,1,0,3
46 | 48,0,1,0,6,2,1352,0,1,23,0,0,0
47 | 50,0,1,3,12,2,2073,2,1,28,1,0,2
48 | 55,1,0,1,36,3,2225,4,0,57,2,0,2
49 | 57,1,0,1,12,2,6468,0,0,52,1,0,3
50 | 58,0,1,3,36,4,9566,2,1,31,1,0,2
51 | 59,0,1,2,18,2,1961,4,1,23,1,0,3
52 | 60,1,1,0,36,4,6229,1,1,23,0,0,1
53 | 63,1,0,1,36,0,1953,4,0,61,2,0,3
54 | 64,1,0,1,48,0,14421,2,0,25,1,0,2
55 | 65,0,1,3,24,2,3181,1,1,26,1,0,2
56 | 67,0,1,3,12,2,2171,1,1,29,1,0,2
57 | 69,1,0,3,36,2,1819,2,0,37,2,0,2
58 | 70,0,1,3,36,2,2394,2,1,25,1,0,2
59 | 71,0,1,3,36,2,8133,2,1,30,1,0,2
60 | 74,0,1,1,42,4,5954,3,1,41,1,0,1
61 | 75,1,0,0,36,2,1977,4,0,40,1,0,3
62 | 77,1,0,0,42,2,3965,1,0,34,1,0,2
63 | 81,1,1,3,24,2,5943,1,1,44,1,0,2
64 | 83,0,1,3,18,2,1568,2,1,24,0,0,1
65 | 84,0,1,0,24,2,1755,4,1,58,1,0,1
66 | 86,0,1,3,12,4,1412,2,1,29,1,0,3
67 | 87,0,1,1,18,4,1295,1,1,27,1,0,2
68 | 88,1,0,1,36,2,12612,2,0,47,2,0,2
69 | 90,1,0,0,12,0,1108,3,0,28,1,0,2
70 | 93,1,1,3,12,4,797,4,1,33,1,0,1
71 | 96,1,0,1,54,0,15945,1,0,58,0,0,2
72 | 97,0,1,3,12,4,2012,3,1,61,1,0,2
73 | 103,0,1,3,6,3,932,2,1,24,1,0,2
74 | 106,1,0,1,24,4,11938,2,0,39,1,0,3
75 | 107,1,0,3,18,1,6458,4,0,39,1,0,3
76 | 109,0,1,0,24,2,7721,1,1,30,1,1,2
77 | 112,0,1,2,15,2,392,1,1,23,0,0,2
78 | 114,1,1,3,36,4,7855,2,1,25,1,0,2
79 | 117,1,1,0,42,2,7174,3,1,30,1,0,3
80 | 118,0,1,0,10,4,2132,1,1,27,0,1,2
81 | 119,1,1,0,33,4,4281,2,1,23,1,0,2
82 | 121,1,1,0,21,2,1835,2,1,25,1,0,2
83 | 122,0,1,3,24,4,3868,4,1,41,0,0,3
84 | 125,1,1,1,18,2,1924,1,1,27,0,0,2
85 | 128,1,0,1,12,2,639,2,0,30,1,0,2
86 | 130,1,1,0,12,4,3499,2,1,29,1,0,2
87 | 131,0,1,1,48,2,8487,3,1,24,1,0,2
88 | 132,1,0,0,36,3,6887,2,0,29,1,0,2
89 | 135,0,1,3,60,2,10144,3,1,21,1,0,2
90 | 136,0,1,3,12,4,1240,4,1,38,1,0,2
91 | 138,1,0,1,12,2,766,2,0,66,1,0,1
92 | 140,0,1,2,12,2,1881,2,1,44,0,0,1
93 | 142,0,1,1,36,2,4795,1,1,30,1,0,3
94 | 144,1,0,0,18,2,2462,2,0,22,1,0,2
95 | 145,0,1,3,21,4,2288,1,1,23,1,0,2
96 | 147,0,1,0,6,4,860,4,1,39,1,0,2
97 | 148,0,1,3,12,4,682,3,1,51,1,0,2
98 | 154,0,1,1,24,4,7758,4,1,29,0,0,2
99 | 156,1,1,0,12,2,1282,2,1,20,0,0,2
100 | 167,1,1,0,18,2,1131,0,1,33,1,0,2
101 | 170,1,0,1,24,4,1935,4,2,31,1,0,2
--------------------------------------------------------------------------------
/app/static/data/german_data_w_selected_features_100_5_5_synthetic.csv:
--------------------------------------------------------------------------------
1 | idx,credit_risk,sex,account_check_status,duration_in_month,credit_history,credit_amount,present_employment_since,marriage,age_in_years,housing,foreign_worker,job
2 | 1,0,0,0,6,4,1169,4,0,72,1,0,2
3 | 2,1,1,1,48,2,5951,2,0,22,1,0,2
4 | 3,0,0,3,12,4,2096,3,0,49,1,0,1
5 | 4,0,0,0,42,2,7882,3,0,47,2,0,2
6 | 5,1,0,0,24,3,4870,2,0,55,2,0,2
7 | 6,0,0,3,36,2,9055,2,0,35,2,1,2
8 | 7,0,0,3,24,2,2835,4,0,57,1,0,2
9 | 8,0,0,1,36,2,6948,2,0,35,0,1,3
10 | 9,0,0,3,12,2,3059,3,2,68,1,0,1
11 | 10,1,0,1,30,4,5234,0,3,28,1,0,3
12 | 11,1,1,1,12,2,1295,1,1,25,0,0,2
13 | 12,1,1,0,48,2,4308,1,1,24,0,0,2
14 | 13,0,1,1,12,2,1567,2,1,22,1,0,2
15 | 14,1,0,0,24,4,1199,4,0,67,1,1,0
16 | 15,0,1,0,15,2,1403,2,1,28,0,0,2
17 | 16,1,1,0,24,2,1282,2,1,32,1,0,1
18 | 17,0,0,3,24,4,2424,4,0,60,1,0,2
19 | 18,0,0,0,30,0,8072,1,0,24,1,1,2
20 | 19,1,1,1,24,2,12579,4,1,44,2,0,3
21 | 20,0,0,3,24,2,3430,4,0,31,1,0,2
22 | 21,0,0,3,9,4,2134,2,0,48,1,0,2
23 | 22,0,0,0,6,2,2647,2,0,44,0,0,2
24 | 23,0,0,0,10,4,2241,1,0,48,0,1,1
25 | 24,0,0,1,12,4,1804,1,0,44,1,0,2
26 | 25,0,0,3,10,4,2069,2,3,25,1,1,2
27 | 26,0,0,0,6,2,1374,2,0,36,1,0,1
28 | 27,0,0,3,6,0,426,4,3,39,1,0,0
29 | 28,0,1,2,12,1,409,2,2,42,0,0,0
30 | 29,0,0,1,7,2,2415,2,0,34,1,1,2
31 | 30,1,0,0,60,3,6836,4,0,70,1,0,2
32 | 31,0,0,1,18,2,1913,1,3,36,1,0,2
33 | 32,0,0,0,24,2,4020,2,0,27,1,1,2
34 | 33,0,0,1,18,2,5866,2,0,30,1,1,2
35 | 34,0,0,3,12,4,1264,4,0,62,0,0,0
36 | 35,0,1,2,12,2,1474,1,1,33,1,0,3
37 | 36,1,0,1,45,4,4746,1,0,24,1,0,1
38 | 37,0,0,3,48,4,6110,2,0,31,2,1,2
39 | 38,1,0,2,18,2,2100,2,0,37,1,0,2
40 | 39,0,0,2,10,2,1225,2,0,37,1,1,2
41 | 40,0,0,1,9,2,458,2,0,23,1,1,2
42 | 41,0,0,3,30,2,2333,4,0,30,1,1,3
43 | 42,0,0,1,12,2,1158,2,2,25,1,0,2
44 | 43,0,0,1,18,3,6204,2,0,46,1,0,1
45 | 44,0,0,0,30,4,6187,3,3,23,0,1,3
46 | 45,1,1,0,48,4,6143,4,2,58,2,0,1
47 | 46,0,1,3,11,4,1393,1,1,35,1,0,3
48 | 47,0,0,3,36,2,2299,4,0,39,1,1,2
49 | 48,0,1,0,6,2,1352,0,1,23,0,0,0
50 | 49,0,0,3,11,4,7228,2,0,39,1,0,1
51 | 50,0,1,3,12,2,2073,2,1,28,1,0,2
52 | 51,0,0,1,24,3,2333,1,0,29,1,0,1
53 | 52,0,0,1,27,3,5965,4,0,30,1,0,3
54 | 53,0,0,3,12,2,1262,2,0,24,1,0,2
55 | 54,0,0,3,18,2,3378,2,0,31,1,0,2
56 | 55,1,0,1,36,3,2225,4,0,64,2,0,2
57 | 56,0,0,3,6,1,783,2,0,25,1,1,1
58 | 57,1,0,1,12,2,6468,0,0,54,1,0,3
59 | 58,0,1,3,36,4,9566,2,1,31,1,0,2
60 | 59,0,1,2,18,2,1961,4,1,23,1,0,3
61 | 60,1,1,0,36,4,6229,1,1,23,0,0,1
62 | 61,0,0,1,9,2,1391,2,3,27,1,1,2
63 | 62,0,0,1,15,4,1537,4,0,52,1,0,2
64 | 63,1,0,1,36,0,1953,4,0,69,2,0,3
65 | 64,1,0,1,48,0,14421,2,0,24,1,0,3
66 | 65,0,1,3,24,2,3181,1,1,26,1,0,2
67 | 66,0,0,3,27,2,5190,4,0,49,1,0,2
68 | 67,0,1,3,12,2,2171,1,1,29,1,0,2
69 | 68,0,0,1,12,2,1007,2,3,22,1,0,2
70 | 70,0,1,3,36,2,2394,2,1,25,1,0,2
71 | 71,0,1,3,36,2,8133,2,2,30,1,0,2
72 | 74,0,1,1,42,4,5954,3,1,41,1,0,1
73 | 81,1,1,3,24,2,5943,1,1,44,1,0,2
74 | 83,0,1,3,18,2,1568,2,1,24,0,0,1
75 | 84,0,1,0,24,2,1755,4,1,58,1,0,1
76 | 86,0,1,3,12,4,1412,2,1,29,1,0,3
77 | 87,0,1,1,18,4,1295,1,1,27,1,0,2
78 | 93,1,1,3,12,4,797,4,1,33,1,0,0
79 | 97,0,1,3,12,4,2012,3,3,61,1,0,2
80 | 103,0,1,3,6,3,932,2,1,24,1,0,0
81 | 109,0,1,0,24,2,7721,1,0,30,1,0,2
82 | 112,0,1,2,15,2,392,1,1,23,0,0,0
83 | 114,1,1,3,36,4,7855,2,1,25,1,0,2
84 | 117,1,1,0,42,2,7174,3,1,30,1,0,3
85 | 118,0,1,0,10,4,2132,1,1,27,0,1,2
86 | 119,1,1,0,33,4,4281,2,1,23,1,0,2
87 | 121,1,1,0,21,2,1835,2,3,25,1,0,2
88 | 122,0,1,3,24,4,3868,4,1,41,0,0,3
89 | 125,1,1,1,18,2,1924,1,1,27,0,0,2
90 | 130,1,1,0,12,4,3499,2,1,29,1,0,2
91 | 131,0,1,1,48,2,8487,3,1,24,1,0,3
92 | 135,0,1,3,60,2,10144,3,1,21,1,0,2
93 | 136,0,1,3,12,4,1240,4,1,38,1,0,2
94 | 140,0,1,2,12,2,1881,2,2,44,0,0,1
95 | 142,0,1,1,36,2,4795,1,1,30,1,0,3
96 | 145,0,1,3,21,4,2288,1,1,23,1,0,2
97 | 147,0,1,0,6,4,860,4,1,39,1,0,2
98 | 148,0,1,3,12,4,682,3,1,51,1,0,2
99 | 154,0,1,1,24,4,7758,4,1,29,0,0,2
100 | 156,1,1,0,12,2,1282,2,1,20,0,0,0
101 | 162,0,1,3,18,4,1055,1,1,30,1,0,2
--------------------------------------------------------------------------------
/app/static/data/german_data_w_selected_features_systematic_synthetic.csv:
--------------------------------------------------------------------------------
1 | idx,credit_risk,sex,account_check_status,duration_in_month,credit_history,credit_amount,present_employment_since,marriage,age_in_years,housing,foreign_worker,job
2 | 2,1,1,1,48,2,5951,2,3,34,1,0,2
3 | 11,1,1,1,12,2,1295,1,1,41,0,0,2
4 | 12,1,1,0,48,2,4308,1,1,29,0,0,2
5 | 13,0,1,1,12,2,1567,2,1,41,1,0,2
6 | 15,0,1,0,15,2,1403,2,1,37,0,0,2
7 | 16,1,1,0,24,2,1282,2,1,42,1,0,1
8 | 19,1,1,1,24,2,12579,4,1,66,2,0,3
9 | 28,0,1,2,12,1,409,2,3,58,0,0,2
10 | 35,0,1,2,12,2,1474,1,1,46,1,0,3
11 | 45,1,1,0,48,4,6143,4,1,75,2,0,1
12 | 46,0,1,3,11,4,1393,1,1,45,1,0,3
13 | 48,0,1,0,6,2,1352,0,3,34,0,0,0
14 | 50,0,1,3,12,2,2073,2,1,39,1,0,2
15 | 58,0,1,3,36,4,9566,2,3,39,1,0,2
16 | 59,0,1,2,18,2,1961,4,3,36,1,0,3
17 | 60,1,1,0,36,4,6229,1,1,28,0,0,1
18 | 65,0,1,3,24,2,3181,1,3,37,1,0,2
19 | 67,0,1,3,12,2,2171,1,3,43,1,0,2
20 | 70,0,1,3,36,2,2394,2,3,41,1,0,2
21 | 71,0,1,3,36,2,8133,2,3,40,1,0,2
22 | 74,0,1,1,42,4,5954,3,3,52,1,0,1
23 | 81,1,1,3,24,2,5943,1,1,59,1,0,2
24 | 83,0,1,3,18,2,1568,2,1,37,0,0,1
25 | 84,0,1,0,24,2,1755,4,1,73,1,0,1
26 | 86,0,1,3,12,4,1412,2,1,44,1,0,3
27 | 87,0,1,1,18,4,1295,1,3,47,1,0,2
28 | 93,1,1,3,12,4,797,4,3,50,1,0,1
29 | 97,0,1,3,12,4,2012,3,1,74,1,0,2
30 | 103,0,1,3,6,3,932,2,3,33,1,0,2
31 | 109,0,1,0,24,2,7721,1,1,43,1,1,2
32 | 112,0,1,2,15,2,392,1,3,35,0,0,2
33 | 114,1,1,3,36,4,7855,2,3,37,1,0,2
34 | 117,1,1,0,42,2,7174,3,1,34,1,0,3
35 | 118,0,1,0,10,4,2132,1,1,40,0,1,2
36 | 119,1,1,0,33,4,4281,2,1,33,1,0,2
37 | 121,1,1,0,21,2,1835,2,3,38,1,0,2
38 | 122,0,1,3,24,4,3868,4,1,60,0,0,3
39 | 125,1,1,1,18,2,1924,1,1,46,0,0,2
40 | 130,1,1,0,12,4,3499,2,1,51,1,0,2
41 | 131,0,1,1,48,2,8487,3,1,40,1,0,2
42 | 135,0,1,3,60,2,10144,3,1,37,1,0,2
43 | 136,0,1,3,12,4,1240,4,1,48,1,0,2
44 | 140,0,1,2,12,2,1881,2,1,65,0,0,1
45 | 142,0,1,1,36,2,4795,1,1,43,1,0,3
46 | 145,0,1,3,21,4,2288,1,1,39,1,0,2
47 | 147,0,1,0,6,4,860,4,1,53,1,0,2
48 | 148,0,1,3,12,4,682,3,1,66,1,0,2
49 | 154,0,1,1,24,4,7758,4,1,49,0,0,2
50 | 156,1,1,0,12,2,1282,2,1,32,0,0,2
51 | 162,0,1,3,18,4,1055,1,3,39,1,0,2
52 | 1,0,0,0,6,4,1169,4,0,54,1,1,2
53 | 3,0,0,3,12,4,2096,3,0,35,1,0,1
54 | 4,0,0,0,42,2,7882,3,0,26,2,1,2
55 | 5,1,0,0,24,3,4870,2,0,40,2,0,2
56 | 6,0,0,3,36,2,9055,2,0,22,2,1,1
57 | 7,0,0,3,24,2,2835,4,0,36,1,0,2
58 | 8,0,0,1,36,2,6948,2,0,25,0,0,3
59 | 9,0,0,3,12,2,3059,3,2,41,1,0,1
60 | 10,1,0,1,30,4,5234,0,0,13,1,1,3
61 | 14,1,0,0,24,4,1199,4,0,43,1,1,1
62 | 17,0,0,3,24,4,2424,4,0,39,1,0,2
63 | 18,0,0,0,30,0,8072,1,0,17,1,0,2
64 | 20,0,0,3,24,2,3430,4,0,20,1,0,2
65 | 21,0,0,3,9,4,2134,2,0,32,1,1,2
66 | 22,0,0,0,6,2,2647,2,0,29,0,0,2
67 | 23,0,0,0,10,4,2241,1,0,36,0,1,1
68 | 24,0,0,1,12,4,1804,1,0,26,1,1,2
69 | 25,0,0,3,10,4,2069,2,3,14,1,1,2
70 | 26,0,0,0,6,2,1374,2,0,26,1,1,1
71 | 27,0,0,3,6,0,426,4,0,32,1,0,1
72 | 29,0,0,1,7,2,2415,2,0,22,1,0,2
73 | 30,1,0,0,60,3,6836,4,0,52,1,0,2
74 | 31,0,0,1,18,2,1913,1,3,22,1,1,2
75 | 32,0,0,0,24,2,4020,2,0,17,1,1,2
76 | 33,0,0,1,18,2,5866,2,0,21,1,0,2
77 | 34,0,0,3,12,4,1264,4,0,43,0,1,1
78 | 36,1,0,1,45,4,4746,1,0,13,1,0,1
79 | 37,0,0,3,48,4,6110,2,0,15,2,0,2
80 | 38,1,0,2,18,2,2100,2,0,23,1,1,2
81 | 39,0,0,2,10,2,1225,2,0,22,1,1,2
82 | 40,0,0,1,9,2,458,2,0,11,1,1,2
83 | 41,0,0,3,30,2,2333,4,0,14,1,0,3
84 | 42,0,0,1,12,2,1158,2,2,13,1,1,2
85 | 43,0,0,1,18,3,6204,2,0,29,1,0,1
86 | 44,0,0,0,30,4,6187,3,3,14,0,0,2
87 | 47,0,0,3,36,2,2299,4,0,21,1,0,2
88 | 49,0,0,3,11,4,7228,2,0,27,1,0,1
89 | 51,0,0,1,24,3,2333,1,0,18,1,0,1
90 | 52,0,0,1,27,3,5965,4,0,19,1,1,3
91 | 53,0,0,3,12,2,1262,2,0,11,1,1,2
92 | 54,0,0,3,18,2,3378,2,0,21,1,0,2
93 | 55,1,0,1,36,3,2225,4,0,44,2,0,2
94 | 56,0,0,3,6,1,783,2,0,19,1,1,1
95 | 57,1,0,1,12,2,6468,0,0,34,1,0,3
96 | 61,0,0,1,9,2,1391,2,0,18,1,1,2
97 | 62,0,0,1,15,4,1537,4,0,35,1,0,2
98 | 63,1,0,1,36,0,1953,4,0,45,2,1,3
99 | 64,1,0,1,48,0,14421,2,0,10,1,0,2
100 | 66,0,0,3,27,2,5190,4,0,35,1,0,2
101 | 68,0,0,1,12,2,1007,2,3,14,1,1,2
--------------------------------------------------------------------------------
/app/static/data/german_data_sample_synthetic.csv:
--------------------------------------------------------------------------------
1 | idx,account_check_status,duration_in_month,credit_history,credit_amount,savings,present_employment_since,sex,marriage,age_in_years,housing,foreign_worker,race,credit_risk
2 | 1,0,6,5,1169,4,4,0,0,67,1,0,0,0
3 | 2,1,48,3,5951,0,2,1,0,22,1,0,0,1
4 | 3,3,12,5,2096,0,3,0,0,49,1,0,0,0
5 | 4,0,42,3,7882,0,3,0,2,45,2,0,0,0
6 | 5,0,24,4,4870,0,2,0,0,53,2,0,0,1
7 | 6,3,36,3,9055,4,2,0,0,35,2,0,0,0
8 | 7,3,24,3,2835,2,4,0,0,53,1,0,0,0
9 | 8,1,36,3,6948,0,2,0,0,35,0,0,0,0
10 | 9,3,12,3,3059,3,3,0,0,61,1,0,0,0
11 | 10,1,30,5,5234,0,0,0,0,28,1,0,0,1
12 | 11,1,12,3,1295,0,1,1,0,25,0,0,0,1
13 | 12,0,48,3,4308,0,1,1,0,24,0,0,0,1
14 | 13,1,12,3,1567,0,2,1,0,22,1,0,0,0
15 | 14,0,24,5,1199,0,4,0,0,60,1,0,0,1
16 | 15,0,15,3,1403,0,2,1,0,28,0,0,0,0
17 | 16,0,24,3,1282,1,2,1,0,32,1,0,0,1
18 | 17,3,24,5,2424,4,4,0,0,53,1,0,0,0
19 | 18,0,30,0,8072,4,1,0,0,25,1,0,0,0
20 | 19,1,24,3,12579,0,4,1,0,44,2,0,0,1
21 | 20,3,24,3,3430,2,4,0,0,31,1,0,0,0
22 | 21,3,9,5,2134,0,2,0,0,48,1,0,0,0
23 | 22,0,6,3,2647,2,2,0,0,44,0,0,0,0
24 | 23,0,10,5,2241,0,1,0,0,48,0,1,1,0
25 | 24,1,12,5,1804,1,1,0,0,44,1,0,0,0
26 | 25,3,10,5,2069,4,2,0,0,26,1,1,1,0
27 | 26,0,6,3,1374,0,2,0,0,36,1,0,0,0
28 | 27,3,6,0,426,0,4,0,0,39,1,0,0,0
29 | 28,2,12,1,409,3,2,1,0,42,0,0,0,0
30 | 29,1,7,3,2415,0,2,0,2,34,1,0,0,0
31 | 30,0,60,4,6836,0,4,0,0,63,1,0,0,1
32 | 31,1,18,3,1913,3,1,0,0,36,1,0,0,0
33 | 32,0,24,3,4020,0,2,0,0,27,1,0,0,0
34 | 33,1,18,3,5866,1,2,0,0,30,1,0,0,0
35 | 34,3,12,5,1264,4,4,0,0,57,0,0,0,0
36 | 35,2,12,3,1474,0,1,1,0,33,1,0,0,0
37 | 36,1,45,5,4746,0,1,0,0,25,1,0,0,1
38 | 37,3,48,5,6110,0,2,0,0,31,2,0,0,0
39 | 38,2,18,3,2100,0,2,0,1,37,1,0,0,1
40 | 39,2,10,3,1225,0,2,0,0,37,1,0,0,0
41 | 40,1,9,3,458,0,2,0,0,24,1,0,0,0
42 | 41,3,30,3,2333,2,4,0,0,30,1,0,0,0
43 | 42,1,12,3,1158,2,2,0,0,26,1,0,0,0
44 | 43,1,18,4,6204,0,2,0,0,44,1,0,0,0
45 | 44,0,30,5,6187,1,3,0,0,24,0,0,0,0
46 | 45,0,48,5,6143,0,4,1,0,58,2,0,0,1
47 | 46,3,11,5,1393,0,1,1,0,35,1,0,0,0
48 | 47,3,36,3,2299,2,4,0,0,39,1,0,0,0
49 | 48,0,6,3,1352,2,0,1,0,23,0,0,0,0
50 | 49,3,11,5,7228,0,2,0,0,39,1,0,0,0
51 | 50,3,12,3,2073,1,2,1,1,28,1,0,0,0
52 | 51,1,24,4,2333,4,1,0,0,29,1,0,0,0
53 | 52,1,27,4,5965,0,4,0,0,30,1,0,0,0
54 | 53,3,12,3,1262,0,2,0,0,25,1,0,0,0
55 | 54,3,18,3,3378,4,2,0,0,31,1,0,0,0
56 | 55,1,36,4,2225,0,4,0,0,57,2,0,0,1
57 | 56,3,6,1,783,4,2,0,2,26,1,0,0,0
58 | 57,1,12,3,6468,4,0,0,0,52,1,0,0,1
59 | 58,3,36,5,9566,0,2,1,0,31,1,0,0,0
60 | 59,2,18,3,1961,0,4,1,0,23,1,0,0,0
61 | 60,0,36,5,6229,0,1,1,1,23,0,0,0,1
62 | 61,1,9,3,1391,0,2,0,0,27,1,0,0,0
63 | 62,1,15,5,1537,4,4,0,2,50,1,0,0,0
64 | 63,1,36,0,1953,0,4,0,0,61,2,0,0,1
65 | 64,1,48,0,14421,0,2,0,0,25,1,0,0,1
66 | 65,3,24,3,3181,0,1,1,0,26,1,0,0,0
67 | 66,3,27,3,5190,4,4,0,0,48,1,0,0,0
68 | 67,3,12,3,2171,0,1,1,0,29,1,0,0,0
69 | 68,1,12,3,1007,3,2,0,0,22,1,0,0,0
70 | 69,3,36,3,1819,0,2,0,0,37,2,0,0,1
71 | 70,3,36,3,2394,4,2,1,0,25,1,0,0,0
72 | 71,3,36,3,8133,0,2,1,0,30,1,0,0,0
73 | 72,3,7,5,730,4,4,0,0,46,0,0,0,0
74 | 73,0,8,5,1164,0,4,0,0,51,2,0,0,0
75 | 74,1,42,5,5954,0,3,1,0,41,1,0,0,0
76 | 75,0,36,3,1977,4,4,0,0,40,1,0,0,1
77 | 76,0,12,5,1526,0,4,0,0,66,2,0,0,0
78 | 77,0,42,3,3965,0,1,0,0,34,1,0,0,1
79 | 78,1,11,4,4771,0,3,0,0,51,1,0,0,0
80 | 79,3,54,0,9436,4,2,0,0,39,1,0,0,0
81 | 80,1,30,3,3832,0,1,0,0,22,1,0,0,0
82 | 81,3,24,3,5943,4,1,1,0,44,1,0,0,1
83 | 82,3,15,3,1213,2,4,0,0,47,1,0,0,0
84 | 83,3,18,3,1568,1,2,1,0,24,0,0,0,0
85 | 84,0,24,3,1755,0,4,1,2,58,1,0,0,0
86 | 85,0,10,3,2315,0,4,0,0,52,1,0,0,0
87 | 86,3,12,5,1412,0,2,1,2,29,1,0,0,0
88 | 87,1,18,5,1295,0,1,1,0,27,1,0,0,0
89 | 88,1,36,3,12612,1,2,0,0,47,2,0,0,1
90 | 89,0,18,3,2249,1,3,0,0,30,1,0,0,0
91 | 90,0,12,0,1108,0,3,0,0,28,1,0,0,1
92 | 91,3,12,5,618,0,4,0,0,56,1,0,0,0
93 | 92,0,12,5,1409,0,4,0,0,54,1,0,0,0
94 | 93,3,12,5,797,4,4,1,0,33,1,0,0,1
95 | 94,2,24,5,3617,4,4,0,1,20,0,0,0,0
96 | 95,1,12,3,1318,3,4,0,0,54,1,0,0,0
97 | 96,1,54,0,15945,0,1,0,0,58,0,0,0,1
98 | 97,3,12,5,2012,4,3,1,0,61,1,0,0,0
99 | 98,1,18,3,2622,1,2,0,0,34,1,0,0,0
100 | 99,1,36,5,2337,0,4,0,0,36,1,0,0,0
101 | 100,1,20,4,7057,4,3,0,0,36,0,0,0,0
--------------------------------------------------------------------------------
/src/src/components/UtilityBar/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import * as d3 from 'd3';
3 | import ReactFauxDOM from 'react-faux-dom';
4 | import _ from 'lodash';
5 | import { Table, Tag, Icon } from 'antd';
6 |
7 | import styles from './styles.scss';
8 | import index from '../../index.css';
9 | import gs from '../../config/_variables.scss'; // gs (=global style)
10 |
11 | class UtilityBar extends Component {
12 | constructor(props) {
13 | super(props);
14 | }
15 |
16 | render() {
17 | console.log('MeasureView rendered');
18 | if (!this.props.measure || this.props.measure.length === 0) {
19 | return
;
20 | }
21 |
22 | const { measure, measureDomain, perfectScore, color } = this.props;
23 |
24 | const svg = new ReactFauxDOM.Element('svg');
25 |
26 | svg.setAttribute('width', '110px');
27 | svg.setAttribute('height', '40px');
28 | svg.setAttribute('0 0 200 200');
29 | svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
30 | svg.setAttribute('transform', 'translate(0,0)');
31 |
32 | const measureScale = d3
33 | .scaleLinear()
34 | .domain(measureDomain)
35 | .range([5, 65]);
36 |
37 | const g = d3
38 | .select(svg)
39 | .append('g')
40 | .attr('transform', 'translate(3,0)');
41 |
42 | const xAxisSetting = d3
43 | .axisBottom(measureScale)
44 | .tickValues(measureDomain)
45 | .tickSize(0),
46 | xAxis = d3
47 | .select(svg)
48 | .append('g')
49 | .call(xAxisSetting)
50 | .attr('class', 'measure_x_axis')
51 | .attr('transform', 'translate(7,' + 23 + ')');
52 |
53 | xAxis.select('.domain').remove();
54 |
55 | const backgroundRect = g
56 | .append('rect')
57 | .attr('x', 5)
58 | .attr('y', 10)
59 | .attr('width', 60)
60 | .attr('height', 10)
61 | .style('stroke', '#d0d0d0')
62 | .style('fill', '#efefef');
63 |
64 | const currentMeasure = g
65 | .append('line')
66 | .attr('x1', measureScale(measure))
67 | .attr('y1', 10)
68 | .attr('x2', measureScale(measure))
69 | .attr('y2', 21)
70 | .style('stroke', 'black');
71 |
72 | const avgCircle = g
73 | .append('circle')
74 | .attr('cx', measureScale(0.7))
75 | .attr('cy', 0 + 10)
76 | .attr('r', 3)
77 | .style('fill', 'none')
78 | .style('stroke', '#c91765')
79 | .style('stroke', '1px');
80 |
81 | const score = g
82 | .append('text')
83 | .attr('x', 60 + 10)
84 | .attr('y', 21)
85 | .style('font-size', 16)
86 | .text(Math.round(measure * 100) / 100);
87 |
88 | const fairRect = g
89 | .append('rect')
90 | .attr('width', 5)
91 | .attr('height', 5)
92 | .style('fill', color)
93 | .style('stroke', color)
94 | .attr(
95 | 'transform',
96 | 'translate(' + measureScale(perfectScore) + ',2)' + 'rotate(45)'
97 | );
98 |
99 | const fairLine = g
100 | .append('line')
101 | .attr('x1', measureScale(perfectScore))
102 | .attr('y1', 10)
103 | .attr('x2', measureScale(perfectScore))
104 | .attr('y2', 20)
105 | .style('stroke', color)
106 | .style('stroke-width', 2);
107 |
108 | // Traingle-shaped indicator for current fair score
109 | var triangleSize = 20;
110 | var verticalTransform = 100 + Math.sqrt(triangleSize);
111 |
112 | const triangle = d3
113 | .symbol()
114 | .type(d3.symbolTriangle)
115 | .size(triangleSize);
116 |
117 | g.append('path')
118 | .attr('class', 'point_to_selected_instance')
119 | .attr('d', triangle)
120 | .attr('stroke', 'black')
121 | .attr('fill', 'black')
122 | .attr('transform', function(d) {
123 | return 'translate(' + measureScale(measure) + ',' + 25 + ')';
124 | });
125 |
126 | return {svg.toReact()}
;
127 | }
128 | }
129 |
130 | export default UtilityBar;
131 |
--------------------------------------------------------------------------------
/src/src/components/FairnessBar/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from "react";
2 | import * as d3 from 'd3';
3 | import ReactFauxDOM from 'react-faux-dom';
4 | import _ from 'lodash';
5 | import { Table, Tag, Icon } from 'antd';
6 |
7 | import styles from "./styles.scss";
8 | import index from "../../index.css";
9 | import gs from "../../config/_variables.scss"; // gs (=global style)
10 |
11 | class FairnessBar extends Component {
12 | constructor(props) {
13 | super(props);
14 | }
15 |
16 | render() {
17 | console.log('MeasureView rendered');
18 | if ((!this.props.measure || this.props.measure.length === 0)) {
19 | return
20 | }
21 |
22 | const { measure, measureDomain, perfectScore, color } = this.props;
23 |
24 | const svg = new ReactFauxDOM.Element('svg');
25 |
26 | svg.setAttribute('width', '110px');
27 | svg.setAttribute('height', '40px');
28 | svg.setAttribute('0 0 200 200');
29 | svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
30 | svg.setAttribute('transform', 'translate(0,0)');
31 |
32 | const measureScale = d3.scaleLinear()
33 | .domain(measureDomain)
34 | .range([5, 65]);
35 |
36 | const g = d3.select(svg).append('g')
37 | .attr('transform', 'translate(3,0)');
38 |
39 | const xAxisSetting = d3.axisBottom(measureScale)
40 | .tickValues(measureDomain).tickSize(0),
41 | xAxis = g.append('g')
42 | .call(xAxisSetting)
43 | .attr('class', 'measure_x_axis')
44 | .attr('transform', 'translate(5,' + 20 + ')');
45 |
46 | xAxis.select('.domain').remove();
47 |
48 | const backgroundRect = g.append('rect')
49 | .attr('x', 5)
50 | .attr('y', 10)
51 | .attr('width', 60)
52 | .attr('height', 10)
53 | .style('stroke', '#d0d0d0')
54 | .style('fill', '#efefef');
55 |
56 | const currentMeasure = g.append('line')
57 | .attr('x1', measureScale(measure))
58 | .attr('y1', 10)
59 | .attr('x2', measureScale(measure))
60 | .attr('y2', 21)
61 | .style('stroke', 'black');
62 |
63 | const avgCircle = g.append('circle')
64 | .attr('cx', measureScale(1.3))
65 | .attr('cy', 0 + 10)
66 | .attr('r', 3)
67 | .style('fill', 'none')
68 | .style('stroke', '#003569')
69 | .style('stroke', '1px');
70 |
71 | const score = g.append('text')
72 | .attr('x', 60 + 10)
73 | .attr('y', 21)
74 | .style('font-size', 16)
75 | .text(Math.round(measure * 100) / 100);
76 |
77 | const fairRect = g.append('rect')
78 | .attr('width', 5)
79 | .attr('height', 5)
80 | .style('fill', '#003569')
81 | .style('stroke', '#003569')
82 | .attr('transform', 'translate(' + measureScale(perfectScore) + ',2)rotate(45)');
83 |
84 | const fairLine = g.append('line')
85 | .attr('x1', measureScale(perfectScore))
86 | .attr('y1', 10)
87 | .attr('x2', measureScale(perfectScore))
88 | .attr('y2', 20)
89 | .style('stroke', '#003569')
90 | .style('stroke-width', 2);
91 |
92 | // Traingle-shaped indicator for current fair score
93 | var triangleSize = 20;
94 | var verticalTransform = 100 + Math.sqrt(triangleSize);
95 |
96 | const triangle = d3.symbol()
97 | .type(d3.symbolTriangle)
98 | .size(triangleSize);
99 |
100 | g.append('path')
101 | .attr('class', 'point_to_selected_instance')
102 | .attr("d", triangle)
103 | .attr("stroke", 'black')
104 | .attr("fill", 'black')
105 | .attr("transform", function(d) { return "translate(" + measureScale(measure) + "," + 25 + ")"; });
106 |
107 | return (
108 |
109 | {svg.toReact()}
110 |
111 | );
112 | }
113 | }
114 |
115 | export default FairnessBar;
116 |
--------------------------------------------------------------------------------
/src/src/components/Generator/styles.scss:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css?family=Titillium+Web:300,400,700');
2 |
3 | .Generator {
4 | grid-area: g;
5 |
6 | width: 100%;
7 |
8 | align-items: center;
9 | font-size: 12px;
10 |
11 | // border: 1px solid lightgray;
12 | // padding: 7px;
13 | font-size: 1.1rem;
14 |
15 | .generatorTitleWrapper {
16 | margin-bottom: 20px;
17 | display: flex;
18 | background-color: #003569;
19 |
20 | .generatorTitle {
21 | // padding: 0;
22 | }
23 | .step1 {
24 | color: #b5dafe;
25 | font-size: 1.6rem;
26 | margin-top: 8px;
27 | }
28 | }
29 |
30 | .generatorTitle > span {
31 | color: white !important;
32 | font-size: 1.4rem !important;
33 | }
34 |
35 | .generatorDatasetWrapper {
36 | margin-bottom: 10px;
37 | }
38 |
39 | .generatorSubTitle {
40 | font-weight: 600;
41 | padding: 1px;
42 | margin: 15px 5px;
43 | }
44 |
45 | .generatorDescription {
46 | padding: 5px;
47 | }
48 |
49 | .selectDataset,
50 | .selectSensitiveAttr,
51 | .selectProtectedGroupTitle,
52 | .selectFeatures,
53 | .selectMethod,
54 | .selectTopk {
55 | width: 100%;
56 | margin-top: 10px;
57 | padding: 5px;
58 | }
59 |
60 | .featureSelector {
61 | width: 90% !important;
62 | margin-left: 10px;
63 | }
64 |
65 | .generatorSubtitle {
66 | margin: 8px 0;
67 | border-bottom: 1px solid #cccccc;
68 | }
69 |
70 | .generatorSubSubTitle {
71 | margin: 5px 5px;
72 | font-weight: 500;
73 | font-size: 1rem;
74 | }
75 |
76 | .sensitiveAttrDropdown,
77 | .targetDropdown,
78 | .methodDropdown {
79 | display: grid;
80 |
81 | .sensitiveAttrDropdownToggle,
82 | .targetDropdownToggle,
83 | .methodDropdownToggle {
84 | justify-self: center;
85 | }
86 | }
87 |
88 | .selectProtectedGroupWrapper {
89 | width: 90%;
90 | margin: 0 auto;
91 | font-size: 1rem;
92 |
93 | .selectProtectedGroup {
94 | margin-left: 20px;
95 | }
96 | }
97 |
98 | .targetDropdownToggle .DataLoader {
99 | }
100 | /*** 2. Sensitive Attr & Feature Selector ***/
101 | .FeatureSelector {
102 | display: grid;
103 | grid-template-columns: 30% 70%;
104 | grid-template-rows: 25% 20% 55%;
105 | display: none;
106 |
107 | .firstTitle {
108 | grid-column: 1 / 3;
109 | grid-row: 1 / 2;
110 | }
111 |
112 | .secondTitle1 {
113 | grid-column: 1 / 2;
114 | grid-row: 2 / 3;
115 | }
116 |
117 | .SensitiveAttrSelectorDropdown {
118 | grid-column: 1 / 2;
119 | grid-row: 3 / 4;
120 |
121 | .SensitiveAttrSelectorDropdownToggle {
122 | width: 140px;
123 | }
124 | }
125 | .sensitiveGroupIndicator {
126 | margin: 5px;
127 | }
128 |
129 | .group1 {
130 | color: $group-color1;
131 | background-color: $group-color1;
132 | margin: 3px;
133 | }
134 | .group2 {
135 | color: $group-color2;
136 | background-color: $group-color2;
137 | margin: 3px;
138 | }
139 |
140 | // .sensitiveAttrProperties {
141 | // grid-column: 1 / 2;
142 | // grid-row: 4 / 5;
143 | // }
144 |
145 | .secondTitle2 {
146 | grid-column: 2 / 3;
147 | grid-row: 2 / 3;
148 | }
149 |
150 | .FeatureSelectorDropdown {
151 | grid-column: 2 / 3;
152 | grid-row: 3 / 4;
153 |
154 | .FeatureSelectorDropdownToggle {
155 | width: 140px;
156 | }
157 | }
158 | }
159 |
160 | /*** 3. Method & Top-k Selector ***/
161 | .MethodSelector {
162 | .MethodSelectorDropdown {
163 | width: 140px;
164 | }
165 | .secondTitle2 {
166 | margin-top: 10px;
167 | }
168 | }
169 |
170 | .fairnessQuestion {
171 | padding: 5px 10px;
172 | }
173 | .fairnessQuestion2 label {
174 | padding: 1px 10px !important;
175 | }
176 |
177 | /*** 4. Method & Top-k Selector ***/
178 | .buttonGenerateRanking {
179 | }
180 |
181 | .runButtonWrapper {
182 | display: grid;
183 | justify-content: right;
184 | align-items: center;
185 | padding: 10px;
186 | }
187 |
188 | .methodSelected {
189 | background-color: #003569 !important;
190 | color: white !important;
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/app/static/lib/rankSVM.py:
--------------------------------------------------------------------------------
1 | """
2 | Implementation of pairwise ranking using scikit-learn LinearSVC
3 |
4 | Reference:
5 |
6 | "Large Margin Rank Boundaries for Ordinal Regression", R. Herbrich,
7 | T. Graepel, K. Obermayer 1999
8 |
9 | "Learning to rank from medical imaging data." Pedregosa, Fabian, et al.,
10 | Machine Learning in Medical Imaging 2012.
11 |
12 |
13 | Authors: Fabian Pedregosa
14 | Alexandre Gramfort
15 |
16 | See also https://github.com/fabianp/pysofia for a more efficient implementation
17 | of RankSVM using stochastic gradient descent methdos.
18 | """
19 |
20 | import itertools
21 | import numpy as np
22 |
23 | from sklearn import svm, linear_model
24 | from sklearn.model_selection import cross_validate
25 |
26 |
27 | def transform_pairwise(X, y):
28 | """Transforms data into pairs with balanced labels for ranking
29 |
30 | Transforms a n-class ranking problem into a two-class classification
31 | problem. Subclasses implementing particular strategies for choosing
32 | pairs should override this method.
33 |
34 | In this method, all pairs are choosen, except for those that have the
35 | same target value. The output is an array of balanced classes, i.e.
36 | there are the same number of -1 as +1
37 |
38 | Parameters
39 | ----------
40 | X : array, shape (n_samples, n_features)
41 | The data
42 | y : array, shape (n_samples,) or (n_samples, 2)
43 | Target labels. If it's a 2D array, the second column represents
44 | the grouping of samples, i.e., samples with different groups will
45 | not be considered.
46 |
47 | Returns
48 | -------
49 | X_trans : array, shape (k, n_feaures)
50 | Data as pairs
51 | y_trans : array, shape (k,)
52 | Output class labels, where classes have values {-1, +1}
53 | """
54 | X_new = []
55 | y_new = []
56 | y = np.asarray(y)
57 | if y.ndim == 1:
58 | y = np.c_[y, np.ones(y.shape[0])]
59 | comb = itertools.combinations(range(X.shape[0]), 2)
60 | for k, (i, j) in enumerate(comb):
61 | if y[i, 0] == y[j, 0] or y[i, 1] != y[j, 1]:
62 | # skip if same target or different group
63 | continue
64 | X_new.append(X[i] - X[j])
65 | y_new.append(np.sign(y[i, 0] - y[j, 0]))
66 | # output balanced classes
67 | if y_new[-1] != (-1) ** k:
68 | y_new[-1] = - y_new[-1]
69 | X_new[-1] = - X_new[-1]
70 | return np.asarray(X_new), np.asarray(y_new).ravel()
71 |
72 |
73 | class RankSVM(svm.LinearSVC):
74 | """Performs pairwise ranking with an underlying LinearSVC model
75 |
76 | Input should be a n-class ranking problem, this object will convert it
77 | into a two-class classification problem, a setting known as
78 | `pairwise ranking`.
79 |
80 | See object :ref:`svm.LinearSVC` for a full description of parameters.
81 | """
82 |
83 | def fit(self, X, y):
84 | """
85 | Fit a pairwise ranking model.
86 |
87 | Parameters
88 | ----------
89 | X : array, shape (n_samples, n_features)
90 | y : array, shape (n_samples,) or (n_samples, 2)
91 |
92 | Returns
93 | -------
94 | self
95 | """
96 | X_trans, y_trans = transform_pairwise(X, y)
97 | super(RankSVM, self).fit(X_trans, y_trans)
98 | return self
99 |
100 | def decision_function(self, X):
101 | return np.dot(X, self.coef_.ravel())
102 |
103 | def predict(self, X):
104 | """
105 | Predict an ordering on X. For a list of n samples, this method
106 | returns a list from 0 to n-1 with the relative order of the rows of X.
107 | The item is given such that items ranked on top have are
108 | predicted a higher ordering (i.e. 0 means is the last item
109 | and n_samples would be the item ranked on top).
110 |
111 | Parameters,, y)
112 | return np.mean(super(RankSVM, self).predict(X_trans) == y_trans)
113 | """
114 | if hasattr(self, 'coef_'):
115 | return np.argsort(np.dot(X, self.coef_.ravel()))
116 | else:
117 | raise ValueError("Must call fit() prior to predict()")
118 |
119 | def score(self, X, y):
120 | """
121 | Because we transformed into a pairwise problem, chance level is at 0.5
122 | """
123 | X_trans, y_trans = transform_pairwise(X, y)
124 | return np.mean(super(RankSVM, self).predict(X_trans) == y_trans)
--------------------------------------------------------------------------------
/src/src/components/RankingInspectorView/styles.scss:
--------------------------------------------------------------------------------
1 | .RankingInspectorView {
2 | grid-area: d;
3 |
4 | // background-color: #fbfbfb;
5 | border: 1px solid #f1f0f0;
6 | padding: 10px;
7 |
8 | .subTitle {
9 | border-top: 1px solid #d9d9d9;
10 | padding: 10px 0;
11 | }
12 |
13 | .rankingInspectorViewTitleWrapper {
14 | display: flex;
15 |
16 | .rankingInspectorViewTitle {
17 | grid-area: t;
18 | padding: 0;
19 | }
20 | }
21 |
22 | .inspectorWrapper {
23 | display: flex;
24 | border-bottom: 1px solid lightgray;
25 | height: 650px;
26 | }
27 |
28 | .SpaceView {
29 | width: 70%;
30 | display: grid;
31 | grid-template-columns: 35% 45% 20%;
32 | grid-template-rows: 35px 110px 270px 135px;
33 | grid-template-areas: // nv: navigation bar, lg: legend, st: individual status, dp: distortion plot
34 | 't t t'
35 | 'sm sm sm'
36 | 'i mt tr'
37 | 'lg mt tr';
38 | // background-color: #f5f4f4;
39 | // border: 1px solid #e2e2e2;
40 | margin-right: 10px;
41 | }
42 |
43 | .spaceViewTitleWrapper {
44 | grid-area: t;
45 | display: flex;
46 | justify-content: space-between;
47 | background-color: #00346b;
48 | color: white;
49 | }
50 |
51 | .spaceOverview {
52 | grid-area: sm;
53 | display: grid;
54 | grid-template-columns: 32% 5% 42% 5% 16%;
55 | grid-template-rows: 25px 5px 50px;
56 | grid-template-areas:
57 | 'it i1 mt i2 ot'
58 | 'id i1 md i2 od'
59 | 'im i1 mm i2 om';
60 | margin-top: 10px;
61 | }
62 |
63 | .inputSpaceTitle { grid-area: it; }
64 | .inputSpaceDescription { grid-area: id; }
65 | .inputSpaceMeasure { grid-area: im; display: flex; justify-content: center;}
66 | .mappingSpaceTitle { grid-area: mt; }
67 | .mappingSpaceDescription { grid-area: md; }
68 | .mappingSpaceMeasure { grid-area: mm; display: flex; justify-content: center; }
69 | .outputSpaceTitle { grid-area: ot; }
70 | .outputSpaceDescription { grid-area: od; }
71 | .outputSpaceMeasure { grid-area: om; display: flex; justify-content: center; }
72 | .intervalSpace1 { grid-area: i1; }
73 | .intervalSpace2 { grid-area: i2; }
74 |
75 | .inputSpaceTitle,
76 | .mappingSpaceTitle,
77 | .outputSpaceTitle {
78 | justify-self: center;
79 | color: #00346b;
80 | font-size: 1.1rem;
81 | font-weight: 500;
82 | border-bottom: 1px solid black;
83 | }
84 |
85 | .intervalSpace1,
86 | .intervalSpace2 {
87 | align-self: center;
88 | justify-self: center;
89 | }
90 |
91 | .utilityWrapper,
92 | .groupFairnessWrapper {
93 | width: 30%;
94 | }
95 |
96 | .individualFairnessWrapper {
97 | width: 100%;
98 | }
99 |
100 | .utility,
101 | .inputGroupFairness,
102 | .mappingGroupFairness,
103 | .outputGroupFairness,
104 | .individualFairness {
105 | font-size: 2rem;
106 | margin-bottom: 10px;
107 | }
108 |
109 | .LegendView { grid-area: lg; }
110 | .OutputSpaceView { grid-area: tr; }
111 |
112 | .InspectionComponentsView {
113 | }
114 |
115 | .MatrixWrapper {
116 | grid-area: mt;
117 | border: 1px dashed #e4e4e4;
118 | padding: 15px;
119 | margin: 5px;
120 |
121 | .dropdownWrapper {
122 | width: 30%;
123 | float: right;
124 | }
125 |
126 | .IndividualStatusView {
127 | width: 25%;
128 |
129 | .IndividualStatus {
130 | height: 320px;
131 | padding: 5px;
132 | margin: 5px;
133 | background-color: #f7f7f7;
134 | border: 1px solid lightgray;
135 | }
136 | }
137 | }
138 |
139 | .DistortionPlot {
140 | grid-area: dp;
141 |
142 | .rankingInspectorViewBar {
143 | margin-left: 10px;
144 | padding: 5px;
145 | background-color: #e5e5e5;
146 | border: 1px solid lightgray;
147 |
148 | display: flex;
149 | align-items: center;
150 | // justify-content: flex-end;
151 | }
152 | }
153 |
154 | .CorrelationView {
155 | grid-area: cr;
156 |
157 | .matrixColorDropdownWrapper,
158 | .matrixDropdownWrapper,
159 | .correlationTableWrapper {
160 | border-radius: 3px;
161 | margin: 5px;
162 | padding: 5px;
163 | align-items: center;
164 |
165 | .sortMatrixXdropdownWrapper,
166 | .sortMatrixYdropdownWrapper {
167 | display: flex;
168 | align-items: center;
169 | margin: 3px;
170 | }
171 |
172 | .colorMatrixDropdown,
173 | .sortMatrixXdropdown,
174 | .sortMatrixYdropdown {
175 | width: 90%;
176 | }
177 | }
178 | }
179 | }
--------------------------------------------------------------------------------
/app/templates/base.html:
--------------------------------------------------------------------------------
1 | {% load static i18n %}
2 |
3 |
4 |
5 |
6 | {% block title %}app{% endblock title %}
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 | {% block css %}
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | {% endblock %}
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | app
37 |
38 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | {% if messages %}
74 | {% for message in messages %}
75 |
{{ message }}
76 | {% endfor %}
77 | {% endif %}
78 |
79 | {% block content %}
80 |
Use this document as a way to quick start any new project.
81 | {% endblock content %}
82 |
83 |
84 |
85 | {% block modal %}{% endblock modal %}
86 |
87 |
89 |
90 | {% block javascript %}
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | {% endblock javascript %}
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/src/config/webpackDevServer.config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
4 | const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
5 | const config = require('./webpack.config.dev');
6 | const paths = require('./paths');
7 |
8 | const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
9 | const host = process.env.HOST || '0.0.0.0';
10 |
11 | module.exports = function(proxy, allowedHost) {
12 | return {
13 | // WebpackDevServer 2.4.3 introduced a security fix that prevents remote
14 | // websites from potentially accessing local content through DNS rebinding:
15 | // https://github.com/webpack/webpack-dev-server/issues/887
16 | // https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
17 | // However, it made several existing use cases such as development in cloud
18 | // environment or subdomains in development significantly more complicated:
19 | // https://github.com/facebookincubator/create-react-app/issues/2271
20 | // https://github.com/facebookincubator/create-react-app/issues/2233
21 | // While we're investigating better solutions, for now we will take a
22 | // compromise. Since our WDS configuration only serves files in the `public`
23 | // folder we won't consider accessing them a vulnerability. However, if you
24 | // use the `proxy` feature, it gets more dangerous because it can expose
25 | // remote code execution vulnerabilities in backends like Django and Rails.
26 | // So we will disable the host check normally, but enable it if you have
27 | // specified the `proxy` setting. Finally, we let you override it if you
28 | // really know what you're doing with a special environment variable.
29 | disableHostCheck:
30 | !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
31 | // Enable gzip compression of generated files.
32 | compress: true,
33 | // Silence WebpackDevServer's own logs since they're generally not useful.
34 | // It will still show compile warnings and errors with this setting.
35 | clientLogLevel: 'none',
36 | // By default WebpackDevServer serves physical files from current directory
37 | // in addition to all the virtual build products that it serves from memory.
38 | // This is confusing because those files won’t automatically be available in
39 | // production build folder unless we copy them. However, copying the whole
40 | // project directory is dangerous because we may expose sensitive files.
41 | // Instead, we establish a convention that only files in `public` directory
42 | // get served. Our build script will copy `public` into the `build` folder.
43 | // In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
44 | //
45 | // In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
46 | // Note that we only recommend to use `public` folder as an escape hatch
47 | // for files like `favicon.ico`, `manifest.json`, and libraries that are
48 | // for some reason broken when imported through Webpack. If you just want to
49 | // use an image, put it in `src` and `import` it from JavaScript instead.
50 | contentBase: paths.appPublic,
51 | // By default files from `contentBase` will not trigger a page reload.
52 | watchContentBase: true,
53 | // Enable hot reloading server. It will provide /sockjs-node/ endpoint
54 | // for the WebpackDevServer client so it can learn when the files were
55 | // updated. The WebpackDevServer client is included as an entry point
56 | // in the Webpack development configuration. Note that only changes
57 | // to CSS are currently hot reloaded. JS changes will refresh the browser.
58 | hot: true,
59 | // It is important to tell WebpackDevServer to use the same "root" path
60 | // as we specified in the config. In development, we always serve from /.
61 | publicPath: config.output.publicPath,
62 | // WebpackDevServer is noisy by default so we emit custom message instead
63 | // by listening to the compiler events with `compiler.plugin` calls above.
64 | quiet: true,
65 | // Reportedly, this avoids CPU overload on some systems.
66 | // https://github.com/facebookincubator/create-react-app/issues/293
67 | watchOptions: {
68 | ignored: /node_modules/,
69 | },
70 | // Enable HTTPS if the HTTPS environment variable is set to 'true'
71 | https: protocol === 'https',
72 | host: host,
73 | overlay: false,
74 | historyApiFallback: {
75 | // Paths with dots should still use the history fallback.
76 | // See https://github.com/facebookincubator/create-react-app/issues/387.
77 | disableDotRule: true,
78 | },
79 | public: allowedHost,
80 | proxy,
81 | setup(app) {
82 | // This lets us open files from the runtime error overlay.
83 | app.use(errorOverlayMiddleware());
84 | // This service worker file is effectively a 'no-op' that will reset any
85 | // previous service worker registered for the same host:port combination.
86 | // We do this in development to avoid hitting the production cache if
87 | // it used the same host and port.
88 | // https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
89 | app.use(noopServiceWorkerMiddleware());
90 | },
91 | };
92 | };
93 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Python template
2 | # Byte-compiled / optimized / DLL files
3 | __pycache__/
4 | *.py[cod]
5 | *$py.class
6 |
7 | # C extensions
8 | *.so
9 |
10 | # Distribution / packaging
11 | .Python
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 |
27 | # PyInstaller
28 | # Usually these files are written by a python script from a template
29 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
30 | *.manifest
31 | *.spec
32 |
33 | # Installer logs
34 | pip-log.txt
35 | pip-delete-this-directory.txt
36 |
37 | # Unit test / coverage reports
38 | htmlcov/
39 | .tox/
40 | .coverage
41 | .coverage.*
42 | .cache
43 | nosetests.xml
44 | coverage.xml
45 | *.cover
46 | .hypothesis/
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | staticfiles/
54 |
55 | # Sphinx documentation
56 | docs/_build/
57 |
58 | # PyBuilder
59 | target/
60 |
61 | # pyenv
62 | .python-version
63 |
64 |
65 |
66 | # Environments
67 | .venv
68 | venv/
69 | ENV/
70 |
71 | # Rope project settings
72 | .ropeproject
73 |
74 | # mkdocs documentation
75 | /site
76 |
77 | # mypy
78 | .mypy_cache/
79 |
80 |
81 | ### Node template
82 | # Logs
83 | logs
84 | *.log
85 | npm-debug.log*
86 | yarn-debug.log*
87 | yarn-error.log*
88 |
89 | # Runtime data
90 | pids
91 | *.pid
92 | *.seed
93 | *.pid.lock
94 |
95 | # Directory for instrumented libs generated by jscoverage/JSCover
96 | lib-cov
97 |
98 | # Coverage directory used by tools like istanbul
99 | coverage
100 |
101 | # nyc test coverage
102 | .nyc_output
103 |
104 | # Bower dependency directory (https://bower.io/)
105 | bower_components
106 |
107 | # node-waf configuration
108 | .lock-wscript
109 |
110 | # Compiled binary addons (http://nodejs.org/api/addons.html)
111 | build/Release
112 |
113 | # Dependency directories
114 | node_modules/
115 | jspm_packages/
116 |
117 | # Typescript v1 declaration files
118 | typings/
119 |
120 | # Optional npm cache directory
121 | .npm
122 |
123 | # Optional eslint cache
124 | .eslintcache
125 |
126 | # Optional REPL history
127 | .node_repl_history
128 |
129 | # Output of 'npm pack'
130 | *.tgz
131 |
132 | # Yarn Integrity file
133 | .yarn-integrity
134 |
135 |
136 | ### Linux template
137 | *~
138 |
139 | # temporary files which can be created if a process still has a handle open of a deleted file
140 | .fuse_hidden*
141 |
142 | # KDE directory preferences
143 | .directory
144 |
145 | # Linux trash folder which might appear on any partition or disk
146 | .Trash-*
147 |
148 | # .nfs files are created when an open file is removed but is still being accessed
149 | .nfs*
150 |
151 |
152 | ### VisualStudioCode template
153 | .vscode/*
154 | !.vscode/settings.json
155 | !.vscode/tasks.json
156 | !.vscode/launch.json
157 | !.vscode/extensions.json
158 |
159 |
160 |
161 |
162 |
163 | ### Windows template
164 | # Windows thumbnail cache files
165 | Thumbs.db
166 | ehthumbs.db
167 | ehthumbs_vista.db
168 |
169 | # Dump file
170 | *.stackdump
171 |
172 | # Folder config file
173 | Desktop.ini
174 |
175 | # Recycle Bin used on file shares
176 | $RECYCLE.BIN/
177 |
178 | # Windows Installer files
179 | *.cab
180 | *.msi
181 | *.msm
182 | *.msp
183 |
184 | # Windows shortcuts
185 | *.lnk
186 |
187 |
188 | ### macOS template
189 | # General
190 | *.DS_Store
191 | .AppleDouble
192 | .LSOverride
193 |
194 | # Icon must end with two \r
195 | Icon
196 |
197 | # Thumbnails
198 | ._*
199 |
200 | # Files that might appear in the root of a volume
201 | .DocumentRevisions-V100
202 | .fseventsd
203 | .Spotlight-V100
204 | .TemporaryItems
205 | .Trashes
206 | .VolumeIcon.icns
207 | .com.apple.timemachine.donotpresent
208 |
209 | # Directories potentially created on remote AFP share
210 | .AppleDB
211 | .AppleDesktop
212 | Network Trash Folder
213 | Temporary Items
214 | .apdisk
215 |
216 |
217 | ### SublimeText template
218 | # Cache files for Sublime Text
219 | *.tmlanguage.cache
220 | *.tmPreferences.cache
221 | *.stTheme.cache
222 |
223 | # Workspace files are user-specific
224 | *.sublime-workspace
225 |
226 | # Project files should be checked into the repository, unless a significant
227 | # proportion of contributors will probably not be using Sublime Text
228 | # *.sublime-project
229 |
230 | # SFTP configuration file
231 | sftp-config.json
232 |
233 | # Package control specific files
234 | Package Control.last-run
235 | Package Control.ca-list
236 | Package Control.ca-bundle
237 | Package Control.system-ca-bundle
238 | Package Control.cache/
239 | Package Control.ca-certs/
240 | Package Control.merged-ca-bundle
241 | Package Control.user-ca-bundle
242 | oscrypto-ca-bundle.crt
243 | bh_unicode_properties.cache
244 |
245 | # Sublime-github package stores a github token in this file
246 | # https://packagecontrol.io/packages/sublime-github
247 | GitHub.sublime-settings
248 |
249 |
250 | ### Vim template
251 | # Swap
252 | [._]*.s[a-v][a-z]
253 | [._]*.sw[a-p]
254 | [._]s[a-v][a-z]
255 | [._]sw[a-p]
256 |
257 | # Session
258 | Session.vim
259 |
260 | # Temporary
261 | .netrwhist
262 |
263 | # Auto-generated tag files
264 | tags
265 |
266 |
267 | ### VirtualEnv template
268 | # Virtualenv
269 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
270 | [Bb]in
271 | [Ii]nclude
272 | [Ll]ib
273 | [Ll]ib64
274 | [Ss]cripts
275 | pyvenv.cfg
276 | pip-selfcheck.json
277 |
278 |
279 | ### Project template
280 |
281 | my_awesome_project/media/
282 |
283 | .pytest_cache/
284 |
--------------------------------------------------------------------------------
/app/static/lib/rankSVM2.py:
--------------------------------------------------------------------------------
1 | import itertools
2 |
3 | import numpy as np
4 |
5 | from sklearn.linear_model import SGDClassifier, SGDRanking
6 | from sklearn import metrics
7 | from minirank.compat import RankSVM as MinirankSVM
8 | from scipy import stats
9 |
10 |
11 | def transform_pairwise(X, y):
12 | """Transforms data into pairs with balanced labels for ranking
13 | Transforms a n-class ranking problem into a two-class classification
14 | problem. Subclasses implementing particular strategies for choosing
15 | pairs should override this method.
16 | In this method, all pairs are choosen, except for those that have the
17 | same target value. The output is an array of balanced classes, i.e.
18 | there are the same number of -1 as +1
19 | Parameters
20 | ----------
21 | X : array, shape (n_samples, n_features)
22 | The data
23 | y : array, shape (n_samples,) or (n_samples, 2)
24 | Target labels. If it's a 2D array, the second column represents
25 | the grouping of samples, i.e., samples with different groups will
26 | not be considered.
27 | Returns
28 | -------
29 | X_trans : array, shape (k, n_feaures)
30 | Data as pairs
31 | y_trans : array, shape (k,)
32 | Output class labels, where classes have values {-1, +1}
33 | """
34 | X_new = []
35 | y_new = []
36 | y = np.asarray(y)
37 | if y.ndim == 1:
38 | y = np.c_[y, np.ones(y.shape[0])]
39 | comb = itertools.combinations(range(X.shape[0]), 2)
40 | for k, (i, j) in enumerate(comb):
41 | if y[i, 0] == y[j, 0] or y[i, 1] != y[j, 1]:
42 | # skip if same target or different group
43 | continue
44 | X_new.append(X[i] - X[j])
45 | y_new.append(np.sign(y[i, 0] - y[j, 0]))
46 | # output balanced classes
47 | if y_new[-1] != (-1) ** k:
48 | y_new[-1] = - y_new[-1]
49 | X_new[-1] = - X_new[-1]
50 | return np.asarray(X_new), np.asarray(y_new).ravel()
51 |
52 |
53 | class RankSVM(SGDClassifier):
54 | """Performs pairwise ranking with an underlying SGDClassifer model
55 | Input should be a n-class ranking problem, this object will convert it
56 | into a two-class classification problem, a setting known as
57 | `pairwise ranking`.
58 | Authors: Fabian Pedregosa
59 | Alexandre Gramfort
60 | https://gist.github.com/2071994
61 | """
62 |
63 | def fit(self, X, y):
64 | """
65 | Fit a pairwise ranking model.
66 | Parameters
67 | ----------
68 | X : array, shape (n_samples, n_features)
69 | y : array, shape (n_samples,) or (n_samples, 2)
70 | Returns
71 | -------
72 | self
73 | """
74 | X_trans, y_trans = transform_pairwise(X, y)
75 | super(RankSVM, self).fit(X_trans, y_trans)
76 | return self
77 |
78 | def predict(self, X):
79 | pred = super(RankSVM, self).predict(X)
80 | # preds are mapped to {-1,1}
81 | # FIXME only works in this example!!!
82 | pred[pred == -1] = 0
83 | return pred
84 |
85 | def score(self, X, y):
86 | """
87 | Because we transformed into a pairwise problem, chance level is at 0.5
88 | """
89 | X_trans, y_trans = transform_pairwise(X, y)
90 | return np.mean(super(RankSVM, self).predict(X_trans) == y_trans)
91 |
92 | def rank(clf,X):
93 | if clf.coef_.shape[0] == 1:
94 | coef = clf.coef_[0]
95 | else:
96 | coef = clf.coef_
97 | order = np.argsort(np.dot(X,coef))
98 | order_inv = np.zeros_like(order)
99 | order_inv[order] = np.arange(len(order))
100 | return order_inv
101 |
102 | def kendalltau(clf,X,y):
103 | if clf.coef_.shape[0] == 1:
104 | coef = clf.coef_[0]
105 | else:
106 | coef = clf.coef_
107 | tau, _ = stats.kendalltau(np.dot(X, coef), y)
108 | return np.abs(tau)
109 |
110 |
111 | if __name__=="__main__":
112 | rs = np.random.RandomState(0)
113 | n_samples_1 = 10000
114 | n_samples_2 = 100
115 | X = np.r_[1.5 * rs.randn(n_samples_1, 2),
116 | 0.5 * rs.randn(n_samples_2, 2) + [2, 2]]
117 | y = np.array([0] * (n_samples_1) + [1] * (n_samples_2))
118 | idx = np.arange(y.shape[0])
119 | rs.shuffle(idx)
120 | X = X[idx]
121 | y = y[idx]
122 | mean = X.mean(axis=0)
123 | std = X.std(axis=0)
124 | X = (X - mean) / std
125 |
126 | for clf, name in ((SGDClassifier(n_iter=100, alpha=0.01), "plain sgd"),
127 | (SGDClassifier(n_iter=100, alpha=0.01,
128 | class_weight={1: 10}),"weighted sgd"),
129 | (SGDRanking(n_iter=1000, alpha=0.01,
130 | loss='roc_pairwise_ranking'), "pairwise sgd"),
131 | (RankSVM(n_iter=100, alpha=0.01, loss='hinge'), 'RankSVM'),
132 | ):
133 | clf.fit(X, y)
134 | print clf
135 | pred = clf.predict(X)
136 |
137 | print "ACC: %.4f" % metrics.zero_one_score(y, pred)
138 | print "AUC: %.4f" % metrics.auc_score(y, pred)
139 | print "CONFUSION MATRIX: "
140 | print metrics.confusion_matrix(y, pred)
141 | print "Kendall Tau: %.4f" % kendalltau(clf,X,y)
142 | print 80*'='
143 |
144 | clf = MinirankSVM(max_iter=100, alpha=0.01).fit(X,y)
145 | print clf
146 | scores = np.dot(X,clf.coef_)
147 | pred = (scores > 0).astype(np.int)
148 | print "ACC: %.4f" % metrics.zero_one_score(y, pred)
149 | print "AUC: %.4f" % metrics.auc_score(y, pred)
150 | print "CONFUSION MATRIX: "
151 | print metrics.confusion_matrix(y, pred)
152 | print "Kendall Tau: %.4f" % kendalltau(clf,X,y)
153 | print 80*'='
--------------------------------------------------------------------------------
/docs/make.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | REM Command file for Sphinx documentation
4 |
5 | if "%SPHINXBUILD%" == "" (
6 | set SPHINXBUILD=sphinx-build
7 | )
8 | set BUILDDIR=_build
9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
10 | set I18NSPHINXOPTS=%SPHINXOPTS% .
11 | if NOT "%PAPER%" == "" (
12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
14 | )
15 |
16 | if "%1" == "" goto help
17 |
18 | if "%1" == "help" (
19 | :help
20 | echo.Please use `make ^` where ^ is one of
21 | echo. html to make standalone HTML files
22 | echo. dirhtml to make HTML files named index.html in directories
23 | echo. singlehtml to make a single large HTML file
24 | echo. pickle to make pickle files
25 | echo. json to make JSON files
26 | echo. htmlhelp to make HTML files and a HTML help project
27 | echo. qthelp to make HTML files and a qthelp project
28 | echo. devhelp to make HTML files and a Devhelp project
29 | echo. epub to make an epub
30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
31 | echo. text to make text files
32 | echo. man to make manual pages
33 | echo. texinfo to make Texinfo files
34 | echo. gettext to make PO message catalogs
35 | echo. changes to make an overview over all changed/added/deprecated items
36 | echo. linkcheck to check all external links for integrity
37 | echo. doctest to run all doctests embedded in the documentation if enabled
38 | goto end
39 | )
40 |
41 | if "%1" == "clean" (
42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
43 | del /q /s %BUILDDIR%\*
44 | goto end
45 | )
46 |
47 | if "%1" == "html" (
48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
49 | if errorlevel 1 exit /b 1
50 | echo.
51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html.
52 | goto end
53 | )
54 |
55 | if "%1" == "dirhtml" (
56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
57 | if errorlevel 1 exit /b 1
58 | echo.
59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
60 | goto end
61 | )
62 |
63 | if "%1" == "singlehtml" (
64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
65 | if errorlevel 1 exit /b 1
66 | echo.
67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
68 | goto end
69 | )
70 |
71 | if "%1" == "pickle" (
72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
73 | if errorlevel 1 exit /b 1
74 | echo.
75 | echo.Build finished; now you can process the pickle files.
76 | goto end
77 | )
78 |
79 | if "%1" == "json" (
80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
81 | if errorlevel 1 exit /b 1
82 | echo.
83 | echo.Build finished; now you can process the JSON files.
84 | goto end
85 | )
86 |
87 | if "%1" == "htmlhelp" (
88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
89 | if errorlevel 1 exit /b 1
90 | echo.
91 | echo.Build finished; now you can run HTML Help Workshop with the ^
92 | .hhp project file in %BUILDDIR%/htmlhelp.
93 | goto end
94 | )
95 |
96 | if "%1" == "qthelp" (
97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
98 | if errorlevel 1 exit /b 1
99 | echo.
100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^
101 | .qhcp project file in %BUILDDIR%/qthelp, like this:
102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\my_awesome_project.qhcp
103 | echo.To view the help file:
104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\my_awesome_project.ghc
105 | goto end
106 | )
107 |
108 | if "%1" == "devhelp" (
109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
110 | if errorlevel 1 exit /b 1
111 | echo.
112 | echo.Build finished.
113 | goto end
114 | )
115 |
116 | if "%1" == "epub" (
117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
118 | if errorlevel 1 exit /b 1
119 | echo.
120 | echo.Build finished. The epub file is in %BUILDDIR%/epub.
121 | goto end
122 | )
123 |
124 | if "%1" == "latex" (
125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
126 | if errorlevel 1 exit /b 1
127 | echo.
128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
129 | goto end
130 | )
131 |
132 | if "%1" == "text" (
133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
134 | if errorlevel 1 exit /b 1
135 | echo.
136 | echo.Build finished. The text files are in %BUILDDIR%/text.
137 | goto end
138 | )
139 |
140 | if "%1" == "man" (
141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
142 | if errorlevel 1 exit /b 1
143 | echo.
144 | echo.Build finished. The manual pages are in %BUILDDIR%/man.
145 | goto end
146 | )
147 |
148 | if "%1" == "texinfo" (
149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
150 | if errorlevel 1 exit /b 1
151 | echo.
152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
153 | goto end
154 | )
155 |
156 | if "%1" == "gettext" (
157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
158 | if errorlevel 1 exit /b 1
159 | echo.
160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
161 | goto end
162 | )
163 |
164 | if "%1" == "changes" (
165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
166 | if errorlevel 1 exit /b 1
167 | echo.
168 | echo.The overview file is in %BUILDDIR%/changes.
169 | goto end
170 | )
171 |
172 | if "%1" == "linkcheck" (
173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
174 | if errorlevel 1 exit /b 1
175 | echo.
176 | echo.Link check complete; look for any errors in the above output ^
177 | or in %BUILDDIR%/linkcheck/output.txt.
178 | goto end
179 | )
180 |
181 | if "%1" == "doctest" (
182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
183 | if errorlevel 1 exit /b 1
184 | echo.
185 | echo.Testing of doctests in the sources finished, look at the ^
186 | results in %BUILDDIR%/doctest/output.txt.
187 | goto end
188 | )
189 |
190 | :end
191 |
--------------------------------------------------------------------------------
/src/src/components/RankingView/wholeRankingChart.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import * as d3 from 'd3';
3 | import _ from 'lodash';
4 | import { Bar } from '@vx/shape';
5 | import { genRandomNormalPoints } from '@vx/mock-data';
6 | import { scaleLinear } from '@vx/scale';
7 | import { Group } from '@vx/group';
8 | import { AxisLeft, AxisBottom } from '@vx/axis';
9 | import {
10 | BoxBrush,
11 | withBrush,
12 | getCoordsFromEvent,
13 | constrainToRegion
14 | } from '@vx/brush';
15 | import { Motion, spring } from 'react-motion';
16 |
17 | import styles from './styles.scss';
18 | import index from '../../index.css';
19 | import gs from '../../config/_variables.scss'; // gs (=global style)
20 |
21 | const points = genRandomNormalPoints();
22 |
23 | class WholeRankingChart extends React.Component {
24 | constructor(props) {
25 | super(props);
26 | const { data, width, height, margin } = props;
27 |
28 | this.invertedDomain = [];
29 |
30 | this.layout = {
31 | wholeRankingchart: {
32 | width: 450,
33 | height: 60
34 | }
35 | };
36 |
37 | this.extent = {
38 | x0: margin.left,
39 | x1: width - margin.left,
40 | y0: margin.top,
41 | y1: height - margin.top
42 | };
43 |
44 | this.initialDomain = {
45 | x: [0, 100],
46 | y: d3.extent(data.instances, d => d.score)
47 | };
48 |
49 | this.xScale = scaleLinear({
50 | domain: this.initialDomain.x,
51 | range: [0, this.layout.wholeRankingchart.width] //[0, width - margin.left - margin.right],
52 | });
53 |
54 | this.yScale = scaleLinear({
55 | domain: this.initialDomain.y,
56 | range: [30, 0], //[height - margin.top - margin.bottom, 0],
57 | clamp: true
58 | });
59 |
60 | this.handleMouseDown = this.handleMouseDown.bind(this);
61 | this.handleMouseMove = this.handleMouseMove.bind(this);
62 | this.handleMouseUp = this.handleMouseUp.bind(this);
63 | }
64 |
65 | scaleReset() {
66 | const { xScale, yScale, initialDomain } = this;
67 | xScale.domain(initialDomain.x);
68 | yScale.domain(initialDomain.y);
69 | }
70 |
71 | handleMouseDown(event) {
72 | const { onBrushStart } = this.props;
73 | const { extent: region } = this;
74 | const { x, y } = getCoordsFromEvent(this.svg, event);
75 | onBrushStart(constrainToRegion({ region, x, y }));
76 | }
77 |
78 | handleMouseMove(event) {
79 | const { brush, onBrushDrag, updateBrush } = this.props;
80 | // only update the brush region if we're dragging
81 | if (!brush.isBrushing) return;
82 | const { extent: region } = this;
83 |
84 | const { x, y } = getCoordsFromEvent(this.svg, event);
85 | onBrushDrag(constrainToRegion({ region, x, y }));
86 | }
87 |
88 | handleMouseUp(event) {
89 | const { brush, onBrushEnd, onBrushReset } = this.props;
90 | const { extent: region } = this;
91 |
92 | if (brush.end) {
93 | const { x, y } = getCoordsFromEvent(this.svg, event);
94 | onBrushEnd(constrainToRegion({ region, x, y }));
95 | return;
96 | }
97 | this.props.onSelectedRankingInterval({
98 | from: this.invertedDomain[0],
99 | to: this.invertedDomain[1]
100 | });
101 | onBrushReset(event);
102 | }
103 |
104 | render() {
105 | const _self = this;
106 |
107 | const { data, width, height, brush, margin } = this.props;
108 | const { xScale, yScale } = this;
109 | const { instances } = data;
110 | const dataBin = d3
111 | .histogram()
112 | .domain([0, 100])
113 | .thresholds(d3.range(0, 100, 1))(_.map(instances, d => d.score));
114 | const topInstances = [...instances]
115 | .sort((a, b) => d3.descending(a.score, b.score))
116 | .slice(0, 100);
117 |
118 | const xMax = width - margin.left - margin.right;
119 | const yMax = height - margin.top - margin.bottom;
120 |
121 | _self.xScale.domain([100, 0]);
122 | _self.yScale.domain(
123 | d3.extent(dataBin, d => (typeof d.length !== 'undefined' ? d.length : 0))
124 | );
125 |
126 | if (brush.domain) {
127 | const { domain } = brush;
128 | const { x0, x1, y0, y1 } = domain;
129 | _self.invertedDomain = [x0, x1].map(d => {
130 | return xScale.customInvert(d);
131 | });
132 | }
133 |
134 | xScale.customInvert = (function() {
135 | var domain = xScale.domain();
136 | var range = xScale.range();
137 | var scale = d3
138 | .scaleQuantize()
139 | .domain(range)
140 | .range(domain);
141 |
142 | return function(x) {
143 | return scale(x);
144 | };
145 | })();
146 |
147 | return (
148 |
149 |
{
151 | this.svg = c;
152 | }}
153 | width={this.layout.wholeRankingchart.width}
154 | height={this.layout.wholeRankingchart.height}
155 | margin={10}
156 | onMouseDown={this.handleMouseDown}
157 | onMouseMove={this.handleMouseMove}
158 | onMouseUp={this.handleMouseUp}
159 | >
160 |
168 |
169 | {dataBin.map((bin, idx) => {
170 | return (
171 |
181 | );
182 | })}
183 |
184 |
185 |
186 |
187 | );
188 | }
189 | }
190 |
191 | export default withBrush(WholeRankingChart);
192 |
--------------------------------------------------------------------------------
/src/src/data/dim_reduction_result.json:
--------------------------------------------------------------------------------
1 | {
2 | "19": {
3 | "dim1": -0.1520611601,
4 | "dim2": 0.4130915259,
5 | "sex": "female ",
6 | "default": 1
7 | },
8 | "30": {
9 | "dim1": -0.2061182264,
10 | "dim2": 0.3883319964,
11 | "sex": "male ",
12 | "default": 1
13 | },
14 | "4": {
15 | "dim1": 0.4896267472,
16 | "dim2": 0.1819635753,
17 | "sex": "male ",
18 | "default": 0
19 | },
20 | "6": {
21 | "dim1": -0.4601340337,
22 | "dim2": 0.1022737855,
23 | "sex": "male ",
24 | "default": 0
25 | },
26 | "5": {
27 | "dim1": -0.4105629315,
28 | "dim2": 0.0472031012,
29 | "sex": "male ",
30 | "default": 1
31 | },
32 | "9": {
33 | "dim1": 0.0157274552,
34 | "dim2": -0.4831678968,
35 | "sex": "male ",
36 | "default": 0
37 | },
38 | "1": {
39 | "dim1": 0.3226958333,
40 | "dim2": -0.0225785934,
41 | "sex": "male ",
42 | "default": 0
43 | },
44 | "8": {
45 | "dim1": 0.4753128955,
46 | "dim2": -0.2096250454,
47 | "sex": "male ",
48 | "default": 0
49 | },
50 | "7": {
51 | "dim1": 0.4446316476,
52 | "dim2": 0.3188137594,
53 | "sex": "male ",
54 | "default": 0
55 | },
56 | "18": {
57 | "dim1": 0.2588307855,
58 | "dim2": 0.2539197008,
59 | "sex": "male ",
60 | "default": 0
61 | },
62 | "14": {
63 | "dim1": -0.1531672824,
64 | "dim2": 0.1298578992,
65 | "sex": "male ",
66 | "default": 1
67 | },
68 | "17": {
69 | "dim1": 0.0222000547,
70 | "dim2": 0.0172376965,
71 | "sex": "male ",
72 | "default": 0
73 | },
74 | "34": {
75 | "dim1": 0.4318142297,
76 | "dim2": 0.1352582025,
77 | "sex": "male ",
78 | "default": 0
79 | },
80 | "37": {
81 | "dim1": -0.0556036911,
82 | "dim2": 0.3413660155,
83 | "sex": "male ",
84 | "default": 0
85 | },
86 | "33": {
87 | "dim1": 0.0185895926,
88 | "dim2": 0.4296620226,
89 | "sex": "male ",
90 | "default": 0
91 | },
92 | "3": {
93 | "dim1": -0.2192777212,
94 | "dim2": 0.1400518621,
95 | "sex": "male ",
96 | "default": 0
97 | },
98 | "23": {
99 | "dim1": 0.2576912529,
100 | "dim2": 0.3330047117,
101 | "sex": "male ",
102 | "default": 0
103 | },
104 | "21": {
105 | "dim1": 0.1089814037,
106 | "dim2": -0.4752476743,
107 | "sex": "male ",
108 | "default": 0
109 | },
110 | "22": {
111 | "dim1": 0.242834075,
112 | "dim2": -0.4985553517,
113 | "sex": "male ",
114 | "default": 0
115 | },
116 | "10": {
117 | "dim1": -0.1220959758,
118 | "dim2": -0.2975151318,
119 | "sex": "male ",
120 | "default": 1
121 | },
122 | "2": {
123 | "dim1": 0.0932850521,
124 | "dim2": 0.2574299399,
125 | "sex": "female ",
126 | "default": 1
127 | },
128 | "24": {
129 | "dim1": -0.0072194325,
130 | "dim2": -0.3612800293,
131 | "sex": "male ",
132 | "default": 0
133 | },
134 | "36": {
135 | "dim1": -0.1935707668,
136 | "dim2": 0.5096827362,
137 | "sex": "male ",
138 | "default": 1
139 | },
140 | "20": {
141 | "dim1": 0.4221919548,
142 | "dim2": -0.5288015425,
143 | "sex": "male ",
144 | "default": 0
145 | },
146 | "32": {
147 | "dim1": 0.226957527,
148 | "dim2": 0.1863278511,
149 | "sex": "male ",
150 | "default": 0
151 | },
152 | "38": {
153 | "dim1": -0.5354389586,
154 | "dim2": -0.4195694794,
155 | "sex": "male ",
156 | "default": 1
157 | },
158 | "12": {
159 | "dim1": -0.5767727429,
160 | "dim2": 0.3659868677,
161 | "sex": "female ",
162 | "default": 1
163 | },
164 | "29": {
165 | "dim1": -0.0963727384,
166 | "dim2": -0.0617550812,
167 | "sex": "male ",
168 | "default": 0
169 | },
170 | "31": {
171 | "dim1": 0.239666952,
172 | "dim2": -0.2746505749,
173 | "sex": "male ",
174 | "default": 0
175 | },
176 | "28": {
177 | "dim1": -0.3477406022,
178 | "dim2": -0.4260309183,
179 | "sex": "female ",
180 | "default": 0
181 | },
182 | "39": {
183 | "dim1": -0.3106671926,
184 | "dim2": 0.4200935026,
185 | "sex": "male ",
186 | "default": 0
187 | },
188 | "26": {
189 | "dim1": -0.3637607262,
190 | "dim2": -0.2407150967,
191 | "sex": "male ",
192 | "default": 0
193 | },
194 | "27": {
195 | "dim1": -0.5426012929,
196 | "dim2": -0.6422714318,
197 | "sex": "male ",
198 | "default": 0
199 | },
200 | "35": {
201 | "dim1": -0.5224859311,
202 | "dim2": -0.0344856428,
203 | "sex": "female ",
204 | "default": 0
205 | },
206 | "16": {
207 | "dim1": 0.4514028939,
208 | "dim2": -0.1054612641,
209 | "sex": "female ",
210 | "default": 1
211 | },
212 | "25": {
213 | "dim1": -0.2153514413,
214 | "dim2": -0.4814111153,
215 | "sex": "male ",
216 | "default": 0
217 | },
218 | "15": {
219 | "dim1": -0.3550491313,
220 | "dim2": 0.2225290248,
221 | "sex": "female ",
222 | "default": 0
223 | },
224 | "11": {
225 | "dim1": 0.4170726767,
226 | "dim2": 0.4733347208,
227 | "sex": "female ",
228 | "default": 1
229 | },
230 | "13": {
231 | "dim1": 0.66048088,
232 | "dim2": -0.4869273053,
233 | "sex": "female ",
234 | "default": 0
235 | },
236 | "40": {
237 | "dim1": 0.1834753526,
238 | "dim2": -0.1553025832,
239 | "sex": "male ",
240 | "default": 0
241 | }
242 | }
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = sphinx-build
7 | PAPER =
8 | BUILDDIR = _build
9 |
10 | # Internal variables.
11 | PAPEROPT_a4 = -D latex_paper_size=a4
12 | PAPEROPT_letter = -D latex_paper_size=letter
13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
14 | # the i18n builder cannot share the environment and doctrees with the others
15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
16 |
17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
18 |
19 | help:
20 | @echo "Please use \`make ' where is one of"
21 | @echo " html to make standalone HTML files"
22 | @echo " dirhtml to make HTML files named index.html in directories"
23 | @echo " singlehtml to make a single large HTML file"
24 | @echo " pickle to make pickle files"
25 | @echo " json to make JSON files"
26 | @echo " htmlhelp to make HTML files and a HTML help project"
27 | @echo " qthelp to make HTML files and a qthelp project"
28 | @echo " devhelp to make HTML files and a Devhelp project"
29 | @echo " epub to make an epub"
30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
31 | @echo " latexpdf to make LaTeX files and run them through pdflatex"
32 | @echo " text to make text files"
33 | @echo " man to make manual pages"
34 | @echo " texinfo to make Texinfo files"
35 | @echo " info to make Texinfo files and run them through makeinfo"
36 | @echo " gettext to make PO message catalogs"
37 | @echo " changes to make an overview of all changed/added/deprecated items"
38 | @echo " linkcheck to check all external links for integrity"
39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)"
40 |
41 | clean:
42 | -rm -rf $(BUILDDIR)/*
43 |
44 | html:
45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
46 | @echo
47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
48 |
49 | dirhtml:
50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
51 | @echo
52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
53 |
54 | singlehtml:
55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
56 | @echo
57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
58 |
59 | pickle:
60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
61 | @echo
62 | @echo "Build finished; now you can process the pickle files."
63 |
64 | json:
65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
66 | @echo
67 | @echo "Build finished; now you can process the JSON files."
68 |
69 | htmlhelp:
70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
71 | @echo
72 | @echo "Build finished; now you can run HTML Help Workshop with the" \
73 | ".hhp project file in $(BUILDDIR)/htmlhelp."
74 |
75 | qthelp:
76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
77 | @echo
78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \
79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/my_awesome_project.qhcp"
81 | @echo "To view the help file:"
82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/my_awesome_project.qhc"
83 |
84 | devhelp:
85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
86 | @echo
87 | @echo "Build finished."
88 | @echo "To view the help file:"
89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/my_awesome_project"
90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/my_awesome_project"
91 | @echo "# devhelp"
92 |
93 | epub:
94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
95 | @echo
96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
97 |
98 | latex:
99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
100 | @echo
101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \
103 | "(use \`make latexpdf' here to do that automatically)."
104 |
105 | latexpdf:
106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
107 | @echo "Running LaTeX files through pdflatex..."
108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf
109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
110 |
111 | text:
112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
113 | @echo
114 | @echo "Build finished. The text files are in $(BUILDDIR)/text."
115 |
116 | man:
117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
118 | @echo
119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
120 |
121 | texinfo:
122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
123 | @echo
124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
125 | @echo "Run \`make' in that directory to run these through makeinfo" \
126 | "(use \`make info' here to do that automatically)."
127 |
128 | info:
129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
130 | @echo "Running Texinfo files through makeinfo..."
131 | make -C $(BUILDDIR)/texinfo info
132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
133 |
134 | gettext:
135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
136 | @echo
137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
138 |
139 | changes:
140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
141 | @echo
142 | @echo "The overview file is in $(BUILDDIR)/changes."
143 |
144 | linkcheck:
145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
146 | @echo
147 | @echo "Link check complete; look for any errors in the above output " \
148 | "or in $(BUILDDIR)/linkcheck/output.txt."
149 |
150 | doctest:
151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
152 | @echo "Testing of doctests in the sources finished, look at the " \
153 | "results in $(BUILDDIR)/doctest/output.txt."
154 |
--------------------------------------------------------------------------------
/src/public/index.css:
--------------------------------------------------------------------------------
1 | /* main html */
2 | html {
3 | font-size: 0.8rem;
4 | }
5 | body {
6 | font-size: 1rem !important;
7 | color: #5b5b5b !important;
8 | }
9 |
10 | /* react-slider => customize */
11 | .rangeslider-horizontal .rangeslider__fill {
12 | background-color: blue;
13 | }
14 |
15 | .dropdown-toggle {
16 | width: 90%;
17 | }
18 | .dropdown-toggle,
19 | .dropdown-toggle:hover,
20 | .dropdown-toggle:active,
21 | .dropdown-toggle:focus,
22 | .dropdown-toggle::after {
23 | background-color: white !important;
24 | color: #003569 !important;
25 | }
26 |
27 | .badge-success {
28 | font-size: 1.2rem;
29 | }
30 |
31 | /* ant design => customize */
32 | /* .ant-slider-track,
33 | .ant-slider-handle {
34 | background-color: #00346b !important;
35 | } */
36 | .ant-table {
37 | width: 100% !important;
38 | margin: 10px auto !important;
39 | font-size: 1rem !important;
40 | }
41 | .ant-table-row > td,
42 | .ant-table-thead > tr > th {
43 | padding: 2px !important;
44 | font-size: 1rem !important;
45 | }
46 | .ant-table-thead > tr > th {
47 | background-color: #f2f2f2 !important;
48 | }
49 |
50 | .ant-radio-group {
51 | font-size: 1rem !important;
52 | margin: 2px !important;
53 | margin-left: 10px !important;
54 | }
55 |
56 | .ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled) {
57 | background-color: #ff7043 !important;
58 | border-color: #ff7043 !important;
59 | }
60 |
61 | .ant-radio-button-wrapper {
62 | background-color: mediumspringgreen !important;
63 | padding: 0 15px !important;
64 | }
65 |
66 | .ant-badge-status-default {
67 | background-color: mediumspringgreen !important;
68 | }
69 |
70 | .ant-badge-status-error {
71 | background-color: #ff7043 !important;
72 | }
73 |
74 | .dropdown-menu.show {
75 | width: 90% !important;
76 | }
77 |
78 | .ant-tag {
79 | padding: 0 10px !important;
80 | font-size: 1.2rem !important;
81 | }
82 |
83 | .ant-alert {
84 | padding: 5px 10px !important;
85 | width: 90% !important;
86 | margin-left: 10px !important;
87 | margin-bottom: 5px !important;
88 | }
89 |
90 | .ant-alert-message {
91 | font-size: 1.1rem !important;
92 | }
93 |
94 | .ant-alert-description {
95 | font-size: 1rem !important;
96 | line-height: normal !important;
97 | }
98 |
99 | .ant-alert-icon {
100 | position: absolute !important;
101 | top: 10px !important;
102 | left: 5px !important;
103 | font-size: 12px !important;
104 | }
105 |
106 | .ant-btn-primary {
107 | background-color: white !important;
108 | color: #084b7f !important;
109 | border-color: #084b7f !important;
110 | margin: 5px 3px !important;
111 | }
112 |
113 | .anticon-right-circle {
114 | font-size: 1.2rem;
115 | }
116 |
117 | .ant-tabs.ant-tabs-card, .ant-tabs-card-bar, .ant-tabs-tab-active, .ant-tabs-tab {
118 | /* border: 2px solid #00346b;
119 | color: white; */
120 | }
121 |
122 | .g_x_whole_ranking_topk_axis line { stroke: gray; }
123 | .g_x_whole_ranking_topk_axis path { stroke: gray; }
124 | .g_x_whole_ranking_topk_axis text { fill: gray; }
125 |
126 | .g_x_whole_ranking_selected_non_topk_axis line { stroke: gray; }
127 | .g_x_whole_ranking_selected_non_topk_axis path { stroke: gray; }
128 | .g_x_whole_ranking_selected_non_topk_axis text { fill: gray; }
129 |
130 | .g_x_matrix_axis line { stroke: gray; }
131 | .g_x_matrix_axis path { stroke: none; }
132 | .g_x_matrix_axis text { fill: gray; }
133 |
134 | .g_y_matrix_axis line { stroke: gray; }
135 | .g_y_matrix_axis path { stroke: none; }
136 | .g_y_matrix_axis text { fill: gray; }
137 |
138 | .g_y_output_space_axis line { stroke: gray; }
139 | .g_y_output_space_axis path { stroke: gray; }
140 | .g_y_output_space_axis text { fill: gray; }
141 |
142 | .g_x_distortion_axis line { stroke: gray; stroke-width: 2px; }
143 | .g_x_distortion_axis path { stroke: gray; stroke-width: 2px; }
144 | .g_x_distortion_axis text { fill: gray; }
145 |
146 | .g_cr_plot_axis line { stroke: gray; }
147 | .g_cr_plot_axis path { stroke: gray; }
148 | .g_cr_plot_axis text { fill: gray; }
149 |
150 | .g_x_feature_axis_instances line { stroke: gray; stroke-width: 2px; }
151 | .g_x_feature_axis_instances path { stroke: gray; stroke-width: 2px; }
152 | .g_x_feature_axis_instances text { fill: gray; }
153 |
154 | .g_x_median_axis line { stroke: gray; stroke-width: 2px; }
155 | .g_x_median_axis path { stroke: gray; stroke-width: 2px; }
156 | .g_x_median_axis text { fill: gray; }
157 |
158 | .g_x_feature_axis_outliers line { stroke: gray; stroke-width: 2px; }
159 | .g_x_feature_axis_outliers path { stroke: gray; stroke-width: 2px; }
160 | .g_x_feature_axis_outliers text { fill: gray; }
161 |
162 | .g_x_permutation_axis line { stroke: gray; stroke-width: 2px; }
163 | .g_x_permutation_axis path { stroke: gray; stroke-width: 2px; }
164 | .g_x_permutation_axis text { fill: gray; }
165 |
166 | .g_x_fairness_axis line { stroke: gray; }
167 | .g_x_fairness_axis path { stroke: gray; }
168 | .g_x_fairness_axis text { fill: gray; }
169 |
170 | .g_y_utility_axis line { stroke: gray; }
171 | .g_y_utility_axis path { stroke: gray; }
172 | .g_y_utility_axis text { fill: gray; }
173 |
174 | .g_x_output_space_topk_axis line { stroke: gray; }
175 | .g_x_output_space_topk_axis path { stroke: gray; }
176 | .g_x_output_space_topk_axis text { fill: gray; }
177 |
178 | .g_x_output_space_selected_non_topk_axis line { stroke: gray; }
179 | .g_x_output_space_selected_non_topk_axis path { stroke: gray; }
180 | .g_x_output_space_selected_non_topk_axis text { fill: gray; }
181 |
182 | .g_corr_plot_group1 { stroke-width: 2px; }
183 | .g_corr_plot_group2 { stroke-width: 2px; }
184 |
185 | .g_x_feature_axis_individual line { stroke: gray; stroke-width: 2px; }
186 | .g_x_feature_axis_individual path { stroke: gray; stroke-width: 2px; }
187 |
188 | .selected { stroke-width: 2px !important; }
189 |
190 | .method_selected {
191 | background-color: #003569 !important;
192 | color: white !important;
193 | }
194 |
195 | .tooltip_mouseovered {
196 | opacity: 1 !important;
197 | }
198 |
199 | .d3-tooltip {
200 | line-height: 1.5;
201 | font-weight: 400;
202 | padding: 12px;
203 | background: rgba(0, 0, 0, 0.8);
204 | color: #fff;
205 | border-radius: 2px;
206 | pointer-events: none;
207 | }
208 |
209 | /* Creates a small triangle extender for the tooltip */
210 | .d3-tooltip:after {
211 | box-sizing: border-box;
212 | display: inline;
213 | font-size: 10px;
214 | width: 100%;
215 | line-height: 1;
216 | color: rgba(0, 0, 0, 0.8);
217 | position: absolute;
218 | pointer-events: none;
219 | }
220 |
221 | /* Northward tooltips */
222 | .d3-tooltip.n:after {
223 | content: "\25BC";
224 | margin: -1px 0 0 0;
225 | top: 100%;
226 | left: 0;
227 | text-align: center;
228 | }
229 |
230 | /* Eastward tooltips */
231 | .d3-tooltip.e:after {
232 | content: "\25C0";
233 | margin: -4px 0 0 0;
234 | top: 50%;
235 | left: -8px;
236 | }
237 |
238 | /* Southward tooltips */
239 | .d3-tooltip.s:after {
240 | content: "\25B2";
241 | margin: 0 0 1px 0;
242 | top: -8px;
243 | left: 0;
244 | text-align: center;
245 | }
246 |
247 | /* Westward tooltips */
248 | .d3-tooltip.w:after {
249 | content: "\25B6";
250 | margin: -4px 0 0 -1px;
251 | top: 50%;
252 | left: 100%;
253 | }
--------------------------------------------------------------------------------
/app/static/lib/gower_distance.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pandas as pd
3 | from scipy.spatial import distance
4 | from sklearn.utils import validation
5 | from sklearn.metrics import pairwise
6 | from scipy.sparse import issparse
7 |
8 | # Vectorized Version
9 | def gower_distances(X, Y=None, feature_weight=None, categorical_features=None):
10 | """Computes the gower distances between X and Y
11 |
12 | Gower is a similarity measure for categorical, boolean and numerical mixed
13 | data.
14 |
15 |
16 | Parameters
17 | ----------
18 | X : array-like, or pandas.DataFrame, shape (n_samples, n_features)
19 |
20 | Y : array-like, or pandas.DataFrame, shape (n_samples, n_features)
21 |
22 | feature_weight : array-like, shape (n_features)
23 | According the Gower formula, feature_weight is an attribute weight.
24 |
25 | categorical_features: array-like, shape (n_features)
26 | Indicates with True/False whether a column is a categorical attribute.
27 | This is useful when categorical atributes are represented as integer
28 | values. Categorical ordinal attributes are treated as numeric, and must
29 | be marked as false.
30 |
31 | Alternatively, the categorical_features array can be represented only
32 | with the numerical indexes of the categorical attribtes.
33 |
34 | Returns
35 | -------
36 | similarities : ndarray, shape (n_samples, n_samples)
37 |
38 | Notes
39 | ------
40 | The non-numeric features, and numeric feature ranges are determined from X and not Y.
41 | No support for sparse matrices.
42 |
43 | """
44 |
45 | if issparse(X) or issparse(Y):
46 | raise TypeError("Sparse matrices are not supported for gower distance")
47 |
48 | y_none = Y is None
49 |
50 |
51 | # It is necessary to convert to ndarray in advance to define the dtype
52 | if not isinstance(X, np.ndarray):
53 | X = np.asarray(X)
54 |
55 | array_type = np.object
56 | # this is necessary as strangelly the validator is rejecting numeric
57 | # arrays with NaN
58 | if np.issubdtype(X.dtype, np.number) and (np.isfinite(X.sum()) or np.isfinite(X).all()):
59 | array_type = type(np.zeros(1,X.dtype).flat[0])
60 |
61 | X, Y = check_pairwise_arrays(X, Y, precomputed=False, dtype=array_type)
62 |
63 | n_rows, n_cols = X.shape
64 |
65 | if categorical_features is None:
66 | categorical_features = np.zeros(n_cols, dtype=bool)
67 | for col in range(n_cols):
68 | # In numerical columns, None is converted to NaN,
69 | # and the type of NaN is recognized as a number subtype
70 | if not np.issubdtype(type(X[0, col]), np.number):
71 | categorical_features[col]=True
72 | else:
73 | categorical_features = np.array(categorical_features)
74 |
75 |
76 | #if categorical_features.dtype == np.int32:
77 | if np.issubdtype(categorical_features.dtype, np.int):
78 | new_categorical_features = np.zeros(n_cols, dtype=bool)
79 | new_categorical_features[categorical_features] = True
80 | categorical_features = new_categorical_features
81 |
82 | print('in gower function: ', categorical_features)
83 |
84 | # Categorical columns
85 | X_cat = X[:,categorical_features]
86 |
87 | # Numerical columns
88 | X_num = X[:,np.logical_not(categorical_features)]
89 | ranges_of_numeric = None
90 | max_of_numeric = None
91 |
92 |
93 | # Calculates the normalized ranges and max values of numeric values
94 | _ ,num_cols=X_num.shape
95 | ranges_of_numeric = np.zeros(num_cols)
96 | max_of_numeric = np.zeros(num_cols)
97 | for col in range(num_cols):
98 | col_array = X_num[:, col].astype(np.float32)
99 | max = np.nanmax(col_array)
100 | min = np.nanmin(col_array)
101 |
102 | if np.isnan(max):
103 | max = 0.0
104 | if np.isnan(min):
105 | min = 0.0
106 | max_of_numeric[col] = max
107 | ranges_of_numeric[col] = (1 - min / max) if (max != 0) else 0.0
108 |
109 |
110 | # This is to normalize the numeric values between 0 and 1.
111 | X_num = np.divide(X_num ,max_of_numeric,out=np.zeros_like(X_num), where=max_of_numeric!=0)
112 |
113 |
114 | if feature_weight is None:
115 | feature_weight = np.ones(n_cols)
116 |
117 | feature_weight_cat=feature_weight[categorical_features]
118 | feature_weight_num=feature_weight[np.logical_not(categorical_features)]
119 |
120 |
121 | y_n_rows, _ = Y.shape
122 |
123 | dm = np.zeros((n_rows, y_n_rows), dtype=np.float32)
124 |
125 | feature_weight_sum = feature_weight.sum()
126 |
127 | Y_cat=None
128 | Y_num=None
129 |
130 | if not y_none:
131 | Y_cat = Y[:,categorical_features]
132 | Y_num = Y[:,np.logical_not(categorical_features)]
133 | # This is to normalize the numeric values between 0 and 1.
134 | Y_num = np.divide(Y_num ,max_of_numeric,out=np.zeros_like(Y_num), where=max_of_numeric!=0)
135 | else:
136 | Y_cat=X_cat
137 | Y_num = X_num
138 |
139 | for i in range(n_rows):
140 | j_start= i
141 |
142 | # for non square results
143 | if n_rows != y_n_rows:
144 | j_start = 0
145 |
146 |
147 | Y_cat[j_start:n_rows,:]
148 | Y_num[j_start:n_rows,:]
149 | result= _gower_distance_row(X_cat[i,:], X_num[i,:],Y_cat[j_start:n_rows,:],
150 | Y_num[j_start:n_rows,:],feature_weight_cat,feature_weight_num,
151 | feature_weight_sum,categorical_features,ranges_of_numeric,
152 | max_of_numeric)
153 | dm[i,j_start:]=result
154 | dm[i:,j_start]=result
155 |
156 |
157 | return dm
158 |
159 |
160 | def _gower_distance_row(xi_cat,xi_num,xj_cat,xj_num,feature_weight_cat,feature_weight_num,
161 | feature_weight_sum,categorical_features,ranges_of_numeric,max_of_numeric ):
162 | # categorical columns
163 | sij_cat = np.where(xi_cat == xj_cat,np.zeros_like(xi_cat),np.ones_like(xi_cat))
164 | sum_cat = np.multiply(feature_weight_cat,sij_cat).sum(axis=1)
165 |
166 | # numerical columns
167 | abs_delta=np.absolute( xi_num-xj_num)
168 | sij_num=np.divide(abs_delta, ranges_of_numeric, out=np.zeros_like(abs_delta), where=ranges_of_numeric!=0)
169 |
170 | sum_num = np.multiply(feature_weight_num,sij_num).sum(axis=1)
171 | sums= np.add(sum_cat,sum_num)
172 | sum_sij = np.divide(sums,feature_weight_sum)
173 | return sum_sij
174 |
175 |
176 | def check_pairwise_arrays(X, Y, precomputed=False, dtype=None):
177 | X, Y, dtype_float = pairwise._return_float_dtype(X, Y)
178 |
179 | warn_on_dtype = dtype is not None
180 | estimator = 'check_pairwise_arrays'
181 | if dtype is None:
182 | dtype = dtype_float
183 |
184 | if Y is X or Y is None:
185 | X = Y = validation.check_array(X, accept_sparse='csr', dtype=dtype,
186 | warn_on_dtype=warn_on_dtype, estimator=estimator)
187 | else:
188 | X = validation.check_array(X, accept_sparse='csr', dtype=dtype,
189 | warn_on_dtype=warn_on_dtype, estimator=estimator)
190 | Y = validation.check_array(Y, accept_sparse='csr', dtype=dtype,
191 | warn_on_dtype=warn_on_dtype, estimator=estimator)
192 |
193 | if precomputed:
194 | if X.shape[1] != Y.shape[0]:
195 | raise ValueError("Precomputed metric requires shape "
196 | "(n_queries, n_indexed). Got (%d, %d) "
197 | "for %d indexed." %
198 | (X.shape[0], X.shape[1], Y.shape[0]))
199 | elif X.shape[1] != Y.shape[1]:
200 | raise ValueError("Incompatible dimension for X and Y matrices: "
201 | "X.shape[1] == %d while Y.shape[1] == %d" % (
202 | X.shape[1], Y.shape[1]))
203 |
204 | return X, Y
--------------------------------------------------------------------------------
/docs/docker_ec2.rst:
--------------------------------------------------------------------------------
1 | Developing with Docker
2 | ======================
3 |
4 | You can develop your application in a `Docker`_ container for simpler deployment onto bare Linux machines later. This instruction assumes an `Amazon Web Services`_ EC2 instance, but it should work on any machine with Docker > 1.3 and `Docker compose`_ installed.
5 |
6 | .. _Docker: https://www.docker.com/
7 | .. _Amazon Web Services: http://aws.amazon.com/
8 | .. _Docker compose: https://docs.docker.com/compose/
9 |
10 | Setting up
11 | ^^^^^^^^^^
12 |
13 | Docker encourages running one container for each process. This might mean one container for your web server, one for Django application and a third for your database. Once you're happy composing containers in this way you can easily add more, such as a `Redis`_ cache.
14 |
15 | .. _Redis: http://redis.io/
16 |
17 | The Docker compose tool (previously known as `fig`_) makes linking these containers easy. An example set up for your Cookiecutter Django project might look like this:
18 |
19 | .. _fig: http://www.fig.sh/
20 |
21 | ::
22 |
23 | webapp/ # Your cookiecutter project would be in here
24 | Dockerfile
25 | ...
26 | database/
27 | Dockerfile
28 | ...
29 | webserver/
30 | Dockerfile
31 | ...
32 | production.yml
33 |
34 | Each component of your application would get its own `Dockerfile`_. The rest of this example assumes you are using the `base postgres image`_ for your database. Your database settings in `config/base.py` might then look something like:
35 |
36 | .. _Dockerfile: https://docs.docker.com/reference/builder/
37 | .. _base postgres image: https://registry.hub.docker.com/_/postgres/
38 |
39 | .. code-block:: python
40 |
41 | DATABASES = {
42 | 'default': {
43 | 'ENGINE': 'django.db.backends.postgresql_psycopg2',
44 | 'NAME': 'postgres',
45 | 'USER': 'postgres',
46 | 'HOST': 'database',
47 | 'PORT': 5432,
48 | }
49 | }
50 |
51 | The `Docker compose documentation`_ explains in detail what you can accomplish in the `production.yml` file, but an example configuration might look like this:
52 |
53 | .. _Docker compose documentation: https://docs.docker.com/compose/#compose-documentation
54 |
55 | .. code-block:: yaml
56 |
57 | database:
58 | build: database
59 | webapp:
60 | build: webapp:
61 | command: /usr/bin/python3.6 manage.py runserver 0.0.0.0:8000 # dev setting
62 | # command: gunicorn -b 0.0.0.0:8000 wsgi:application # production setting
63 | volumes:
64 | - webapp/your_project_name:/path/to/container/workdir/
65 | links:
66 | - database
67 | webserver:
68 | build: webserver
69 | ports:
70 | - "80:80"
71 | - "443:443"
72 | links:
73 | - webapp
74 |
75 | We'll ignore the webserver for now (you'll want to comment that part out while we do). A working Dockerfile to run your cookiecutter application might look like this:
76 |
77 | ::
78 |
79 | FROM ubuntu:14.04
80 | ENV REFRESHED_AT 2015-01-13
81 |
82 | # update packages and prepare to build software
83 | RUN ["apt-get", "update"]
84 | RUN ["apt-get", "-y", "install", "build-essential", "vim", "git", "curl"]
85 | RUN ["locale-gen", "en_GB.UTF-8"]
86 |
87 | # install latest python
88 | RUN ["apt-get", "-y", "build-dep", "python3-dev", "python3-imaging"]
89 | RUN ["apt-get", "-y", "install", "python3-dev", "python3-imaging", "python3-pip"]
90 |
91 | # prepare postgreSQL support
92 | RUN ["apt-get", "-y", "build-dep", "python3-psycopg2"]
93 |
94 | # move into our working directory
95 | # ADD must be after chown see http://stackoverflow.com/a/26145444/1281947
96 | RUN ["groupadd", "python"]
97 | RUN ["useradd", "python", "-s", "/bin/bash", "-m", "-g", "python", "-G", "python"]
98 | ENV HOME /home/python
99 | WORKDIR /home/python
100 | RUN ["chown", "-R", "python:python", "/home/python"]
101 | ADD ./ /home/python
102 |
103 | # manage requirements
104 | ENV REQUIREMENTS_REFRESHED_AT 2015-02-25
105 | RUN ["pip3", "install", "-r", "requirements.txt"]
106 |
107 | # uncomment the line below to use container as a non-root user
108 | USER python:python
109 |
110 | Running `sudo docker-compose -f production.yml build` will follow the instructions in your `production.yml` file and build the database container, then your webapp, before mounting your cookiecutter project files as a volume in the webapp container and linking to the database. Our example yaml file runs in development mode but changing it to production mode is as simple as commenting out the line using `runserver` and uncommenting the line using `gunicorn`.
111 |
112 | Both are set to run on port `0.0.0.0:8000`, which is where the Docker daemon will discover it. You can now run `sudo docker-compose -f production.yml up` and browse to `localhost:8000` to see your application running.
113 |
114 | Deployment
115 | ^^^^^^^^^^
116 |
117 | You'll need a webserver container for deployment. An example setup for `Nginx`_ might look like this:
118 |
119 | .. _Nginx: http://wiki.nginx.org/Main
120 |
121 | ::
122 |
123 | FROM ubuntu:14.04
124 | ENV REFRESHED_AT 2015-02-11
125 |
126 | # get the nginx package and set it up
127 | RUN ["apt-get", "update"]
128 | RUN ["apt-get", "-y", "install", "nginx"]
129 |
130 | # forward request and error logs to docker log collector
131 | RUN ln -sf /dev/stdout /var/log/nginx/access.log
132 | RUN ln -sf /dev/stderr /var/log/nginx/error.log
133 | VOLUME ["/var/cache/nginx"]
134 | EXPOSE 80 443
135 |
136 | # load nginx conf
137 | ADD ./site.conf /etc/nginx/sites-available/your_cookiecutter_project
138 | RUN ["ln", "-s", "/etc/nginx/sites-available/your_cookiecutter_project", "/etc/nginx/sites-enabled/your_cookiecutter_project"]
139 | RUN ["rm", "-rf", "/etc/nginx/sites-available/default"]
140 |
141 | #start the server
142 | CMD ["nginx", "-g", "daemon off;"]
143 |
144 | That Dockerfile assumes you have an Nginx conf file named `site.conf` in the same directory as the webserver Dockerfile. A very basic example, which forwards traffic onto the development server or gunicorn for processing, would look like this:
145 |
146 | ::
147 |
148 | # see http://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf#comment730384_577370
149 | upstream localhost {
150 | server webapp_1:8000;
151 | }
152 | server {
153 | location / {
154 | proxy_pass http://localhost;
155 | }
156 | }
157 |
158 | Running `sudo docker-compose -f production.yml build webserver` will build your server container. Running `sudo docker-compose -f production.yml up` will now expose your application directly on `localhost` (no need to specify the port number).
159 |
160 | Building and running your app on EC2
161 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
162 |
163 | All you now need to do to run your app in production is:
164 |
165 | * Create an empty EC2 Linux instance (any Linux machine should do).
166 |
167 | * Install your preferred source control solution, Docker and Docker compose on the news instance.
168 |
169 | * Pull in your code from source control. The root directory should be the one with your `production.yml` file in it.
170 |
171 | * Run `sudo docker-compose -f production.yml build` and `sudo docker-compose -f production.yml up`.
172 |
173 | * Assign an `Elastic IP address`_ to your new machine.
174 |
175 | .. _Elastic IP address: https://aws.amazon.com/articles/1346
176 |
177 | * Point your domain name to the elastic IP.
178 |
179 | **Be careful with Elastic IPs** because, on the AWS free tier, if you assign one and then stop the machine you will incur charges while the machine is down (presumably because you're preventing them allocating the IP to someone else).
180 |
181 | Security advisory
182 | ^^^^^^^^^^^^^^^^^
183 |
184 | The setup described in this instruction will get you up-and-running but it hasn't been audited for security. If you are running your own setup like this it is always advisable to, at a minimum, examine your application with a tool like `OWASP ZAP`_ to see what security holes you might be leaving open.
185 |
186 | .. _OWASP ZAP: https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
187 |
--------------------------------------------------------------------------------
/config/settings/production.py:
--------------------------------------------------------------------------------
1 | """
2 | Production Configurations
3 |
4 |
5 | - Use Amazon's S3 for storing static files and uploaded media
6 | - Use mailgun to send emails
7 | - Use Redis for cache
8 |
9 |
10 | """
11 |
12 |
13 |
14 | from .base import * # noqa
15 |
16 | # SECRET CONFIGURATION
17 | # ------------------------------------------------------------------------------
18 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
19 | # Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ
20 | SECRET_KEY = env('DJANGO_SECRET_KEY', default='.80h]pfMpBKYeMmBUKB`[YN$7q*7^y<284RUt#zq[eWJG[]k&c')
21 |
22 |
23 | # This ensures that Django will be able to detect a secure connection
24 | # properly on Heroku.
25 | SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
26 |
27 | # SECURITY CONFIGURATION
28 | # ------------------------------------------------------------------------------
29 | # See https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.security
30 | # and https://docs.djangoproject.com/en/dev/howto/deployment/checklist/#run-manage-py-check-deploy
31 |
32 | # set this to 60 seconds and then to 518400 when you can prove it works
33 | SECURE_HSTS_SECONDS = 60
34 | SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
35 | 'DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True)
36 | SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
37 | 'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True)
38 | SECURE_BROWSER_XSS_FILTER = True
39 | SESSION_COOKIE_SECURE = True
40 | SESSION_COOKIE_HTTPONLY = True
41 | SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True)
42 | CSRF_COOKIE_SECURE = True
43 | CSRF_COOKIE_HTTPONLY = True
44 | X_FRAME_OPTIONS = 'DENY'
45 |
46 | # SITE CONFIGURATION
47 | # ------------------------------------------------------------------------------
48 | # Hosts/domain names that are valid for this site
49 | # See https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
50 | ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['app.com', ])
51 | # END SITE CONFIGURATION
52 |
53 | INSTALLED_APPS += ['gunicorn', ]
54 |
55 |
56 | # STORAGE CONFIGURATION
57 | # ------------------------------------------------------------------------------
58 | # Uploaded Media Files
59 | # ------------------------
60 | # See: http://django-storages.readthedocs.io/en/latest/index.html
61 | INSTALLED_APPS += ['storages', ]
62 |
63 | AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID', default='.80h]pfMpBKYeMmBUKB`[YN$7q*7^y<284RUt#zq[eWJG[]k&c')
64 | AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY', default='.80h]pfMpBKYeMmBUKB`[YN$7q*7^y<284RUt#zq[eWJG[]k&c')
65 | AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME', default='.80h]pfMpBKYeMmBUKB`[YN$7q*7^y<284RUt#zq[eWJG[]k&c')
66 | AWS_AUTO_CREATE_BUCKET = True
67 | AWS_QUERYSTRING_AUTH = False
68 |
69 | # AWS cache settings, don't change unless you know what you're doing:
70 | AWS_EXPIRY = 60 * 60 * 24 * 7
71 |
72 | # TODO See: https://github.com/jschneier/django-storages/issues/47
73 | # Revert the following and use str after the above-mentioned bug is fixed in
74 | # either django-storage-redux or boto
75 | control = 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIRY, AWS_EXPIRY)
76 | AWS_HEADERS = {
77 | 'Cache-Control': bytes(control, encoding='latin-1')
78 | }
79 |
80 | # URL that handles the media served from MEDIA_ROOT, used for managing
81 | # stored files.
82 |
83 | # See:http://stackoverflow.com/questions/10390244/
84 | from storages.backends.s3boto3 import S3Boto3Storage
85 | StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static')
86 | MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media')
87 | DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage'
88 |
89 | MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME
90 |
91 | # Static Assets
92 | # ------------------------
93 |
94 | STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
95 | STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
96 | # See: https://github.com/antonagestam/collectfast
97 | # For Django 1.7+, 'collectfast' should come before
98 | # 'django.contrib.staticfiles'
99 | AWS_PRELOAD_METADATA = True
100 | INSTALLED_APPS = ['collectfast', ] + INSTALLED_APPS
101 |
102 | # EMAIL
103 | # ------------------------------------------------------------------------------
104 | DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
105 | default='app ')
106 | EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='[app]')
107 | SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)
108 |
109 | # Anymail with Mailgun
110 | INSTALLED_APPS += ['anymail', ]
111 | ANYMAIL = {
112 | 'MAILGUN_API_KEY': env('DJANGO_MAILGUN_API_KEY'),
113 | 'MAILGUN_SENDER_DOMAIN': env('MAILGUN_SENDER_DOMAIN')
114 | }
115 | EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
116 |
117 | # TEMPLATE CONFIGURATION
118 | # ------------------------------------------------------------------------------
119 | # See:
120 | # https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
121 | TEMPLATES[0]['OPTIONS']['loaders'] = [
122 | ('django.template.loaders.cached.Loader', [
123 | 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]),
124 | ]
125 |
126 | # DATABASE CONFIGURATION
127 | # ------------------------------------------------------------------------------
128 |
129 | # Use the Heroku-style specification
130 | # Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
131 | DATABASES['default'] = env.db('DATABASE_URL')
132 |
133 | # CACHING
134 | # ------------------------------------------------------------------------------
135 |
136 | REDIS_LOCATION = '{0}/{1}'.format(env('REDIS_URL', default='redis://127.0.0.1:6379'), 0)
137 | # Heroku URL does not pass the DB number, so we parse it in
138 | CACHES = {
139 | 'default': {
140 | 'BACKEND': 'django_redis.cache.RedisCache',
141 | 'LOCATION': REDIS_LOCATION,
142 | 'OPTIONS': {
143 | 'CLIENT_CLASS': 'django_redis.client.DefaultClient',
144 | 'IGNORE_EXCEPTIONS': True, # mimics memcache behavior.
145 | # http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
146 | }
147 | }
148 | }
149 |
150 |
151 | # LOGGING CONFIGURATION
152 | # ------------------------------------------------------------------------------
153 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
154 | # A sample logging configuration. The only tangible logging
155 | # performed by this configuration is to send an email to
156 | # the site admins on every HTTP 500 error when DEBUG=False.
157 | # See https://docs.djangoproject.com/en/dev/topics/logging for
158 | # more details on how to customize your logging configuration.
159 | LOGGING = {
160 | 'version': 1,
161 | 'disable_existing_loggers': False,
162 | 'filters': {
163 | 'require_debug_false': {
164 | '()': 'django.utils.log.RequireDebugFalse'
165 | }
166 | },
167 | 'formatters': {
168 | 'verbose': {
169 | 'format': '%(levelname)s %(asctime)s %(module)s '
170 | '%(process)d %(thread)d %(message)s'
171 | },
172 | },
173 | 'handlers': {
174 | 'mail_admins': {
175 | 'level': 'ERROR',
176 | 'filters': ['require_debug_false', ],
177 | 'class': 'django.utils.log.AdminEmailHandler'
178 | },
179 | 'console': {
180 | 'level': 'DEBUG',
181 | 'class': 'logging.StreamHandler',
182 | 'formatter': 'verbose',
183 | },
184 | },
185 | 'loggers': {
186 | 'django.request': {
187 | 'handlers': ['mail_admins', ],
188 | 'level': 'ERROR',
189 | 'propagate': True
190 | },
191 | 'django.security.DisallowedHost': {
192 | 'level': 'ERROR',
193 | 'handlers': ['console', 'mail_admins', ],
194 | 'propagate': True
195 | }
196 | }
197 | }
198 |
199 | # Custom Admin URL, use {% url 'admin:index' %}
200 | ADMIN_URL = env('DJANGO_ADMIN_URL')
201 |
202 | # Your production stuff: Below this line define 3rd party library settings
203 | # ------------------------------------------------------------------------------
204 |
--------------------------------------------------------------------------------