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

Models for Lokniti Data #20

Merged
merged 31 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d38130d
add LoknitiResponse model and serializer
vaeyias Apr 30, 2024
cd8fcc6
update Lokniti models and serializers
vaeyias May 1, 2024
89474c3
:construction: create load command for codebook
vaeyias May 1, 2024
2392540
replace load_codebook.py with update_db
vaeyias May 1, 2024
90d26b1
rename data files and add a column name
vaeyias May 1, 2024
56f7e19
generalize load_responders for all years
vaeyias May 1, 2024
f79a7b9
add 2014 NES data file
vaeyias May 1, 2024
773d199
fix default values for responders model
vaeyias May 3, 2024
fefcefe
Merge branch 'main' into lokniti-data
vaeyias May 3, 2024
5a38d60
first draft of load_responses method
czheng10 May 4, 2024
ebc35ea
update entry and response
czheng10 May 5, 2024
4b0a753
increase width of competitiveness map
vaeyias May 10, 2024
6663f46
generalize GradientLegend component
vaeyias May 13, 2024
164bbe3
start mapping caste distribution
vaeyias May 13, 2024
4eba1bf
fix pylint errors
vaeyias May 13, 2024
9c23d67
Merge branch 'main' into lokniti-data
JusticeV452 May 14, 2024
28e50bd
Updated load_responders to work with load_responses
JusticeV452 May 14, 2024
aeb484b
Removed redundant Response attributes
JusticeV452 May 14, 2024
d8c0615
Fixed linter errors in api_views
JusticeV452 May 14, 2024
df115b6
Updated update_db to work with load_responders
JusticeV452 May 14, 2024
b288d87
Update command description text
JusticeV452 May 14, 2024
65ef464
Fixed trailing whitespace
JusticeV452 May 14, 2024
bc45638
Fixed filter LoknitiResponder based on state_name
JusticeV452 May 14, 2024
9812fb5
Removed all_responders test view
JusticeV452 May 14, 2024
d3cf86e
Removed all_responders from urls
JusticeV452 May 14, 2024
08f29ba
Applied formatter and removed debug console logs
JusticeV452 May 14, 2024
b7e2559
Removed console.logs
JusticeV452 May 14, 2024
48f1b59
Added TODO for MapBaseCaste to make more general
JusticeV452 May 14, 2024
94804ae
update data being displayed when year changes
vaeyias May 14, 2024
c548567
Merge branch 'lokniti-data' of https://github.com/dhmit/data-driven-d…
vaeyias May 14, 2024
6e6c00e
put caste map data in backend files
vaeyias May 14, 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
77 changes: 77 additions & 0 deletions backend/app/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

from .models import (
LSElection,
LoknitiResponders,
LoknitiResponses,
LoknitiCodebook,
TCPDElection,
SeatShare,
CampaignFinance,
)

