Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hard-coded errors #78

Merged
merged 8 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions api/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Module produces json objects"""
import json
from flask import jsonify, request, render_template, abort, url_for # pylint: disable=unused-import
from flask import (
jsonify,
request,
render_template,
abort,
url_for,
) # pylint: disable=unused-import

from .database import app
from .models import Population, GDPperCapita, ForestArea
Expand Down Expand Up @@ -264,7 +270,8 @@ def compare():
) from json_decode_error
try:
years = year_input_manager(
json.loads(request.args.get("Year")), "gdp_per_capita"
json.loads(request.args.get("Year")),
[first_parameter, second_parameter],
)
except json.decoder.JSONDecodeError as json_decode_error:
raise InvalidParameterException(
Expand Down
82 changes: 44 additions & 38 deletions api/templates/api-documentation.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- @format -->

<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -144,13 +146,16 @@ <h3>Welcome to the API-documentation Page</h3>
&nbsp;&nbsp;
<input type="text" v-model="tablePivot" />
</li>
<br/>
<br />
<li>
<label>Query_type (either population, gdp_per_capita or forest_area) :</label>
<label
>Query_type (either population, gdp_per_capita or forest_area)
:</label
>
&nbsp;&nbsp;
<input type="text" v-model="tableQueryType" />
</li>
<br/>
<br />
</ul>
<br />
<br />
Expand All @@ -176,8 +181,9 @@ <h3>Welcome to the API-documentation Page</h3>
<br />
<label
><strong>Description</strong>: <br />This API returns a table of
population, gdp_per_capita or forest area <br/> (in accordance with
the query type) with countries and years as columns. <br /><br />
population, gdp_per_capita or forest area <br />
(in accordance with the query type) with countries and years as
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because of prettify ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, prettier

columns. <br /><br />
<strong>Year parameter takes 3 types of inputs.</strong>
<br />
• A single Number e.g. 2000. <br />• An array of numbers e.g.
Expand All @@ -189,12 +195,9 @@ <h3>Welcome to the API-documentation Page</h3>
e.g. ["India","China"]<br /><br /><strong
>Pivot takes two values.</strong
><br />• Year <br />• Region <br />It determines the axes.<br />
<br /><strong>
Query_type parameter takes three values
</strong>
<br /><strong> Query_type parameter takes three values </strong>
<br />• population <br />• gdp_per_capita <br />• forest_area <br />
</label
>
</label>
</div>
<div class="flex-child" v-if="showTablePage">
<p>The response might take some time to show up.</p>
Expand Down Expand Up @@ -242,9 +245,12 @@ <h3>Welcome to the API-documentation Page</h3>
&nbsp;&nbsp;
<input type="text" v-model="jsonPivot" />
</li>
<br/>
<br />
<li>
<label>Query_type (either population, gdp_per_capita or forest_area) :</label>
<label
>Query_type (either population, gdp_per_capita or forest_area)
:</label
>
&nbsp;&nbsp;
<input type="text" v-model="jsonQueryType" />
</li>
Expand Down Expand Up @@ -273,8 +279,8 @@ <h3>Welcome to the API-documentation Page</h3>
<br />
<label
><strong>Description</strong>: <br />This API returns json response
of the query (population, gdp_per_capita <br/> or forest_area data
depending on the query). <br /><br />
of the query (population, gdp_per_capita <br />
or forest_area data depending on the query). <br /><br />
<strong>Year parameter takes 3 types of inputs.</strong>
<br />
• A single Number e.g. 2000. <br />• An array of numbers e.g.
Expand All @@ -287,13 +293,11 @@ <h3>Welcome to the API-documentation Page</h3>
>Pivot takes two values.</strong
><br />• None <br />• Year <br />• Region <br />It determines the
type of JSON object <br />If Year or Region is selcted, they will be
the key.
<br /><br /><strong>
Query_type parameter takes three values
the key. <br /><br /><strong>
Query_type parameter takes three values
</strong>
<br />• population <br />• gdp_per_capita <br />• forest_area <br />
</label
>
</label>
</div>
<div class="flex-child" v-if="showJsonPage">
<p>The response might take some time to show up.</p>
Expand Down Expand Up @@ -336,13 +340,16 @@ <h3>Welcome to the API-documentation Page</h3>
<input type="text" v-model="graphYears" />
</li>
<br />

<li>
<label>Query_type (either population, gdp_per_capita or forest_area) :</label>
<label
>Query_type (either population, gdp_per_capita or forest_area)
:</label
>
&nbsp;&nbsp;
<input type="text" v-model="graphQueryType" />
</li>
<br/>
<br />
<li>
<label>Theme:</label>
&nbsp;&nbsp;
Expand All @@ -354,7 +361,6 @@ <h3>Welcome to the API-documentation Page</h3>
&nbsp;&nbsp;
<input type="text" v-model="graphPlot" />
</li>

</ul>
<br />
<br />
Expand All @@ -380,8 +386,9 @@ <h3>Welcome to the API-documentation Page</h3>
<br />
<label
><strong>Description</strong>: <br />This API returns a graph of
population, gdp_per_capita or <br/> forest_area depending on the
type of query wrt countries and years<br /><br />
population, gdp_per_capita or <br />
forest_area depending on the type of query wrt countries and
years<br /><br />
<strong>Year parameter takes 3 types of inputs.</strong>
<br />
• A single Number e.g. 2000. <br />• An array of numbers e.g.
Expand All @@ -393,9 +400,8 @@ <h3>Welcome to the API-documentation Page</h3>
e.g. ["India","China"]<br /><br /><strong
>Plot parameter takes two values</strong
>
<br />• None<br />• bar<br /><br /> <br /><strong>
Query_type parameter takes three values
</strong>
<br />• None<br />• bar<br /><br />
<br /><strong> Query_type parameter takes three values </strong>
<br />• population <br />• gdp_per_capita <br />• forest_area <br />
<br />
<br />
Expand Down Expand Up @@ -441,9 +447,12 @@ <h3>Welcome to the API-documentation Page</h3>
&nbsp;&nbsp;
<input type="text" v-model="statsNumber" />
</li>
<br/>
<br />
<li>
<label>Query_type (either population, gdp_per_capita or forest_area) :</label>
<label
>Query_type (either population, gdp_per_capita or forest_area)
:</label
>
&nbsp;&nbsp;
<input type="text" v-model="statsQueryType" />
</li>
Expand Down Expand Up @@ -487,16 +496,13 @@ <h3>Welcome to the API-documentation Page</h3>
</strong>
<br />
<br /><br />
<strong>
Query_type parameter takes three values
</strong>
<strong> Query_type parameter takes three values </strong>
<br />• population <br />• gdp_per_capita <br />• forest_area <br />
</label>
<br/><br/>
<strong>Theme parameters take six values</strong>
<br />• none<br />• fluorescent <br />• light<br />• blackpink
<br />• dark<br />• aquamarine
</label>
<br /><br />
<strong>Theme parameters take six values</strong>
<br />• none<br />• fluorescent <br />• light<br />• blackpink <br />•
dark<br />• aquamarine
</div>
<div class="flex-child" v-if="showStatsPage">
<p>The response might take some time to show up.</p>
Expand Down
5 changes: 1 addition & 4 deletions api/templates/query_builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ <h3>Welcome to the QueryBuilder Page</h3>
<div class="flex-child" v-if="dropdownSelectedAPI==`stats`">
<p>Select a year</p>
<select v-model="dropdownSelectedYear">
<option
v-for="dropdownYear in years"
v-bind:value="dropdownYear"
>
<option v-for="dropdownYear in years" v-bind:value="dropdownYear">
((dropdownYear))
</option>
</select>
Expand Down
2 changes: 2 additions & 0 deletions api/templates/table_view.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- @format -->

<!DOCTYPE html>
<html lang="en">
<head>
Expand Down
8 changes: 5 additions & 3 deletions api/utils/input_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ def year_input_manager(year_or_tuple_or_array, query_type="population"):
years = list(range(start, stop + 1, step))
else:
years = [year_or_tuple_or_array]
if query_type == "forest_area" and str(max(years)) > str(2020):
if isinstance(query_type, str):
query_type = [query_type]
if "forest_area" in query_type and str(max(years)) > str(2020):
raise InvalidParameterException("We have Forest area percentage data upto 2020")
if query_type == "gdp_per_capita" and str(max(years)) > str(2018):
if "gdp_per_capita" in query_type and str(max(years)) > str(2018):
raise InvalidParameterException("We have GDP per capita data upto 2018")
if query_type == "population" and str(max(years)) > str(2021):
if "population" in query_type and str(max(years)) > str(2021):
raise InvalidParameterException("We have population data upto 2021")
return years
Loading