diff --git a/classes/Policies.php b/classes/Policies.php index de6a34471f..74a894f8e0 100644 --- a/classes/Policies.php +++ b/classes/Policies.php @@ -15,124 +15,32 @@ class Policies { - /** - * Policy Positions - * - * Array of all policy positions available to use. - * - * Arrays are in the form `{id} => {text}` - */ - - protected $policies = array( - 363 => 'introducing foundation hospitals', - 810 => 'greater regulation of gambling', - 811 => 'smoking bans', - 826 => 'equal gay rights', - 837 => 'a wholly elected House of Lords', - 975 => 'investigations into the Iraq war', - 984 => 'replacing Trident with a new nuclear weapons system', - 996 => 'a transparent Parliament', - 1027 => 'a referendum on the UK\'s membership of the EU', - 1030 => 'measures to prevent climate change', - 1049 => 'the Iraq war', - 1050 => 'the hunting ban', - 1051 => 'introducing ID cards', - 1052 => 'university tuition fees', - 1053 => 'Labour\'s anti-terrorism laws', - 1065 => 'more EU integration', - 1071 => 'allowing ministers to intervene in inquests', - 1074 => 'greater autonomy for schools', - 1079 => 'removing hereditary peers from the House of Lords', - 1084 => 'a more proportional system for electing MPs', - 1087 => 'a stricter asylum system', - 1105 => 'the privatisation of Royal Mail', - 1109 => 'encouraging occupational pensions', - 1110 => 'increasing the rate of VAT', - 1113 => 'an equal number of electors per parliamentary constituency', - 1120 => 'capping civil service redundancy payments', - 1124 => 'automatic enrolment in occupational pensions', - 1132 => 'raising England’s undergraduate tuition fee cap to £9,000 per year', - 1136 => 'fewer MPs in the House of Commons', - 6667 => 'the policies included in the 2010 Conservative - Liberal Democrat Coalition Agreement', - 6670 => 'a reduction in spending on welfare benefits', - 6671 => 'reducing central government funding of local government', - 6672 => 'reducing housing benefit for social tenants deemed to have excess bedrooms (which Labour describe as the "bedroom tax")', - 6673 => 'paying higher benefits over longer periods for those unable to work due to illness or disability', - 6674 => 'raising welfare benefits at least in line with prices', - 6676 => 'reforming the NHS so GPs buy services on behalf of their patients', - 6677 => 'restricting the provision of services to private patients by the NHS', - 6678 => 'greater restrictions on campaigning by third parties, such as charities, during elections', - 6679 => 'reducing the rate of corporation tax', - 6680 => 'raising the threshold at which people start to pay income tax', - 6681 => 'increasing the tax rate applied to income over £150,000', - 6682 => 'ending financial support for some 16-19 year olds in training and further education', - 6683 => 'local councils keeping money raised from taxes on business premises in their areas', - 6684 => 'making local councils responsible for helping those in financial need afford their council tax and reducing the amount spent on such support', - 6685 => 'a banker’s bonus tax', - 6686 => 'allowing marriage between two people of same sex', - 6687 => 'academy schools', - 6688 => 'use of UK military forces in combat operations overseas', - 6690 => 'measures to reduce tax avoidance', - 6691 => 'stronger tax incentives for companies to invest in assets', - 6692 => 'slowing the rise in rail fares', - 6693 => 'lower taxes on fuel for motor vehicles', - 6694 => 'higher taxes on alcoholic drinks', - 6695 => 'more powers for local councils', - 6696 => 'the introduction of elected Police and Crime Commissioners', - 6698 => 'fixed periods between parliamentary elections', - 6699 => 'higher taxes on plane tickets', - 6697 => 'selling England’s state owned forests', - 6702 => 'spending public money to create guaranteed jobs for young people who have spent a long time unemployed', - 6703 => 'laws to promote equality and human rights', - 6704 => 'financial incentives for low carbon emission electricity generation methods', - 6705 => 'requiring pub companies to offer pub landlords rent-only leases', - 6706 => 'strengthening the Military Covenant', - 6707 => 'restricting the scope of legal aid', - 6708 => 'transferring more powers to the Senedd/Welsh Parliament', - 6709 => 'transferring more powers to the Scottish Parliament', - 6710 => 'culling badgers to tackle bovine tuberculosis', - 6711 => 'an annual tax on the value of expensive homes (popularly known as a mansion tax)', - 6715 => 'allowing national security sensitive evidence to be put before courts in secret sessions', - 6716 => 'allowing employees to exchange some employment rights for shares in the company they work for', - 6718 => 'restrictions on fees charged to tenants by letting agents', - 6719 => 'limits on success fees paid to lawyers in no-win no fee cases', - 6720 => 'a statutory register of lobbyists', - 6721 => 'requiring the mass retention of information about communications', - 6731 => 'more restrictive regulation of trade union activity', - 6732 => 'allowing terminally ill people to be given assistance to end their life', - 6733 => 'higher taxes on banks', - 6734 => 'stronger enforcement of immigration rules', - 6736 => 'a veto for MPs from England, Wales and Northern Ireland over laws specifically impacting their part of the UK', - 6741 => 'greater regulation of hydraulic fracturing (fracking) to extract shale gas', - 6753 => 'new high speed rail infrastructure', - 6751 => 'mass surveillance of people’s communications and activities', - 6764 => 'a right to remain for EU nationals already in living in the UK', - 6761 => 'UK membership of the EU', - 6758 => 'merging police and fire services under Police and Crime Commissioners', - 6754 => 'reducing capital gains tax', - 6747 => 'greater public control of bus services', - 6746 => 'a publicly owned railway system', - 6744 => 'phasing out secure tenancies for life', - 6743 => 'charging a market rent to high earners renting a council home', - 6757 => 'military action against ISIL (Daesh)', - 842 => 'a lower voting age', - ); - private $commons_only = array( 811, 826, 1053, ); - /** - * Policy Sets - * - * Collections of policies (by ID number) to be used for sorted and - * restricted displays. - */ + # policies where votes affected by covid voting restrictions + protected $covid_affected = [1136, 6860]; + + private $db; - private $sets = array( - 'summary' => array( + private $policy_id; + + public function __construct($policy_id = null) { + $this->db = new \ParlDB; + + if (TESTING) { + $policy_data = json_decode(file_get_contents(dirname(__FILE__) . '/../tests/policies.json'), true); + } else { + $policy_data = json_decode(file_get_contents(RAWDATA . '/scrapedjson/policies.json'), true); + } + $this->policies = $policy_data['policies']; + $this->set_descs = $policy_data['set_descs']; + $this->sets = $policy_data['sets']; + + $this->sets['summary'] = array( 1113, 1136, 1132, @@ -151,159 +59,7 @@ class Policies { 1079, 6671, 6672, - ), - 'social' => array( - 826, - 811, - 1050, - 6686, - 6703, - 6732, - ), - 'foreignpolicy' => array( - 6688, - 1049, - 975, - 984, - 1065, - 1027, - 6706, - 6764, - 6761, - 6757, - ), - 'welfare' => array( - 6672, - 6674, - 6673, - 6684, - 6670, - 6702, - ), - 'taxation' => array( - 6680, - 1110, - 6694, - 6699, - 6693, - 6681, - 1109, - 1124, - 6685, - 6733, - 6711, - 6716, - 6731, - 6754, - ), - 'business' => array( - 6679, - 6690, - 6691, - 6753, - ), - 'health' => array( - 6677, - 6676, - 363, - 811, - 6732, - ), - 'education' => array( - 1074, - 1132, - 6687, - 6682, - 1052 - ), - 'reform' => array( - 6671, - 1113, - 1136, - 996, - 1084, - 837, - 6683, - 6678, - 6698, - 1079, - 6708, - 6709, - 6695, - 6736, - 842, - ), - 'home' => array( - 1087, - 1071, - 1051, - 6696, - 6721, - 6734, - 6751, - 6758, - ), - 'environment' => array( - 1030, - 6693, - 6697, - 6699, - 6704, - 6710, - 6741, - 6753, - ), - 'transport' => array( - 6747, - 6692, - 6693, - 6699, - 6746, - ), - 'housing' => array( - 6744, - 6743, - ), - 'misc' => array( - 810, - 1120, - 1053, - 1105, - 6705, - 6707, - 6715, - 6720, - 6719, - 6718, - 6667, - ) - ); - - # policies where votes affected by covid voting restrictions - protected $covid_affected = [1136, 6860]; - - protected $set_descs = array( - 'social' => 'Social Issues', - 'foreignpolicy' => 'Foreign Policy and Defence', - 'welfare' => 'Welfare and Benefits', - 'taxation' => 'Taxation and Employment', - 'business' => 'Business and the Economy', - 'health' => 'Health', - 'education' => 'Education', - 'reform' => 'Constitutional Reform', - 'home' => 'Home Affairs', - 'environment' => 'Environmental Issues', - 'transport' => 'Transport', - 'housing' => 'Housing', - 'misc' => 'Miscellaneous Topics', - ); - - private $db; - - private $policy_id; - - public function __construct($policy_id = null) { - $this->db = new \ParlDB; + ); if ( $policy_id ) { $this->policy_id = $policy_id; diff --git a/scripts/json2db.pl b/scripts/json2db.pl index 0199239971..61727d7590 100755 --- a/scripts/json2db.pl +++ b/scripts/json2db.pl @@ -24,9 +24,8 @@ use JSON::XS; use LWP::Simple; -use vars qw($motion_count $policy_count $align_count @policyids); +use vars qw($motion_count $policy_count $align_count); -require 'policyids.pl'; my $json = JSON::XS->new->latin1; my $dsn = 'DBI:mysql:database=' . mySociety::Config::get('TWFY_DB_NAME'). ':host=' . mySociety::Config::get('TWFY_DB_HOST'); @@ -45,6 +44,8 @@ $motion_count = $policy_count = $align_count = 0; +my @policyids = fetch_policies(); + foreach my $dreamid ( @policyids ) { my $policy_url = mySociety::Config::get('TWFY_VOTES_URL') . '/twfy-compatible/popolo/' . $dreamid . '.json'; my $policy_json = get($policy_url); @@ -71,6 +72,33 @@ print "parsed $policy_count policies, $motion_count divisions, and $align_count alignments from JSON\n"; +# --- + +sub fetch_policies { + my $policies_url = mySociety::Config::get('TWFY_VOTES_URL') . '/policies/commons/active/all.json'; + my $policies_json = get($policies_url); + my $policies = $json->decode($policies_json); + + my @ids; + my $out = {}; + foreach my $policy (@{$policies->{policies}}) { + say "Processing policy $policy->{id} $policy->{name}" if $verbose; + push @ids, $policy->{id}; + foreach (@{$policy->{groups}}) { + push @{$out->{sets}{$_->{slug}}}, $policy->{id}; + $out->{set_descs}{$_->{slug}} = $_->{name}; + } + $out->{policies}{$policy->{id}} = $policy->{context_description}; + } + + $out = $json->encode($out); + open(my $fp, '>', mySociety::Config::get('RAWDATA') . '/scrapedjson/policies.json'); + $fp->write($out); + close $fp; + + return @ids; +} + sub process_motions { my ($aspects, $dreamid) = @_; # Set AutoCommit off diff --git a/scripts/policyids.pl b/scripts/policyids.pl deleted file mode 100644 index d351654daa..0000000000 --- a/scripts/policyids.pl +++ /dev/null @@ -1,96 +0,0 @@ -@policyids = ( - 363, - 810, - 811, - 826, - 837, - 975, - 984, - 996, - 1027, - 1030, - 1049, - 1050, - 1051, - 1052, - 1053, - 1065, - 1071, - 1074, - 1079, - 1084, - 1087, - 1105, - 1109, - 1110, - 1113, - 1120, - 1124, - 1132, - 1136, - 6667, - 6670, - 6671, - 6672, - 6673, - 6674, - 6676, - 6677, - 6678, - 6679, - 6680, - 6681, - 6682, - 6683, - 6684, - 6685, - 6686, - 6687, - 6688, - 6690, - 6691, - 6692, - 6693, - 6694, - 6695, - 6696, - 6697, - 6698, - 6699, - 6702, - 6703, - 6704, - 6705, - 6706, - 6707, - 6708, - 6709, - 6710, - 6711, - 6715, - 6716, - 6718, - 6719, - 6720, - 6721, - 6731, - 6732, - 6733, - 6734, - 6736, - 6741, - 6753, - 6751, - 6764, - 6761, - 6758, - 6754, - 6747, - 6746, - 6744, - 6743, - 6757, - 842, -); - -1; diff --git a/tests/policies.json b/tests/policies.json new file mode 100644 index 0000000000..b95ecd4bd6 --- /dev/null +++ b/tests/policies.json @@ -0,0 +1,126 @@ +{ + "set_descs":{ + "housing": "Housing", + "health": "Health", + "welfare": "Welfare, Benefits and Pensions", + "transport": "Transport", + "environment": "Environmental Issues", + "social": "Social Issues", + "foreignpolicy": "Foreign Policy and Defence", + "business": "Business and the Economy", + "reform": "Constitutional Reform", + "taxation": "Taxation and Employment", + "home": "Home Affairs", + "education": "Education", + "misc": "Miscellaneous Topics" + }, + "policies":{ + "363": "introducing foundation hospitals", + "810": "greater regulation of gambling", + "811": "smoking bans", + "826": "equal gay rights", + "837": "a wholly elected House of Lords", + "842": "a lower voting age", + "975": "investigations into the Iraq war", + "984": "replacing Trident with a new nuclear weapons system", + "996": "a transparent Parliament", + "1027": "a referendum on the UK's membership of the EU", + "1030": "measures to prevent climate change", + "1049": "the Iraq war", + "1050": "the hunting ban", + "1051": "introducing ID cards", + "1052": "university tuition fees", + "1053": "Labour's anti-terrorism laws", + "1065": "more EU integration", + "1071": "allowing ministers to intervene in inquests", + "1074": "greater autonomy for schools", + "1079": "removing hereditary peers from the House of Lords", + "1084": "a more proportional system for electing MPs", + "1087": "a stricter asylum system", + "1105": "the privatisation of Royal Mail", + "1109": "encouraging occupational pensions", + "1110": "increasing the rate of VAT", + "1113": "an equal number of electors per parliamentary constituency", + "1120": "capping civil service redundancy payments", + "1124": "automatic enrolment in occupational pensions", + "1132": "raising England’s undergraduate tuition fee cap to £9,000 per year", + "1136": "fewer MPs in the House of Commons", + "6667": "the policies included in the 2010 Conservative - Liberal Democrat Coalition Agreement", + "6670": "a reduction in spending on welfare benefits", + "6671": "reducing central government funding of local government", + "6672": "reducing housing benefit for social tenants deemed to have excess bedrooms (which Labour describe as the \"bedroom tax\")", + "6673": "paying higher benefits over longer periods for those unable to work due to illness or disability", + "6674": "raising welfare benefits at least in line with prices", + "6676": "reforming the NHS so GPs buy services on behalf of their patients", + "6677": "restricting the provision of services to private patients by the NHS", + "6678": "greater restrictions on campaigning by third parties, such as charities, during elections", + "6679": "reducing the rate of corporation tax", + "6680": "raising the threshold at which people start to pay income tax", + "6681": "increasing the tax rate applied to income over £150,000", + "6682": "ending financial support for some 16-19 year olds in training and further education", + "6683": "local councils keeping money raised from taxes on business premises in their areas", + "6684": "making local councils responsible for helping those in financial need afford their council tax and reducing the amount spent on such support", + "6685": "a banker’s bonus tax", + "6686": "allowing marriage between two people of same sex", + "6687": "academy schools", + "6688": "use of UK military forces in combat operations overseas", + "6690": "measures to reduce tax avoidance", + "6691": "stronger tax incentives for companies to invest in assets", + "6692": "slowing the rise in rail fares", + "6693": "lower taxes on fuel for motor vehicles", + "6694": "higher taxes on alcoholic drinks", + "6695": "more powers for local councils", + "6696": "the introduction of elected Police and Crime Commissioners", + "6697": "selling England’s state owned forests", + "6698": "fixed periods between parliamentary elections", + "6699": "higher taxes on plane tickets", + "6702": "spending public money to create guaranteed jobs for young people who have spent a long time unemployed", + "6703": "laws to promote equality and human rights", + "6704": "financial incentives for low carbon emission electricity generation methods", + "6705": "requiring pub companies to offer pub landlords rent-only leases", + "6706": "strengthening the Military Covenant", + "6707": "restricting the scope of legal aid", + "6708": "transferring more powers to the Senedd/Welsh Parliament", + "6709": "transferring more powers to the Scottish Parliament", + "6710": "culling badgers to tackle bovine tuberculosis", + "6711": "an annual tax on the value of expensive homes (popularly known as a mansion tax)", + "6715": "allowing national security sensitive evidence to be put before courts in secret sessions", + "6716": "allowing employees to exchange some employment rights for shares in the company they work for", + "6718": "restrictions on fees charged to tenants by letting agents", + "6719": "limits on success fees paid to lawyers in no-win no fee cases", + "6720": "a statutory register of lobbyists", + "6721": "requiring the mass retention of information about communications", + "6731": "more restrictive regulation of trade union activity", + "6732": "allowing terminally ill people to be given assistance to end their life", + "6733": "higher taxes on banks", + "6734": "stronger enforcement of immigration rules", + "6736": "a veto for MPs from England, Wales and Northern Ireland over laws specifically impacting their part of the UK", + "6741": "greater regulation of hydraulic fracturing (fracking) to extract shale gas", + "6743": "charging a market rent to high earners renting a council home", + "6744": "phasing out secure tenancies for life", + "6746": "a publicly owned railway system", + "6747": "greater public control of bus services", + "6751": "mass surveillance of people’s communications and activities", + "6753": "new high speed rail infrastructure", + "6754": "reducing capital gains tax", + "6757": "military action against ISIL (Daesh)", + "6758": "merging police and fire services under Police and Crime Commissioners", + "6761": "UK membership of the EU", + "6764": "a right to remain for EU nationals already in living in the UK" + }, + "sets":{ + "housing": ["6743", "6744"], + "transport": ["6692", "6693", "6699", "6746", "6747"], + "environment": ["1030", "6693", "6697", "6699", "6704", "6710", "6741", "6753"], + "welfare": ["6670", "6672", "6673", "6674", "6684", "6702"], + "health": ["363", "811", "6676", "6677", "6732"], + "reform": ["837", "842", "996", "1079", "1084", "1113", "1136", "6671", "6678", "6683", "6695", "6698", "6708", "6709", "6736"], + "social": ["811", "826", "1050", "6686", "6703", "6732"], + "business": ["6679", "6690", "6691", "6753"], + "foreignpolicy": ["975", "984", "1027", "1049", "1065", "6688", "6706", "6757", "6761", "6764"], + "education": ["1052", "1074", "1132", "6682", "6687"], + "misc": ["810", "1053", "1105", "1120", "6667", "6705", "6707", "6715", "6718", "6719", "6720"], + "taxation": ["1109", "1110", "1124", "6680", "6681", "6685", "6693", "6694", "6699", "6711", "6716", "6731", "6733", "6754"], + "home": ["1051", "1071", "1087", "6696", "6721", "6734", "6751", "6758"] + } +}