from .serializers import (
LSElectionSerializaer,
LoknitiRespondersSerializer,
LoknitiResponsesSerializer,
LoknitiCodebookSerializer,
TCPDElectionSerializer,
SeatShareSerializer,
CampaignFinanceSerializer,
Expand Down Expand Up @@ -181,3 +187,74 @@ def campaign_finance_donor_subset(request, donor_name):
campaign_finances = CampaignFinance.objects.filter(donor_name=donor_name)
serializer = CampaignFinanceSerializer(campaign_finances, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_lokniti_codebook(request):
"""
API endpoint to get codebook
"""
responses = LoknitiCodebook.objects.all()
serializer = LoknitiCodebookSerializer(responses, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_lokniti_responders(request):
"""
API endpoint to get responders
"""
responses = LoknitiResponders.objects.filter(PC_id=1, PS_id=1)
serializer = LoknitiRespondersSerializer(responses, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_responders_by_constituency(request, election_year, state_name, pc_id):
"""
API endpoint to get responders by constituency
"""
state_name = state_name.replace("_", " ")
if election_year == 2009:
state_name = state_name.upper()
responses = LoknitiResponders.objects.filter(
election_year=election_year, state_name__icontains=state_name, PC_id=pc_id)
serializer = LoknitiRespondersSerializer(responses, many=True)
return Response(serializer.data)


@api_view(['GET'])
def get_lokniti_responses_by_question_and_year(request, election_year, question_var):
"""
API endpoint to get all responses to a question in a specific
election year
"""
responses = LoknitiResponses.objects.filter(
responder__election_year=election_year, question_var=question_var)
serializer = LoknitiResponsesSerializer(responses, many=True)
return Response(serializer.data)


@api_view(['GET'])
# pylint: disable=too-many-arguments
def get_lokniti_responses_by_constituency(
request, election_year, state_name, PC_id, question_election_year, question_var_orig):
"""
API endpoint to get all responses to a question in a specific
election year and constituency based on a question variable name
from a specific year
"""

question_text = LoknitiCodebook.objects.get(
question_var=question_var_orig, election_year=question_election_year).question_text

question_var = LoknitiCodebook.objects.get(
question_text=question_text, election_year=election_year).question_var

responses = LoknitiResponses.objects.filter(
responder__election_year=election_year, question_var=question_var,
responder__state_name__icontains=state_name, responder__PC_id=PC_id
)
serializer = LoknitiResponsesSerializer(responses, many=True)

return Response(serializer.data)
14 changes: 14 additions & 0 deletions backend/app/data/database_update_config/lokniticodebook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"model_name": "LoknitiCodebook",
"attr_to_column": {
"election_year": "year",
"question_var": "var_name",
"question_text": "question_text"
},
"file_names": [
"lokniti_data/Lokniti_Data_Codebook_2004.csv",
"lokniti_data/Lokniti_Data_Codebook_2009.csv",
"lokniti_data/Lokniti_Data_Codebook_2014.csv",
"lokniti_data/Lokniti_Data_Codebook_2019.csv"
]
}
11 changes: 11 additions & 0 deletions backend/app/data/database_update_config/loknitiresponders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"config_type": "management_command",
"command_name": "load_responders",
"model_names": ["LoknitiResponders", "LoknitiResponses"],
"file_names": [
"lokniti_data/NES_2004_Data_file.csv",
"lokniti_data/NES_2009_Data_file.csv",
"lokniti_data/NES_2014_Data_file.csv",
"lokniti_data/NES_2019_Data_file.csv"
]
}
45 changes: 45 additions & 0 deletions backend/app/data/lokniti_data/Lokniti_Data_Codebook_2004.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var_name,year,question_text,,,,,,
v1,2004,State Name,,,,,,
v2,2004,P.C. ID,,,,,,
v3,2004,A.C. ID,,,,,,
v4,2004,P.S. ID,,,,,,
v5,2004,Respondent Number,,,,,,
q2a,2004,Who did you vote for?,,,,,,
q5a,2004,Which party did you vote for in the previous election?,,,,,,
q9,2004,"In deciding whom to vote for, whose opinion mattered to you most?",,,,,,
q10,2004,"While voting, what is the most important consideration for you, the candidate, your caste community’s interest or something else?",,,,,,
q20a,2004,"Now I will talk about the changes that have taken place in the country during the last five years. You tell me, in the last five years have the conditions regarding these issues im proved or deteriorated ? Curbing corruption",,,,,,
q20b,2004,Security of the country/National security,,,,,,
q20c,2004,Employment opportunities.,,,,,,
q20d,2004,India’s image in the world.,,,,,,
q20e,2004,Hindu-Muslim brotherhood,,,,,,
q20f,2004,Development of the country,,,,,,
q24a,2004,Agree/Disagree: We should be loyal to our own region first and then to the country.,,,,,,
q24b,2004,Agree/Disagree: One should vote in the same way ones caste/community votes.,,,,,,
q24c,2004,"Agree/Disagree: Compared to national parties, regional/local parties can provide better government in states",,,,,,
q24d,2004,"Agree/Disagree: On the site of Babri Masjid, only Ram temple should be built.",,,,,,
q24e,2004,Agree/Disagree: Making of the atomic bomb has not benefitted the country.,,,,,,
q24f,2004,Agree/Disagree: The needs and problems of Muslims have been neglected in India,,,,,,
q24g,2004,Agree/Disagree: Large states should be divided up and smaller states should be created.,,,,,,
q24h,2004,Agree/Disagree: Protecting the interests of the minorities is the responsibility of the government. ,,,,,,
q24i,2004,Agree/Disagree: Country should increase spending on the army even if it increases the burden on ordinary people.,,,,,,
q24j,2004,"Fully agree, somewhat agree somewhat disagree or fully disagree: Those who are not well educated should not be allowed to contest elections.",,,,,,
q24k,2004,Agree/Disagree: War is the only solution to Indo-Pakistan problem,,,,,,
q29,2004,"People have different opinions about the NDA Government. Some people believe that the economic policies of this Government have brought prosperity to the whole country, whereas some believe that only the rich have benefited and others believe that no one has benefited. What is your
opinion - the whole country has become prosperous, only the rich have benefited or no one has benefited? ",,,,,,
q36a,2004,Agree/Disagree: Every community should be allowed to have it’s own laws to govern marriage and property rights.,,,,,,
q36b,2004,Agree/Disagree: Marriage of boys and girls from different religions should be banned.,,,,,,
q36c,2004,Agree/Disagree: Seats should be reserved for women in Lok Sabha and Vidhan Sabha. ,,,,,,
q36d,2004,Agree/Disagree: There should not be caste-based reservations in jobs. ,,,,,,
q36e,2004,Agree/Disagree: Higher education is not good for women.,,,,,,
q36f,2004,"Agree/Disagree: In a democracy, it is appropriate that tthe opinions of the majority community should prevail.",,,,,,
q36g,2004,"Agree/Disagree: Like men, women also have the right to work.",,,,,,
q36h,2004,Agree/Disagree: There should be a legal ban on religious conversions.,,,,,,b19
q36i,2004,Agree/Disagree: Marriage of boys and girls from different castes should be banned.,,,,,,
q36j,2004,Agree/Disagree: Doing politics is not meant for women.,,,,,,
q41,2004,"Who do you think was primarily responsible for the riots in Gujarat - the Government, Muslim extremists, Hindu extremists or someone else?",,,,,,
b2,2004,What is your age?,,,,,,
b3,2004,What is your gender?,,,,,,
b6a,2004,What is your caste?,,,,,,
b7,2004,What is your religion?,,,,,,
b19,2004,What is your total monthly household income?,,,,,,
58 changes: 58 additions & 0 deletions backend/app/data/lokniti_data/Lokniti_Data_Codebook_2009.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var_name,year,question_text
st_id,2009,State Name
pc_id,2009,P.C. ID
ac_id,2009,A.C. ID
ps_id,2009,P.S. ID
res,2009,Respondent Number
q1a,2009,Who did you vote for?
q3a1,2009,Heard/Not Heard: Indo-US Nuclear Deal
q3a2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Indo-US Nuclear Deal"
q3b1,2009,Heard/Not Heard: Ram Setu controversy
q3b2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Ram Setu controversy"
q3c1,2009,Heard/Not Heard: Prices of everyday goods
q3c2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Prices of everyday goods"
q3d1,2009,Heard/Not Heard: Terrorist attacks
q3d2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Terrorist attacks"
q3e1,2009,Heard/Not Heard: Farmers sucides
q3e2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Farmers sucides"
q3f1,2009,Heard/Not Heard: Reservations for OBCs
q3f2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Reservations for OBCs"
q3g1,2009,Heard/Not Heard: Livelihood/employment opportunities
q3g2,2009,"(If Yes) For each one of them, please tell me how it affected your decision of whom to vote for - not very much, a lot or almost entierly?: Livelihood/employment opportunities"
q10,2009,What mattered to you more while deciding whom to vote for in the recent election - party or candidate?
q10a,2009,(If ‘Party’ in Q10) What was the most important consideration in favour of the party?
q10b,2009,(If ‘Candidate’ in Q10) What was the most important consideration in favour of the candidate?
q16a,2009,(Now I will ask you about the last Lok Sabha elections held in 2004? I mean the MP elections for electing the Central Government in Delhi. Were you able to cast your vote or not? If yes) Who did you vote for?
q20,2009,What is your opinion about the performance of the Congress led UPA Government during the last five years – would you say that you are satisfied or dissatisfied with it?
q26a,2009,"(Agree/Disagree) People themselves are responsible for their poverty, not the government"
q26b,2009,(Agree/Disagree) Foreign companies should not be allowed free trade in India
q26c,2009,(Agree/Disagree) Country should increase spending on the army even if it increases the burden on ordinary people
q26d,2009,(Agree/Disagree) The number of government employees should be reduced
q26e,2009,(Agree/Disagree) The government factories and businesses should be sold/handed over to private companies.
q26f,2009,(Agree/Disagree) Government should curb the right of workers and employees to strike
q26g,2009,(Agree/Disagree) War is the only solution to the Indo-Pakistan problem
a3a,2009,(Have you heard of the disputed structure (Babri Masjid) at Ayodhya? If Yes) Some people say that the demolition was justified while others say it was not justified – what would you say – was it justified or not justified?
a3b,2009,"(Have you heard of the disputed structure (Babri Masjid) at Ayodhya? If heard about demolition) What would you suggest should be built on that site now - neither mosque nor temple, a mosque should be built, a temple should be built or both a mosque and a temple should be built?"
a4a,2009,(Agree/Disagree) We should be loyal to our own region first and then to the country
a4b,2009,(Agree/Disagree) Every community should be allowed to have it’s own laws to govern marriage and property rights
a4c,2009,(Agree/Disagree) There should be a legal ban on religious conversions
a4d,2009,(Agree/Disagree) Marriage of boys and girls from different castes should be banned
a4e,2009,(Agree/Disagree) Prohibition (Ban of Liquor) should be imposed all over the country
a4f,2009,"(Agree/Disagree) In a democracy, the will of the majority community should prevail"
a4g,2009,(Agree/Disagree) Both sons and daughters should have equal share in their parents property
a4h,2009,(Agree/Disagree) Minorities should adopt the customs of the majority community
a4i,2009,(Agree/Disagree) Too much education for women is not good
a6a,2009,(1) Reservation for SCs and STs is correct because it is in accordance with the principle of social justice. (2) Reservation for SCs and STs is wrong because it goes against the principle of merit
a6b,2009,"(1) It is important that the government should make special schemes to uplift the poor and disadvantaged. (2) Instead of wasting money on such schemes, the government should improve the entire economy"
a6c,2009,"(1) It does not matter what we wear Religion is about faith and not about tilak, cap, cross etc. (2) Tilak, cap, cross etc. are Markers of religion; it is essential that we wear such distinct Symbol of our religion."
a6d,2009,"(1) Temples, Mosques, Churches and Gurudwaras are place of worship and should not be used for political purpose. (2) Even though Temples, Mosques, Churches and Gurudwaras are place of worship, there is nothing wrong in using them political purpose"
a9,2009,Would you say that you belong to the majority community or you belong to the minority community?
c11a,2009,(1) Someone who is accessible but corrupt. (2) Someone who is honest but inaccessible.
c11b,2009,"(1) Someone who is involved in criminal cases, but can be relied on to get work done. (2)Someone who is known to be a gentleman, but can not always get work done."
c11c,2009,"(1) A strong leader who does not listen to anyone else. (2) Someone who consults everyone, but is not a strong leader"
c13,2009,"People have different opinions about the Congress led UPA Government. Some people believe that the economic policies of this Government have brought prosperity to the whole country, whereas some believe that only the rich have benefited and others believe that no one has benefited. What is your opinion – the whole country has become prosperous, only the rich have benefited or no one has benefited?"
z2,2009,What is your age?
z3,2009,What is your gender?
z5,2009,Up to what level have you studied?
z7a,2009,What is your caste?
z8,2009,What is your religion?
48 changes: 48 additions & 0 deletions backend/app/data/lokniti_data/Lokniti_Data_Codebook_2014.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var_name,year,question_text
state_id,2014,State Name
pc_id,2014,P.C. ID
ac_id,2014,A.C. ID
ps_id,2014,P.S. ID
resno,2014,Respondent Number
q1a,2014,Who did you vote for?
q5,2014,What was the most important issue for you while voting in this election?
q7,2014,What mattered to you more while deciding whom to vote for in the recent election - party or candidate?
q7a,2014,What was the most important consideration in favour of the party?
q7b,2014,What was the most important consideration in favour of the candidate?
q8,2014,"As compared to five years ago, would you say the economic condition of India has become much better, better, remained same, become worse or much worse?"
q9a,2014,Who do you think cares for people like you?
q9b,2014,Who do you think is reliable/trustworthy?
q9c,2014,Who do you think can get things done?
q9d,2014,Who do you think can take along other leaders of his/her party?
q9e,2014,Who do you think is experienced?
q10a,2014,"Agree/Disagree: In a democracy, the will of the majority
community should prevail."
q10b,2014,"Agree/Disagree: Reservations based on caste and religion
divide the people of India."
q10c,2014,"Agree/Disagree: We should consider ourselves Indians first
and only then comes our region."
q10d,2014,"Agree/Disagree: The government/state should treat minorities
in the same way as it treats the majority."
q10e,2014,"Agree/Disagree: The government should make special
provision to accomodate minorities."
q15a,2014,Which party is better for administration?
q15b,2014,Which party takes care of your religious sentiments?
q15c,2014,Which party is better for national security?
q15d,2014,Which party has good leadership?
q15e,2014,Which party offers lots of free gifts/freebies?
q24a,2014,Who do you think is best for women empowerment?
q24b,2014,Who do you think is development of the country?
q24c,2014,Who do you think is best for controlling price rise?
q24d,2014,Who do you think is best for upliftment of Dalits and Adivasis?
q24e,2014,Who do you think if best for controlling corruption?
q24f,2014,Who do you think is best for the betterment of the Muslim community?
q24g,2014,Who do you think is best for national security?
q27,2014,Which party have you traditionally supported?
q29,2014,"Let us assume that in this election Narendra Modi was not the PM candidate of the BJP/NDA in this Lok Sabha election. In such a situation, would you have voted for some other party instead of the party you have voted for or this would have made no difference on your decision?"
z1,2014,What is your age?
z2,2014,What is your gender?
z3,2014,Up to what level have you studied?
z4a,2014,What is your main occupation?
z5a,2014,What is your caste?
z6,2014,What is your religion?
z13,2014,What is your total monthly household income?
Loading