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

Constituency Map - Competitiveness #6

Merged
merged 36 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cd3391d
add model for LS elections
vaeyias Mar 12, 2024
0fe851c
add vote shares to model
vaeyias Mar 12, 2024
a6c683f
Merge branch 'main' into constituency-map
vaeyias Mar 15, 2024
4aa9acd
Add 2019 constituency map
vaeyias Mar 15, 2024
74af1f1
change ls-elections url name
vaeyias Mar 15, 2024
00bf3d5
add get request to get specific election year
vaeyias Mar 15, 2024
5faa992
update map to only fetch once
vaeyias Mar 16, 2024
324f7c7
update map to fetch data from db
vaeyias Mar 16, 2024
8cefe3e
add map colors and display data on hover
vaeyias Mar 16, 2024
37938b6
add more election data to display
vaeyias Mar 16, 2024
2fca924
add onclick template for map
vaeyias Mar 22, 2024
9afe963
update map to filter by pc number
vaeyias Apr 2, 2024
e2345af
add discrete slider
vaeyias Apr 5, 2024
e0d3136
add gradient legend
vaeyias Apr 12, 2024
56cbb68
add default color for undefined constituencies
vaeyias Apr 12, 2024
3ef440f
add previewData legend on map
vaeyias Apr 16, 2024
7dea52c
add onClick feature on map
vaeyias Apr 16, 2024
d18b5d5
reduce map laoding time
vaeyias Apr 16, 2024
a523f7b
fix ESlint warnings
vaeyias Apr 16, 2024
f06d2a7
clean up comments
vaeyias Apr 16, 2024
aa885d5
set map boundaries and center map title
vaeyias Apr 17, 2024
4690204
style slider
vaeyias Apr 17, 2024
81b8f99
adjust map bounds
vaeyias Apr 17, 2024
89c7c91
merge main into map branch
vaeyias Apr 17, 2024
eb94aca
Merge branch 'main' into constituency-map
vaeyias Apr 17, 2024
1882888
remove duplicate functions
vaeyias Apr 17, 2024
123d97b
remove unused geojson
vaeyias Apr 17, 2024
bf3e98d
fix backend pylint errors 1
vaeyias Apr 17, 2024
ce7298f
merge migrations
vaeyias Apr 17, 2024
cd126ea
fix backend pylint errors 2
vaeyias Apr 17, 2024
2a028a5
disable pylint similar lines warning in load_loksabha and load_seatshare
vaeyias Apr 17, 2024
39cfd06
fix function name
vaeyias Apr 18, 2024
d82245e
edit pylint warning comments and improve code style
vaeyias Apr 18, 2024
99e3899
remove unnecessary comments
vaeyias Apr 18, 2024
ee5db47
remove changes from .vscode\settings.json
vaeyias Apr 18, 2024
a395a15
add .vscode directory to .gitignore
vaeyias Apr 18, 2024
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
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"editor.defaultFormatter": "ms-python.autopep8",
"pylint.args": [
"--disable=E0015"
]
}
],
"[javascript]": {
"editor.defaultFormatter": "ms-vsliveshare.vsliveshare"
JusticeV452 marked this conversation as resolved.
Show resolved Hide resolved
}
}
102 changes: 96 additions & 6 deletions backend/app/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from rest_framework.response import Response

from .models import (
LSElection,
TCPDElection,
SeatShare,
CampaignFinance,
)

from .serializers import (
LSElectionSerializaer,
TCPDElectionSerializer,
SeatShareSerializer,
CampaignFinanceSerializer,
Expand Down Expand Up @@ -40,18 +42,106 @@ def all_seats(request):
return Response(serializer.data)


@api_view(['GET'])
def all_ls_elections(request):
"""
API endpoint to get each Lok Sahbha election
in the database
"""
ls_elections = LSElection.objects.all()
serializer = LSElectionSerializaer(ls_elections, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_ls_election_year(request, year):
"""
API endpoint to get each Lok Sahbha election
in the database
"""
ls_elections = LSElection.objects.filter(election_year=year)
serializer = LSElectionSerializaer(ls_elections, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_specific_ls_election(request, year, state, constituency_no):
"""
API endpoint to get each Lok Sahbha election
in the database
"""
ls_elections = LSElection.objects.filter(
election_year=year, state_name=state, constituency_no=constituency_no)
serializer = LSElectionSerializaer(ls_elections, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_SDE_DATA_IN_F7DSTRBND_1991(request, feature_limit=10):
"""
API endpoint to get SDE_DATA_IN_F7DSTRBND_1991 geojson
"""
geojson_path = os.path.join(settings.GEOJSON_DIR, "SDE_DATA_IN_F7DSTRBND_1991.geojson")
with open(geojson_path, encoding='utf-8') as f:
geocolors_path = os.path.join(
settings.GEOJSON_DIR, "SDE_DATA_IN_F7DSTRBND_1991.geojson")
with open(geocolors_path, encoding='utf-8') as f:
geojson = json.load(f)

return Response({
"type": geojson["type"],
"features": geojson["features"]
})


@api_view(['GET'])
def get_India_PC_2019_simplified(request, feature_limit=10):
"""
API endpoint to get SDE_DATA_IN_F7DSTRBND_1991 geojson
"""
geocolors_path = os.path.join(
settings.GEOJSON_DIR, "india_pc_2019_simplified.geojson")
with open(geocolors_path, encoding='utf-8') as f:
geojson = json.load(f)
num_features = feature_limit if feature_limit is not None else len(geojson["features"])

return Response({
"type": geojson["type"],
"features": geojson["features"][:num_features]
"features": geojson["features"]
})


@api_view(['GET'])
def get_India_PC_2019(request, feature_limit=10):
"""
API endpoint to get SDE_DATA_IN_F7DSTRBND_1991 geojson
"""
geocolors_path = os.path.join(
settings.GEOJSON_DIR, "India_PC_2019.geojson")
with open(geocolors_path, encoding='utf-8') as f:
geojson = json.load(f)

return Response({
"type": geojson["type"],
"features": geojson["features"]
})


@api_view(['GET'])
def get_competiveness_colors(request, election_year=2004):
vaeyias marked this conversation as resolved.
Show resolved Hide resolved
"""
API endpoint to get data and colors for competitiveness map
"""
colors_path = os.path.join(
settings.GEOJSON_DIR, "competitivenessColors.json")
with open(colors_path, encoding='utf-8') as f:
colors_json = json.load(f)

data_path = os.path.join(
settings.GEOJSON_DIR, "competitivenessData.json")
with open(data_path, encoding='utf-8') as f:
data_json = json.load(f)

return Response({
"colors": colors_json[str(election_year)],
"data": data_json[str(election_year)]
})


Expand All @@ -74,7 +164,7 @@ def campaign_finance(request, donor_name=None, party_name=None):
@api_view(['GET'])
def campaign_finance_party_subset(request, party_name):
"""
API endpoint to get campaign finance donations made by all donors to
API endpoint to get campaign finance donations made by all donors to
a specified party
"""
campaign_finances = CampaignFinance.objects.filter(party_name=party_name)
Expand All @@ -85,7 +175,7 @@ def campaign_finance_party_subset(request, party_name):
@api_view(['GET'])
def campaign_finance_donor_subset(request, donor_name):
"""
API endpoint to get campaign finance donations made to all parties by
API endpoint to get campaign finance donations made to all parties by
a specified donor
"""
campaign_finances = CampaignFinance.objects.filter(donor_name=donor_name)
Expand Down
Loading