Skip to content

Commit

Permalink
Modify pylint and minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aritra8438 committed Jul 2, 2023
1 parent eaf6d51 commit 35b4442
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[MASTER]

[MESSAGES CONTROL]
disable = C0114, C0115, C0116
disable = C0114, C0115, C0116, R1710, R0902
4 changes: 0 additions & 4 deletions api/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
Expand Down
21 changes: 11 additions & 10 deletions api/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

"""Module produces json objects"""
import json
from flask import jsonify, request, render_template, abort
Expand All @@ -12,17 +8,21 @@
from .utils.input_serializer import region_input_manager, year_input_manager
from .utils.output_serializer import serialize_queryset, serialize_pivoted_queryset
from .utils.queryset_to_structures import (
convert_to_table, convert_to_dicts, convert_to_single_dict, convert_to_double_lists)
convert_to_table,
convert_to_dicts,
convert_to_single_dict,
convert_to_double_lists,
)
from .utils.create_figure import create_bar, create_pie, create_scatter



@app.route("/")
def home():
if request.method == "GET":
return render_template("index.html")
abort("Method not allowed", 405)


@app.route("/querybuilder")
def build_query():
if request.method == "GET":
Expand All @@ -36,7 +36,7 @@ def get_table_response():
cities, countries = region_input_manager(json.loads(request.args.get("Region")))
years = year_input_manager(json.loads(request.args.get("Year")))
pivot = request.args.get("Pivot")
if pivot not in ['Region', 'Year']:
if pivot not in ["Region", "Year"]:
pivot = "Year"
queryset = Population.query.filter(
Population.year.in_(years), Population.country.in_(countries)
Expand All @@ -52,7 +52,7 @@ def get_table_response():
@app.route("/json")
def get_json_response():
if request.method == "GET":
_ , countries = region_input_manager(json.loads(request.args.get("Region")))
_, countries = region_input_manager(json.loads(request.args.get("Region")))
years = year_input_manager(json.loads(request.args.get("Year")))
pivot = request.args.get("Pivot")
if pivot == "Region":
Expand All @@ -74,8 +74,8 @@ def get_json_response():
json_response = serialize_pivoted_queryset(pivoted_queryset, "Region")
return jsonify(json_response)
queryset = Population.query.filter(
Population.year.in_(years), Population.country.in_(countries)
)
Population.year.in_(years), Population.country.in_(countries)
)
json_response = serialize_queryset(queryset)
return jsonify(json_response)
abort("Method not allowed", 405)
Expand All @@ -97,6 +97,7 @@ def get_graph_response():
return create_scatter(country_year, country_population)
abort("Method not allowed", 405)


@app.route("/stats")
def get_stats_response():
if request.method == "GET":
Expand Down
4 changes: 0 additions & 4 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=too-few-public-methods
from .database import db


Expand Down
3 changes: 0 additions & 3 deletions api/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
import pytest

from api.index import app
Expand Down
3 changes: 0 additions & 3 deletions api/tests/test_apis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
def test_home(client):
response = client.get("/")
assert response.status_code == 200
Expand Down
7 changes: 1 addition & 6 deletions api/utils/create_figure.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots



def create_scatter(country_year_dict, country_pop_dict):
fig = go.Figure()
layout = go.Layout(
Expand Down Expand Up @@ -65,7 +60,7 @@ def create_pie(array1, label1, array2, label2, num):
go.Pie(
values=array2,
labels=label2,
name= f"Bottom {num}",
name=f"Bottom {num}",
),
row=1,
col=2,
Expand Down
8 changes: 2 additions & 6 deletions api/utils/infer_region.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

from thefuzz import process

countries = [
Expand Down Expand Up @@ -201,7 +197,7 @@
"Vietnam",
"Yemen",
"Zambia",
"Zimbabwe"
"Zimbabwe",
]
cities = [
"Abidjan",
Expand Down Expand Up @@ -477,7 +473,7 @@
"Yaoundé",
"Yerevan",
"Zagreb",
"Zurich"
"Zurich",
]


Expand Down
4 changes: 0 additions & 4 deletions api/utils/input_serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

from . import infer_region


Expand Down
4 changes: 0 additions & 4 deletions api/utils/output_serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

# serialize the queryset to create an array
def serialize_queryset(queryset):
json_response = []
Expand Down
9 changes: 2 additions & 7 deletions api/utils/queryset_to_structures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring

from .output_serializer import serialize_queryset



def transpose_table(table):
"""Function transposes the table"""
num_rows = len(table)
Expand All @@ -31,9 +26,9 @@ def convert_to_table(queryset, years, regions, pivot=0):
num_regions = len(regions) + 1
table = [[0] * num_regions for _ in range(num_years)]
table[0][0] = "↘"
for i , _ in enumerate(regions):
for i, _ in enumerate(regions):
table[0][i + 1] = regions[i]
for i , _ in enumerate(years):
for i, _ in enumerate(years):
table[i + 1][0] = years[i]
for element in queryset:
country = element.country
Expand Down

0 comments on commit 35b4442

Please sign in to comment.